Skip to content

Commit

Permalink
P4ADEV-1167_add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
antocalo committed Oct 8, 2024
1 parent cf81f2e commit 075b08d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;
import it.gov.pagopa.payhub.auth.exception.custom.InvalidTokenException;
import it.gov.pagopa.payhub.auth.service.exchange.AccessTokenBuilderService;
import it.gov.pagopa.payhub.auth.utils.JWTValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -12,7 +13,6 @@
@Slf4j
public class ValidateTokenService {
private final String publicKey;
public static final String ALLOWED_TYPE = "at+JWT";
private final JWTValidator jwtValidator;

public ValidateTokenService(JWTValidator jwtValidator,
Expand All @@ -28,7 +28,7 @@ public void validate(String token) {
}

private void validateAccessType(String type) {
if(!ALLOWED_TYPE.equalsIgnoreCase(type)) {
if(!AccessTokenBuilderService.ACCESS_TOKEN_TYPE.equalsIgnoreCase(type)) {
throw new InvalidTokenException("Invalid token type " + type);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import it.gov.pagopa.payhub.auth.service.ValidateTokenService;
import it.gov.pagopa.payhub.auth.utils.CertUtils;
import it.gov.pagopa.payhub.model.generated.AccessToken;
import java.util.HashMap;
Expand All @@ -19,7 +20,7 @@

@Service
public class AccessTokenBuilderService {
private static final String ACCESS_TOKEN_TYPE = "at+JWT";
public static final String ACCESS_TOKEN_TYPE = "at+JWT";
private final String allowedAudience;
private final int expireIn;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class JWTValidatorUtils {
private static final String AUD = "AUD";
private static final String ISS = "ISS";
private static final String ACCESS_TOKEN_TYPE = "at+JWT";

public JWTValidatorUtils(WireMockServer wireMockServer) {
this.wireMockServer = wireMockServer;
}
Expand Down

0 comments on commit 075b08d

Please sign in to comment.