Skip to content

Commit

Permalink
feat: fixed relative address construction for manual HTTP client (#156)
Browse files Browse the repository at this point in the history
* Fixed relative URI construction error in ApiUrls
* Added relative uri test

---------

Co-authored-by: Juan Santos <[email protected]>
  • Loading branch information
juan-dev-santos and Juan Santos authored Nov 23, 2024
1 parent 6075dc3 commit 0e1ae3c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Keycloak.AuthServices.Sdk/Admin/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Keycloak.AuthServices.Sdk.Admin;
/// </summary>
internal static class ApiUrls
{
private const string AdminApiBase = "/admin";
private const string AdminApiBase = "admin";

private const string RealmParam = "{realm}";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Keycloak.AuthServices.Sdk.Tests;

using System.Net;
using Admin;
using RichardSzalay.MockHttp;

public class KeycloakClientRelativeAddressTests
{
private const string BaseAddress = "http://localhost:8080/identity/";
private const string MediaType = "application/json";
private readonly MockHttpMessageHandler handler = new();
private readonly IKeycloakRealmClient keycloakRealmClient;

public KeycloakClientRelativeAddressTests()
{
var httpClient = this.handler.ToHttpClient();
httpClient.BaseAddress = new Uri(BaseAddress);

this.keycloakRealmClient = new KeycloakClient(httpClient);
}

[Fact]
public async Task GetRealmShouldCallRealmRelativeEndpoint()
{
this.handler.Expect(HttpMethod.Get, "/identity/admin/realms/master")
.Respond(HttpStatusCode.OK, MediaType, "{}");

await this.keycloakRealmClient.GetRealmAsync("master");

this.handler.VerifyNoOutstandingExpectation();
}
}

0 comments on commit 0e1ae3c

Please sign in to comment.