Skip to content

Commit

Permalink
fix sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rogermiretin2 committed Feb 24, 2025
1 parent 31a2f69 commit ec2e928
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 77 deletions.
3 changes: 1 addition & 2 deletions src/main/java/es/in2/vcverifier/config/BackendConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<BackendProperties.TrustFramework> getAllTrustFrameworks() {
return properties.trustFrameworks();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/es/in2/vcverifier/config/BackendConfigTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -310,10 +286,6 @@ void authenticate_OAuth2ClientCredentialsAuthenticationToken_without_vc_paramete

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");

OAuth2AuthenticationException exception = assertThrows(OAuth2AuthenticationException.class, () -> customAuthenticationProvider.authenticate(auth));

Expand All @@ -332,10 +304,6 @@ void authenticate_OAuth2AuthorizationCodeAuthenticationToken_without_vc_paramete

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");

OAuth2AuthenticationException exception = assertThrows(OAuth2AuthenticationException.class, () -> customAuthenticationProvider.authenticate(auth));

Expand All @@ -355,10 +323,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);
Expand Down Expand Up @@ -395,17 +359,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
Expand Down Expand Up @@ -469,8 +422,6 @@ void authenticate_withProfileAndEmailScopes_addsCorrespondingClaims() throws Exc
}
}



@Test
void supports_returnsTrue_forAuthorizationCodeAuthenticationToken() {
boolean result = customAuthenticationProvider.supports(OAuth2AuthorizationCodeAuthenticationToken.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down

0 comments on commit ec2e928

Please sign in to comment.