Search in sources :

Example 1 with Aspsp

use of net.petafuel.styx.core.banklookup.sad.entities.Aspsp in project styx by petafuel.

the class SADTest method testXS2AStandardInitialisationProduction.

@ParameterizedTest
@MethodSource("BICProvider")
@DisplayName("testXS2AStandardInitialisationProduction() -> Check if PRODUCTION XS2AStandards can be created for all available BICs in SAD")
public void testXS2AStandardInitialisationProduction(String bic) throws BankNotFoundException, BankLookupFailedException {
    SAD sad = new SAD();
    Aspsp bank = PersistentSAD.getByBIC(bic);
    XS2AStandard xs2AStandard = sad.getBankByBIC(bic);
    try {
        Assertions.assertAll(() -> {
            if (bank.getProductionUrl().getCommonUrl() == null) {
                if (bank.getProductionUrl().getAisUrl() != null) {
                    Assert.assertTrue("AIS Url was specified but no Consent Service was initialized", xs2AStandard.isCSImplemented());
                    Assert.assertTrue("AIS Url was specified but no related Service was initialized", xs2AStandard.isAISImplemented());
                }
                if (bank.getProductionUrl().getPisUrl() != null) {
                    Assert.assertTrue("PIS Url was specified but no related Service was initialized", xs2AStandard.isPISImplemented());
                }
                if (bank.getProductionUrl().getPiisUrl() != null) {
                    Assert.assertTrue("PIIS Url was specified but no related Service was initialized", xs2AStandard.isPIISImplemented());
                }
            } else {
                boolean atLeastOneServiceImplemented = false;
                if ((xs2AStandard.isAISImplemented() && xs2AStandard.isCSImplemented()) || xs2AStandard.isPIISImplemented() || xs2AStandard.isPISImplemented()) {
                    atLeastOneServiceImplemented = true;
                }
                Assert.assertTrue("General Url was specified but no related Service was initialized", atLeastOneServiceImplemented);
            }
        });
    } catch (MultipleFailuresError e) {
        if (!bank.isActive()) {
            System.err.println("Test failed for bic=" + bic + " but bank is deactivated in styx: ");
            e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
            Assert.assertTrue(true);
        } else {
            System.err.println("Test failed for bic=" + bic + ": " + e.getMessage());
            e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
            Assert.fail();
        }
    }
}
Also used : Persistence(net.petafuel.styx.core.persistence.Persistence) Connection(java.sql.Connection) MultipleFailuresError(org.opentest4j.MultipleFailuresError) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) Arguments(org.junit.jupiter.params.provider.Arguments) PreparedStatement(java.sql.PreparedStatement) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SQLException(java.sql.SQLException) Stream(java.util.stream.Stream) ResultSet(java.sql.ResultSet) Assertions(org.junit.jupiter.api.Assertions) Tag(org.junit.jupiter.api.Tag) Assert(org.junit.Assert) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) SAD(net.petafuel.styx.core.banklookup.sad.SAD) PersistentSAD(net.petafuel.styx.core.persistence.layers.PersistentSAD) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException) MethodSource(org.junit.jupiter.params.provider.MethodSource) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) SAD(net.petafuel.styx.core.banklookup.sad.SAD) PersistentSAD(net.petafuel.styx.core.persistence.layers.PersistentSAD) MultipleFailuresError(org.opentest4j.MultipleFailuresError) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with Aspsp

use of net.petafuel.styx.core.banklookup.sad.entities.Aspsp in project styx by petafuel.

the class SADTest method testPersistentSAD.

@ParameterizedTest
@MethodSource("BICProvider")
public void testPersistentSAD(String bic) throws SQLException {
    Aspsp bank = PersistentSAD.getByBIC(bic);
    Assert.assertNotNull(bank);
    Assert.assertEquals(bic, bank.getBic());
    Assert.assertNotNull(bank.getAspspGroup());
    Assert.assertNotNull(bank.getConfig());
    Connection connection = Persistence.getInstance().getConnection();
    ResultSet resultSet;
    int sandboxUrlsId = bank.getSandboxUrl().getId();
    try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT * from urls WHERE id = ?")) {
        preparedStatement.setInt(1, sandboxUrlsId);
        resultSet = preparedStatement.executeQuery();
        resultSet.next();
        Assert.assertNotNull(bank.getSandboxUrl());
        if (bank.getSandboxUrl().getCommonUrl() == null) {
            Assert.assertNotNull(bank.getSandboxUrl().getAisUrl());
            Assert.assertEquals(resultSet.getString("ais_url"), bank.getSandboxUrl().getAisUrl());
            Assert.assertNotNull(bank.getSandboxUrl().getPisUrl());
            Assert.assertEquals(resultSet.getString("pis_url"), bank.getSandboxUrl().getPisUrl());
            Assert.assertNotNull(bank.getSandboxUrl().getPiisUrl());
            Assert.assertEquals(resultSet.getString("piis_url"), bank.getSandboxUrl().getPiisUrl());
        } else {
            Assert.assertNotNull(bank.getSandboxUrl().getCommonUrl());
            Assert.assertEquals(resultSet.getString("url"), bank.getSandboxUrl().getCommonUrl());
        }
    }
    int productionUrlsId = bank.getProductionUrl().getId();
    try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT * from urls WHERE id = ?")) {
        preparedStatement.setInt(1, productionUrlsId);
        resultSet = preparedStatement.executeQuery();
        resultSet.next();
        Assert.assertNotNull(bank.getProductionUrl());
        if (bank.getProductionUrl().getCommonUrl() == null) {
            Assert.assertNotNull(bank.getProductionUrl().getAisUrl());
            Assert.assertEquals(resultSet.getString("ais_url"), bank.getProductionUrl().getAisUrl());
            Assert.assertNotNull(bank.getProductionUrl().getPisUrl());
            Assert.assertEquals(resultSet.getString("pis_url"), bank.getProductionUrl().getPisUrl());
            Assert.assertNotNull(bank.getProductionUrl().getPiisUrl());
            Assert.assertEquals(resultSet.getString("piis_url"), bank.getProductionUrl().getPiisUrl());
        } else {
            Assert.assertNotNull(bank.getProductionUrl().getCommonUrl());
            Assert.assertEquals(resultSet.getString("url"), bank.getProductionUrl().getCommonUrl());
        }
    }
}
Also used : Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with Aspsp

use of net.petafuel.styx.core.banklookup.sad.entities.Aspsp in project styx by petafuel.

the class STYX05 method apply.

@Override
public boolean apply(XS2AFactoryInput xs2AFactoryInput, XS2ARequest xs2ARequest, XS2AResponse xs2AResponse) throws ImplementerOptionException {
    if (xs2AResponse instanceof StrongAuthenticatableResource) {
        Boolean optionRequired = ioParser.getOption(IO, IOParser.Option.REQUIRED);
        if (optionRequired != null && optionRequired) {
            StrongAuthenticatableResource response = (StrongAuthenticatableResource) xs2AResponse;
            String authorizationLink = response.getLinks().getScaRedirect().getUrl();
            OAuthSession oAuthSession = OAuthSession.start(response.getxRequestId());
            oAuthSession.setScope(SCAHandler.getQueryParameterValue(authorizationLink, "scope"));
            oAuthSession.setAuthorizationEndpoint(getBaseUrl(authorizationLink));
            boolean isSandbox = WebServer.isSandbox();
            Aspsp aspsp = ioParser.getAspsp();
            if (isSandbox) {
                oAuthSession.setTokenEndpoint(aspsp.getSandboxUrl().getPreauthTokenEndpoint());
            } else {
                oAuthSession.setTokenEndpoint(aspsp.getProductionUrl().getPreauthTokenEndpoint());
            }
            PersistentOAuthSession.create(oAuthSession);
            String generatedCodeChallenge = OAuthService.getCodeChallengeFromState(oAuthSession.getState());
            String codeChallengePlaceholder = SCAHandler.getQueryParameterValue(authorizationLink, "code_challenge");
            authorizationLink = authorizationLink.replace(codeChallengePlaceholder, generatedCodeChallenge) + "&state=" + oAuthSession.getState();
            response.getLinks().setScaRedirect(new Links.Href(authorizationLink, LinkType.SCA_REDIRECT));
            return true;
        }
    }
    return false;
}
Also used : Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) PersistentOAuthSession(net.petafuel.styx.core.persistence.layers.PersistentOAuthSession) Links(net.petafuel.styx.core.xs2a.entities.Links) StrongAuthenticatableResource(net.petafuel.styx.core.xs2a.entities.StrongAuthenticatableResource)

Example 4 with Aspsp

use of net.petafuel.styx.core.banklookup.sad.entities.Aspsp in project styx by petafuel.

the class SADResourceTest method GetAspspDataSuccessTest.

@Test
@Category(IntegrationTest.class)
public void GetAspspDataSuccessTest() throws BankLookupFailedException, BankNotFoundException {
    Aspsp aspsp = getAspspByBic(BIC);
    Map<String, ImplementerOption> implementerOptions = aspsp.getConfig().getImplementerOptions();
    Invocation.Builder invocationBuilder = target("/v1/aspsp/" + BIC).request();
    invocationBuilder.header("token", pisAccessToken);
    invocationBuilder.header("Content-Type", "application/json");
    Invocation invocation = invocationBuilder.buildGet();
    Response response = invocation.invoke(Response.class);
    Assertions.assertEquals(200, response.getStatus());
    JsonObject jsonResponse = response.readEntity(JsonObject.class);
    JsonObject jsonScaApproaches = (JsonObject) jsonResponse.get("scaApproaches");
    JsonObject jsonSupportedServices = (JsonObject) jsonResponse.get("supportedServices");
    JsonObject jsonSupportedServicesAis = (JsonObject) jsonSupportedServices.get("ais");
    JsonObject jsonSupportedServicesCof = (JsonObject) jsonSupportedServices.get("cof");
    JsonObject jsonSupportedServicesPis = (JsonObject) jsonSupportedServices.get("pis");
    Assertions.assertEquals(aspsp.isActive(), jsonResponse.getBoolean("active"));
    Assertions.assertEquals(aspsp.getName(), jsonResponse.getString("name"));
    Assertions.assertFalse(jsonResponse.getBoolean("multicurrencyAccountsSupported"));
    Assertions.assertFalse(jsonResponse.getBoolean("prestepRequired"));
    Assertions.assertTrue(jsonResponse.containsKey("scaApproaches"));
    Assertions.assertEquals(implementerOptions.get("IO5").getOptions().get("decoupled"), jsonScaApproaches.getBoolean("decoupled"));
    Assertions.assertEquals(implementerOptions.get("IO5").getOptions().get("embedded"), jsonScaApproaches.getBoolean("embedded"));
    Assertions.assertEquals(implementerOptions.get("IO5").getOptions().get("oauth"), jsonScaApproaches.getBoolean("oAuth"));
    Assertions.assertEquals(implementerOptions.get("IO5").getOptions().get("redirect"), jsonScaApproaches.getBoolean("redirect"));
    Assertions.assertTrue(jsonResponse.containsKey("supportedServices"));
    Assertions.assertTrue(jsonSupportedServices.containsKey("ais"));
    Assertions.assertTrue(jsonSupportedServicesAis.getBoolean("accountDetails"));
    Assertions.assertTrue(jsonSupportedServicesAis.getBoolean("accountList"));
    Assertions.assertFalse(jsonSupportedServicesAis.getBoolean("accountsAccountIdTransactionsResourceId"));
    Assertions.assertFalse(jsonSupportedServicesAis.getBoolean("accountsAccountIdTransactionsWithBalance"));
    Assertions.assertFalse(jsonSupportedServicesAis.getBoolean("accountsAccountIdWithBalance"));
    Assertions.assertFalse(jsonSupportedServicesAis.getBoolean("accountsWithBalance"));
    Assertions.assertTrue(jsonSupportedServices.containsKey("cof"));
    Assertions.assertTrue(jsonSupportedServicesCof.containsKey("fundsConfirmation"));
    Assertions.assertTrue(jsonSupportedServices.containsKey("pis"));
    Assertions.assertTrue(jsonSupportedServicesPis.getBoolean("bulkPayments"));
    Assertions.assertTrue(jsonSupportedServicesPis.getBoolean("futureDatedPayments"));
    Assertions.assertTrue(jsonSupportedServicesPis.getBoolean("periodicPayments"));
    Assertions.assertTrue(jsonSupportedServicesPis.getBoolean("singlePayments"));
    Response response2 = invocation.invoke(Response.class);
    Assertions.assertEquals(200, response2.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) Invocation(javax.ws.rs.client.Invocation) JsonObject(javax.json.JsonObject) ImplementerOption(net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption) ResponseCategory(net.petafuel.styx.api.exception.ResponseCategory) Category(org.junit.experimental.categories.Category) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test) StyxRESTTest(net.petafuel.styx.api.StyxRESTTest)

Example 5 with Aspsp

use of net.petafuel.styx.core.banklookup.sad.entities.Aspsp in project styx by petafuel.

the class STYX09IntegrationTest method configure.

@Override
protected Application configure() {
    styx09Option = new ImplementerOption();
    styx09Option.setId("STYX09");
    ing = new Aspsp();
    ing.setConfig(new Config());
    ing.setBic(TEST_BIC);
    Url url = new Url();
    url.setCommonUrl("https://api.sandbox.ing.com");
    ing.setSandboxUrl(url);
    ResourceConfig config = setupFiltersAndErrorHandlers();
    if (pisAccessToken == null || Objects.equals(pisAccessToken, "")) {
        Assertions.fail("test.token.access.pis not set in test properties");
    }
    return config.register(AuthenticationResource.class).register(PaymentInitiationResource.class);
}
Also used : Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) Config(net.petafuel.styx.core.banklookup.sad.entities.Config) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ImplementerOption(net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption) Url(net.petafuel.styx.core.banklookup.sad.entities.Url) AuthenticationResource(net.petafuel.styx.api.v1.authentication.boundary.AuthenticationResource)

Aggregations

Aspsp (net.petafuel.styx.core.banklookup.sad.entities.Aspsp)17 ImplementerOption (net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption)10 Config (net.petafuel.styx.core.banklookup.sad.entities.Config)8 BeforeAll (org.junit.jupiter.api.BeforeAll)6 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 BankLookupFailedException (net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)4 BankNotFoundException (net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)4 SQLException (java.sql.SQLException)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Stream (java.util.stream.Stream)2 SAD (net.petafuel.styx.core.banklookup.sad.SAD)2 Persistence (net.petafuel.styx.core.persistence.Persistence)2 PersistentSAD (net.petafuel.styx.core.persistence.layers.PersistentSAD)2 Assert (org.junit.Assert)2 Assertions (org.junit.jupiter.api.Assertions)2