From 8ecbad2b176cb195eca56feca0818cf70161fa35 Mon Sep 17 00:00:00 2001 From: roger Date: Mon, 24 Feb 2025 11:23:33 +0100 Subject: [PATCH] fix sonar issues --- .../in2/vcverifier/config/BackendConfig.java | 3 +- .../config/properties/FrontendProperties.java | 9 ---- .../vcverifier/config/BackendConfigTest.java | 2 - .../properties/BackendPropertiesTest.java | 1 - .../properties/FrontendPropertiesTest.java | 1 - .../CustomAuthenticationProviderTest.java | 41 ------------------- ...stomAuthorizationRequestConverterTest.java | 5 --- ...ationResponseProcessorServiceImplTest.java | 8 ---- 8 files changed, 1 insertion(+), 69 deletions(-) diff --git a/src/main/java/es/in2/vcverifier/config/BackendConfig.java b/src/main/java/es/in2/vcverifier/config/BackendConfig.java index b0a66bc..b76f5e3 100644 --- a/src/main/java/es/in2/vcverifier/config/BackendConfig.java +++ b/src/main/java/es/in2/vcverifier/config/BackendConfig.java @@ -3,7 +3,6 @@ import es.in2.vcverifier.config.properties.BackendProperties; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import java.util.List; @@ -41,7 +40,7 @@ public String getRevocationListUri() { return getSelectedTrustFramework().revokedCredentialListUrl().uri(); } - // todo currently unused + // todo currently unused, will be used when Verifier can manage multiple trustframeworks public List getAllTrustFrameworks() { return properties.trustFrameworks(); } diff --git a/src/main/java/es/in2/vcverifier/config/properties/FrontendProperties.java b/src/main/java/es/in2/vcverifier/config/properties/FrontendProperties.java index db4eccd..cea0658 100644 --- a/src/main/java/es/in2/vcverifier/config/properties/FrontendProperties.java +++ b/src/main/java/es/in2/vcverifier/config/properties/FrontendProperties.java @@ -4,7 +4,6 @@ import org.hibernate.validator.constraints.URL; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; -import org.springframework.boot.context.properties.bind.ConstructorBinding; import org.springframework.validation.annotation.Validated; @Validated @@ -15,14 +14,6 @@ public record FrontendProperties( @NotNull String logoSrc, String faviconSrc) { - @ConstructorBinding - public FrontendProperties(Urls urls, Colors colors, String logoSrc, String faviconSrc) { - this.urls = urls; - this.colors = colors; - this.logoSrc = logoSrc; - this.faviconSrc = faviconSrc; - } - public record Urls( @NotNull @URL String onboarding, @NotNull @URL String support, diff --git a/src/test/java/es/in2/vcverifier/config/BackendConfigTest.java b/src/test/java/es/in2/vcverifier/config/BackendConfigTest.java index 377450f..ae964da 100644 --- a/src/test/java/es/in2/vcverifier/config/BackendConfigTest.java +++ b/src/test/java/es/in2/vcverifier/config/BackendConfigTest.java @@ -1,6 +1,5 @@ package es.in2.vcverifier.config; -import es.in2.vcverifier.config.BackendConfig; import es.in2.vcverifier.config.properties.BackendProperties; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -9,7 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/es/in2/vcverifier/config/properties/BackendPropertiesTest.java b/src/test/java/es/in2/vcverifier/config/properties/BackendPropertiesTest.java index 9ae7e20..4d038f8 100644 --- a/src/test/java/es/in2/vcverifier/config/properties/BackendPropertiesTest.java +++ b/src/test/java/es/in2/vcverifier/config/properties/BackendPropertiesTest.java @@ -5,7 +5,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import java.util.List; diff --git a/src/test/java/es/in2/vcverifier/config/properties/FrontendPropertiesTest.java b/src/test/java/es/in2/vcverifier/config/properties/FrontendPropertiesTest.java index 96d92d8..c382f42 100644 --- a/src/test/java/es/in2/vcverifier/config/properties/FrontendPropertiesTest.java +++ b/src/test/java/es/in2/vcverifier/config/properties/FrontendPropertiesTest.java @@ -5,7 +5,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/es/in2/vcverifier/security/filters/CustomAuthenticationProviderTest.java b/src/test/java/es/in2/vcverifier/security/filters/CustomAuthenticationProviderTest.java index 83f8882..003fd1e 100644 --- a/src/test/java/es/in2/vcverifier/security/filters/CustomAuthenticationProviderTest.java +++ b/src/test/java/es/in2/vcverifier/security/filters/CustomAuthenticationProviderTest.java @@ -88,19 +88,6 @@ void authenticate_validAuthorizationCodeGrant_withEmployeeCredential_success() t when(registeredClientRepository.findByClientId(clientId)).thenReturn(registeredClient); when(registeredClient.getClientId()).thenReturn("test-client-id"); -// SecurityProperties.TokenProperties tokenProperties = mock(SecurityProperties.TokenProperties.class); -// SecurityProperties.TokenProperties.AccessTokenProperties accessTokenProperties = mock(SecurityProperties.TokenProperties.AccessTokenProperties.class); -// SecurityProperties.TokenProperties.IdTokenProperties idTokenProperties = mock(SecurityProperties.TokenProperties.IdTokenProperties.class); - -// when(securityProperties.token()).thenReturn(tokenProperties); -// when(tokenProperties.accessToken()).thenReturn(accessTokenProperties); -// when(accessTokenProperties.expiration()).thenReturn("3600"); -// when(accessTokenProperties.cronUnit()).thenReturn("SECONDS"); -// when(tokenProperties.idToken()).thenReturn(idTokenProperties); -// when(idTokenProperties.expiration()).thenReturn("3600"); -// when(idTokenProperties.cronUnit()).thenReturn("SECONDS"); -// when(backendConfig.getUrl()).thenReturn("https://auth.server"); - JsonNode vcJsonNode = mock(JsonNode.class); when(objectMapper.convertValue(vcMap, JsonNode.class)).thenReturn(vcJsonNode); @@ -163,17 +150,6 @@ void authenticate_validClientCredentialsGrant_withMachineCredential_success() th when(registeredClient.getClientId()).thenReturn(clientId); when(registeredClient.getId()).thenReturn("registered-client-id"); -// SecurityProperties.TokenProperties tokenProperties = mock(SecurityProperties.TokenProperties.class); -// SecurityProperties.TokenProperties.AccessTokenProperties accessTokenProperties = mock(SecurityProperties.TokenProperties.AccessTokenProperties.class); -// SecurityProperties.TokenProperties.IdTokenProperties idTokenProperties = mock(SecurityProperties.TokenProperties.IdTokenProperties.class); -// -// when(securityProperties.token()).thenReturn(tokenProperties); -// when(tokenProperties.accessToken()).thenReturn(accessTokenProperties); -// when(accessTokenProperties.expiration()).thenReturn("3600"); -// when(accessTokenProperties.cronUnit()).thenReturn("SECONDS"); -// when(tokenProperties.idToken()).thenReturn(idTokenProperties); -// when(idTokenProperties.expiration()).thenReturn("3600"); -// when(idTokenProperties.cronUnit()).thenReturn("SECONDS"); when(backendConfig.getUrl()).thenReturn("https://auth.server"); JsonNode vcJsonNode = mock(JsonNode.class); @@ -355,10 +331,6 @@ void authenticate_OAuth2AuthorizationCodeAuthenticationToken_without_audience_ma RegisteredClient registeredClient = mock(RegisteredClient.class); when(registeredClientRepository.findByClientId(clientId)).thenReturn(registeredClient); -// when(securityProperties.token()).thenReturn(mock(SecurityProperties.TokenProperties.class)); -// when(securityProperties.token().accessToken()).thenReturn(mock(SecurityProperties.TokenProperties.AccessTokenProperties.class)); -// when(securityProperties.token().accessToken().expiration()).thenReturn("3600"); -// when(securityProperties.token().accessToken().cronUnit()).thenReturn("SECONDS"); JsonNode jsonNode = mock(JsonNode.class); when(objectMapper.convertValue(additionalParameters.get("vc"), JsonNode.class)).thenReturn(jsonNode); @@ -395,17 +367,6 @@ void authenticate_withProfileAndEmailScopes_addsCorrespondingClaims() throws Exc when(registeredClient.getClientId()).thenReturn(clientId); when(registeredClient.getId()).thenReturn("registered-client-id"); -// SecurityProperties.TokenProperties tokenProperties = mock(SecurityProperties.TokenProperties.class); -// SecurityProperties.TokenProperties.AccessTokenProperties accessTokenProperties = mock(SecurityProperties.TokenProperties.AccessTokenProperties.class); -// SecurityProperties.TokenProperties.IdTokenProperties idTokenProperties = mock(SecurityProperties.TokenProperties.IdTokenProperties.class); - -// when(securityProperties.token()).thenReturn(tokenProperties); -// when(tokenProperties.accessToken()).thenReturn(accessTokenProperties); -// when(accessTokenProperties.expiration()).thenReturn("3600"); -// when(accessTokenProperties.cronUnit()).thenReturn("SECONDS"); -// when(tokenProperties.idToken()).thenReturn(idTokenProperties); -// when(idTokenProperties.expiration()).thenReturn("3600"); -// when(idTokenProperties.cronUnit()).thenReturn("SECONDS"); when(backendConfig.getUrl()).thenReturn("https://auth.server"); // Mock verifiable credential @@ -469,8 +430,6 @@ void authenticate_withProfileAndEmailScopes_addsCorrespondingClaims() throws Exc } } - - @Test void supports_returnsTrue_forAuthorizationCodeAuthenticationToken() { boolean result = customAuthenticationProvider.supports(OAuth2AuthorizationCodeAuthenticationToken.class); diff --git a/src/test/java/es/in2/vcverifier/security/filters/CustomAuthorizationRequestConverterTest.java b/src/test/java/es/in2/vcverifier/security/filters/CustomAuthorizationRequestConverterTest.java index b8d21c4..4168400 100644 --- a/src/test/java/es/in2/vcverifier/security/filters/CustomAuthorizationRequestConverterTest.java +++ b/src/test/java/es/in2/vcverifier/security/filters/CustomAuthorizationRequestConverterTest.java @@ -13,12 +13,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.security.oauth2.core.AuthorizationGrantType; import org.springframework.security.oauth2.core.OAuth2AuthenticationException; import org.springframework.security.oauth2.core.OAuth2Error; @@ -329,7 +327,6 @@ void convert_fapiRequestWithRequestUri_shouldProcessSuccessfully() throws Except when(backendConfig.getUrl()).thenReturn("https://auth.server.com"); -// when(flagsProperties.isNonceRequiredOnFapiProfile()).thenReturn(true); // Act & Assert OAuth2AuthorizationCodeRequestAuthenticationException exception = assertThrows( OAuth2AuthorizationCodeRequestAuthenticationException.class, @@ -483,8 +480,6 @@ void convert_validFAPIRequestWithRequestParameter_shouldProcessSuccessfully() { when(backendConfig.getUrl()).thenReturn("https://auth.server.com"); -// when(flagsProperties.isNonceRequiredOnFapiProfile()).thenReturn(true); - // Act & Assert OAuth2AuthorizationCodeRequestAuthenticationException exception = assertThrows( OAuth2AuthorizationCodeRequestAuthenticationException.class, diff --git a/src/test/java/es/in2/vcverifier/service/AuthorizationResponseProcessorServiceImplTest.java b/src/test/java/es/in2/vcverifier/service/AuthorizationResponseProcessorServiceImplTest.java index 819fbaf..ca578f2 100644 --- a/src/test/java/es/in2/vcverifier/service/AuthorizationResponseProcessorServiceImplTest.java +++ b/src/test/java/es/in2/vcverifier/service/AuthorizationResponseProcessorServiceImplTest.java @@ -73,9 +73,6 @@ void processAuthResponse_validInput_shouldProcessSuccessfully() { .scope("read") .build(); -// SecurityProperties.TokenProperties.AccessTokenProperties accessTokenProperties = mock(SecurityProperties.TokenProperties.AccessTokenProperties.class); -// SecurityProperties.TokenProperties tokenProperties = mock(SecurityProperties.TokenProperties.class); - when(cacheStoreForOAuth2AuthorizationRequest.get(state)).thenReturn(oAuth2AuthorizationRequest); doNothing().when(cacheStoreForOAuth2AuthorizationRequest).delete(state); @@ -84,11 +81,6 @@ void processAuthResponse_validInput_shouldProcessSuccessfully() { when(registeredClientRepository.findByClientId("client-id")).thenReturn(registeredClient); -// when(securityProperties.token()).thenReturn(tokenProperties); -// when(tokenProperties.accessToken()).thenReturn(accessTokenProperties); -// when(accessTokenProperties.expiration()).thenReturn("5"); -// when(accessTokenProperties.cronUnit()).thenReturn("MINUTES"); - doNothing().when(oAuth2AuthorizationService).save(any(OAuth2Authorization.class)); // Act