diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/client/ClientManagementAPIIntegrationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/client/ClientManagementAPIIntegrationTests.java index 8fa263587..1a3a6a92d 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/client/ClientManagementAPIIntegrationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/client/ClientManagementAPIIntegrationTests.java @@ -121,7 +121,7 @@ private void clientManagementFailsWithResponseForClient(ResultMatcher response, private void paginatedGetClientsTest() throws Exception { mvc.perform(get(ClientManagementAPIController.ENDPOINT)) .andExpect(OK) - .andExpect(jsonPath("$.totalResults").value(21)) + .andExpect(jsonPath("$.totalResults").value(22)) .andExpect(jsonPath("$.itemsPerPage").value(10)) .andExpect(jsonPath("$.startIndex").value(1)) .andExpect(jsonPath("$.Resources", hasSize(10))) @@ -129,11 +129,11 @@ private void paginatedGetClientsTest() throws Exception { mvc.perform(get(ClientManagementAPIController.ENDPOINT).param("startIndex", "13")) .andExpect(OK) - .andExpect(jsonPath("$.totalResults").value(21)) - .andExpect(jsonPath("$.itemsPerPage").value(9)) + .andExpect(jsonPath("$.totalResults").value(22)) + .andExpect(jsonPath("$.itemsPerPage").value(10)) .andExpect(jsonPath("$.startIndex").value(13)) - .andExpect(jsonPath("$.Resources", hasSize(9))) - .andExpect(jsonPath("$.Resources[0].client_id").value("public-dc-client")); + .andExpect(jsonPath("$.Resources", hasSize(10))) + .andExpect(jsonPath("$.Resources[0].client_id").value("public-client-having-secret")); } @Test diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/client/SearchClientControllerTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/client/SearchClientControllerTests.java index b608dd00b..73b441473 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/client/SearchClientControllerTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/client/SearchClientControllerTests.java @@ -71,7 +71,7 @@ void searchForPublicClientByName() throws Exception { .getResponse() .getContentAsString(), new TypeReference>() {}); - assertEquals(1, response.getTotalResults()); + assertEquals(2, response.getTotalResults()); assertEquals("Public client", response.getResources().get(0).getClientName()); } diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/TokenEndpointClientAuthenticationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/TokenEndpointClientAuthenticationTests.java index e70d56cf0..5997e8d27 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/TokenEndpointClientAuthenticationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/TokenEndpointClientAuthenticationTests.java @@ -26,6 +26,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -33,7 +35,6 @@ import org.springframework.test.web.servlet.MockMvc; import com.fasterxml.jackson.databind.ObjectMapper; - import it.infn.mw.iam.IamLoginService; import it.infn.mw.iam.test.util.WithAnonymousUser; import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest; @@ -73,6 +74,24 @@ void testTokenEndpointFormClientAuthentication() throws Exception { // @formatter:on } + @Test + void testTokenEndpointFormClientWithNoAuthenticationFailed() throws Exception { + // Replicate: When user is changing client auth method to No authentication from others, + // the previous secret value persist in the database. So when the client is in use, it is still checking for the secret. + String clientId = "public-client-having-secret"; + String clientSecret = ""; + + // @formatter:off + mvc.perform(post(TOKEN_ENDPOINT) + .param("grant_type", GRANT_TYPE) + .param("client_id", clientId) + .param("client_secret", clientSecret) + .param("scope", SCOPE)) + .andDo(print()) + .andExpect(status().isUnauthorized()); + // @formatter:on + } + @Test void testTokenEndpointFormClientAuthenticationInvalidCredentials() throws Exception { diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/client/ClientManagementServiceTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/client/ClientManagementServiceTests.java index 2dde17b2b..fb5b9f7f7 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/client/ClientManagementServiceTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/client/ClientManagementServiceTests.java @@ -98,7 +98,7 @@ void testPagedClientLookup() { ListResponseDTO clients = managementService.retrieveAllClients(pageable); - assertThat(clients.getTotalResults(), is(21L)); + assertThat(clients.getTotalResults(), is(22L)); assertThat(clients.getItemsPerPage(), is(10)); assertThat(clients.getStartIndex(), is(1)); assertThat(clients.getResources().get(0).getClientId(), is("admin-client-ro")); diff --git a/iam-persistence/src/main/resources/db/migration/test/V100000___test_data.sql b/iam-persistence/src/main/resources/db/migration/test/V100000___test_data.sql index 80708fb9c..aecbcbeca 100644 --- a/iam-persistence/src/main/resources/db/migration/test/V100000___test_data.sql +++ b/iam-persistence/src/main/resources/db/migration/test/V100000___test_data.sql @@ -28,7 +28,8 @@ INSERT INTO client_details (id, client_id, client_secret, client_name, dynamical (18, 'admin-client-rw', 'secret', 'Admin client (read-write)', false, null, 3600, 600, true, 'SECRET_POST',false, null, CURRENT_TIMESTAMP(), true), (19, 'public-client', null, 'Public client', false, 3600, 3600, 600, true, 'NONE', false, null, CURRENT_TIMESTAMP(), true), (20, 'refresh-client', 'secret', 'Refresh Flow client', false, 36000, 3600, 600, true, 'SECRET_BASIC', true, 30, CURRENT_TIMESTAMP(), true), - (21, 'protected-resource', 'secret', 'Protected Resource allowed only to introspect', false, 0, 0, 0, true, 'SECRET_BASIC', true, 0, CURRENT_TIMESTAMP(), true); + (21, 'protected-resource', 'secret', 'Protected Resource allowed only to introspect', false, 0, 0, 0, true, 'SECRET_BASIC', true, 0, CURRENT_TIMESTAMP(), true), + (22, 'public-client-having-secret', 'secret', 'Public client', false, 3600, 3600, 600, true, 'NONE', false, null, CURRENT_TIMESTAMP(), true); INSERT INTO client_details (id, client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection,