Skip to content

Commit

Permalink
Merge pull request #2369 from alphagov/PP-6364-Add-ePDQ-3DS2-contract…
Browse files Browse the repository at this point in the history
…-test

PP-6364 - Add contract test for ePDQ 3DS2
  • Loading branch information
nimalank7 authored Jun 2, 2020
2 parents 5eebced + 4d32b36 commit 7de113b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import uk.gov.pay.connector.charge.model.domain.Charge;
import uk.gov.pay.connector.charge.model.domain.ChargeEntity;
import uk.gov.pay.connector.charge.model.domain.ChargeStatus;
import uk.gov.pay.connector.common.model.domain.Address;
import uk.gov.pay.connector.gateway.CaptureResponse;
import uk.gov.pay.connector.gateway.ChargeQueryResponse;
import uk.gov.pay.connector.gateway.GatewayClient;
Expand Down Expand Up @@ -77,6 +78,13 @@
public class EpdqPaymentProviderTest {

private static final String VISA_CARD_NUMBER_RECOGNISED_AS_REQUIRING_3DS1_BY_EPDQ = "4000000000000002";
private static final String VISA_CARD_NUMBER_RECOGNISED_AS_REQUIRING_3DS2_BY_EPDQ = "4874970686672022";
private static final String ADDRESS_LINE_1 = "The Money Pool";
private static final String ADDRESS_LINE_2 = "1 Gold Way";
private static final String ADDRESS_CITY = "London";
private static final String ADDRESS_POSTCODE = "DO11 4RS";
private static final String ADDRESS_COUNTRY = "GB";
private static final String IP_ADDRESS = "8.8.8.8";

private String url = "https://mdepayments.epdq.co.uk/ncol/test";
private String merchantId = envOrThrow("GDS_CONNECTOR_EPDQ_MERCHANT_ID");
Expand Down Expand Up @@ -118,7 +126,6 @@ public void setUp() {
when(mockLinksConfig.getFrontendUrl()).thenReturn("http://frontendUrl");
when(mockGatewayConfig.getUrls()).thenReturn(Map.of(TEST.toString(), url));
when(mockMetricRegistry.histogram(anyString())).thenReturn(mockHistogram);
when(mockMetricRegistry.counter(anyString())).thenReturn(mockCounter);
when(mockEnvironment.metrics()).thenReturn(mockMetricRegistry);

Client client = TestClientFactory.createJerseyClient();
Expand Down Expand Up @@ -169,6 +176,15 @@ public void shouldAuthoriseWith3dsOnSuccessfully() throws Exception {
assertThat(response.isSuccessful(), is(true));
assertThat(response.getBaseResponse().get().authoriseStatus(), is(REQUIRES_3DS));
}

@Test
public void shouldAuthoriseWith3ds2OnSuccessfully() throws Exception {
setUpFor3ds2AndCheckThatEpdqIsUp();
CardAuthorisationGatewayRequest request = buildAuthorisationRequestThatWillRequire3ds2(chargeEntity);
GatewayResponse<BaseAuthoriseResponse> response = paymentProvider.authorise(request);
assertThat(response.isSuccessful(), is(true));
assertThat(response.getBaseResponse().get().authoriseStatus(), is(REQUIRES_3DS));
}

@Test
public void shouldAuthoriseWith3dsOnAndNoAddressInRequestSuccessfully() throws Exception {
Expand Down Expand Up @@ -294,21 +310,41 @@ private static CardAuthorisationGatewayRequest buildAuthorisationRequestThatWill
return new CardAuthorisationGatewayRequest(chargeEntity, authCardDetails);
}

private static CardAuthorisationGatewayRequest buildAuthorisationRequestThatWillRequire3ds2(ChargeEntity chargeEntity) {
AuthCardDetails authCardDetails = AuthCardDetailsFixture.anAuthCardDetails()
.withCardNo(VISA_CARD_NUMBER_RECOGNISED_AS_REQUIRING_3DS2_BY_EPDQ)
.withAddress(new Address(
ADDRESS_LINE_1,
ADDRESS_LINE_2,
ADDRESS_POSTCODE,
ADDRESS_CITY,
null,
ADDRESS_COUNTRY
))
.withIpAddress(IP_ADDRESS)
.build();
return new CardAuthorisationGatewayRequest(chargeEntity, authCardDetails);
}

private static Auth3dsResponseGatewayRequest buildQueryRequest(ChargeEntity chargeEntity, String auth3DResult) {
Auth3dsResult auth3DsResult = new Auth3dsResult();
auth3DsResult.setAuth3dsResult(auth3DResult);
return new Auth3dsResponseGatewayRequest(chargeEntity, auth3DsResult);
}

private void setUpFor3ds2AndCheckThatEpdqIsUp() {
epdqSetupWithStatusCheck(true, true);
}

private void setUpFor3dsAndCheckThatEpdqIsUp() {
epdqSetupWithStatusCheck(true);
epdqSetupWithStatusCheck(true, false);
}

private void setUpAndCheckThatEpdqIsUp() {
epdqSetupWithStatusCheck(false);
epdqSetupWithStatusCheck(false, false);
}

private void epdqSetupWithStatusCheck(boolean require3ds) {
private void epdqSetupWithStatusCheck(boolean require3ds, boolean requires3ds2) {
try {
new URL(url).openConnection().connect();
Map<String, String> validEpdqCredentials = ImmutableMap.of(
Expand All @@ -323,6 +359,11 @@ private void epdqSetupWithStatusCheck(boolean require3ds) {
gatewayAccountEntity.setCredentials(validEpdqCredentials);
gatewayAccountEntity.setType(TEST);
gatewayAccountEntity.setRequires3ds(require3ds);

if(requires3ds2) {
gatewayAccountEntity.setIntegrationVersion3ds(2);
gatewayAccountEntity.setSendPayerIpAddressToGateway(true);
}

chargeEntity = aValidChargeEntity()
.withGatewayAccountEntity(gatewayAccountEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public final class AuthCardDetailsFixture {
private Boolean corporateCard = Boolean.FALSE;
private String worldpay3dsFlexDdcResult;
private String ipAddress;
private String jsScreenColorDepth;
private String jsNavigatorLanguage;
private String jsScreenHeight;
private String jsScreenWidth;
private String jsTimezoneOffsetMins;

private AuthCardDetailsFixture() {
}
Expand Down Expand Up @@ -93,6 +98,36 @@ public AuthCardDetailsFixture withWorldpay3dsFlexDdcResult(String worldpay3dsFle
return this;
}

public AuthCardDetailsFixture withIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
return this;
}

public AuthCardDetailsFixture withJsScreenColorDepth(String jsScreenColorDepth) {
this.jsScreenColorDepth = jsScreenColorDepth;
return this;
}

public AuthCardDetailsFixture withJsNavigatorLanguage(String jsNavigatorLanguage) {
this.jsNavigatorLanguage = jsNavigatorLanguage;
return this;
}

public AuthCardDetailsFixture withJsScreenHeight(String jsScreenHeight) {
this.jsScreenHeight = jsScreenHeight;
return this;
}

public AuthCardDetailsFixture withJsScreenWidth(String jsScreenWidth) {
this.jsScreenWidth = jsScreenWidth;
return this;
}

public AuthCardDetailsFixture withJsTimezoneOffsetMins(String jsTimezoneOffsetMins) {
this.jsTimezoneOffsetMins = jsTimezoneOffsetMins;
return this;
}

public CardDetailsEntity getCardDetailsEntity() {
CardDetailsEntity cardDetailsEntity = new CardDetailsEntity();
cardDetailsEntity.setCardBrand(cardBrand);
Expand Down Expand Up @@ -133,11 +168,11 @@ public AuthCardDetails build() {
authCardDetails.setCorporateCard(corporateCard);
authCardDetails.setWorldpay3dsFlexDdcResult(worldpay3dsFlexDdcResult);
authCardDetails.setIpAddress(ipAddress);
authCardDetails.setJsScreenColorDepth(jsScreenColorDepth);
authCardDetails.setJsNavigatorLanguage(jsNavigatorLanguage);
authCardDetails.setJsScreenHeight(jsScreenHeight);
authCardDetails.setJsScreenWidth(jsScreenWidth);
authCardDetails.setJsTimezoneOffsetMins(jsTimezoneOffsetMins);
return authCardDetails;
}

public AuthCardDetailsFixture withIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
return this;
}
}

0 comments on commit 7de113b

Please sign in to comment.