From 634db479b4dd0dd06cfc02b6d124c9b020076ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szrnka?= Date: Thu, 4 Apr 2024 13:27:28 +0200 Subject: [PATCH] GMS-72 Another pack of boring tests --- .../KeycloakAuthenticationServiceImplTest.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/code/gms-backend/src/test/java/io/github/gms/auth/sso/keycloak/service/impl/KeycloakAuthenticationServiceImplTest.java b/code/gms-backend/src/test/java/io/github/gms/auth/sso/keycloak/service/impl/KeycloakAuthenticationServiceImplTest.java index fb569659..65309c4c 100644 --- a/code/gms-backend/src/test/java/io/github/gms/auth/sso/keycloak/service/impl/KeycloakAuthenticationServiceImplTest.java +++ b/code/gms-backend/src/test/java/io/github/gms/auth/sso/keycloak/service/impl/KeycloakAuthenticationServiceImplTest.java @@ -137,25 +137,33 @@ void shouldLoginFail() { verify(converter, never()).toUserInfoDto(any(IntrospectResponse.class)); } - @Test - void shouldLoginFailWhenResponseIsNot2xx() { + @ParameterizedTest + @MethodSource("not2xxInputData") + void shouldLoginFailWhenResponseIsNot2xx(String errorDescription, AuthResponsePhase authResponsePhaseExpected) { // arrange when(keycloakLoginService.login(DemoData.USERNAME1, DemoData.CREDENTIAL_TEST)) .thenReturn(ResponseEntity.status(400).body(LoginResponse.builder() - .error("error").errorDescription("Account disabled").build())); + .error("error").errorDescription(errorDescription).build())); // act AuthenticationResponse response = service.authenticate(DemoData.USERNAME1, DemoData.CREDENTIAL_TEST); // assert assertNotNull(response); - assertEquals(AuthResponsePhase.BLOCKED, response.getPhase()); + assertEquals(authResponsePhaseExpected, response.getPhase()); verify(keycloakLoginService).login(DemoData.USERNAME1, DemoData.CREDENTIAL_TEST); verify(converter, never()).toUserInfoDto(any(IntrospectResponse.class)); verify(keycloakIntrospectService, never()).getUserDetails(MOCK_ACCESS_TOKEN, MOCK_REFRESH_TOKEN); assertLogContains(logAppender, "Login failed! Status code=400"); } + private static Object[][] not2xxInputData() { + return new Object[][] { + { "Account disabled", AuthResponsePhase.BLOCKED }, + { "Other issue", AuthResponsePhase.FAILED } + }; + } + @Test void shouldLoginFailedWhenIntrospectFailed() { // arrange