diff --git a/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPlugin.cs b/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPlugin.cs index c154e74..1389ad5 100644 --- a/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPlugin.cs +++ b/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPlugin.cs @@ -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 }); } diff --git a/PiBox.Plugins/Authorization/Keycloak/test/PiBox.Plugins.Authorization.Keycloak.Tests/KeycloakPluginTests.cs b/PiBox.Plugins/Authorization/Keycloak/test/PiBox.Plugins.Authorization.Keycloak.Tests/KeycloakPluginTests.cs index 007ba6a..f76ad06 100644 --- a/PiBox.Plugins/Authorization/Keycloak/test/PiBox.Plugins.Authorization.Keycloak.Tests/KeycloakPluginTests.cs +++ b/PiBox.Plugins/Authorization/Keycloak/test/PiBox.Plugins.Authorization.Keycloak.Tests/KeycloakPluginTests.cs @@ -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] @@ -111,17 +110,8 @@ public void TestRedirectUriHttpToHttpsReplace(string uri, string expected) KeycloakDefaults.BuildCorrectRedirectUri(uri).Should().Be(expected); } - private static void AssertMiddleware(ICall call) - { - var func = (call.GetOriginalArguments()[0] as Func)?.Target; - func.Should().NotBeNull(); - var registeredMiddleware = func!.GetInaccessibleValue("_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 { @@ -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 { @@ -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 { @@ -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(ICall call) + { + var func = (call.GetOriginalArguments()[0] as Func)?.Target; + func.Should().NotBeNull(); + var registeredMiddleware = func!.GetInaccessibleValue("_middleware"); + if (registeredMiddleware.BaseType == typeof(TMiddleware)) + return; + registeredMiddleware.Should().Be(typeof(TMiddleware)); + } } }