Skip to content

Commit

Permalink
P4ADEV-1341 fix PdndServiceTest and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
antocalo committed Nov 22, 2024
1 parent 08fde8a commit cf54c2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ RUN mkdir -p src/main/java && \

USER ${APP_USER}

RUN gradle openApiGenerate dependencies --no-daemon
RUN gradle openApiGeneratePayhub dependencies --no-daemon

RUN gradle openApiGeneratePdndClient dependencies --no-daemon

#
# 🏗️ Build Stage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PdndService {

private final PdndClientImpl pdndClientImpl;
private final PdndClientAssertionBuilderService pdndClientAssertionBuilderService;
private final ConcurrentHashMap<PdndGenericConfig, String> jwtCache = new ConcurrentHashMap<>();
protected final ConcurrentHashMap<PdndGenericConfig, String> jwtCache = new ConcurrentHashMap<>();

public PdndService(PdndClientImpl pdndClientImpl,
PdndClientAssertionBuilderService pdndClientAssertionBuilderService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import static org.junit.jupiter.api.Assertions.*;

import com.nimbusds.jose.JOSEException;
import it.gov.pagopa.common.pdnd.generated.dto.ClientCredentialsResponseDTO;
import it.gov.pagopa.payhub.pdnd.connector.pdnd.client.PdndClientImpl;
import it.gov.pagopa.payhub.pdnd.connector.pdnd.service.PdndClientAssertionBuilderService;
import it.gov.pagopa.payhub.pdnd.exception.custom.JwtClaimBuildException;
import it.gov.pagopa.payhub.pdnd.model.PdndGenericConfig;
import it.gov.pagopa.payhub.pdnd.utils.JWTUtils;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -58,6 +55,22 @@ void givenValidConfigWhenGenerateTokenThenGeneratesNewToken() throws Exception {
Mockito.verify(pdndClientImpl, Mockito.times(1)).getAccessToken(clientId, clientAssertion);
}

@Test
void givenTokenInCacheWhenGenerateTokenThenReturnCachedToken() {
// Given
PdndGenericConfig config = Mockito.mock(PdndGenericConfig.class);
String cachedToken = "CACHED_TOKEN";
pdndService.jwtCache.put(config, cachedToken);

try (MockedStatic<JWTUtils> mockedStatic = Mockito.mockStatic(JWTUtils.class)) {
// When
mockedStatic.when(() -> JWTUtils.isJWTExpired(cachedToken)).thenReturn(false);
String token = pdndService.generateToken(config);

// Then
assertEquals(cachedToken, token);
}
}

@Test
void givenInvalidAssertionWhenGenerateTokenThenException() throws Exception {
Expand Down

0 comments on commit cf54c2f

Please sign in to comment.