diff --git a/iam-login-service/src/main/java/it/infn/mw/iam/api/common/OffsetPageable.java b/iam-login-service/src/main/java/it/infn/mw/iam/api/common/OffsetPageable.java index 0efada7cc..1c3e1eaef 100644 --- a/iam-login-service/src/main/java/it/infn/mw/iam/api/common/OffsetPageable.java +++ b/iam-login-service/src/main/java/it/infn/mw/iam/api/common/OffsetPageable.java @@ -17,6 +17,8 @@ import static com.google.common.base.Preconditions.checkArgument; +import java.util.Objects; + import javax.annotation.Generated; import org.apache.commons.lang3.NotImplementedException; @@ -31,7 +33,7 @@ public class OffsetPageable implements Pageable { public OffsetPageable(int count) { - this(0, count, null); + this(0, count, Sort.unsorted()); } public OffsetPageable(int count, Sort sort) { @@ -51,7 +53,14 @@ public OffsetPageable(int offset, int count, Sort sort) { this.offset = offset; this.count = count; - this.sort = sort; + + if (Objects.isNull(sort)) { + this.sort = Sort.unsorted(); + } else { + this.sort = sort; + } + + } @Override diff --git a/iam-login-service/src/main/java/it/infn/mw/iam/config/MitreServicesConfig.java b/iam-login-service/src/main/java/it/infn/mw/iam/config/MitreServicesConfig.java index 4fb0594e2..62c7feef3 100644 --- a/iam-login-service/src/main/java/it/infn/mw/iam/config/MitreServicesConfig.java +++ b/iam-login-service/src/main/java/it/infn/mw/iam/config/MitreServicesConfig.java @@ -75,7 +75,6 @@ import org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint; import org.springframework.security.oauth2.provider.token.TokenEnhancer; import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint; -import org.springframework.web.servlet.AsyncHandlerInterceptor; import com.google.common.collect.Sets; @@ -190,13 +189,13 @@ OAuth2TokenEntityService tokenServices() { @Bean(name = "mitreUserInfoInterceptor") - public AsyncHandlerInterceptor userInfoInterceptor(UserInfoService service) { + public IamUserInfoInterceptor userInfoInterceptor(UserInfoService service) { return new IamUserInfoInterceptor(service); } @Bean(name = "mitreServerConfigInterceptor") - public AsyncHandlerInterceptor serverConfigInterceptor() { + public ServerConfigInterceptor serverConfigInterceptor() { return new ServerConfigInterceptor(); } diff --git a/iam-login-service/src/main/java/it/infn/mw/iam/config/MvcConfig.java b/iam-login-service/src/main/java/it/infn/mw/iam/config/MvcConfig.java index c4eca4d43..96c0f657f 100644 --- a/iam-login-service/src/main/java/it/infn/mw/iam/config/MvcConfig.java +++ b/iam-login-service/src/main/java/it/infn/mw/iam/config/MvcConfig.java @@ -20,6 +20,7 @@ import java.util.Locale; import java.util.concurrent.TimeUnit; +import org.mitre.openid.connect.web.ServerConfigInterceptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -30,7 +31,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.http.CacheControl; -import org.springframework.web.servlet.AsyncHandlerInterceptor; import org.springframework.web.servlet.LocaleResolver; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; @@ -44,7 +44,9 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; +import it.infn.mw.iam.core.userinfo.IamUserInfoInterceptor; import it.infn.mw.iam.core.util.PoliteJsonMessageSource; +import it.infn.mw.iam.core.web.IamViewInfoInterceptor; @Configuration public class MvcConfig implements WebMvcConfigurer { @@ -53,14 +55,14 @@ public class MvcConfig implements WebMvcConfigurer { @Autowired @Qualifier("mitreUserInfoInterceptor") - AsyncHandlerInterceptor userInfoInterceptor; + IamUserInfoInterceptor userInfoInterceptor; @Autowired @Qualifier("mitreServerConfigInterceptor") - AsyncHandlerInterceptor serverConfigInterceptor; + ServerConfigInterceptor serverConfigInterceptor; @Autowired - AsyncHandlerInterceptor iamViewInfoInterceptor; + IamViewInfoInterceptor iamViewInfoInterceptor; @Autowired IamProperties iamProperties; diff --git a/iam-login-service/src/main/java/it/infn/mw/iam/config/security/SpringHttpFirewallConfig.java b/iam-login-service/src/main/java/it/infn/mw/iam/config/security/SpringHttpFirewallConfig.java new file mode 100644 index 000000000..60651f391 --- /dev/null +++ b/iam-login-service/src/main/java/it/infn/mw/iam/config/security/SpringHttpFirewallConfig.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2021 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.infn.mw.iam.config.security; + +import java.util.function.Predicate; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.web.firewall.HttpFirewall; +import org.springframework.security.web.firewall.StrictHttpFirewall; + +@Configuration +public class SpringHttpFirewallConfig { + + public static final Predicate ANY_VALUE = (s) -> true; + + @Bean + HttpFirewall iamHttpFirewall() { + + StrictHttpFirewall httpFirewall = new StrictHttpFirewall(); + httpFirewall.setAllowedHeaderValues(ANY_VALUE); + + return httpFirewall; + } + +} diff --git a/iam-login-service/src/main/java/it/infn/mw/iam/core/userinfo/IamUserInfoInterceptor.java b/iam-login-service/src/main/java/it/infn/mw/iam/core/userinfo/IamUserInfoInterceptor.java index 4ca60cc90..7d7a52126 100644 --- a/iam-login-service/src/main/java/it/infn/mw/iam/core/userinfo/IamUserInfoInterceptor.java +++ b/iam-login-service/src/main/java/it/infn/mw/iam/core/userinfo/IamUserInfoInterceptor.java @@ -29,7 +29,8 @@ import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.oauth2.provider.OAuth2Authentication; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import org.springframework.web.servlet.AsyncHandlerInterceptor; +import org.springframework.web.servlet.HandlerInterceptor; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -39,7 +40,7 @@ import com.google.gson.JsonSerializer; @SuppressWarnings("deprecation") -public class IamUserInfoInterceptor extends HandlerInterceptorAdapter { +public class IamUserInfoInterceptor implements HandlerInterceptor, AsyncHandlerInterceptor { public static final String USERINFO_ATTR_NAME = "userInfo"; public static final String USERINFO_JSON_ATTR_NAME = "userInfoJson"; diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/account/labels/AccountLabelsTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/account/labels/AccountLabelsTests.java index 636d510d6..3e2f4a9cc 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/account/labels/AccountLabelsTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/account/labels/AccountLabelsTests.java @@ -21,9 +21,9 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8; +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; @@ -95,7 +95,7 @@ public void managingLabelsRequiresAuthenticatedUser() throws Exception { mvc.perform(get(RESOURCE, TEST_100_USER_UUID)).andExpect(UNAUTHORIZED); mvc - .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(UNAUTHORIZED); @@ -116,7 +116,7 @@ public void managingLabelsRequiresPrivilegedUser() throws Exception { mvc.perform(get(RESOURCE, TEST_100_USER_UUID)).andExpect(FORBIDDEN); mvc - .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(FORBIDDEN); @@ -139,7 +139,7 @@ public void gettingLabelsWorksForAdminUser() throws Exception { public void setLabelWorks() throws Exception { mvc - .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(OK); @@ -154,7 +154,7 @@ public void setLabelWorks() throws Exception { LabelDTO label = LabelDTO.builder().prefix(LABEL_PREFIX).name(LABEL_NAME).build(); mvc - .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(label))) .andExpect(OK); @@ -173,12 +173,12 @@ public void deleteLabelWorks() throws Exception { LabelDTO unqualified = LabelDTO.builder().name(LABEL_NAME).build(); mvc - .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(OK); mvc - .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(unqualified))) .andExpect(OK); @@ -224,7 +224,7 @@ public void nonExistingResourceHandledCorrectly() throws Exception { .andExpect(ACCOUNT_NOT_FOUND_ERROR_MESSAGE); mvc - .perform(put(RESOURCE, RANDOM_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, RANDOM_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(NOT_FOUND) .andExpect(ACCOUNT_NOT_FOUND_ERROR_MESSAGE); @@ -247,12 +247,12 @@ public void multipleLabelsHandledCorrectly() throws Exception { for (LabelDTO l : labels) { mvc - .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_100_USER_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(l))) .andExpect(OK); mvc - .perform(put(RESOURCE, TEST_USER_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_USER_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(l))) .andExpect(OK); } @@ -299,7 +299,7 @@ public void labelValidationTests() throws Exception { for (String p : SOME_INVALID_PREFIXES) { LabelDTO l = LabelDTO.builder().prefix(p).value(LABEL_VALUE).name(LABEL_NAME).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(l))) .andExpect(BAD_REQUEST) .andExpect(INVALID_PREFIX_ERROR_MESSAGE); @@ -308,7 +308,7 @@ public void labelValidationTests() throws Exception { LabelDTO noNameLabel = LabelDTO.builder().prefix(LABEL_PREFIX).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(noNameLabel))) .andExpect(BAD_REQUEST) .andExpect(NAME_REQUIRED_ERROR_MESSAGE); @@ -318,7 +318,7 @@ public void labelValidationTests() throws Exception { for (String in : SOME_INVALID_NAMES) { LabelDTO invalidNameLabel = LabelDTO.builder().prefix(LABEL_PREFIX).name(in).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(invalidNameLabel))) .andExpect(BAD_REQUEST) .andExpect(INVALID_NAME_ERROR_MESSAGE); @@ -328,7 +328,7 @@ public void labelValidationTests() throws Exception { LabelDTO.builder().prefix(LABEL_PREFIX).name(randomAlphabetic(65)).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(longNameLabel))) .andExpect(BAD_REQUEST) .andExpect(NAME_TOO_LONG_ERROR_MESSAGE); @@ -341,7 +341,7 @@ public void labelValidationTests() throws Exception { .build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(longValueLabel))) .andExpect(BAD_REQUEST) .andExpect(VALUE_TOO_LONG_ERROR_MESSAGE); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/aup/EnforceAupSignatureSuccessHandlerTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/aup/EnforceAupSignatureSuccessHandlerTests.java index cef1cfba8..f13996e33 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/aup/EnforceAupSignatureSuccessHandlerTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/aup/EnforceAupSignatureSuccessHandlerTests.java @@ -91,7 +91,7 @@ public void before() { @Test public void userIsRedirectedToSignAupPageWhenNeeded() throws IOException, ServletException { - when(accountUtils.getAuthenticatedUserAccount()).thenReturn(Optional.of(account)); + // when(accountUtils.getAuthenticatedUserAccount()).thenReturn(Optional.of(account)); when(accountUtils.getAuthenticatedUserAccount(Mockito.any())).thenReturn(Optional.of(account)); when(signatureCheckService.needsAupSignature(Mockito.any())).thenReturn(true); @@ -104,7 +104,7 @@ public void userIsRedirectedToSignAupPageWhenNeeded() throws IOException, Servle @Test public void delegateIsCalledIfNoSignatureIsNeeded()throws IOException, ServletException { - when(accountUtils.getAuthenticatedUserAccount()).thenReturn(Optional.of(account)); + // when(accountUtils.getAuthenticatedUserAccount()).thenReturn(Optional.of(account)); when(accountUtils.getAuthenticatedUserAccount(Mockito.any())).thenReturn(Optional.of(account)); when(signatureCheckService.needsAupSignature(Mockito.any())).thenReturn(false); @@ -121,7 +121,7 @@ public void testOAuthAuthenticationIsUnderstood() throws IOException, ServletExc when(oauth.getName()).thenReturn("oauth-client-for-test"); when(oauth.getUserAuthentication()).thenReturn(auth); - when(accountUtils.getAuthenticatedUserAccount()).thenReturn(Optional.of(account)); + // when(accountUtils.getAuthenticatedUserAccount()).thenReturn(Optional.of(account)); when(accountUtils.getAuthenticatedUserAccount(Mockito.any())).thenReturn(Optional.of(account)); when(signatureCheckService.needsAupSignature(Mockito.any())).thenReturn(false); @@ -136,10 +136,10 @@ public void testOAuthClientAuthenticationDoesNotResultInUserLoginTimeUpdate() th OAuth2Authentication oauth = Mockito.mock(OAuth2Authentication.class); when(oauth.getName()).thenReturn("oauth-client-for-test"); when(oauth.getUserAuthentication()).thenReturn(null); - when(signatureCheckService.needsAupSignature(Mockito.any())).thenReturn(false); + // when(signatureCheckService.needsAupSignature(Mockito.any())).thenReturn(false); - when(accountUtils.getAuthenticatedUserAccount()).thenReturn(Optional.empty()); - when(accountUtils.getAuthenticatedUserAccount(Mockito.any())).thenReturn(Optional.empty()); + // when(accountUtils.getAuthenticatedUserAccount()).thenReturn(Optional.empty()); + // when(accountUtils.getAuthenticatedUserAccount(Mockito.any())).thenReturn(Optional.empty()); handler.onAuthenticationSuccess(request, response, oauth); verify(session).setAttribute(Mockito.eq(AuthenticationTimeStamper.AUTH_TIMESTAMP), Mockito.any()); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupAttributeTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupAttributeTests.java index dab1bde40..40183956c 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupAttributeTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupAttributeTests.java @@ -19,7 +19,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.hasSize; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; @@ -105,7 +105,7 @@ public void managingAttributesRequiresAuthenticatedUser() throws Exception { attr.setValue(ATTR_VALUE); mvc.perform( - put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON_UTF8) + put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(attr))) .andExpect(UNAUTHORIZED); @@ -128,7 +128,7 @@ public void managingAttributesRequiresPrivilegedUser() throws Exception { attr.setValue(ATTR_VALUE); mvc.perform( - put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON_UTF8) + put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(attr))) .andExpect(FORBIDDEN); @@ -161,7 +161,7 @@ public void setAttributeWorks() throws Exception { attr.setValue(ATTR_VALUE); mvc.perform( - put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON_UTF8) + put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(attr))) .andExpect(status().isOk()); @@ -174,7 +174,7 @@ public void setAttributeWorks() throws Exception { attr.setValue(null); mvc.perform( - put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON_UTF8) + put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(attr))) .andExpect(status().isOk()); @@ -198,7 +198,7 @@ public void deleteAttributeWorks() throws Exception { attr.setValue(ATTR_VALUE); mvc.perform( - put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON_UTF8) + put("/iam/group/{id}/attributes", testGroup.getUuid()).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(attr))) .andExpect(status().isOk()); @@ -224,7 +224,7 @@ public void nonExistingGroupIsHandledCorrectly() throws Exception { .andExpect(jsonPath("$.error", containsString("Group not found"))); mvc - .perform(put("/iam/group/{id}/attributes", randomUuid).contentType(APPLICATION_JSON_UTF8) + .perform(put("/iam/group/{id}/attributes", randomUuid).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(attr))) .andExpect(NOT_FOUND) .andExpect(jsonPath("$.error", containsString("Group not found"))); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupCreationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupCreationTests.java index ef34b326c..24d17d5f5 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupCreationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupCreationTests.java @@ -18,7 +18,7 @@ import static java.lang.String.format; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -88,7 +88,7 @@ public void createGroupRequiresAuthenticatedUser() throws Exception { mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(model)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isUnauthorized()); } @@ -101,7 +101,7 @@ public void createGroupFailsForNonAdminUser() throws Exception { mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(model)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isForbidden()); } @@ -113,7 +113,7 @@ public void createGroupSucceedsForAdminUser() throws Exception { mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(model)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isCreated()) .andExpect(jsonPath("$.id").exists()) .andExpect(jsonPath("$.name", is(NEW_GROUP_NAME))) @@ -129,7 +129,7 @@ public void createGroupSucceedsForAdminUser() throws Exception { mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(child)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isCreated()) .andExpect(jsonPath("$.id").exists()) .andExpect(jsonPath("$.name", is(format("%s/%s", NEW_GROUP_NAME, child.getName())))) @@ -144,7 +144,7 @@ public void slashNotAllowedInGroupName() throws Exception { mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(model)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.error", containsString("invalid name"))); } @@ -156,7 +156,7 @@ public void blankNameNotAllowed() throws Exception { GroupDTO blanky = GroupDTO.builder().name("").build(); mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(blanky)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.error", containsString("invalid name"))); } @@ -174,7 +174,7 @@ public void longCompositeNameNotAllowed() throws Exception { mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(model)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isCreated()); IamGroup g = @@ -186,7 +186,7 @@ public void longCompositeNameNotAllowed() throws Exception { mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(child)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.error", containsString("group name too long"))); } @@ -204,7 +204,7 @@ public void longDescriptionNotAllowed() throws Exception { GroupDTO.builder().name(NEW_GROUP_NAME).description(longNameBuilder.toString()).build(); mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(model)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andExpect( jsonPath("$.error", containsString("description cannot be longer than 512 chars"))); @@ -223,7 +223,7 @@ public void longDescriptionNotAllowedInUpdate() throws Exception { GroupDTO model = GroupDTO.builder().name(NEW_GROUP_NAME).build(); mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(model)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isCreated()); @@ -234,7 +234,7 @@ public void longDescriptionNotAllowedInUpdate() throws Exception { mvc .perform(MockMvcRequestBuilders.put("/iam/group/{id}", g.getUuid()) .content(mapper.writeValueAsBytes(desc)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andExpect( jsonPath("$.error", containsString("description cannot be longer than 512 chars"))); @@ -249,7 +249,7 @@ public void adminCanUpdateDescription() throws Exception { GroupDTO model = GroupDTO.builder().name(NEW_GROUP_NAME).build(); mvc .perform(post("/iam/group").content(mapper.writeValueAsBytes(model)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isCreated()); @@ -259,7 +259,7 @@ public void adminCanUpdateDescription() throws Exception { GroupDTO desc = GroupDTO.builder().description(NEW_GROUP_DESC).build(); mvc .perform(put("/iam/group/{id}", g.getUuid()).content(mapper.writeValueAsBytes(desc)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.description", is(NEW_GROUP_DESC))); @@ -276,7 +276,7 @@ public void userCannotUpdateDescription() throws Exception { GroupDTO desc = GroupDTO.builder().description(NEW_GROUP_DESC).build(); mvc.perform(put("/iam/group/{id}", g.getUuid()).content(mapper.writeValueAsBytes(desc)) - .contentType(APPLICATION_JSON_UTF8)).andExpect(status().isForbidden()); + .contentType(APPLICATION_JSON)).andExpect(status().isForbidden()); } @@ -289,7 +289,7 @@ public void nonExistingGroupCorrectlyHandled() throws Exception { mvc .perform(put("/iam/group/{id}", UUID.randomUUID().toString()) .content(mapper.writeValueAsBytes(desc)) - .contentType(APPLICATION_JSON_UTF8)) + .contentType(APPLICATION_JSON)) .andExpect(status().isNotFound()) .andExpect(jsonPath("$.error", containsString("Group not found"))); } diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupLabelTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupLabelTests.java index 67b70949c..9fa786450 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupLabelTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/group/GroupLabelTests.java @@ -23,7 +23,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; @@ -97,7 +97,7 @@ public void managingLabelsRequiresAuthenticatedUser() throws Exception { mvc.perform(get(RESOURCE, TEST_001_GROUP_UUID)).andExpect(UNAUTHORIZED); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(UNAUTHORIZED); @@ -112,7 +112,7 @@ public void managingLabelsRequiresPrivilegedUser() throws Exception { mvc.perform(get(RESOURCE, TEST_001_GROUP_UUID)).andExpect(FORBIDDEN); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(FORBIDDEN); @@ -146,7 +146,7 @@ public void gettingLabelsWorksForAdminOAuthUser() throws Exception { public void setLabelWorks() throws Exception { mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(OK); @@ -161,7 +161,7 @@ public void setLabelWorks() throws Exception { LabelDTO label = LabelDTO.builder().prefix(LABEL_PREFIX).name(LABEL_NAME).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(label))) .andExpect(OK); @@ -180,12 +180,12 @@ public void deleteLabelWorks() throws Exception { LabelDTO unqualified = LabelDTO.builder().name(LABEL_NAME).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(OK); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(unqualified))) .andExpect(OK); @@ -231,7 +231,7 @@ public void nonExistingResourceHandledCorrectly() throws Exception { .andExpect(GROUP_NOT_FOUND_ERROR_MESSAGE); mvc - .perform(put(RESOURCE, RANDOM_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, RANDOM_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(TEST_LABEL))) .andExpect(NOT_FOUND) .andExpect(GROUP_NOT_FOUND_ERROR_MESSAGE); @@ -254,12 +254,12 @@ public void multipleLabelsHandledCorrectly() throws Exception { for (LabelDTO l : labels) { mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(l))) .andExpect(OK); mvc - .perform(put(RESOURCE, TEST_002_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_002_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(l))) .andExpect(OK); } @@ -306,7 +306,7 @@ public void labelValidationTests() throws Exception { for (String p : SOME_INVALID_PREFIXES) { LabelDTO l = LabelDTO.builder().prefix(p).value(LABEL_VALUE).name(LABEL_NAME).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(l))) .andExpect(BAD_REQUEST) .andExpect(INVALID_PREFIX_ERROR_MESSAGE); @@ -315,7 +315,7 @@ public void labelValidationTests() throws Exception { LabelDTO noNameLabel = LabelDTO.builder().prefix(LABEL_PREFIX).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(noNameLabel))) .andExpect(BAD_REQUEST) .andExpect(NAME_REQUIRED_ERROR_MESSAGE); @@ -325,7 +325,7 @@ public void labelValidationTests() throws Exception { for (String in : SOME_INVALID_NAMES) { LabelDTO invalidNameLabel = LabelDTO.builder().prefix(LABEL_PREFIX).name(in).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(invalidNameLabel))) .andExpect(BAD_REQUEST) .andExpect(INVALID_NAME_ERROR_MESSAGE); @@ -335,7 +335,7 @@ public void labelValidationTests() throws Exception { LabelDTO.builder().prefix(LABEL_PREFIX).name(randomAlphabetic(65)).build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(longNameLabel))) .andExpect(BAD_REQUEST) .andExpect(NAME_TOO_LONG_ERROR_MESSAGE); @@ -348,7 +348,7 @@ public void labelValidationTests() throws Exception { .build(); mvc - .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON_UTF8) + .perform(put(RESOURCE, TEST_001_GROUP_UUID).contentType(APPLICATION_JSON) .content(mapper.writeValueAsString(longValueLabel))) .andExpect(BAD_REQUEST) .andExpect(VALUE_TOO_LONG_ERROR_MESSAGE); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/proxy/ProxyServiceTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/proxy/ProxyServiceTests.java index 1d4f96235..9568fb68b 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/proxy/ProxyServiceTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/proxy/ProxyServiceTests.java @@ -18,9 +18,9 @@ import static java.util.Optional.empty; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -101,7 +101,7 @@ public void setup() { proxyService = new DefaultProxyCertificateService(clock, accountRepo, properties, proxyHelper); when(principal.getName()).thenReturn(TEST_USER_USERNAME); when(account.getUsername()).thenReturn(TEST_USER_USERNAME); - when(properties.getKeySize()).thenReturn(DEFAULT_KEY_SIZE); + // when(properties.getKeySize()).thenReturn(DEFAULT_KEY_SIZE); when(properties.getMaxLifetimeSeconds()).thenReturn(DEFAULT_PROXY_LIFETIME_SECONDS); when(request.getLifetimeSecs()).thenReturn(null); } @@ -135,9 +135,9 @@ public void testExpiredProxyHandled() throws InvalidKeyException, CertificatePar String pemProxy = generateTest0Proxy(A_WEEK_AGO, AN_HOUR_AGO); - when(proxyCert.getCertificate()).thenReturn(mockedTest0Cert); + // when(proxyCert.getCertificate()).thenReturn(mockedTest0Cert); when(proxyCert.getExpirationTime()).thenReturn(Date.from(AN_HOUR_AGO)); - when(proxyCert.getChain()).thenReturn(pemProxy); + // when(proxyCert.getChain()).thenReturn(pemProxy); when(account.getX509Certificates()).thenReturn(Sets.newHashSet(mockedTest0Cert)); @@ -234,14 +234,14 @@ public void testRequestIssuerIsHonoured() throws InvalidKeyException, Certificat IamX509Certificate mockedTest0Cert = spy(TEST_0_IAM_X509_CERT); when(mockedTest0Cert.getProxy()).thenReturn(proxyCert); - when(request.getLifetimeSecs()).thenReturn(DEFAULT_PROXY_LIFETIME_SECONDS * 2); + // when(request.getLifetimeSecs()).thenReturn(DEFAULT_PROXY_LIFETIME_SECONDS * 2); when(request.getIssuer()).thenReturn("CN=A custom issuer"); String pemProxy = generateTest0Proxy(A_WEEK_AGO, ONE_YEAR_FROM_NOW); - when(proxyCert.getExpirationTime()).thenReturn(Date.from(ONE_YEAR_FROM_NOW)); - when(proxyCert.getCertificate()).thenReturn(mockedTest0Cert); + // when(proxyCert.getExpirationTime()).thenReturn(Date.from(ONE_YEAR_FROM_NOW)); + // when(proxyCert.getCertificate()).thenReturn(mockedTest0Cert); - when(proxyCert.getChain()).thenReturn(pemProxy); + // when(proxyCert.getChain()).thenReturn(pemProxy); when(account.getX509Certificates()).thenReturn(Sets.newHashSet(mockedTest0Cert)); @@ -262,7 +262,7 @@ public void testListProxies() throws InvalidKeyException, CertificateParsingExce when(proxyCert.getExpirationTime()).thenReturn(Date.from(ONE_YEAR_FROM_NOW)); when(proxyCert.getCertificate()).thenReturn(mockedTest0Cert); - when(proxyCert.getChain()).thenReturn(pemProxy); + // when(proxyCert.getChain()).thenReturn(pemProxy); when(account.getX509Certificates()).thenReturn(Sets.newHashSet(mockedTest0Cert)); when(accountRepo.findByUsername(TEST_USER_USERNAME)).thenReturn(Optional.of(account)); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/tokens/TestTokensUtils.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/tokens/TestTokensUtils.java index 3ba5dd5a3..a2f975a38 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/tokens/TestTokensUtils.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/tokens/TestTokensUtils.java @@ -81,6 +81,7 @@ public class TestTokensUtils { @Autowired protected MockMvc mvc; + @SuppressWarnings("deprecation") private OAuth2Authentication oauth2Authentication(ClientDetailsEntity client, String username, String[] scopes) { diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/core/CoreControllerTestSupport.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/core/CoreControllerTestSupport.java index 50e1fa626..1c35b64e1 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/core/CoreControllerTestSupport.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/core/CoreControllerTestSupport.java @@ -27,6 +27,7 @@ import it.infn.mw.iam.test.util.MockTimeProvider; import it.infn.mw.iam.test.util.oauth.MockOAuth2Filter; +@SuppressWarnings("deprecation") @Configuration public class CoreControllerTestSupport { public static final Instant NOW = Instant.parse("2019-01-01T00:00:00.00Z"); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/HintAwareAuthenticationEntryPointTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/HintAwareAuthenticationEntryPointTests.java index 8c0d5bda9..1fa13de45 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/HintAwareAuthenticationEntryPointTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/HintAwareAuthenticationEntryPointTests.java @@ -16,8 +16,8 @@ package it.infn.mw.iam.test.ext_authn; import static it.infn.mw.iam.authn.HintAwareAuthenticationEntryPoint.EXT_AUTHN_HINT_PARAM; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -66,7 +66,7 @@ public class HintAwareAuthenticationEntryPointTests { @Before public void before() { - when(request.getContextPath()).thenReturn(""); + // when(request.getContextPath()).thenReturn(""); } @Test diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/oidc/OidcExternalAuthenticationTestsSupport.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/oidc/OidcExternalAuthenticationTestsSupport.java index d705a9fe5..2515fc411 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/oidc/OidcExternalAuthenticationTestsSupport.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/oidc/OidcExternalAuthenticationTestsSupport.java @@ -17,10 +17,10 @@ import static it.infn.mw.iam.test.ext_authn.oidc.OidcTestConfig.TEST_OIDC_AUTHORIZATION_ENDPOINT_URI; import static it.infn.mw.iam.test.ext_authn.oidc.OidcTestConfig.TEST_OIDC_TOKEN_ENDPOINT_URI; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertNotNull; -import static org.hamcrest.MatcherAssert.assertThat; import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; @@ -45,6 +45,7 @@ import org.springframework.web.util.UriComponentsBuilder; import it.infn.mw.iam.authn.oidc.RestTemplateFactory; +import it.infn.mw.iam.test.rcauth.RCAuthTestSupport; import it.infn.mw.iam.test.util.oidc.CodeRequestHolder; import it.infn.mw.iam.test.util.oidc.MockOIDCProvider; import it.infn.mw.iam.test.util.oidc.MockRestTemplateFactory; @@ -135,7 +136,7 @@ protected CodeRequestHolder buildCodeRequest(String sessionCookie, ResponseEntit String nonce = locationUri.getQueryParams().get("nonce").get(0); requestHeaders.add("Cookie", sessionCookie); - requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + requestHeaders.setContentType(RCAuthTestSupport.APPLICATION_FORM_URLENCODED_UTF8); MultiValueMap params = new LinkedMultiValueMap<>(); @@ -155,7 +156,7 @@ protected void prepareSuccessResponse(String tokenResponse) { tf.getMockServer() .expect(requestTo(TEST_OIDC_TOKEN_ENDPOINT_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(RCAuthTestSupport.APPLICATION_FORM_URLENCODED_UTF8)) .andRespond(MockRestResponseCreators.withSuccess(tokenResponse, MediaType.APPLICATION_JSON)); } @@ -164,7 +165,7 @@ protected void prepareErrorResponse(String errorResponse) { tf.getMockServer() .expect(requestTo(TEST_OIDC_TOKEN_ENDPOINT_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(RCAuthTestSupport.APPLICATION_FORM_URLENCODED_UTF8)) .andRespond(MockRestResponseCreators.withBadRequest() .contentType(MediaType.APPLICATION_JSON) .body(errorResponse)); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/AttributeMetadataFilterTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/AttributeMetadataFilterTests.java index 560dcef19..28fbbd286 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/AttributeMetadataFilterTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/AttributeMetadataFilterTests.java @@ -21,9 +21,9 @@ import static it.infn.mw.iam.authn.saml.util.metadata.SirtfiAttributeMetadataFilter.SIRTFI_ATTRIBUTE_VALUE; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.opensaml.saml2.core.Attribute.URI_REFERENCE; @@ -111,7 +111,7 @@ protected EntityAttributes buildMockEntityAttributes(String attributeName, Strin @Before public void setup() { - when(entityDescriptor1.getEntityID()).thenReturn("1"); + // when(entityDescriptor1.getEntityID()).thenReturn("1"); when(entityDescriptor2.getEntityID()).thenReturn("2"); when(entityDescriptor3.getEntityID()).thenReturn("3"); when(entityDescriptor4.getEntityID()).thenReturn("4"); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/jit_account_provisioning/JitUserCleanupTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/jit_account_provisioning/JitUserCleanupTests.java index f09224239..c709f5242 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/jit_account_provisioning/JitUserCleanupTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/jit_account_provisioning/JitUserCleanupTests.java @@ -19,7 +19,7 @@ import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; import java.time.Instant; @@ -131,7 +131,7 @@ public void testSomethingToCleanup() { IamAccount anAccount = IamAccount.newAccount(); - when(accountService.deleteInactiveProvisionedUsersSinceTime(anyObject())) + when(accountService.deleteInactiveProvisionedUsersSinceTime(any())) .thenReturn(asList(anAccount)); cleanupTask.run(); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/jit_account_provisioning/JitUserDetailServiceTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/jit_account_provisioning/JitUserDetailServiceTests.java index 080daed48..5f66fee83 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/jit_account_provisioning/JitUserDetailServiceTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/saml/jit_account_provisioning/JitUserDetailServiceTests.java @@ -21,21 +21,20 @@ import static it.infn.mw.iam.test.ext_authn.saml.SamlAuthenticationTestSupport.T1_GIVEN_NAME; import static it.infn.mw.iam.test.ext_authn.saml.SamlAuthenticationTestSupport.T1_MAIL; import static it.infn.mw.iam.test.ext_authn.saml.SamlAuthenticationTestSupport.T1_SN; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import java.util.Optional; import java.util.Set; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -80,22 +79,22 @@ public class JitUserDetailServiceTests extends JitUserDetailsServiceTestsSupport @Before public void setup() { - when(accountRepo.findBySamlId(anyObject())).thenReturn(Optional.empty()); - when(accountRepo.findBySamlId(anyString(), anyString(), anyString())) - .thenReturn(Optional.empty()); + when(accountRepo.findBySamlId(any())).thenReturn(Optional.empty()); + // when(accountRepo.findBySamlId(anyString(), anyString(), anyString())) + // .thenReturn(Optional.empty()); - when(accountService.createAccount(anyObject())).thenAnswer(invocation -> { + when(accountService.createAccount(any())).thenAnswer(invocation -> { IamAccount account = (IamAccount) invocation.getArguments()[0]; account.setPassword("password"); return account; }); - when(resolver.resolveSamlUserIdentifier(anyObject())) + when(resolver.resolveSamlUserIdentifier(any())) .thenReturn(SamlUserIdentifierResolutionResult.resolutionFailure("No suitable user id found")); AttributeMappingProperties defaultMappingProps = new AttributeMappingProperties(); - when(mpResolver.resolveMappingProperties(anyString())).thenReturn(defaultMappingProps); + when(mpResolver.resolveMappingProperties(Mockito.any())).thenReturn(defaultMappingProps); userDetailsService = new JustInTimeProvisioningSAMLUserDetailsService(resolver, accountService, inactiveAccountHander, accountRepo, Optional.empty(), mpResolver); @@ -106,7 +105,7 @@ public void testNullSamlCredential() { try { userDetailsService.loadUserBySAML(null); } catch (NullPointerException e) { - Assert.assertThat(e.getMessage(), equalTo("null saml credential")); + assertThat(e.getMessage(), equalTo("null saml credential")); throw e; } } @@ -201,10 +200,7 @@ public void testEntityIdSanityChecksWorkForUntrustedIdp() { when(resolver.resolveSamlUserIdentifier(cred)).thenReturn(resolutionSuccess(T1_SAML_ID)); when(cred.getRemoteEntityID()).thenReturn(SamlAuthenticationTestSupport.DEFAULT_IDP_ID); - when(cred.getAttributeAsString(Saml2Attribute.MAIL.getAttributeName())).thenReturn(T1_MAIL); - when(cred.getAttributeAsString(Saml2Attribute.GIVEN_NAME.getAttributeName())) - .thenReturn(T1_GIVEN_NAME); - when(cred.getAttributeAsString(Saml2Attribute.SN.getAttributeName())).thenReturn(T1_SN); + try { userDetailsService.loadUserBySAML(cred); } catch (UsernameNotFoundException e) { diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/x509/X509TestSupport.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/x509/X509TestSupport.java index 9d558dfe8..7f1c04380 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/x509/X509TestSupport.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/ext_authn/x509/X509TestSupport.java @@ -290,10 +290,10 @@ protected void mockHttpRequestWithTest0SSLHeaders(HttpServletRequest request) { .getHeader(DefaultX509AuthenticationCredentialExtractor.Headers.PROTOCOL.getHeader())) .thenReturn("TLS"); - Mockito - .when(request - .getHeader(DefaultX509AuthenticationCredentialExtractor.Headers.SERVER_NAME.getHeader())) - .thenReturn("serverName"); + // Mockito + // .when(request + // .getHeader(DefaultX509AuthenticationCredentialExtractor.Headers.SERVER_NAME.getHeader())) + // .thenReturn("serverName"); Mockito .when(request diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/lifecycle/cern/CernAccountLifecycleTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/lifecycle/cern/CernAccountLifecycleTests.java index 793ec8583..33af02cc7 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/lifecycle/cern/CernAccountLifecycleTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/lifecycle/cern/CernAccountLifecycleTests.java @@ -40,6 +40,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; @@ -51,6 +52,7 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import it.infn.mw.iam.IamLoginService; import it.infn.mw.iam.api.registration.cern.CernHrDBApiService; import it.infn.mw.iam.api.registration.cern.CernHrDbApiError; import it.infn.mw.iam.api.registration.cern.dto.VOPersonDTO; @@ -60,11 +62,14 @@ import it.infn.mw.iam.persistence.model.IamLabel; import it.infn.mw.iam.persistence.repository.IamAccountRepository; import it.infn.mw.iam.test.api.TestSupport; +import it.infn.mw.iam.test.core.CoreControllerTestSupport; import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest; @RunWith(SpringRunner.class) @IamMockMvcIntegrationTest +@SpringBootTest(classes = {IamLoginService.class, CoreControllerTestSupport.class, + CernAccountLifecycleTests.TestConfig.class}) @TestPropertySource(properties = { // @formatter:off "lifecycle.account.expiredAccountPolicy.suspensionGracePeriodDays=0", diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/exchange/TokenExchangePdPTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/exchange/TokenExchangePdPTests.java index f6bd92c36..40a3a4d9f 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/exchange/TokenExchangePdPTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/exchange/TokenExchangePdPTests.java @@ -49,6 +49,7 @@ import it.infn.mw.iam.persistence.model.IamTokenExchangePolicyEntity; import it.infn.mw.iam.persistence.repository.IamTokenExchangePolicyRepository; +@SuppressWarnings("deprecation") @RunWith(MockitoJUnitRunner.class) public class TokenExchangePdPTests extends TokenExchangePdpTestSupport { @@ -70,14 +71,16 @@ public class TokenExchangePdPTests extends TokenExchangePdpTestSupport { @InjectMocks DefaultTokenExchangePdp pdp; + private TokenRequest buildTokenRequest() { return new TokenRequest(emptyMap(), "destination", Collections.emptySet(), TOKEN_EXCHANGE_GRANT_TYPE); } + @Before public void before() { when(originClient.getClientId()).thenReturn(ORIGIN_CLIENT_ID); - when(destinationClient.getClientId()).thenReturn(DESTINATION_CLIENT_ID); + // when(destinationClient.getClientId()).thenReturn(DESTINATION_CLIENT_ID); when(originClient.getScope()).thenReturn(ORIGIN_CLIENT_SCOPES); when(destinationClient.getScope()).thenReturn(DESTINATION_CLIENT_SCOPES); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKDefaultKeyTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKDefaultKeyTests.java index 73d04b8f7..b391359e9 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKDefaultKeyTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKDefaultKeyTests.java @@ -16,9 +16,10 @@ package it.infn.mw.iam.test.oauth.jwk; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.CombinableMatcher.either; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -28,7 +29,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.http.MediaType; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -69,7 +69,7 @@ public void testJwkEndpointResult() throws Exception { mvc.perform(get(JWK_ENDPOINT)) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(APPLICATION_JSON)) .andExpect(jsonPath("$.keys", hasSize(2))) .andExpect(jsonPath("$.keys[0].kid", either(is("iam1")).or(is("iam2")))) .andExpect(jsonPath("$.keys[1].kid", either(is("iam1")).or(is("iam2")))); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKECKeyTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKECKeyTests.java index 8d2bcbf9e..3fb03850b 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKECKeyTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKECKeyTests.java @@ -16,8 +16,9 @@ package it.infn.mw.iam.test.oauth.jwk; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -27,7 +28,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.http.MediaType; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -68,7 +68,7 @@ public void testJwkEndpointResult() throws Exception { mvc.perform(get(JWK_ENDPOINT)) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(APPLICATION_JSON)) .andExpect(jsonPath("$.keys", hasSize(1))) .andExpect(jsonPath("$.keys[0].kid", is("iam"))); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKEndpointTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKEndpointTests.java index 339b4fa40..b1dde9b42 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKEndpointTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/jwk/JWKEndpointTests.java @@ -16,6 +16,7 @@ package it.infn.mw.iam.test.oauth.jwk; import static org.hamcrest.Matchers.hasSize; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -23,7 +24,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; import it.infn.mw.iam.core.web.jwk.IamJWKSetPublishingEndpoint; @@ -43,7 +43,7 @@ public void testKeys() throws Exception { // @formatter:off mvc.perform(get(ENDPOINT)) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andExpect(jsonPath("$.keys", hasSize(1))) .andExpect(jsonPath("$.keys[0].kty").value("RSA")) .andExpect(jsonPath("$.keys[0].e").value("AQAB")) diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/IamAccessTokenBuilderTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/IamAccessTokenBuilderTests.java index bb001e12c..b0d2aa966 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/IamAccessTokenBuilderTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/IamAccessTokenBuilderTests.java @@ -83,9 +83,9 @@ public void setup() { when(tokenEntity.getExpiration()).thenReturn(null); when(tokenEntity.getClient()).thenReturn(client); when(client.getClientId()).thenReturn("client"); - when(authentication.getName()).thenReturn("auth-name"); + // when(authentication.getName()).thenReturn("auth-name"); when(authentication.getOAuth2Request()).thenReturn(oauth2Request); - when(authentication.isClientOnly()).thenReturn(false); + // when(authentication.isClientOnly()).thenReturn(false); when(userInfo.getSub()).thenReturn("userinfo-sub"); when(oauth2Request.getGrantType()).thenReturn(TOKEN_EXCHANGE_GRANT_TYPE); } diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/WLCGGroupHelperTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/WLCGGroupHelperTests.java index f5eb58aea..15dc1d5ea 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/WLCGGroupHelperTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/WLCGGroupHelperTests.java @@ -20,9 +20,9 @@ import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import java.util.Collections; @@ -98,7 +98,7 @@ public void testNoWLCGGroupScopeNoGroups() { IamGroup g2 = buildGroup("g2"); IamGroup g3 = buildOptionalGroup("g3"); - when(userInfo.getGroups()).thenReturn(Sets.newHashSet(g1, g2, g3)); + // when(userInfo.getGroups()).thenReturn(Sets.newHashSet(g1, g2, g3)); assertThat(helper.resolveGroups(token, userInfo), empty()); } diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/WLCGProfileIntegrationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/WLCGProfileIntegrationTests.java index d287b9cd6..4d8b518d1 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/WLCGProfileIntegrationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/profile/WLCGProfileIntegrationTests.java @@ -150,6 +150,7 @@ private void setOAuthAdminSecurityContext() { String[] authnScopes = new String[] {"openid"}; + @SuppressWarnings("deprecation") OAuth2Authentication authn = new OAuth2Authentication(new MockOAuth2Request("password-grant", authnScopes), userAuth); @@ -691,6 +692,7 @@ public void testUserInfoEndpointReturnsMinimailInformationAcrossRefresh() throws String[] authnScopes = new String[] {"openid"}; + @SuppressWarnings("deprecation") OAuth2Authentication authn = new OAuth2Authentication(new MockOAuth2Request("password-grant", authnScopes), userAuth); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/DynClientScopeValidationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/DynClientScopeValidationTests.java index 6c9740a96..b2ad041d7 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/DynClientScopeValidationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/DynClientScopeValidationTests.java @@ -20,8 +20,8 @@ import static it.infn.mw.iam.core.oauth.scope.matchers.StructuredPathScopeMatcher.structuredPathMatcher; import static java.util.Collections.emptySet; import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; import static org.mitre.oauth2.model.ClientDetailsEntity.AuthMethod.SECRET_BASIC; import static org.mockito.Mockito.when; @@ -80,8 +80,8 @@ public void setup() { when(scopeService.getRestricted()).thenReturn(emptySet()); - when(registry.findMatcherForScope("openid")).thenReturn(stringEqualsMatcher("openid")); - when(registry.findMatcherForScope("profile")).thenReturn(stringEqualsMatcher("profile")); + // when(registry.findMatcherForScope("openid")).thenReturn(stringEqualsMatcher("openid")); + // when(registry.findMatcherForScope("profile")).thenReturn(stringEqualsMatcher("profile")); when(registry.findMatcherForScope("restricted")).thenReturn(stringEqualsMatcher("restricted")); when(clientService.generateClientSecret(Mockito.any())).thenAnswer(i -> i.getArguments()[0]); @@ -115,7 +115,8 @@ public void staticStructuredScopeFilterTest() throws ValidationException { when(scopeService.getRestricted()).thenReturn(newHashSet(new SystemScope("read:/"))); when(registry.findMatcherForScope("read:/")).thenReturn(structuredPathMatcher("read", "/")); - when(registry.findMatcherForScope("read:/sub/path")).thenReturn(structuredPathMatcher("read", "/")); + // when(registry.findMatcherForScope("read:/sub/path")).thenReturn(structuredPathMatcher("read", + // "/")); client = clientValidationService.validateClient(client); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/OAuthRequestValidatorTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/OAuthRequestValidatorTests.java index 960ad3e5d..9cff21610 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/OAuthRequestValidatorTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/OAuthRequestValidatorTests.java @@ -39,6 +39,7 @@ @RunWith(MockitoJUnitRunner.class) public class OAuthRequestValidatorTests { + @SuppressWarnings("deprecation") @Spy AuthorizationRequest authzRequest = new AuthorizationRequest(); @@ -57,7 +58,7 @@ public class OAuthRequestValidatorTests { public void setup() { when(client.getClientId()).thenReturn("exampleClient"); - when(client.getScope()).thenReturn(newHashSet("openid", "profile")); + // when(client.getScope()).thenReturn(newHashSet("openid", "profile")); authzRequest.setScope(Sets.newHashSet("openid")); when(registry.findMatchersForClient(client)) .thenReturn(newHashSet(stringEqualsMatcher("openid"), stringEqualsMatcher("profile"))); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/pdp/ScopePolicyAuditTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/pdp/ScopePolicyAuditTests.java index ffa5a46ce..65dfd5e5f 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/pdp/ScopePolicyAuditTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/scope/pdp/ScopePolicyAuditTests.java @@ -16,9 +16,9 @@ package it.infn.mw.iam.test.oauth.scope.pdp; import static java.util.Collections.emptyList; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.AdditionalAnswers.returnsFirstArg; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -78,8 +78,8 @@ public void init() { converter = new DefaultScopePolicyConverter(new DefaultScimResourceLocationProvider(), accountRepo, groupRepo); - when(scopePolicyRepo.findDefaultPolicies()).thenReturn(emptyList()); - when(scopePolicyRepo.findEquivalentPolicies(Mockito.anyObject())) + // when(scopePolicyRepo.findDefaultPolicies()).thenReturn(emptyList()); + when(scopePolicyRepo.findEquivalentPolicies(Mockito.any())) .thenReturn(emptyList()); when(scopePolicyRepo.save(Mockito.any(IamScopePolicy.class))).thenAnswer(returnsFirstArg()); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthCertificateRequestorTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthCertificateRequestorTests.java index 8cab92829..f108af7d6 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthCertificateRequestorTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthCertificateRequestorTests.java @@ -52,7 +52,9 @@ @RunWith(SpringRunner.class) @IamMockMvcIntegrationTest -@SpringBootTest(classes = {IamLoginService.class, RCAuthTestConfig.class}, +@SpringBootTest( + classes = {IamLoginService.class, RCAuthTestConfig.class, + RCAuthCertificateRequestorTests.TestConfig.class}, webEnvironment = WebEnvironment.MOCK) @TestPropertySource( properties = {"rcauth.enabled=true", "rcauth.client-id=" + RCAuthTestSupport.CLIENT_ID, @@ -60,6 +62,7 @@ "rcauth.issuer=" + RCAuthTestSupport.ISSUER}) public class RCAuthCertificateRequestorTests extends RCAuthTestSupport { + @TestConfiguration public static class TestConfig { @Bean @@ -116,7 +119,7 @@ public void prepareCertificateResponse() { mockRtf.getMockServer() .expect(requestTo(GET_CERT_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(APPLICATION_FORM_URLENCODED_UTF8_VALUE)) .andRespond(MockRestResponseCreators.withSuccess(TEST_0_CERT_STRING, MediaType.TEXT_PLAIN)); } @@ -124,7 +127,7 @@ public void prepareErrorResponse() { mockRtf.getMockServer() .expect(requestTo(GET_CERT_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(APPLICATION_FORM_URLENCODED_UTF8_VALUE)) .andRespond(withServerError()); } diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthIntegrationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthIntegrationTests.java index 42afa6e2c..156f7d34a 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthIntegrationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthIntegrationTests.java @@ -22,9 +22,9 @@ import static it.infn.mw.iam.rcauth.RCAuthController.CALLBACK_PATH; import static it.infn.mw.iam.rcauth.RCAuthController.GETCERT_PATH; import static org.hamcrest.CoreMatchers.startsWith; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; import static org.springframework.http.MediaType.TEXT_PLAIN; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; @@ -75,7 +75,9 @@ @RunWith(SpringRunner.class) @IamMockMvcIntegrationTest -@SpringBootTest(classes = {IamLoginService.class, RCAuthTestConfig.class}, +@SpringBootTest( + classes = {IamLoginService.class, RCAuthTestConfig.class, + RCAuthIntegrationTests.TestConfig.class}, webEnvironment = WebEnvironment.MOCK) @TestPropertySource( properties = {"rcauth.enabled=true", "rcauth.client-id=" + RCAuthTestSupport.CLIENT_ID, @@ -212,7 +214,7 @@ void prepareTokenResponse(String nonce) throws JsonProcessingException, JOSEExce mockRtf.getMockServer() .expect(requestTo(TOKEN_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(APPLICATION_FORM_URLENCODED_UTF8_VALUE)) .andRespond(withSuccess(mapper.writeValueAsString(tr), MediaType.APPLICATION_JSON)); } @@ -220,7 +222,7 @@ public void prepareCertificateResponse() { mockRtf.getMockServer() .expect(requestTo(GET_CERT_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(APPLICATION_FORM_URLENCODED_UTF8_VALUE)) .andRespond(withSuccess(TEST_0_CERT_STRING, TEXT_PLAIN)); } diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthTestSupport.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthTestSupport.java index 84cd91c11..1fcfbfc14 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthTestSupport.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthTestSupport.java @@ -17,6 +17,7 @@ import org.mitre.jose.keystore.JWKSetKeyStore; import org.springframework.core.io.ClassPathResource; +import org.springframework.http.MediaType; import com.nimbusds.jose.JWSAlgorithm; @@ -56,6 +57,12 @@ public class RCAuthTestSupport extends X509TestSupport { public static final String IAM_ENTITY_ID = "iam-entity-id"; public static final String CODE_VALUE = "diablocode"; + + public static final String APPLICATION_FORM_URLENCODED_UTF8_VALUE = + MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=UTF-8"; + + public static final MediaType APPLICATION_FORM_URLENCODED_UTF8 = + MediaType.valueOf(APPLICATION_FORM_URLENCODED_UTF8_VALUE); protected JWKSetKeyStore rcAuthKeyStore = rcAuthKeyStore(); protected JWSAlgorithm jwsAlgo = JWSAlgorithm.RS256; diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthTokenRequestorTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthTokenRequestorTests.java index 761d75e36..7f31bb1a9 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthTokenRequestorTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RCAuthTokenRequestorTests.java @@ -25,7 +25,6 @@ import java.text.ParseException; import java.util.UUID; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -60,7 +59,9 @@ @RunWith(SpringRunner.class) @IamMockMvcIntegrationTest -@SpringBootTest(classes = {IamLoginService.class, RCAuthTestConfig.class}, +@SpringBootTest( + classes = {IamLoginService.class, RCAuthTestConfig.class, + RCAuthTokenRequestorTests.TestConfig.class}, webEnvironment = WebEnvironment.MOCK) @TestPropertySource( properties = {"rcauth.enabled=true", "rcauth.client-id=" + RCAuthTestSupport.CLIENT_ID, @@ -119,7 +120,7 @@ public void testGetAccessTokenError() throws JsonProcessingException { try { tokenRequestor.getAccessToken(RANDOM_AUTHZ_CODE); } catch (RCAuthError e) { - Assert.assertThat(e.getMessage(), containsString("Token request error: invalid_request")); + assertThat(e.getMessage(), containsString("Token request error: invalid_request")); throw e; } finally { verifyMockServerCalls(); @@ -133,7 +134,7 @@ public void testGetAccessTokenBogusError() throws JsonProcessingException { try { tokenRequestor.getAccessToken(RANDOM_AUTHZ_CODE); } catch (RCAuthError e) { - Assert.assertThat(e.getMessage(), containsString("Token request error:")); + assertThat(e.getMessage(), containsString("Token request error:")); throw e; } finally { verifyMockServerCalls(); @@ -146,7 +147,7 @@ public void testGetAccessTokenInternalServerError() throws JsonProcessingExcepti try { tokenRequestor.getAccessToken(RANDOM_AUTHZ_CODE); } catch (RCAuthError e) { - Assert.assertThat(e.getMessage(), containsString("Token request error:")); + assertThat(e.getMessage(), containsString("Token request error:")); throw e; } finally { verifyMockServerCalls(); @@ -156,7 +157,7 @@ private void prepareInternalServerErrorResponse() { mockRtf.getMockServer() .expect(requestTo(TOKEN_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(APPLICATION_FORM_URLENCODED_UTF8)) .andRespond(MockRestResponseCreators.withServerError() .body("internal server error")); } @@ -166,7 +167,7 @@ private void prepareBogusErrorRespose() { mockRtf.getMockServer() .expect(requestTo(TOKEN_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(APPLICATION_FORM_URLENCODED_UTF8)) .andRespond(MockRestResponseCreators.withBadRequest() .body("64372tfgd") .contentType(MediaType.APPLICATION_JSON)); @@ -180,7 +181,7 @@ void prepareErrorRespose() throws JsonProcessingException { mockRtf.getMockServer() .expect(requestTo(TOKEN_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(APPLICATION_FORM_URLENCODED_UTF8)) .andRespond(MockRestResponseCreators.withBadRequest() .body(mapper.writeValueAsString(response)) .contentType(MediaType.APPLICATION_JSON)); @@ -199,7 +200,7 @@ void prepareTokenResponse(String nonce) throws JsonProcessingException, JOSEExce mockRtf.getMockServer() .expect(requestTo(TOKEN_URI)) .andExpect(method(HttpMethod.POST)) - .andExpect(content().contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) + .andExpect(content().contentType(APPLICATION_FORM_URLENCODED_UTF8)) .andRespond(MockRestResponseCreators.withSuccess(mapper.writeValueAsString(tr), MediaType.APPLICATION_JSON)); } diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RequestServiceTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RequestServiceTests.java index ee6512743..df65ba6ea 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RequestServiceTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/rcauth/RequestServiceTests.java @@ -29,9 +29,9 @@ import static it.infn.mw.iam.rcauth.RCAuthController.CALLBACK_PATH; import static java.lang.String.format; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -176,7 +176,7 @@ public void testHandleCodeResponseInvalidState() throws UnsupportedEncodingExcep @Test(expected = RCAuthError.class) public void testHandleCodeResponseContextNotFound() throws UnsupportedEncodingException { - when(authzResponse.getState()).thenReturn("76321"); + // when(authzResponse.getState()).thenReturn("76321"); try { service.handleAuthorizationCodeResponse(session, authzResponse); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/ExternalAuthenticationRegistrationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/ExternalAuthenticationRegistrationTests.java index dab4dc06b..721ca17ee 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/ExternalAuthenticationRegistrationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/ExternalAuthenticationRegistrationTests.java @@ -81,7 +81,7 @@ public void testExtAuthOIDC() throws JsonProcessingException, Exception { request.setNotes("Some short notes..."); byte[] requestBytes = mvc - .perform(post("/registration/create").contentType(MediaType.APPLICATION_JSON_UTF8) + .perform(post("/registration/create").contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsBytes(request))) .andExpect(status().isOk()) .andReturn() @@ -126,7 +126,7 @@ public void testExtAuthSAML() throws JsonProcessingException, Exception { request.setNotes("Some short notes..."); byte[] requestBytes = mvc - .perform(post("/registration/create").contentType(MediaType.APPLICATION_JSON_UTF8) + .perform(post("/registration/create").contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsBytes(request))) .andExpect(status().isOk()) .andReturn() diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/OidcExtAuthRegistrationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/OidcExtAuthRegistrationTests.java index 01a3ce8f8..a9caaddb4 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/OidcExtAuthRegistrationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/OidcExtAuthRegistrationTests.java @@ -101,7 +101,7 @@ public void externalOidcRegistrationCreatesDisabledAccount() throws Exception { request.setNotes("Some short notes..."); byte[] requestBytes = mvc - .perform(post("/registration/create").contentType(MediaType.APPLICATION_JSON_UTF8) + .perform(post("/registration/create").contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsBytes(request))) .andExpect(status().isOk()) .andReturn() diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/SamlExtAuthRegistrationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/SamlExtAuthRegistrationTests.java index 23b5205d5..7c378c6be 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/SamlExtAuthRegistrationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/SamlExtAuthRegistrationTests.java @@ -77,7 +77,7 @@ public void externalSamlRegistrationCreatesDisabledAccount() throws Throwable { request.setNotes("Some short notes..."); byte[] requestBytes = mvc - .perform(post("/registration/create").contentType(MediaType.APPLICATION_JSON_UTF8) + .perform(post("/registration/create").contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsBytes(request))) .andExpect(status().isOk()) .andReturn() diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/cern/CernHrDbApiClientTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/cern/CernHrDbApiClientTests.java index 5aa357c6c..aeb70e84c 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/cern/CernHrDbApiClientTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/cern/CernHrDbApiClientTests.java @@ -18,10 +18,11 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.startsWith; import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.OK; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.client.match.MockRestRequestMatchers.header; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; @@ -56,7 +57,8 @@ @RunWith(SpringRunner.class) @IamMockMvcIntegrationTest -@SpringBootTest(classes = {IamLoginService.class}, webEnvironment = WebEnvironment.MOCK) +@SpringBootTest(classes = {IamLoginService.class, CernHrDbApiClientTests.TestConfig.class}, + webEnvironment = WebEnvironment.MOCK) @TestPropertySource(properties = {"cern.hr-api.username=" + CernTestSupport.HR_API_USERNAME, "cern.hr-api.password=" + CernTestSupport.HR_API_PASSWORD, "cern.hr-api.url=" + CernTestSupport.HR_API_URL, @@ -98,7 +100,7 @@ public void checkMembershipSuccess() { .expect(requestTo(apiValidationUrl)) .andExpect(method(GET)) .andExpect(header("Authorization", BASIC_AUTH_HEADER_VALUE)) - .andRespond(withStatus(OK).contentType(APPLICATION_JSON_UTF8).body("true")); + .andRespond(withStatus(OK).contentType(APPLICATION_JSON).body("true")); assertThat(hrDbService.hasValidExperimentParticipation(personId), is(true)); } @@ -111,7 +113,7 @@ public void checkMembershipFailure() { .expect(requestTo(apiValidationUrl)) .andExpect(method(GET)) .andExpect(header("Authorization", BASIC_AUTH_HEADER_VALUE)) - .andRespond(withStatus(OK).contentType(APPLICATION_JSON_UTF8).body("false")); + .andRespond(withStatus(OK).contentType(APPLICATION_JSON).body("false")); assertThat(hrDbService.hasValidExperimentParticipation(personId), is(false)); } @@ -141,7 +143,7 @@ public void checkPersonRecord() throws JsonProcessingException { .expect(requestTo(voPersonUrl)) .andExpect(method(GET)) .andExpect(header("Authorization", BASIC_AUTH_HEADER_VALUE)) - .andRespond(withStatus(OK).contentType(APPLICATION_JSON_UTF8) + .andRespond(withStatus(OK).contentType(APPLICATION_JSON) .body(mapper.writeValueAsString(mockHrUser(personId)))); VOPersonDTO user = hrDbService.getHrDbPersonRecord(personId); @@ -157,13 +159,13 @@ public void checkErrorPersonRecord() throws JsonProcessingException { .expect(requestTo(voPersonUrl)) .andExpect(method(GET)) .andExpect(header("Authorization", BASIC_AUTH_HEADER_VALUE)) - .andRespond(withStatus(NOT_FOUND).contentType(APPLICATION_JSON_UTF8) + .andRespond(withStatus(NOT_FOUND).contentType(APPLICATION_JSON) .body(mapper.writeValueAsString(ErrorDTO.newError("NOT_FOUND", "User not found")))); try { hrDbService.getHrDbPersonRecord(personId); } catch (CernHrDbApiError e) { - assertThat(e.getMessage(), is("HR db api error: 404 Not Found")); + assertThat(e.getMessage(), startsWith("HR db api error: 404 Not Found")); throw e; } } diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/cern/CernRegistrationValidationServiceTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/cern/CernRegistrationValidationServiceTests.java index f18e74f8e..01418fb7d 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/cern/CernRegistrationValidationServiceTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/registration/cern/CernRegistrationValidationServiceTests.java @@ -17,10 +17,10 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; @@ -40,6 +40,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; @@ -54,6 +56,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Sets; +import it.infn.mw.iam.IamLoginService; import it.infn.mw.iam.api.registration.cern.CernHrDBApiService; import it.infn.mw.iam.api.registration.cern.CernHrDbApiError; import it.infn.mw.iam.api.registration.cern.dto.InstituteDTO; @@ -63,13 +66,16 @@ import it.infn.mw.iam.persistence.model.IamLabel; import it.infn.mw.iam.persistence.repository.IamAccountRepository; import it.infn.mw.iam.registration.RegistrationRequestDto; +import it.infn.mw.iam.test.core.CoreControllerTestSupport; import it.infn.mw.iam.test.util.WithAnonymousUser; import it.infn.mw.iam.test.util.WithMockOIDCUser; -import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest; @RunWith(SpringRunner.class) -@IamMockMvcIntegrationTest +@SpringBootTest( + classes = {IamLoginService.class, CoreControllerTestSupport.class, + CernRegistrationValidationServiceTests.TestConfig.class}, + webEnvironment = WebEnvironment.MOCK) @ActiveProfiles({"h2-test", "cern"}) @TestPropertySource(properties = {"cern.task.enabled=false"}) public class CernRegistrationValidationServiceTests { diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/repository/IamTokenRepositoryTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/repository/IamTokenRepositoryTests.java index c786b3884..3c279f488 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/repository/IamTokenRepositoryTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/repository/IamTokenRepositoryTests.java @@ -15,8 +15,8 @@ */ package it.infn.mw.iam.test.repository; -import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; import java.util.Calendar; import java.util.Date; @@ -64,6 +64,7 @@ public class IamTokenRepositoryTests { @Autowired private DefaultOAuth2ProviderTokenService tokenService; + @SuppressWarnings("deprecation") private OAuth2Authentication oauth2Authentication(ClientDetailsEntity client, String username) { String[] scopes = {}; diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/scim/updater/factory/DefaultAccountUpdaterFactoryTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/scim/updater/factory/DefaultAccountUpdaterFactoryTests.java index 4b295b8bb..44e09cd31 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/scim/updater/factory/DefaultAccountUpdaterFactoryTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/scim/updater/factory/DefaultAccountUpdaterFactoryTests.java @@ -37,7 +37,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.isIn; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import java.util.List; @@ -214,7 +214,6 @@ public IamAccount answer(InvocationOnMock invocation) throws Throwable { IamSshKey key = invocation.getArgument(1, IamSshKey.class); account.getSshKeys().add(key); key.setAccount(account); - when(repo.findBySshKeyValue(key.getValue())).thenReturn(Optional.of(account)); return account; } }); @@ -253,21 +252,21 @@ public void testPatchAddOpMultipleParsing() { when(repo.findByEmail(NEW)).thenReturn(Optional.empty()); when(repo.findByOidcId(NEW, NEW)).thenReturn(Optional.empty()); - when(repo.findBySamlId(anyObject())).thenReturn(Optional.empty()); + when(repo.findBySamlId(any())).thenReturn(Optional.empty()); when(repo.findBySshKeyValue(NEW)).thenReturn(Optional.empty()); when(repo.findByCertificate(x509Certs.get(0).certificate)).thenReturn(Optional.empty()); - when(accountService.addSshKey(Mockito.any(), Mockito.any())) - .thenAnswer(new Answer() { - @Override - public IamAccount answer(InvocationOnMock invocation) throws Throwable { - IamAccount account = invocation.getArgument(0, IamAccount.class); - IamSshKey key = invocation.getArgument(1, IamSshKey.class); - account.getSshKeys().add(key); - key.setAccount(account); - when(repo.findBySshKeyValue(key.getValue())).thenReturn(Optional.of(account)); - return account; - } - }); + // when(accountService.addSshKey(Mockito.any(), Mockito.any())) + // .thenAnswer(new Answer() { + // @Override + // public IamAccount answer(InvocationOnMock invocation) throws Throwable { + // IamAccount account = invocation.getArgument(0, IamAccount.class); + // IamSshKey key = invocation.getArgument(1, IamSshKey.class); + // account.getSshKeys().add(key); + // key.setAccount(account); + // when(repo.findBySshKeyValue(key.getValue())).thenReturn(Optional.of(account)); + // return account; + // } + // }); ScimUser user = ScimUser.builder() .buildName(NEW, NEW) @@ -373,10 +372,10 @@ public void testPatchRemoveOpMultipleParsing() { IamSamlId oldId = new IamSamlId(OLD, Saml2Attribute.EPUID.getAttributeName(), OLD); - when(repo.findByOidcId(OLD, OLD)).thenReturn(Optional.of(account)); - when(repo.findBySamlId(oldId)).thenReturn(Optional.of(account)); + + when(repo.findBySshKeyValue(OLD)).thenReturn(Optional.of(account)); - when(repo.findByCertificate(x509Certs.get(0).certificate)).thenReturn(Optional.of(account)); + when(accountService.removeSshKey(Mockito.any(), Mockito.any())) .thenAnswer(new Answer() { @Override @@ -385,7 +384,6 @@ public IamAccount answer(InvocationOnMock invocation) throws Throwable { IamSshKey key = invocation.getArgument(1, IamSshKey.class); account.getSshKeys().remove(key); key.setAccount(null); - when(repo.findBySshKeyValue(key.getValue())).thenReturn(Optional.empty()); return account; } }); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/AccountUtilsTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/AccountUtilsTests.java index 43f92fe17..fb30a6a07 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/AccountUtilsTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/AccountUtilsTests.java @@ -15,9 +15,9 @@ */ package it.infn.mw.iam.test.service; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import java.util.Optional; @@ -39,6 +39,7 @@ import it.infn.mw.iam.persistence.model.IamAccount; import it.infn.mw.iam.persistence.repository.IamAccountRepository; +@SuppressWarnings("deprecation") @RunWith(MockitoJUnitRunner.class) public class AccountUtilsTests { @@ -78,7 +79,7 @@ public void isAuthenticatedReturnsFalseForNullAuthentication() { @Test public void isAuthenticatedReturnsTrueForUsernamePasswordAuthenticationToken() { UsernamePasswordAuthenticationToken token = Mockito.mock(UsernamePasswordAuthenticationToken.class); - when(token.getName()).thenReturn("test"); + when(securityContext.getAuthentication()).thenReturn(token); SecurityContextHolder.setContext(securityContext); assertThat(utils.isAuthenticated(), is(true)); @@ -122,7 +123,7 @@ public void getAuthenticatedUserAccountWorksForOauthToken() { when(token.getName()).thenReturn("test"); OAuth2Authentication oauth = Mockito.mock(OAuth2Authentication.class); - when(oauth.getName()).thenReturn("oauth-client-for-test"); + when(oauth.getUserAuthentication()).thenReturn(token); when(securityContext.getAuthentication()).thenReturn(oauth); @@ -137,7 +138,7 @@ public void getAuthenticatedUserAccountWorksForOauthToken() { @Test public void getAuthenticatedUserAccountReturnsEmptyOptionalForClientOAuthToken() { OAuth2Authentication oauth = Mockito.mock(OAuth2Authentication.class); - when(oauth.getName()).thenReturn("oauth-client-for-test"); + when(oauth.getUserAuthentication()).thenReturn(null); when(securityContext.getAuthentication()).thenReturn(oauth); SecurityContextHolder.setContext(securityContext); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/DefaultNotificationStoreServiceTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/DefaultNotificationStoreServiceTests.java index ad84d97b2..e0891e257 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/DefaultNotificationStoreServiceTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/DefaultNotificationStoreServiceTests.java @@ -90,8 +90,8 @@ public class DefaultNotificationStoreServiceTests { @Before public void setup() { - when(properties.getMailFrom()).thenReturn(IAM_MAIL_FROM); - when(properties.getAdminAddress()).thenReturn(IAM_ADMIN_ADDRESS); + // when(properties.getMailFrom()).thenReturn(IAM_MAIL_FROM); + // when(properties.getAdminAddress()).thenReturn(IAM_ADMIN_ADDRESS); when(properties.getCleanupAge()).thenReturn(1); } @@ -119,15 +119,15 @@ public void clearExpiredNotificationsClearsTheRightNotifications() { IamEmailNotification notification = mock(IamEmailNotification.class); IamNotificationReceiver receiver = mock(IamNotificationReceiver.class); - when(receiver.getIamEmailNotification()).thenReturn(notification); - when(receiver.getEmailAddress()).thenReturn(TEST_0_EMAIL); + // when(receiver.getIamEmailNotification()).thenReturn(notification); + // when(receiver.getEmailAddress()).thenReturn(TEST_0_EMAIL); - when(notification.getBody()).thenReturn("Body"); - when(notification.getSubject()).thenReturn("Subject"); - when(notification.getDeliveryStatus()).thenReturn(IamDeliveryStatus.DELIVERED); - when(notification.getCreationTime()).thenReturn(twoDaysAfterNow); - when(notification.getLastUpdate()).thenReturn(oneDayAfterNow); - when(notification.getUuid()).thenReturn(randomUuid); + // when(notification.getBody()).thenReturn("Body"); + // when(notification.getSubject()).thenReturn("Subject"); + // when(notification.getDeliveryStatus()).thenReturn(IamDeliveryStatus.DELIVERED); + // when(notification.getCreationTime()).thenReturn(twoDaysAfterNow); + // when(notification.getLastUpdate()).thenReturn(oneDayAfterNow); + // when(notification.getUuid()).thenReturn(randomUuid); when(notificationRepo.findByStatusWithUpdateTime(Mockito.any(), Mockito.any())) .thenReturn(Arrays.asList(notification)); diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/IamAccountServiceTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/IamAccountServiceTests.java index 468408530..dc3cdeec8 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/IamAccountServiceTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/IamAccountServiceTests.java @@ -21,13 +21,13 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -109,11 +109,11 @@ public class IamAccountServiceTests extends IamAccountServiceTestSupport { @Before public void setup() { - when(accountRepo.findProvisionedAccountsWithLastLoginTimeBeforeTimestamp(anyObject())) + when(accountRepo.findProvisionedAccountsWithLastLoginTimeBeforeTimestamp(any())) .thenReturn(emptyList()); when(accountRepo.findByCertificateSubject(anyString())).thenReturn(Optional.empty()); when(accountRepo.findBySshKeyValue(anyString())).thenReturn(Optional.empty()); - when(accountRepo.findBySamlId(anyObject())).thenReturn(Optional.empty()); + when(accountRepo.findBySamlId(any())).thenReturn(Optional.empty()); when(accountRepo.findByOidcId(anyString(), anyString())).thenReturn(Optional.empty()); when(accountRepo.findByUsername(anyString())).thenReturn(Optional.empty()); when(accountRepo.findByEmail(anyString())).thenReturn(Optional.empty()); @@ -121,7 +121,7 @@ public void setup() { when(accountRepo.findByEmail(TEST_EMAIL)).thenReturn(Optional.of(TEST_ACCOUNT)); when(authoritiesRepo.findByAuthority(anyString())).thenReturn(Optional.empty()); when(authoritiesRepo.findByAuthority("ROLE_USER")).thenReturn(Optional.of(ROLE_USER_AUTHORITY)); - when(passwordEncoder.encode(anyObject())).thenReturn(PASSWORD); + when(passwordEncoder.encode(any())).thenReturn(PASSWORD); accountService = new DefaultIamAccountService(clock, accountRepo, groupRepo, authoritiesRepo, passwordEncoder, eventPublisher, tokenService); @@ -757,7 +757,7 @@ public void testNullDeleteAccountFails() { public void testAccountDeletion() { accountService.deleteAccount(CICCIO_ACCOUNT); verify(accountRepo, times(1)).delete(CICCIO_ACCOUNT); - verify(eventPublisher, times(1)).publishEvent(anyObject()); + verify(eventPublisher, times(1)).publishEvent(any()); } @Test(expected = NullPointerException.class) @@ -773,14 +773,14 @@ public void testDeleteInactiveProvisionedAccountFailsWithNullTimestamp() { @Test public void testDeleteInactiveProvisionedAccountWorks() { - when(accountRepo.findProvisionedAccountsWithLastLoginTimeBeforeTimestamp(anyObject())) + when(accountRepo.findProvisionedAccountsWithLastLoginTimeBeforeTimestamp(any())) .thenReturn(Arrays.asList(CICCIO_ACCOUNT, TEST_ACCOUNT)); accountService.deleteInactiveProvisionedUsersSinceTime(new Date()); verify(accountRepo, times(1)).delete(CICCIO_ACCOUNT); verify(accountRepo, times(1)).delete(TEST_ACCOUNT); - verify(eventPublisher, times(2)).publishEvent(anyObject()); + verify(eventPublisher, times(2)).publishEvent(any()); } @Test diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/JavamailNotificationDeliveryTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/JavamailNotificationDeliveryTests.java index 76ce9c31f..b728567f0 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/service/JavamailNotificationDeliveryTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/service/JavamailNotificationDeliveryTests.java @@ -18,14 +18,14 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItemInArray; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import java.util.Date; @@ -88,7 +88,7 @@ public class JavamailNotificationDeliveryTests { public void setup() { when(properties.getMailFrom()).thenReturn(IAM_MAIL_FROM); - when(properties.getAdminAddress()).thenReturn(IAM_ADMIN_ADDRESS); + // when(properties.getAdminAddress()).thenReturn(IAM_ADMIN_ADDRESS); } @@ -97,26 +97,25 @@ public void testNoMessageDelivery() { when(notificationRepo.findByDeliveryStatus(IamDeliveryStatus.PENDING)).thenReturn(emptyList()); delivery.sendPendingNotifications(); - verifyZeroInteractions(mailSender); - + verifyNoInteractions(mailSender); } @Test public void testMessageIsDelivered() { - String randomUuid = UUID.randomUUID().toString(); - Date currentTime = new Date(); + // String randomUuid = UUID.randomUUID().toString(); + // Date currentTime = new Date(); IamEmailNotification notification = mock(IamEmailNotification.class); IamNotificationReceiver receiver = mock(IamNotificationReceiver.class); when(receiver.getIamEmailNotification()).thenReturn(notification); - when(receiver.getEmailAddress()).thenReturn(TEST_0_EMAIL); + // when(receiver.getEmailAddress()).thenReturn(TEST_0_EMAIL); when(notification.getBody()).thenReturn("Body"); when(notification.getSubject()).thenReturn("Subject"); when(notification.getDeliveryStatus()).thenReturn(IamDeliveryStatus.PENDING); - when(notification.getCreationTime()).thenReturn(currentTime); - when(notification.getUuid()).thenReturn(randomUuid); + // when(notification.getCreationTime()).thenReturn(currentTime); + // when(notification.getUuid()).thenReturn(randomUuid); when(notification.getReceivers()).thenReturn(asList(receiver)); @@ -146,13 +145,13 @@ public void testDeliveryErrorIsPropagated() { IamNotificationReceiver receiver = Mockito.mock(IamNotificationReceiver.class); when(receiver.getIamEmailNotification()).thenReturn(notification); - when(receiver.getEmailAddress()).thenReturn(TEST_0_EMAIL); + // when(receiver.getEmailAddress()).thenReturn(TEST_0_EMAIL); when(notification.getBody()).thenReturn("Body"); when(notification.getSubject()).thenReturn("Subject"); when(notification.getDeliveryStatus()).thenReturn(IamDeliveryStatus.PENDING); - when(notification.getCreationTime()).thenReturn(currentTime); - when(notification.getUuid()).thenReturn(randomUuid); + // when(notification.getCreationTime()).thenReturn(currentTime); + // when(notification.getUuid()).thenReturn(randomUuid); doThrow(new MailSendException("Error sending email")).when(mailSender) .send(Mockito.any(SimpleMailMessage.class)); diff --git a/iam-login-service/src/test/resources/oidc/mock_op_keys.jks b/iam-login-service/src/test/resources/oidc/mock_op_keys.jks index 7aebfb281..fe8e21d0a 100644 --- a/iam-login-service/src/test/resources/oidc/mock_op_keys.jks +++ b/iam-login-service/src/test/resources/oidc/mock_op_keys.jks @@ -1,16 +1,16 @@ { "keys": [ { - "p": "6TROgJgYA5K1z-waHOwIich2eAxvl7Tg7WLYNdOMlRgqHhUWdqR1PW38a15Jc3JVsmd0yVPVwOmpZoN13lyQgQ", + "p": "6p3laAacZIlbhUmzy_dWspO3KjNaGg59mEZEHlyFhizxd_5JqWkBY7oVes9qTQZ1rcCRQ3AY-Z4NJQEXh1_y1gPhxuTxAoh8z_rj6dRAOSXGILwPsBRC7OI42d1TaB7wpq2czuCFXEkJ4ViP4q5r-q3DxvkU6jfUyVPV3PVUmbE", "kty": "RSA", - "q": "0DUsBkm27fU9iE9WN-xN6giMwcT8PRR1ZBHpcHEmZtx_9W88cI-hBCEVfGcx_rxZ_VPKDhCJLAXPrR-5NqOe2w", - "d": "BbXAs8AtyqzcCWlAybY-lFAGC6Pfn1CdQi0QqAaDAWbiIHRMC6hs4khnKQPdMto4eXLuHam-CuzGdnidjhF-JdMlvWi2IRE1p1N_i1RlKgdRCKbZMVAFLEXMYZdHng54MGUAvecu3YHRNkrbLVsW2ufnrmlHr4YYzibG7RpNMQE", + "q": "yemiqtmBFFAp45ujD8dNtyDpdk2s547EL_Xl_QWyP4qO4Qio3QCWt6SHdlmW7GdecWELxHtveQP86frZKHVH4k0AJCStHXzbDFTE7g7UQSdz_GxuhXp93-PY4-vrk0YAIhtBWk93jdkzVO-MJpL-SIHSgGqg56DOZ-LkchIJDNM", + "d": "dq6z8x6qQ_wqTKNctwBSbaDj1GeluKgMwNL8AjdWOYeiZRI81FHFtzEpcMb-VlEIBHOk39gjq-_ZJGTKHV-v539Hj0Edh_vPwBpTMK3OYniKuqwMtjjspCZjx85U1kKlI122ncBFbwr8JfIk7mpG6QvE-rAgOi-RkOd5mPMPknx4j8kQSkkV_m5wgK5AyPqKEpk31i4KQ9whMeLXiJG_G_4P4ou9Jj2TzkF--811-lXifw8KRCe2wo00Gyow_4YQUc4XeCN-7CIbfsJ4T6w43pqkKJFj362YiSg4Ey8uvcIZBBVdEWnrRtc_TY23bnxQN3AS3MzXVdXLIYAP7B5EYQ", "e": "AQAB", "kid": "rsa1", - "qi": "yMl2fra1tta7cdw2CUk43-d1ANx8dVR6PXBOOTpihG3eDLy40GzLwXeE9Fug4CK-AC9mN9CpbeoVSxoCgp26fw", - "dp": "XIkB4Wr4lGphtHh2QCW0mZ-uyqH8odEHM4r2Sh2AeiTViYxKlpdZYh_DeoM2WBX1RU5h_AVFG0BclK3zVmGagQ", - "dq": "VPru3h4mMNeg5sri-O5VGsmkkc4R2ehIxbBd5Ev6jY9AFu_w7kxhPus19tGz4TIFVNVnKfhr1HEGw7WoBfogcw", - "n": "varvt3QRf17w2qtMShenEAml6KJadhrNoRBTs5kcZ4cCo4rE9Qg-odZoPqxWge-QXuakV7GXgbpfqK_yVcWjy2WJNdEreoTkiHLxt6_dc_fpZtwd_t4P1JAUym25QoA0WtKopGCe9kvF1uCQ9dYeVkGmAdpjkRx3nVpctpKCPFs" + "qi": "fMR75aFnPkQ4qE4kNLfZLrDX8JSLov18dz73HfevhJCEXdcFsWSEFnWOpSCBMjIPHTeTYT1wAHB_28ZY_qSBeg4I_hzUHB4HRxDdFC9hOmhm_JeB5IUEiFt8FOlH1SAD1_B8s-ek8D7NKaj2g1XPOUI6iGbXedH15QAGDJD-Uig", + "dp": "Df9Znnk2f3EKestI5NRe4cyaUvQ5XfCbYahfjAgtFzI7PdN4BZl0McT6Xxdc2jeWccVZZVKcyte5JQoJo1QAIvCcWcdy8Zm_CJGJY3v8UOyGA5H0xaaPz543khf4T-_4n5kgD9-pVTYuVrl37ChH3O7dDVPzAX5PPau4yLQCViE", + "dq": "If9n93KWLHBvDTcYlsCNUmeFR_k-QuMkH5s89YSvBcnz0updXJELz7IxaPke04F4Qoj_rT7Hf03vmQo25HwS9YTXoD5Ys91hGMtxOVBf5vSYsAkl9u2wIjHARGhmCy8_OH70WxuEWusWnJeVNq2LiXPqmNrbawUFnDJ1Gsv0oCc", + "n": "uQwX6Pg7Hi5KBzu_3qetym-4T6K1C_El24Q_QCWRj548T9yjYsjjQLqEk5xhEMBA1fe8u-Jr-_P4ylYruv50aG8iAZmNGq2jHr0tZfRDmw_-p8Kav3UOw4KDCxqEAhFOLubT-yUtYDOFMqG4Ez2ywbqw2F0tZN_7IWmX3jbUVbY23d4VZJdCKqq4Lp49xy1L0IFWPU0AIKq-0CzFY5PmkS5n89O_hcRWCCSEWAgo9xzXMMabOZT_68B3K29yzHveXLmO8GvXuZWRGW-fulNwJEi0hoVQONgUM3bq2IKg0qQMoJZ-1gzW2ASYl7GOgoCQWbRLYMK56KZp9Eg4BSf44w" } ] } \ No newline at end of file diff --git a/iam-persistence/pom.xml b/iam-persistence/pom.xml index a2a6541d1..3e1a98f67 100644 --- a/iam-persistence/pom.xml +++ b/iam-persistence/pom.xml @@ -68,8 +68,6 @@ com.google.code.gson gson - - 2.8.5 diff --git a/iam-persistence/src/main/java/it/infn/mw/iam/persistence/migrations/SpringJdbcFlywayMigration.java b/iam-persistence/src/main/java/it/infn/mw/iam/persistence/migrations/SpringJdbcFlywayMigration.java index bdeccedf7..323b07812 100644 --- a/iam-persistence/src/main/java/it/infn/mw/iam/persistence/migrations/SpringJdbcFlywayMigration.java +++ b/iam-persistence/src/main/java/it/infn/mw/iam/persistence/migrations/SpringJdbcFlywayMigration.java @@ -1,3 +1,18 @@ +/** + * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2021 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package it.infn.mw.iam.persistence.migrations; import org.springframework.jdbc.core.JdbcTemplate; diff --git a/iam-test-client/src/main/java/it/infn/mw/tc/IamClient.java b/iam-test-client/src/main/java/it/infn/mw/tc/IamClient.java index c53ccec70..9ae62391f 100644 --- a/iam-test-client/src/main/java/it/infn/mw/tc/IamClient.java +++ b/iam-test-client/src/main/java/it/infn/mw/tc/IamClient.java @@ -49,9 +49,10 @@ public class IamClient { private IamClientConfig iamClientConfig; @Bean - public FilterRegistrationBean disabledAutomaticOidcFilterRegistration( + public FilterRegistrationBean disabledAutomaticOidcFilterRegistration( OIDCAuthenticationFilter f) { - FilterRegistrationBean b = new FilterRegistrationBean(f); + FilterRegistrationBean b = + new FilterRegistrationBean(f); b.setEnabled(false); return b; } diff --git a/iam-test-client/src/main/java/it/infn/mw/tc/IamDynamicServerConfigurationService.java b/iam-test-client/src/main/java/it/infn/mw/tc/IamDynamicServerConfigurationService.java index 57ea736d5..619b0c2d3 100644 --- a/iam-test-client/src/main/java/it/infn/mw/tc/IamDynamicServerConfigurationService.java +++ b/iam-test-client/src/main/java/it/infn/mw/tc/IamDynamicServerConfigurationService.java @@ -64,7 +64,7 @@ private static class Fetcher extends CacheLoader { private static final Logger logger = LoggerFactory.getLogger(Fetcher.class); private ClientHttpRequestFactory factory; - private JsonParser parser = new JsonParser(); + private JsonParser parser; public Fetcher(ClientHttpRequestFactory factory) { this.factory = factory; diff --git a/iam-test-client/src/main/java/it/infn/mw/tc/IamOIDCClientFilter.java b/iam-test-client/src/main/java/it/infn/mw/tc/IamOIDCClientFilter.java index 2189104dd..631af7714 100644 --- a/iam-test-client/src/main/java/it/infn/mw/tc/IamOIDCClientFilter.java +++ b/iam-test-client/src/main/java/it/infn/mw/tc/IamOIDCClientFilter.java @@ -202,7 +202,7 @@ private OpenIDProviderConfiguration lookupProvider(HttpServletRequest request) { private JsonObject jsonStringSanityChecks(String jsonString) { - JsonElement jsonRoot = new JsonParser().parse(jsonString); + JsonElement jsonRoot = JsonParser.parseString(jsonString); if (!jsonRoot.isJsonObject()) { throw new AuthenticationServiceException( "Token Endpoint did not return a JSON object: " + jsonRoot); diff --git a/iam-test-client/src/main/java/it/infn/mw/tc/IamUserInfoFetcher.java b/iam-test-client/src/main/java/it/infn/mw/tc/IamUserInfoFetcher.java index d4a73d6a1..83c824f6b 100644 --- a/iam-test-client/src/main/java/it/infn/mw/tc/IamUserInfoFetcher.java +++ b/iam-test-client/src/main/java/it/infn/mw/tc/IamUserInfoFetcher.java @@ -112,7 +112,7 @@ protected ClientHttpRequest createRequest(URI url, HttpMethod method) if (!Strings.isNullOrEmpty(userInfoString)) { - JsonObject userInfoJson = new JsonParser().parse(userInfoString).getAsJsonObject(); + JsonObject userInfoJson = JsonParser.parseString(userInfoString).getAsJsonObject(); UserInfo userInfo = fromJson(userInfoJson);