|
| 1 | +/* |
| 2 | + * Copyright 2018-2021 adorsys GmbH & Co KG |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package de.adorsys.aspsp.xs2a.connector.spi.impl.authorisation; |
| 18 | + |
| 19 | +import de.adorsys.aspsp.xs2a.connector.spi.impl.SpiMockData; |
| 20 | +import de.adorsys.psd2.xs2a.core.profile.ScaApproach; |
| 21 | +import de.adorsys.psd2.xs2a.core.sca.ScaStatus; |
| 22 | +import de.adorsys.psd2.xs2a.core.tpp.TppInfo; |
| 23 | +import de.adorsys.psd2.xs2a.spi.domain.SpiAspspConsentDataProvider; |
| 24 | +import de.adorsys.psd2.xs2a.spi.domain.SpiContextData; |
| 25 | +import de.adorsys.psd2.xs2a.spi.domain.authorisation.SpiStartAuthorisationResponse; |
| 26 | +import de.adorsys.psd2.xs2a.spi.domain.psu.SpiPsuData; |
| 27 | +import de.adorsys.psd2.xs2a.spi.domain.response.SpiResponse; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 30 | +import org.mockito.Mock; |
| 31 | +import org.mockito.Mockito; |
| 32 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 33 | + |
| 34 | +import java.util.UUID; |
| 35 | + |
| 36 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 37 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 38 | + |
| 39 | +@ExtendWith(MockitoExtension.class) |
| 40 | +class AbstractAuthorisationSpiTest { |
| 41 | + private static final String PSU_ID = "anton.brueckner"; |
| 42 | + private static final String AUTHORISATION_ID = "authorisation Id"; |
| 43 | + private static final ScaApproach DECOUPLED_APPROACH = ScaApproach.DECOUPLED; |
| 44 | + private static final ScaApproach NON_DECOUPLED_APPROACH = ScaApproach.EMBEDDED; |
| 45 | + private static final ScaStatus SCA_STATUS = ScaStatus.PSUAUTHENTICATED; |
| 46 | + private static final SpiPsuData PSU_ID_DATA_1 = SpiPsuData.builder() |
| 47 | + .psuId(PSU_ID) |
| 48 | + .psuIdType("2") |
| 49 | + .psuCorporateId("3") |
| 50 | + .psuCorporateIdType("4") |
| 51 | + .psuIpAddress("5") |
| 52 | + .psuIpPort("6") |
| 53 | + .psuUserAgent("7") |
| 54 | + .psuGeoLocation("8") |
| 55 | + .psuAccept("9") |
| 56 | + .psuAcceptCharset("10") |
| 57 | + .psuAcceptEncoding("11") |
| 58 | + .psuAcceptLanguage("12") |
| 59 | + .psuHttpMethod("13") |
| 60 | + .psuDeviceId(UUID.randomUUID()) |
| 61 | + .build(); |
| 62 | + private static final String ACCESS_TOKEN = "access_token"; |
| 63 | + private static final SpiContextData SPI_CONTEXT_DATA = new SpiContextData(PSU_ID_DATA_1, new TppInfo(), UUID.randomUUID(), UUID.randomUUID(), ACCESS_TOKEN, null, null, null, null); |
| 64 | + |
| 65 | + private final AbstractAuthorisationSpi authorisationSpi = Mockito.mock(AbstractAuthorisationSpi.class, Mockito.CALLS_REAL_METHODS); |
| 66 | + |
| 67 | + @Mock |
| 68 | + private SpiAspspConsentDataProvider spiAspspConsentDataProvider; |
| 69 | + |
| 70 | + @Test |
| 71 | + void startAuthorisation_decoupledApproach() { |
| 72 | + //Given |
| 73 | + String expected = SpiMockData.DECOUPLED_PSU_MESSAGE; |
| 74 | + |
| 75 | + //When |
| 76 | + SpiResponse<SpiStartAuthorisationResponse> actual = |
| 77 | + authorisationSpi.startAuthorisation(SPI_CONTEXT_DATA, DECOUPLED_APPROACH, SCA_STATUS, AUTHORISATION_ID, null, spiAspspConsentDataProvider); |
| 78 | + |
| 79 | + //Then |
| 80 | + assertNotNull(actual.getPayload()); |
| 81 | + assertEquals(expected, actual.getPayload().getPsuMessage()); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + void startAuthorisation_nonDecoupledApproach() { |
| 86 | + //Given |
| 87 | + String expected = SpiMockData.PSU_MESSAGE_START_AUTHORISATION; |
| 88 | + |
| 89 | + //When |
| 90 | + SpiResponse<SpiStartAuthorisationResponse> actual = |
| 91 | + authorisationSpi.startAuthorisation(SPI_CONTEXT_DATA, NON_DECOUPLED_APPROACH, SCA_STATUS, AUTHORISATION_ID, null, spiAspspConsentDataProvider); |
| 92 | + |
| 93 | + //Then |
| 94 | + assertNotNull(actual.getPayload()); |
| 95 | + assertEquals(expected, actual.getPayload().getPsuMessage()); |
| 96 | + } |
| 97 | +} |
0 commit comments