Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core-sprint3-fixes] Fixing sonar smells #31

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,7 @@ private String calculateThumbprint(String inResponseToAlgorithm, String publicKe
throws AssertionThumbprintException {
Base64URL thumbprint;
try {
try {
publicKey = new String(Base64.getDecoder().decode(publicKey));
} catch (Exception e) {
log.log(Level.FINE, "Key not in Base64");
}
publicKey = getPublicKey(publicKey);
thumbprint = ThumbprintUtils.compute(inResponseToAlgorithm, JWK.parse(publicKey));
} catch (JOSEException | ParseException e) {
String errMsg = String.format("Can not calculate JwkThumbprint: %S", e.getMessage());
Expand All @@ -297,4 +293,13 @@ private String calculateThumbprint(String inResponseToAlgorithm, String publicKe
}
return calculatedThumbprint;
}

private String getPublicKey(String publicKey) {
try {
publicKey = new String(Base64.getDecoder().decode(publicKey));
} catch (Exception e) {
log.log(Level.FINE, "Key not in Base64");
}
return publicKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import it.pagopa.tech.lollipop.consumer.service.LollipopConsumerRequestValidationService;
import java.util.Base64;
import java.util.Map;
import java.util.logging.Level;
import java.util.regex.Pattern;
import lombok.extern.java.Log;

@Log
public class LollipopConsumerRequestValidationServiceImpl
implements LollipopConsumerRequestValidationService {

Expand Down Expand Up @@ -52,7 +55,7 @@ private void validatePublicKey(String publicKey)
try {
publicKey = new String(Base64.getDecoder().decode(publicKey.getBytes()));
} catch (Exception e) {
//
log.log(Level.FINE, "Key not in Base64");
}

if (isNotValidPublicKey(publicKey, ECPublicKey.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import it.pagopa.tech.lollipop.consumer.service.LollipopConsumerRequestValidationService;
import it.pagopa.tech.lollipop.consumer.service.impl.LollipopConsumerRequestValidationServiceImpl;
import it.pagopa.tech.lollipop.consumer.spring.HttpVerifierHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -21,22 +20,22 @@
@Configuration
public class HttpVerifierConfiguration {

@Autowired private SpringLollipopConsumerRequestConfig springLollipopConsumerRequestConfig;

@Bean
public LollipopConsumerFactoryHelper lollipopConsumerFactoryHelper(
HttpMessageVerifierFactory httpMessageVerifierFactory,
IdpCertProviderFactory idpCertProviderFactory,
AssertionServiceFactory assertionServiceFactory) {
AssertionServiceFactory assertionServiceFactory,
LollipopConsumerRequestValidationService lollipopConsumerRequestValidationService) {
return new LollipopConsumerFactoryHelper(
httpMessageVerifierFactory,
idpCertProviderFactory,
assertionServiceFactory,
getLollipopConsumerRequestValidationService());
lollipopConsumerRequestValidationService);
}

@Bean
public LollipopConsumerRequestValidationService getLollipopConsumerRequestValidationService() {
public LollipopConsumerRequestValidationService getLollipopConsumerRequestValidationService(
SpringLollipopConsumerRequestConfig springLollipopConsumerRequestConfig) {
return new LollipopConsumerRequestValidationServiceImpl(
springLollipopConsumerRequestConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
/** Class to be used for conversion of the http requests to be validated */
public class LollipopConsumerRequestConverter {

private LollipopConsumerRequestConverter() {}

/**
* Utility method to be used to generate a LollipopConsumerRequest
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void startServer() {
@Autowired private HttpVerifierHandlerInterceptor interceptor;

@Test
public void testWithValidRequestReturnsSuccess() {
void testWithValidRequestReturnsSuccess() {
AssertionSimpleClientTestUtils.createExpectationAssertionFound();

String signatureInput =
Expand Down Expand Up @@ -93,7 +93,8 @@ public void testWithValidRequestReturnsSuccess() {
Assertions.assertEquals(200, response.getStatusCodeValue());
}

public void testWithinvalidPayloadRequestReturnsUnauthorized() {
@Test
void testWithinvalidPayloadRequestReturnsUnauthorized() {
AssertionSimpleClientTestUtils.createExpectationAssertionFound();

String signatureInput =
Expand Down