Skip to content

Commit

Permalink
Review verbesserung
Browse files Browse the repository at this point in the history
  • Loading branch information
vojislav.gojkovic committed Sep 27, 2024
1 parent f51f19f commit fdca68e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void ConfigureApplication(IApplicationBuilder applicationBuilder)
public void ConfigureHealthChecks(IHealthChecksBuilder healthChecksBuilder)
{
var uriBuilder = new UriBuilder(_keycloakPluginConfiguration.GetHealthCheck()) { Path = _keycloakPluginConfiguration.HealthCheckConfig.Prefix };
//var uriBuilder = new UriBuilder(_keycloakPluginConfiguration.GetAuthority()) { Path = $"{_keycloakPluginConfiguration.Realms.Prefix.TrimEnd('/')}/master" };
var uri = uriBuilder.Uri;
healthChecksBuilder.AddUrlGroup(uri, "keycloak", HealthStatus.Unhealthy, new[] { HealthCheckTag.Readiness.Value });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void AuthenticationCanBeSetup()
httpClient.BaseAddress!.Scheme.Should().Be("https");
httpClient.BaseAddress!.Host.Should().Be("example.com");
httpClient.BaseAddress!.Port.Should().Be(8080);

}

[Test]
Expand Down Expand Up @@ -111,17 +110,8 @@ public void TestRedirectUriHttpToHttpsReplace(string uri, string expected)
KeycloakDefaults.BuildCorrectRedirectUri(uri).Should().Be(expected);
}

private static void AssertMiddleware<TMiddleware>(ICall call)
{
var func = (call.GetOriginalArguments()[0] as Func<RequestDelegate, RequestDelegate>)?.Target;
func.Should().NotBeNull();
var registeredMiddleware = func!.GetInaccessibleValue<Type>("_middleware");
if (registeredMiddleware.BaseType == typeof(TMiddleware))
return;
registeredMiddleware.Should().Be(typeof(TMiddleware));
}
[Test]
public void ConfigureHealtChecks_Use9000ForHealth()
public void ConfigureHealthChecks_Use9000ForHealth()
{
var config = new KeycloakPluginConfiguration
{
Expand All @@ -132,15 +122,16 @@ public void ConfigureHealtChecks_Use9000ForHealth()
HealthCheckConfig = new HealthCheckConfig
{
Host = "example.com",
Port = 9100,
Port = 9000,
Prefix = "/health/ready"
}
};
var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheckConfig.Prefix };
uriBuilder.Uri.Should().Be("https://example.com:9100/health/ready");
uriBuilder.Uri.Should().Be("https://example.com:9000/health/ready");
}

[Test]
public void ConfigureHealtChecks_WithoutSettingHealthCheckConfig()
public void ConfigureHealthChecks_WithoutSettingHealthCheckConfig()
{
var config = new KeycloakPluginConfiguration
{
Expand All @@ -152,8 +143,9 @@ public void ConfigureHealtChecks_WithoutSettingHealthCheckConfig()
var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheckConfig.Prefix };
uriBuilder.Uri.Should().Be("https://example.com:9000/health/ready");
}

[Test]
public void ConfigureHealtChecks_DifferentPrefixAndPort()
public void ConfigureHealthChecks_DifferentPrefixAndPort()
{
var config = new KeycloakPluginConfiguration
{
Expand All @@ -171,5 +163,34 @@ public void ConfigureHealtChecks_DifferentPrefixAndPort()
var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheckConfig.Prefix };
uriBuilder.Uri.Should().Be("https://health.com:9999/something/notready");
}

[Test]
public void ConfigureHealthChecks_DefaultHealthHost()
{
var config = new KeycloakPluginConfiguration
{
Enabled = true,
Host = "newhost.com",
Insecure = false,
Port = 8080,
HealthCheckConfig = new HealthCheckConfig
{
Port = 9999,
Prefix = "/something/notready"
}
};
var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheckConfig.Prefix };
uriBuilder.Uri.Should().Be("https://example.com:9999/something/notready");
}

private static void AssertMiddleware<TMiddleware>(ICall call)
{
var func = (call.GetOriginalArguments()[0] as Func<RequestDelegate, RequestDelegate>)?.Target;
func.Should().NotBeNull();
var registeredMiddleware = func!.GetInaccessibleValue<Type>("_middleware");
if (registeredMiddleware.BaseType == typeof(TMiddleware))
return;
registeredMiddleware.Should().Be(typeof(TMiddleware));
}
}
}

0 comments on commit fdca68e

Please sign in to comment.