Skip to content

Commit

Permalink
[DMS-443] Update content type to url encoded (#372)
Browse files Browse the repository at this point in the history
* Update content type to url encoded

* update the default realm

* Setup .net version

* Add setup dotnet to config pull request file

* Update the response to match admin api

* set the .net version on dms pull request file

* Format C#

---------

Co-authored-by: Adam Hopkins <[email protected]>
  • Loading branch information
CSR2017 and simpat-adam authored Dec 17, 2024
1 parent edad6e3 commit d09533e
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 70 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
- name: Checkout the Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup dotnet
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
with:
dotnet-version: '8.0.x'

- name: Dependency Review ("Dependabot on PR")
if: ${{ github.event_name == 'pull_request' && !github.event.repository.fork }}
uses: actions/dependency-review-action@9129d7d40b8c12c1ed0f60400d00c92d437adcce # v4.1.3
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/on-config-pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
- name: Checkout the Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup dotnet
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
with:
dotnet-version: '8.0.x'

- name: Build
run: ./build-config.ps1 Build -Configuration Debug

Expand Down Expand Up @@ -101,6 +106,11 @@ jobs:
- name: Checkout the Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup dotnet
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
with:
dotnet-version: '8.0.x'

- name: Build
run: ./build-config.ps1 Build -Configuration Debug

Expand Down Expand Up @@ -128,6 +138,11 @@ jobs:
- name: Checkout the Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup dotnet
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
with:
dotnet-version: '8.0.x'

- name: Build
run: ./build-config.ps1 Build -Configuration Debug

Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/on-dms-pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
- name: Checkout the Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup dotnet
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
with:
dotnet-version: '8.0.x'

- name: Build
run: ./build-dms.ps1 Build -Configuration Debug

Expand Down Expand Up @@ -101,6 +106,11 @@ jobs:
- name: Checkout the Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup dotnet
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
with:
dotnet-version: '8.0.x'

- name: Build
run: ./build-dms.ps1 Build -Configuration Debug

Expand Down Expand Up @@ -128,6 +138,11 @@ jobs:
- name: Checkout the Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup dotnet
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
with:
dotnet-version: '8.0.x'

- name: Run OpenSearch End to End Tests
if: success()
run: ./build-dms.ps1 E2ETest -EnableOpenSearch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// See the LICENSE and NOTICES files in the project root for more information.

using System.Net;
using System.Net.Http.Json;
using System.Text.Json.Nodes;
using EdFi.DmsConfigurationService.Backend;
using EdFi.DmsConfigurationService.Backend.Repositories;
Expand Down Expand Up @@ -62,13 +61,14 @@ public async Task Given_valid_client_details()
using var client = factory.CreateClient();

// Act
var requestContent = new
{
clientid = "CSClient1",
clientsecret = "test123@Puiu",
displayname = "CSClient1",
};
var response = await client.PostAsJsonAsync("/connect/register", requestContent);
var requestContent = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("clientid", "CSClient1"),
new KeyValuePair<string, string>("clientsecret", "test123@Puiu"),
new KeyValuePair<string, string>("displayname", "CSClient1"),
]
);
var response = await client.PostAsync("/connect/register", requestContent);
string content = await response.Content.ReadAsStringAsync();

// Assert
Expand All @@ -94,13 +94,14 @@ public async Task Given_empty_client_details()
using var client = factory.CreateClient();

// Act
var requestContent = new
{
clientid = "",
clientsecret = "",
displayname = "",
};
var response = await client.PostAsJsonAsync("/connect/register", requestContent);
var requestContent = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("clientid", ""),
new KeyValuePair<string, string>("clientsecret", ""),
new KeyValuePair<string, string>("displayname", ""),
]
);
var response = await client.PostAsync("/connect/register", requestContent);
string content = await response.Content.ReadAsStringAsync();
content = System.Text.RegularExpressions.Regex.Unescape(content);

Expand Down Expand Up @@ -135,13 +136,14 @@ public async Task Given_invalid_client_secret(string secret)
using var client = factory.CreateClient();

// Act
var requestContent = new
{
clientid = "CSClient2",
clientsecret = secret,
displayname = "[email protected]",
};
var response = await client.PostAsJsonAsync("/connect/register", requestContent);
var requestContent = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("clientid", "CSClient2"),
new KeyValuePair<string, string>("clientsecret", secret),
new KeyValuePair<string, string>("displayname", "[email protected]"),
]
);
var response = await client.PostAsync("/connect/register", requestContent);
string content = await response.Content.ReadAsStringAsync();

// Assert
Expand Down Expand Up @@ -178,13 +180,14 @@ public async Task When_provider_has_bad_credentials()
using var client = factory.CreateClient();

// Act
var requestContent = new
{
clientid = "CSClient3",
clientsecret = "test123@Puiu",
displayname = "CSClient3",
};
var response = await client.PostAsJsonAsync("/connect/register", requestContent);
var requestContent = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("clientid", "CSClient3"),
new KeyValuePair<string, string>("clientsecret", "test123@Puiu"),
new KeyValuePair<string, string>("displayname", "CSClient3"),
]
);
var response = await client.PostAsync("/connect/register", requestContent);
string content = await response.Content.ReadAsStringAsync();

// Assert
Expand Down Expand Up @@ -217,13 +220,14 @@ public async Task When_provider_has_not_real_admin_role()
using var client = factory.CreateClient();

// Act
var requestContent = new
{
clientid = "CSClient3",
clientsecret = "test123@Puiu",
displayname = "CSClient3",
};
var response = await client.PostAsJsonAsync("/connect/register", requestContent);
var requestContent = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("clientid", "CSClient3"),
new KeyValuePair<string, string>("clientsecret", "test123@Puiu"),
new KeyValuePair<string, string>("displayname", "CSClient3"),
]
);
var response = await client.PostAsync("/connect/register", requestContent);
string content = await response.Content.ReadAsStringAsync();

// Assert
Expand Down Expand Up @@ -256,13 +260,14 @@ public async Task When_provider_has_invalid_real()
using var client = factory.CreateClient();

// Act
var requestContent = new
{
clientid = "CSClient3",
clientsecret = "test123@Puiu",
displayname = "CSClient3",
};
var response = await client.PostAsJsonAsync("/connect/register", requestContent);
var requestContent = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("clientid", "CSClient3"),
new KeyValuePair<string, string>("clientsecret", "test123@Puiu"),
new KeyValuePair<string, string>("displayname", "CSClient3"),
]
);
var response = await client.PostAsync("/connect/register", requestContent);
string content = await response.Content.ReadAsStringAsync();

// Assert
Expand Down Expand Up @@ -294,13 +299,15 @@ public async Task Given_client_with_existing_client_id()
using var client = factory.CreateClient();

// Act
var requestContent = new
{
clientid = "CSClient2",
clientsecret = "test123@Puiu",
displayname = "[email protected]",
};
var response = await client.PostAsJsonAsync("/connect/register", requestContent);
var requestContent = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("clientid", "CSClient2"),
new KeyValuePair<string, string>("clientsecret", "test123@Puiu"),
new KeyValuePair<string, string>("displayname", "[email protected]"),
]
);

var response = await client.PostAsync("/connect/register", requestContent);
string content = await response.Content.ReadAsStringAsync();

// Assert
Expand Down Expand Up @@ -332,13 +339,14 @@ public async Task When_allow_registration_is_disabled()
using var client = factory.CreateClient();

// Act
var requestContent = new
{
clientid = "CSClient2",
clientsecret = "test123@Puiu",
displayname = "[email protected]",
};
var response = await client.PostAsJsonAsync("/connect/register", requestContent);
var requestContent = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("clientid", "CSClient2"),
new KeyValuePair<string, string>("clientsecret", "test123@Puiu"),
new KeyValuePair<string, string>("displayname", "[email protected]"),
]
);
var response = await client.PostAsync("/connect/register", requestContent);

// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Expand Down Expand Up @@ -371,13 +379,14 @@ public async Task When_provider_is_unreachable()
using var client = factory.CreateClient();

//Act
var requestContent = new
{
clientid = "CSClient3",
clientsecret = "test123@Puiu",
displayname = "CSClient3",
};
var response = await client.PostAsJsonAsync("/connect/register", requestContent);
var requestContent = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("clientid", "CSClient3"),
new KeyValuePair<string, string>("clientsecret", "test123@Puiu"),
new KeyValuePair<string, string>("displayname", "CSClient3"),
]
);
var response = await client.PostAsync("/connect/register", requestContent);
string content = await response.Content.ReadAsStringAsync();

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public class IdentityModule : IEndpointModule
{
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapPost("/connect/register", RegisterClient);
endpoints.MapPost("/connect/register", RegisterClient).DisableAntiforgery();
endpoints.MapPost("/connect/token", GetClientAccessToken).DisableAntiforgery();
}

private async Task<IResult> RegisterClient(
RegisterRequest.Validator validator,
RegisterRequest model,
[FromForm] RegisterRequest model,
IClientRepository clientRepository,
IOptions<IdentitySettings> identitySettings,
HttpContext httpContext
Expand Down Expand Up @@ -61,8 +61,12 @@ HttpContext httpContext
);
return result switch
{
ClientCreateResult.Success => Results.Ok(
$"Registered client {model.ClientId} successfully."
ClientCreateResult.Success => Results.Json(
new
{
Title = $"Registered client {model.ClientId} successfully.",
Status = 200,
}
),
ClientCreateResult.FailureIdentityProvider failureIdentityProvider =>
FailureResults.BadGateway(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"AllowRegistration": false,
"ConfigServiceRole": "config-service-app",
"ClientRole": "dms-client",
"Authority": "http://localhost:8045/realms/dms",
"Authority": "http://localhost:8045/realms/edfi",
"Audience": "account",
"ClientId": "DmsConfigurationService",
"ClientSecret": "",
Expand All @@ -21,7 +21,7 @@
},
"KeycloakSettings": {
"Url": "http://localhost:8045",
"Realm": "dms"
"Realm": "edfi"
},
"AllowedHosts": "*",
"Serilog": {
Expand Down

0 comments on commit d09533e

Please sign in to comment.