DefaultWorldpaySessionService implements WorldpaySessionService { @Override public void setSessionAttributesFor3DSecure(final DirectAuthoriseServiceResponse authoriseServiceResponse, final WorldpayAdditionalInfoData worldpayAdditionalInfoData) { authoriseServiceResponse.get3DSecureFlow().filter(version -> ThreeDSecureFlowEnum.LEGACY_FLOW.equals(version) || ThreeDSecureFlowEnum.THREEDSFLEX_FLOW.equals(version)) .ifPresent(flow -> { sessionService.setAttribute(THREED_SECURE_ECHO_DATA_KEY, authoriseServiceResponse.getEchoData()); sessionService.setAttribute(THREED_SECURE_COOKIE_KEY, authoriseServiceResponse.getCookie()); if (ThreeDSecureFlowEnum.THREEDSFLEX_FLOW.toString().equals(flow.name())) { sessionService.setAttribute(THREED_SECURE_WINDOW_KEY, worldpayAdditionalInfoData.getAdditional3DS2().getChallengeWindowSize()); } }); } DefaultWorldpaySessionService(final SessionService sessionService); @Override void setSessionAttributesFor3DSecure(final DirectAuthoriseServiceResponse authoriseServiceResponse, final WorldpayAdditionalInfoData worldpayAdditionalInfoData); @Override String getAndRemoveThreeDSecureCookie(); @Override String getAndRemoveAdditionalDataSessionId(); @Override ChallengeWindowSizeEnum getWindowSizeChallengeFromSession();  }
@Test public void setSessionAttributesStoresInSessionTheValuesForTheCookieEchoDataAndWindowSize() { when(responseMock.getEchoData()).thenReturn(THREED_SECURE_ECHO_DATA_VALUE); when(responseMock.getCookie()).thenReturn(THREED_SECURE_COOKIE_VALUE); when(responseMock.get3DSecureFlow()).thenReturn(Optional.of(ThreeDSecureFlowEnum.THREEDSFLEX_FLOW)); when(worldpayAdditionalInfoDataMock.getAdditional3DS2().getChallengeWindowSize()).thenReturn(THREED_SECURE_WINDOW_SIZE_VALUE); testObj.setSessionAttributesFor3DSecure(responseMock, worldpayAdditionalInfoDataMock); verify(sessionServiceMock).setAttribute(THREED_SECURE_ECHO_DATA_KEY, THREED_SECURE_ECHO_DATA_VALUE); verify(sessionServiceMock).setAttribute(THREED_SECURE_COOKIE_KEY, THREED_SECURE_COOKIE_VALUE); verify(sessionServiceMock).setAttribute(THREED_SECURE_WINDOW_KEY, THREED_SECURE_WINDOW_SIZE_VALUE); }
@Test public void setSessionAttributeStoresNothingInSessionWhenItIsNot3DSecure() { when(responseMock.get3DSecureFlow()).thenReturn(Optional.empty()); testObj.setSessionAttributesFor3DSecure(responseMock, worldpayAdditionalInfoDataMock); verify(sessionServiceMock, never()).setAttribute(THREED_SECURE_ECHO_DATA_KEY, THREED_SECURE_ECHO_DATA_VALUE); verify(sessionServiceMock, never()).setAttribute(THREED_SECURE_COOKIE_KEY, THREED_SECURE_COOKIE_VALUE); verify(sessionServiceMock, never()).setAttribute(THREED_SECURE_WINDOW_KEY, THREED_SECURE_WINDOW_SIZE_VALUE); }