Search in sources :

Example 1 with PaymentConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent in project openbanking-aspsp by OpenBankingToolkit.

the class PaymentsRequestPaymentIdEndpointWrapperTest method verifyAccessUsing_GrantTypeWrong.

@Test
public void verifyAccessUsing_GrantTypeWrong() throws Exception {
    // given
    PaymentConsent payment = FRDomesticConsent.builder().status(ConsentStatusCode.AUTHORISED).build();
    String jws = jws("payments", OIDCConstants.GrantType.AUTHORIZATION_CODE);
    wrapper.authorization("Bearer " + jws);
    when(amResourceServerService.verifyAccessToken("Bearer " + jws)).thenReturn((SignedJWT) JWTParser.parse(jws));
    // then
    // When
    OBErrorException obErrorException = catchThrowableOfType(() -> wrapper.payment(payment).applyFilters(), OBErrorException.class);
    assertThat(obErrorException.getObriErrorType().getHttpStatus().value()).isEqualTo(403);
    assertThat(obErrorException.getOBError().getErrorCode()).isEqualTo(ErrorCode.OBRI_ACCESS_TOKEN_INVALID.getValue());
    assertThat(obErrorException.getMessage()).isEqualTo("The access token grant type AUTHORIZATION_CODE doesn't match one of the expected grant types [CLIENT_CREDENTIAL]");
}
Also used : PaymentConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) Test(org.junit.Test)

Example 2 with PaymentConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent in project openbanking-aspsp by OpenBankingToolkit.

the class PaymentsRequestPaymentIdEndpointWrapperTest method verifyAccessToken.

@Test
public void verifyAccessToken() throws Exception {
    // given
    PaymentConsent payment = FRDomesticConsent.builder().status(ConsentStatusCode.AUTHORISED).build();
    String jws = jws("payments", OIDCConstants.GrantType.CLIENT_CREDENTIAL);
    wrapper.authorization("Bearer " + jws);
    when(amResourceServerService.verifyAccessToken("Bearer " + jws)).thenReturn((SignedJWT) JWTParser.parse(jws));
    // then
    assertThatCode(() -> {
        wrapper.payment(payment).verifyAccessToken(Arrays.asList("payments"), Arrays.asList(OIDCConstants.GrantType.CLIENT_CREDENTIAL));
    }).doesNotThrowAnyException();
}
Also used : PaymentConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent) Test(org.junit.Test)

Example 3 with PaymentConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent in project openbanking-aspsp by OpenBankingToolkit.

the class PaymentsSubmissionEndpointWrapperTest method verifyPaymentStatus_notConsented.

@Test
public void verifyPaymentStatus_notConsented() throws Exception {
    // given
    PaymentConsent payment = FRDomesticConsent.builder().status(ConsentStatusCode.ACCEPTEDTECHNICALVALIDATION).build();
    // When
    OBErrorException obErrorException = catchThrowableOfType(() -> wrapper.payment(payment).verifyPaymentStatus(), OBErrorException.class);
    assertThat(obErrorException.getObriErrorType().getHttpStatus().value()).isEqualTo(406);
    assertThat(obErrorException.getMessage()).isEqualTo("Payment invalid. Payment request hasn't been authorised by the PSU yet. Payment request status: 'ACCEPTEDTECHNICALVALIDATION'");
}
Also used : PaymentConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) Test(org.junit.Test)

Example 4 with PaymentConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent in project openbanking-aspsp by OpenBankingToolkit.

the class PaymentsSubmissionEndpointWrapperTest method verifyPaymentStatus_complete.

@Test
public void verifyPaymentStatus_complete() throws Exception {
    // given
    PaymentConsent payment = FRDomesticConsent.builder().status(ConsentStatusCode.AUTHORISED).build();
    // then
    assertThatCode(() -> {
        wrapper.payment(payment).verifyPaymentStatus();
    }).doesNotThrowAnyException();
}
Also used : PaymentConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent) Test(org.junit.Test)

Example 5 with PaymentConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent in project openbanking-aspsp by OpenBankingToolkit.

the class PaymentsSubmissionEndpointWrapperTest method verifyAccessUsing_GrantTypeWrong.

@Test
public void verifyAccessUsing_GrantTypeWrong() throws Exception {
    // given
    PaymentConsent payment = FRDomesticConsent.builder().status(ConsentStatusCode.AUTHORISED).build();
    String jws = jws("payments", OIDCConstants.GrantType.CLIENT_CREDENTIAL);
    wrapper.authorization("Bearer " + jws);
    // mock handled stubbed
    when(amResourceServerService.verifyAccessToken("Bearer " + jws)).thenReturn((SignedJWT) JWTParser.parse(jws));
    // then
    // When
    OBErrorException obErrorException = catchThrowableOfType(() -> wrapper.payment(payment).applyFilters(), OBErrorException.class);
    assertThat(obErrorException.getObriErrorType().getHttpStatus().value()).isEqualTo(403);
    assertThat(obErrorException.getOBError().getErrorCode()).isEqualTo(ErrorCode.OBRI_ACCESS_TOKEN_INVALID.getValue());
    assertThat(obErrorException.getMessage()).isEqualTo("The access token grant type CLIENT_CREDENTIAL doesn't match one of the expected grant types [AUTHORIZATION_CODE, HEADLESS_AUTH]");
}
Also used : PaymentConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) Test(org.junit.Test)

Aggregations

PaymentConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent)10 Test (org.junit.Test)10 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)5 EventSubject (com.forgerock.openbanking.common.services.notification.EventSubject)1