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

feat: P4ADEV-1341 retrieve pdnd access token #4

Merged
merged 37 commits into from
Nov 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6dda65d
P4ADEV-1341 retrieve access token
antocalo Nov 21, 2024
b28d4c3
P4ADEV-1341 edit helm variables
antocalo Nov 21, 2024
3c14c08
P4ADEV-1341 edit helm variables
antocalo Nov 21, 2024
3729434
P4ADEV-1341 add PdndClientImplTest
antocalo Nov 21, 2024
7f98030
P4ADEV-1341 add CertUtilsTest
antocalo Nov 21, 2024
84691ee
P4ADEV-1341 add PdndUtilsTest
antocalo Nov 21, 2024
096811b
P4ADEV-1341 change generic exception
antocalo Nov 21, 2024
b3dd116
P4ADEV-1341 fix issues
antocalo Nov 21, 2024
878d5e2
P4ADEV-1341 refactor
antocalo Nov 22, 2024
717efe0
P4ADEV-1341 introduced cache token
antocalo Nov 22, 2024
3020f16
P4ADEV-1341 add JWTUtilsTest
antocalo Nov 22, 2024
9f5c044
P4ADEV-1341 add excludes to codereview
antocalo Nov 22, 2024
9516cd0
P4ADEV-1341 add unitTest
antocalo Nov 22, 2024
7bc0622
P4ADEV-1341 add PdndServiceTest
antocalo Nov 22, 2024
19c2570
P4ADEV-1341_retrievePDNDAccessToken
LarissaASLeite Nov 22, 2024
94f943c
P4ADEV-1341 fix PdndServiceTest
antocalo Nov 22, 2024
73ca6c7
Merge remote-tracking branch 'origin/P4ADEV-1341_retrievePDNDAccessTo…
antocalo Nov 22, 2024
b441102
P4ADEV-1341 fix PdndServiceTest
antocalo Nov 22, 2024
08fde8a
P4ADEV-1341 fix PdndServiceTest
antocalo Nov 22, 2024
cf54c2f
P4ADEV-1341 fix PdndServiceTest and Dockerfile
antocalo Nov 22, 2024
3ff7eca
P4ADEV-1341 fix Dockerfile
antocalo Nov 22, 2024
4b5d6fa
P4ADEV-1341 add PdndClientImplTest
antocalo Nov 22, 2024
0504483
P4ADEV-1341 add RestTemplateConfig and resolve pr requests
antocalo Nov 25, 2024
37eeb5a
P4ADEV-1341 fix import
antocalo Nov 25, 2024
126b044
P4ADEV-1341 edit timeout restTemplate
antocalo Nov 25, 2024
727ac19
P4ADEV-1341 refactor config
antocalo Nov 26, 2024
be5c7c2
P4ADEV-1341 refactor config
antocalo Nov 26, 2024
edfa8db
P4ADEV-1341 add RestTemplateConfig
antocalo Nov 26, 2024
1b95770
P4ADEV-1341 fix test
antocalo Nov 26, 2024
cde681c
P4ADEV-1341 upgrade jdk version
antocalo Nov 26, 2024
2858518
P4ADEV-1341 refactor config
antocalo Nov 26, 2024
78dd618
P4ADEV-1341 upgrade jdk version
antocalo Nov 26, 2024
c30e1dc
P4ADEV-1341 resolve isseus
antocalo Nov 26, 2024
5f328f6
P4ADEV-1341 - fix issues
antocalo Nov 27, 2024
7dfdc61
P4ADEV-1341 rename class
antocalo Nov 27, 2024
c5127af
P4ADEV-1341 fix
antocalo Nov 27, 2024
3306841
P4ADEV-1341 - rename ENV variable
antocalo Nov 27, 2024
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
Prev Previous commit
Next Next commit
P4ADEV-1341 add unitTest
antocalo committed Nov 22, 2024
commit 9516cd068330ca81c00704d4865cc53a4a5a6b6f
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ val javaJwtVersion = "4.4.0"
val jwksRsaVersion = "0.22.1"
val nimbusJoseJwtVersion = "9.47"
val jjwtVersion = "0.12.6"
val wiremockVersion = "3.9.2"

dependencies {
implementation("org.springframework.boot:spring-boot-starter")
@@ -58,8 +59,11 @@ dependencies {
// Testing
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.mockito:mockito-core")
testImplementation ("org.projectlombok:lombok")
testImplementation ("org.wiremock:wiremock-standalone:$wiremockVersion")
}

tasks.withType<Test> {
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ public class PdndClientImpl implements PdndClient {
public PdndClientImpl(RestTemplateBuilder restTemplateBuilder,
@Value("${app.pdnd.base-url}") String pdndBaseUrl) {
RestTemplate restTemplate = restTemplateBuilder.build();

ApiClient apiClient = new ApiClient(restTemplate);
apiClient.setBasePath(pdndBaseUrl);
authApi = new AuthApi(apiClient);
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package it.gov.pagopa.payhub.pdnd.connector.pdnd.service;

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

import it.gov.pagopa.payhub.pdnd.config.PdndConfig;
import it.gov.pagopa.payhub.pdnd.model.PdndGenericConfig;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class PdndClientAssertionBuilderServiceTest {


@Mock
private PdndConfig pdndConfig;

@Mock
private PdndGenericConfig pdndGenericConfig;

@InjectMocks
private PdndClientAssertionBuilderService pdndClientAssertionBuilderService;

private String pemKey = """
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCT5fdA/ZKoyLas
R5/kxfFm8KBz4v3i8k76Xd8j2vh8kBaapzn9hAHWJXOJ+GOUFOxkw1bnI2PUtZjj
tw49XrjcxQ37sOV407+B3ko49zZjNB97OPFQyZx9V3uNcBjKnM3UqNbcBwdIIlVW
Egt0Cao7gEGE1CKsaXpuZkofVgGo5f8K8IdETLJPFuspDTR4UPofDraL2HCxbsVx
dE0UBFXgB9vQmBMkPk27cz+Ze6j5wgSGME/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O60MSeToPa8dUK7+UGymL6VgarLzMjAXfYYMEO52sXlVAvVn5I8+BvvYd3B
VGf9ZyguOySZXLkoqVkAtvA7Nlr09QA6q+oWL5MCgYAsLS2PEMY/HMR1Z5P/uMxw
q7eQ7K3YYKcJpbM2da7r38UaZc/HhtiaU/XOdTnT/M/eF4hoW0yxO5YKfgurgosz
OjAnn7+Ed5S5Sh8E4EHUGCcawErZEZCtlsns0fNPGfNjadZAjq0X+5VP1EVXca0B
VrSp9ZTif3cvyxNTOogbgA==
-----END PRIVATE KEY-----
""";

@Test
void givenValidPDNDConfigWhenBuildPdndClientAssertionThenVerifyToken() throws Exception {
// Given
Mockito.when(pdndConfig.getAudience()).thenReturn("AUDIENCE");
Mockito.when(pdndConfig.getKey()).thenReturn(pemKey);

Mockito.when(pdndGenericConfig.getClientId()).thenReturn("CLIENTID");
Mockito.when(pdndGenericConfig.getPurposeId()).thenReturn("PURPOSEID");
Mockito.when(pdndGenericConfig.getKid()).thenReturn("KID");
// When
String token = pdndClientAssertionBuilderService.buildPdndClientAssertion(pdndGenericConfig);

// Then
assertNotNull(token);
}
}
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
class CertUtilsTest {

@Test
void whenPemKey2PrivateKeyThenValidKey() throws InvalidKeySpecException, NoSuchAlgorithmException, IOException {
void givenValidPrivateKeyWhenPemKey2PrivateKeyThenValidKey() throws InvalidKeySpecException, NoSuchAlgorithmException, IOException {
// Given
String pemKey = """
-----BEGIN PRIVATE KEY-----
@@ -53,7 +53,7 @@ void whenPemKey2PrivateKeyThenValidKey() throws InvalidKeySpecException, NoSuchA
}

@Test
void whenPemKey2PrivateKeyThenInvalidKey() {
void givenInvalidPrivateKeyWhenPemKey2PrivateKeyThenInvalidKey() {
// Given
String invalidPemKey = """
-----BEGIN PRIVATE KEY-----
@@ -66,7 +66,7 @@ void whenPemKey2PrivateKeyThenInvalidKey() {
}

@Test
void whenPemKey2PrivateKeyThenNullKey() {
void givenNullPrivateKeyWhenPemKey2PrivateKeyThenNullKey() {
// Given
String nullKey = null;

@@ -75,7 +75,7 @@ void whenPemKey2PrivateKeyThenNullKey() {
}

@Test
void whenExtractInlinePemBodyThenValidPem() {
void givenValidPemWhenExtractInlinePemBodyThenValidPem() {
// Given
String pemKey = """
-----BEGIN PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
class JWTUtilsTest {

@Test
public void givenValidTokenWhenIsJWTExpiredThenTokenNotExpired() {
void givenValidTokenWhenIsJWTExpiredThenTokenNotExpired() {
// Given
Date futureDate = new Date(System.currentTimeMillis() + 3600 * 1000); // 1 hour from now
String token = JWT.create()
@@ -22,7 +22,7 @@ public void givenValidTokenWhenIsJWTExpiredThenTokenNotExpired() {
}

@Test
public void givenExpiredTokenWhenIsJWTExpiredThenTokenExpired() {
void givenExpiredTokenWhenIsJWTExpiredThenTokenExpired() {
// Given
Date pastDate = new Date(System.currentTimeMillis() - 3600 * 1000); // 1 hour ago
String token = JWT.create()
@@ -33,7 +33,7 @@ public void givenExpiredTokenWhenIsJWTExpiredThenTokenExpired() {
}

@Test
public void givenInvalidTokenWhenIsJWTExpiredThenException() {
void givenInvalidTokenWhenIsJWTExpiredThenException() {
// Given
String invalidtoken = "INVALIDTOKEN";
// Then
120 changes: 0 additions & 120 deletions src/test/java/it/gov/pagopa/payhub/pdnd/utils/PdndUtilsTest.java

This file was deleted.