Skip to content

Commit

Permalink
OBG-51: add e2e tests for delete bank admin api
Browse files Browse the repository at this point in the history
  • Loading branch information
clovisgakam committed Sep 10, 2021
1 parent ce208f6 commit f005d49
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public BankData updateBank(UUID bankId, BankData bankData) {
@Transactional
public void deleteBank(UUID bankId) {
Bank bank = bankRepository.findByUuid(bankId).orElseThrow(() -> new EntityNotFoundException("No bank: " + bankId));
bankProfileJpaRepository.deleteAll(bankProfileJpaRepository.findByBankUuid(bank.getUuid()));
bankProfileJpaRepository.deleteByBank(bank);
psuAspspPrvKeyRepository.deleteByAspsp(bank);
fintechPsuAspspPrvKeyRepository.deleteByAspsp(bank);
fintechPsuAspspPrvKeyInboxRepository.deleteByAspsp(bank);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.adorsys.opba.db.repository.jpa;

import de.adorsys.opba.db.domain.entity.Bank;
import de.adorsys.opba.db.domain.entity.BankProfile;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -14,6 +15,8 @@ public interface BankProfileJpaRepository extends JpaRepository<BankProfile, Lon

Optional<BankProfile> findByUuid(UUID uuid);

void deleteByBank(Bank bank);

List<BankProfile> findByBankUuid(UUID bankUuid);

List<BankProfile> findByBankIdIn(Collection<Long> bankIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>de.adorsys.opba</groupId>
<artifactId>opba-admin-rest-impl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>de.adorsys.opba</groupId>
<artifactId>opba-banking-rest-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@
import static de.adorsys.opba.protocol.xs2a.tests.e2e.ResourceUtil.readResource;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.AccountInformationResult.ONLINE;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.PaymentStagesCommonUtil.PIS_ANONYMOUS_LOGIN_USER_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.ADMIN_API;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.AIS_ACCOUNTS_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.AIS_LOGIN_USER_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.AIS_TRANSACTIONS_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.AIS_TRANSACTIONS_WITHOUT_RESOURCE_ID_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.ANTON_BRUECKNER;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.AUTHORIZE_CONSENT_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.BASIC_AUTH;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.DENY_CONSENT_AUTH_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.FINTECH_REDIR_NOK;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.GET_CONSENT_AUTH_STATE;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.LOGIN;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.MAX_MUSTERMAN;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.PASSWORD;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.SANDBOX_BANK_PROFILE_ID;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.headersWithAuthorization;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.withAccountsHeaders;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.withAccountsHeadersMissingIpAddress;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.withDefaultHeaders;
Expand Down Expand Up @@ -709,6 +712,15 @@ public SELF user_anton_brueckner_sees_that_he_needs_to_be_redirected_to_aspsp_an
return self();
}

public SELF open_banking_admin_delete_bank(String bankUuid) {
headersWithAuthorization(BASIC_AUTH)
.when()
.delete(ADMIN_API + "banks/" + bankUuid)
.then()
.statusCode(HttpStatus.OK.value());
return self();

}
protected ExtractableResponse<Response> startInitialInternalConsentAuthorization(String uriPath, String resourceData) {
ExtractableResponse<Response> response =
startInitialInternalConsentAuthorization(uriPath, resourceData, ACCEPTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@
import static de.adorsys.opba.protocol.xs2a.tests.HeaderNames.X_XSRF_TOKEN;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.ResourceUtil.readResource;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.RequestCommon.X_XSRF_TOKEN_QUERY;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.ADMIN_API;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.AIS_ACCOUNTS_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.AIS_TRANSACTIONS_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.ANTON_BRUECKNER;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.AUTHORIZE_CONSENT_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.BASIC_AUTH;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.CONFIRM_CONSENT_ENDPOINT;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.MAX_MUSTERMAN;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.SANDBOX_BANK_PROFILE_ID;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.SESSION_PASSWORD;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.headersWithAuthorization;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.withAccountsHeaders;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.withSignatureHeaders;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.stages.StagesCommonUtil.withTransactionsHeaders;
Expand Down Expand Up @@ -93,6 +96,13 @@ public SELF open_banking_has_consent_for_anton_brueckner_account_list() {
return self();
}

@SneakyThrows
@Transactional
public SELF open_banking_has_no_consent_for_anton_brueckner_account_list() {
assertThat(consents.findByServiceSessionIdOrderByModifiedAtDesc(UUID.fromString(serviceSessionId))).isEmpty();
return self();
}

@SneakyThrows
@Transactional
public SELF open_banking_has_no_consent() {
Expand Down Expand Up @@ -130,6 +140,18 @@ public SELF open_banking_can_read_anton_brueckner_account_data_using_consent_bou
return open_banking_can_read_anton_brueckner_account_data_using_consent_bound_to_service_session(true, bankProfileId);
}



@SneakyThrows
public SELF open_banking_admin_check_that_bank_is_deleted(String bankUuid) {
headersWithAuthorization(BASIC_AUTH)
.when()
.get(ADMIN_API + "banks/" + bankUuid)
.then()
.statusCode(HttpStatus.NOT_FOUND.value());
return self();
}

@SneakyThrows
public SELF open_banking_can_read_anton_brueckner_account_data_using_consent_bound_to_service_session(
boolean validateResourceId
Expand Down Expand Up @@ -163,6 +185,16 @@ private void open_banking_can_read_anton_brueckner_account_data_using_consent_bo
this.responseContent = response.body().asString();
}

public void open_banking_can_not_read_anton_brueckner_account_data_using_consent_bound_to_service_session_and_bank_profile_id() {
withAccountsHeaders(ANTON_BRUECKNER, SANDBOX_BANK_PROFILE_ID)
.header(SERVICE_SESSION_ID, serviceSessionId)
.when()
.get(AIS_ACCOUNTS_ENDPOINT)
.then()
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
.body("message", equalTo("No bank profile for bank: " + SANDBOX_BANK_PROFILE_ID))
.extract();
}
@SneakyThrows
public SELF open_banking_can_read_user_account_data_using_consent_bound_to_service_session(
String user, boolean validateResourceId
Expand Down Expand Up @@ -456,20 +488,24 @@ public SELF user_anton_brueckner_provided_initial_parameters_to_list_accounts_wi
return self();
}

public SELF fintech_calls_consent_activation_for_current_authorization_id(String serviceSessionId) {
public SELF fintech_calls_consent_activation_for_current_authorization_id(String serviceSessionId, HttpStatus status) {
withSignatureHeaders(RestAssured
.given()
.header(SERVICE_SESSION_PASSWORD, SESSION_PASSWORD)
.contentType(MediaType.APPLICATION_JSON_VALUE))
.when()
.post(CONFIRM_CONSENT_ENDPOINT, serviceSessionId)
.then()
.statusCode(HttpStatus.OK.value());
.statusCode(status.value());
return self();
}

public SELF fintech_calls_consent_activation_for_current_authorization_id() {
return fintech_calls_consent_activation_for_current_authorization_id(serviceSessionId);
return fintech_calls_consent_activation_for_current_authorization_id(serviceSessionId, HttpStatus.OK);
}

public SELF fintech_calls_consent_activation_for_current_authorization_id_failed_with_not_found() {
return fintech_calls_consent_activation_for_current_authorization_id(serviceSessionId, HttpStatus.NOT_FOUND);
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static de.adorsys.opba.protocol.xs2a.tests.HeaderNames.X_TIMESTAMP_UTC;
import static de.adorsys.opba.restapi.shared.HttpHeaders.COMPUTE_PSU_IP_ADDRESS;
import static de.adorsys.opba.restapi.shared.HttpHeaders.UserAgentContext.PSU_IP_ADDRESS;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;

@UtilityClass
@SuppressWarnings({"checkstyle:HideUtilityClassConstructor", "PMD.AvoidUsingHardCodedIP"}) //Checkstyle doesn't recognise Lombok
Expand Down Expand Up @@ -71,6 +72,9 @@ public class StagesCommonUtil {
public static final String POSTBANK_BANK_PROFILE_ID = "e431a602-15ab-48b8-8c9b-ce381d2034c4";
public static final String SPARKASSE_BANK_PROFILE_ID = "f31a87dd-5d3e-41b8-924a-0d85b10288bc";

public static final String ADMIN_API = "/admin/v1/";
public static final String BASIC_AUTH = "Basic QWxhZGRpbjpPcGVuU2VzYW1l";

public static RequestSpecification withAccountsHeaders(String fintechUserId) {
return withAccountsHeaders(fintechUserId, SANDBOX_BANK_PROFILE_ID);
}
Expand Down Expand Up @@ -127,6 +131,12 @@ public static RequestSpecification withSignatureHeaders(RequestSpecification spe
.header(X_TIMESTAMP_UTC, xTimestampUtc.toString());
}

public static RequestSpecification headersWithAuthorization(String authorization) {
return RestAssured
.given()
.header(AUTHORIZATION, authorization);
}

private static RequestSpecification headersWithoutIpAddress(String fintechUserId, UUID xRequestId, Instant xTimestampUtc) {
return headersWithoutIpAddress(fintechUserId, SANDBOX_BANK_PROFILE_ID, xRequestId, xTimestampUtc);
}
Expand All @@ -143,4 +153,7 @@ private static RequestSpecification headersWithoutIpAddress(String fintechUserId
.header(X_REQUEST_ID, xRequestId.toString())
.header(X_TIMESTAMP_UTC, xTimestampUtc.toString());
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class MockServers<SELF extends MockServers<SELF>> extends CommonGivenStag
public static final String POSTBANK_BANK_ID = "01aa84f2-25c0-4e02-8065-c401657e3fb0";
public static final String CONSORS_BANK_BANK_ID = "81cecc67-6d1b-4169-b67c-2de52b99a0cc";
public static final String SPARKASSE_BANK_ID = "03668d3e-c2a7-425a-b50a-f73347fbfb33";
public static final String SANDBOX_BANK_ID = "adadadad-4000-0000-0000-b0b0b0b0b0b0";


@Autowired
private BankProfileJpaRepository bankProfileJpaRepository;
Expand Down Expand Up @@ -359,7 +361,7 @@ public SELF embedded_mock_of_sandbox_for_max_musterman_transactions_running_for_

@SneakyThrows
private void startWireMock(WireMockConfiguration config) {
startWireMock(config, "adadadad-4000-0000-0000-b0b0b0b0b0b0", defaultBankProfileConfigurer);
startWireMock(config, SANDBOX_BANK_ID, defaultBankProfileConfigurer);
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package de.adorsys.opba.protocol.xs2a.tests.e2e.wiremock.mocks;

import de.adorsys.opba.adminapi.config.EnableAdminApi;
import de.adorsys.opba.api.security.internal.EnableTokenBasedApiSecurity;
import de.adorsys.opba.consentapi.config.EnableConsentApi;
import de.adorsys.opba.db.config.EnableBankingPersistence;
import de.adorsys.opba.protocol.xs2a.EnableXs2aProtocol;
import de.adorsys.opba.tppauthapi.config.EnableTppAuthApi;
import de.adorsys.opba.tppbankingapi.config.EnableBankingApi;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@EnableAdminApi
@EnableTppAuthApi
@EnableConsentApi
@EnableBankingApi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package de.adorsys.opba.protocol.xs2a.tests.e2e.wiremock;

import com.tngtech.jgiven.integration.spring.junit5.SpringScenarioTest;
import de.adorsys.opba.protocol.api.common.Approach;
import de.adorsys.opba.protocol.xs2a.config.protocol.ProtocolUrlsConfiguration;
import de.adorsys.opba.protocol.xs2a.tests.e2e.JGivenConfig;
import de.adorsys.opba.protocol.xs2a.tests.e2e.stages.AccountInformationResult;
import de.adorsys.opba.protocol.xs2a.tests.e2e.wiremock.mocks.MockServers;
import de.adorsys.opba.protocol.xs2a.tests.e2e.wiremock.mocks.WiremockAccountInformationRequest;
import de.adorsys.opba.protocol.xs2a.tests.e2e.wiremock.mocks.Xs2aProtocolApplication;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

import static de.adorsys.opba.protocol.xs2a.tests.TestProfiles.MOCKED_SANDBOX;
import static de.adorsys.opba.protocol.xs2a.tests.TestProfiles.ONE_TIME_POSTGRES_RAMFS;
import static de.adorsys.opba.protocol.xs2a.tests.e2e.wiremock.mocks.MockServers.SANDBOX_BANK_ID;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

@Sql(statements = "UPDATE opb_bank_action SET protocol_bean_name = 'xs2aListTransactions' WHERE protocol_bean_name = 'xs2aSandboxListTransactions'")

@Transactional(propagation = Propagation.NOT_SUPPORTED)
@SpringBootTest(classes = {Xs2aProtocolApplication.class, JGivenConfig.class}, webEnvironment = RANDOM_PORT, properties = {"spring.datasource.url=jdbc:tc:postgresql:12:////open_banking?TC_INITSCRIPT=init.sql"})
@ActiveProfiles(profiles = {ONE_TIME_POSTGRES_RAMFS, MOCKED_SANDBOX})
class WiremockDeleteBankAfterConsentE2EXs2aProtocolTest extends SpringScenarioTest<MockServers, WiremockAccountInformationRequest<? extends WiremockAccountInformationRequest<?>>, AccountInformationResult> {

private final String OPBA_LOGIN = UUID.randomUUID().toString();
private final String OPBA_PASSWORD = UUID.randomUUID().toString();

@LocalServerPort
private int port;

@Autowired
private ProtocolUrlsConfiguration urlsConfiguration;

@BeforeEach
void setBaseUrl() {
ProtocolUrlsConfiguration.WebHooks aisUrls = urlsConfiguration.getAis().getWebHooks();
aisUrls.setOk(aisUrls.getOk().replaceAll("localhost:\\d+", "localhost:" + port));
aisUrls.setNok(aisUrls.getNok().replaceAll("localhost:\\d+", "localhost:" + port));
}


@Test
void testBankDeletionAfterAccountsListWithConsentUsingRedirect() {
given()
.redirect_mock_of_sandbox_for_anton_brueckner_accounts_running()
.set_default_preferred_approach()
.preferred_sca_approach_selected_for_all_banks_in_opba(Approach.REDIRECT)
.rest_assured_points_to_opba_server_with_fintech_signer_on_banking_api()
.user_registered_in_opba_with_credentials(OPBA_LOGIN, OPBA_PASSWORD);

when()
.fintech_calls_list_accounts_for_anton_brueckner()
.and()
.user_logged_in_into_opba_as_opba_user_with_credentials_using_fintech_supplied_url(OPBA_LOGIN, OPBA_PASSWORD)
.and()
.user_anton_brueckner_provided_initial_parameters_to_list_accounts_with_all_accounts_consent_with_ip_address_check()
.and()
.open_banking_redirect_from_aspsp_ok_webhook_called_for_api_test()
.and()
.open_banking_admin_delete_bank(SANDBOX_BANK_ID);
then()
.open_banking_admin_check_that_bank_is_deleted(SANDBOX_BANK_ID)
.open_banking_has_no_consent_for_anton_brueckner_account_list()
.fintech_calls_consent_activation_for_current_authorization_id_failed_with_not_found()
.open_banking_can_not_read_anton_brueckner_account_data_using_consent_bound_to_service_session_and_bank_profile_id();

}
}

0 comments on commit f005d49

Please sign in to comment.