Skip to content

Commit

Permalink
Adding a test where user event metrics are disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Schwartz <[email protected]>
  • Loading branch information
ahus1 committed Oct 21, 2024
1 parent e768f75 commit f31d9f6
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ void testMetricsEndpointWithCacheMetricsHistograms() {
@Test
@Launch({ "start-dev", "--metrics-enabled=true", "--features=user-event-metrics", "--user-event-metrics-enabled=true" })
void testMetricsEndpointWithUserEventMetrics(KeycloakDistribution distribution) {
distribution.setRequestPort(8080);
given().formParam("grant_type", "client_credentials")
.formParam("client_id", "unknown")
.formParam("client_secret", "unknown").
when().post("/realms/master/protocol/openid-connect/token")
.then()
.statusCode(401);
runClientCredentialGrantWithUnknownClientId(distribution);

distribution.setRequestPort(9000);
when().get("/metrics").then()
Expand All @@ -99,6 +93,28 @@ void testMetricsEndpointWithUserEventMetrics(KeycloakDistribution distribution)

}

@Test
@Launch({ "start-dev", "--metrics-enabled=true", "--features=user-event-metrics", "--user-event-metrics-enabled=false" })
void testMetricsEndpointWithoutUserEventMetrics(KeycloakDistribution distribution) {
runClientCredentialGrantWithUnknownClientId(distribution);

distribution.setRequestPort(9000);
when().get("/metrics").then()
.statusCode(200)
.body(not(containsString("keycloak_user_events_total{error=\"client_not_found\",event=\"client_login\",realm=\"master\"}")));

}

private static void runClientCredentialGrantWithUnknownClientId(KeycloakDistribution distribution) {
distribution.setRequestPort(8080);
given().formParam("grant_type", "client_credentials")
.formParam("client_id", "unknown")
.formParam("client_secret", "unknown").
when().post("/realms/master/protocol/openid-connect/token")
.then()
.statusCode(401);
}

@Test
void testUsingRelativePath(KeycloakDistribution distribution) {
for (String relativePath : List.of("/auth", "/auth/", "auth")) {
Expand Down

0 comments on commit f31d9f6

Please sign in to comment.