Skip to content

Commit

Permalink
Fix response authorize from idpay
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoGiuliani committed Feb 21, 2024
1 parent 9dfd37c commit 836fde0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 114 deletions.
3 changes: 0 additions & 3 deletions src/main/java/it/pagopa/swclient/mil/idpay/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public final class ErrorCode {
public static final String ERROR_NOT_FOUND_IDPAY_REST_SERVICES = MODULE_ID + "000051";
public static final String ERROR_CALLING_AUTHORIZE_REST_SERVICES = MODULE_ID + "000052";
public static final String ERROR_IDPAY_PAYMENT_INVALID_PINBLOCK = MODULE_ID + "000053";
public static final String ERROR_IDPAY_UNKNOWN_ERROR_CODE = MODULE_ID + "000054";
public static final String ERROR_RETRIEVING_SECOND_FACTOR = MODULE_ID + "000055";
public static final String ERROR_PIN_CIE_CURRENT_USER = MODULE_ID + "000056";

Expand Down Expand Up @@ -95,7 +94,6 @@ public final class ErrorCode {
public static final String ERROR_RETRIEVING_KEY_PAIR_DESCR = "Azure KV key pair retrieving error";
public static final String ERROR_CALLING_AUTHORIZE_REST_SERVICES_DESCR = "Error calling IdPay rest service with authorize transaction";
public static final String ERROR_RETRIEVING_PUBLIC_KEY_IDPAY_DESCR = "IDPay public key retrieving error";
public static final String ERROR_IDPAY_UNKNOWN_ERROR_DESCR = "IDPay responds with an unknown error 500";
public static final String ERROR_ENCRYPTING_SESSION_KEY_DESCR = "Error occurs during encrypting session key";
public static final String ERROR_RETRIEVING_SECOND_FACTOR_DESCR = "Error retrieving second factor";
public static final String ERROR_RETRIEVING_CERT_FOR_IDPAY_DESCR = "Azure KV certificate for idpay retrieving error";
Expand Down Expand Up @@ -125,7 +123,6 @@ public final class ErrorCode {
public static final String ERROR_RETRIEVING_KEY_PAIR_MSG = "[" + ERROR_RETRIEVING_KEY_PAIR + "] " + ERROR_RETRIEVING_KEY_PAIR_DESCR;
public static final String ERROR_CALLING_AUTHORIZE_REST_SERVICES_MSG = "[" + ERROR_CALLING_AUTHORIZE_REST_SERVICES + "] " + ERROR_CALLING_AUTHORIZE_REST_SERVICES_DESCR;
public static final String ERROR_RETRIEVING_PUBLIC_KEY_IDPAY_MSG = "[" + ERROR_RETRIEVING_PUBLIC_KEY_IDPAY + "] " + ERROR_RETRIEVING_PUBLIC_KEY_IDPAY_DESCR;
public static final String ERROR_IDPAY_UNKNOWN_ERROR_MSG = "[" + ERROR_IDPAY_UNKNOWN_ERROR_CODE + "] " + ERROR_IDPAY_UNKNOWN_ERROR_DESCR;
public static final String ERROR_ENCRYPTING_SESSION_KEY_MSG = "[" + ERROR_ENCRYPTING_SESSION_KEY + "] " + ERROR_ENCRYPTING_SESSION_KEY_DESCR;
public static final String ERROR_RETRIEVING_SECOND_FACTOR_MSG = "[" + ERROR_RETRIEVING_SECOND_FACTOR + "] " + ERROR_RETRIEVING_SECOND_FACTOR_DESCR;
public static final String ERROR_RETRIEVING_CERT_FOR_IDPAY_MSG = "[" + ERROR_RETRIEVING_CERT_FOR_IDPAY + "] " + ERROR_RETRIEVING_CERT_FOR_IDPAY_DESCR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
@RegisterForReflection
public class AuthTransactionResponse {

private AuthTransactionResponseOk authTransactionResponseOk;
private AuthTransactionResponseWrong authTransactionResponseWrong;
private String id;
private String trxCode;
private String initiativeId;
private TransactionStatus status;
private Long amountCents;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -673,26 +673,14 @@ private Uni<Response> authorize(IdpayTransactionEntity dbData, PinBlockDTO pinBl
}
}))
.chain(finalResult -> {
if (finalResult.getAuthTransactionResponseOk() != null) {

// If all went ok, send 200 OK to client
Log.debugf("TransactionsService -> authorizeTransaction: call to authorize returned a 200 status, response with public key: [%s]", finalResult.getAuthTransactionResponseOk());
// If all went ok, send 200 OK to client
Log.debugf("TransactionsService -> authorizeTransaction: call to authorize returned a 200 status, response with public key: [%s]", finalResult);

// Start updating transaction with new status AUTHORIZED
return updateAuthorizeTransactionStatus(dbData)
.onItem()
.transform(result -> result);
} else {

// If any other from IDPay, send INTERNAL_SERVER_ERROR to client
Log.errorf("TransactionsService -> authorizeTransaction: IDPay responds with unknown error 500 for transaction: [%s]", dbData.transactionId);
Errors errors = new Errors(List.of(ErrorCode.ERROR_IDPAY_UNKNOWN_ERROR_CODE), List.of(ErrorCode.ERROR_IDPAY_UNKNOWN_ERROR_MSG));

return Uni.createFrom().item((Response
.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(errors)
.build()));
}
// Start updating transaction with new status AUTHORIZED
return updateAuthorizeTransactionStatus(dbData)
.onItem()
.transform(result -> result);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,55 +406,6 @@ void authorizeTransactionTest_KOAuthorize400() {
Assertions.assertTrue(response.jsonPath().getList("errors").contains(ErrorCode.ERROR_IDPAY_PAYMENT_INVALID_PINBLOCK));
}

@Test
@TestSecurity(user = "testUser", roles = {"PayWithIDPay"})
void authorizeTransactionTest_KOAuthorizeOther500() {

Mockito.when(idpayTransactionRepository.findById(Mockito.any(String.class))).thenReturn(Uni.createFrom().item(idpayTransactionEntity));

Mockito.when(azureADRestClient.getAccessToken(Mockito.any(String.class), Mockito.any(String.class)))
.thenReturn((Uni.createFrom().item(azureAdAccessToken)));

Mockito.when(azureKeyVaultClient.getCertificate(Mockito.any(String.class), Mockito.any(String.class)))
.thenReturn(Uni.createFrom().item(certificateBundle));

Mockito.when(azureKeyVaultClient.getSecret(Mockito.any(String.class), Mockito.any(String.class)))
.thenReturn(Uni.createFrom().item(secretBundle));

Mockito.when(azureKeyVaultClient.unwrapKey(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(UnwrapKeyRequest.class)))
.thenReturn(Uni.createFrom().item(unwrapKeyResponse));

Mockito.when(idPayRestService.retrieveIdpayPublicKey(Mockito.any(String.class)))
.thenReturn(Uni.createFrom().item(publicKeyIDPay));

authTransactionResponse.setAuthTransactionResponseOk(null);
authTransactionResponse.setAuthTransactionResponseWrong(null);

Mockito.when(idPayRestService.authorize(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(PinBlockDTO.class)))
.thenReturn(Uni.createFrom().item(authTransactionResponse));


Response response = given()
.contentType(ContentType.JSON)
.headers(validMilHeaders)
.and()
.body(authorizeTransaction)
.pathParam("milTransactionId", transactionId)
.when()
.post("/{milTransactionId}/authorize")
.then()
.extract()
.response();

authTransactionResponse = TransactionsTestData.getAuthTransactionResponse();

Assertions.assertEquals(500, response.statusCode());
Assertions.assertEquals(1, response.jsonPath().getList("errors").size());
Assertions.assertEquals(1, response.jsonPath().getList("descriptions").size());

Assertions.assertTrue(response.jsonPath().getList("errors").contains(ErrorCode.ERROR_IDPAY_UNKNOWN_ERROR_CODE));
}

@Test
@TestSecurity(user = "testUser", roles = {"PayWithIDPay"})
void authorizeTransactionTest_KOEncryptingSessionKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public final class TransactionsTestData {

//valore vaultUrl deve coincidere con valore del parametro %test.quarkus.rest-client.azure-key-vault-api.url del application.properties
//value vaultUrl must coincide with value of param %test.quarkus.rest-client.azure-key-vault-api.url of application.properties
private static final String vaultUrl = "https://156360cd-f617-4dcb-b908-ae29a2a8651c.mock.pstmn.io";
private static final SimpleDateFormat lastUpdateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

Expand Down Expand Up @@ -266,19 +266,15 @@ public static TransactionResponse getIdentifiedTransaction() {
}

public static AuthTransactionResponse getAuthTransactionResponse() {
AuthTransactionResponse authTransactionResponse = new AuthTransactionResponse();
AuthTransactionResponseOk authTransactionResponseOk = AuthTransactionResponseOk

return AuthTransactionResponse
.builder()
.id("1")
.trxCode("12345678")
.amountCents(99999999999L)
.initiativeId("InitiativeId2")
.status(TransactionStatus.AUTHORIZED)
.build();

authTransactionResponse.setAuthTransactionResponseOk(authTransactionResponseOk);

return authTransactionResponse;
}

public static PublicKeyIDPay getPublicKeyIdPay() {
Expand Down

0 comments on commit 836fde0

Please sign in to comment.