diff options
Diffstat (limited to 'eaaf_core/src/test/java')
-rw-r--r-- | eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/controller/ProtocolFinalizationControllerTest.java | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/controller/ProtocolFinalizationControllerTest.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/controller/ProtocolFinalizationControllerTest.java index 8aa3e8a9..4341d141 100644 --- a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/controller/ProtocolFinalizationControllerTest.java +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/controller/ProtocolFinalizationControllerTest.java @@ -254,7 +254,62 @@ public class ProtocolFinalizationControllerTest { } - + @Test + public void performErrorHandlingWithoutTokenAndRedirect() throws EaafException, IOException { + MockHttpServletRequest httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); + httpReq.addHeader("Accept", "application/json"); + MockHttpServletResponse httpResp = new MockHttpServletResponse(); + guiConfigFactory.setErrorGuiConfig( + new DummyGuiBuilderConfig("https://localhost/authhandler", "jUnitView", "/junitSubmit")); + + String token = requestIdValidationStragegy.generateExternalPendingRequestId(); + httpReq.setParameter(EaafConstants.PARAM_HTTP_ERROR_CODE, token); + + TestRequestImpl protocolRequest = new TestRequestImpl(); + Map<String, String> spConfig = new HashMap<>(); + spConfig.put(EaafConfigConstants.SERVICE_UNIQUEIDENTIFIER, RandomStringUtils.randomAlphabetic(10)); + + protocolRequest.setSpConfig(new DummySpConfiguration(spConfig, config)); + protocolRequest.setTransactionId(RandomStringUtils.randomAlphanumeric(10)); + + Throwable throwable = new EaafException("internal.00"); + final ExceptionContainer exceptionContainer = new ExceptionContainer(protocolRequest, throwable); + final byte[] serialized = SerializationUtils.serialize(exceptionContainer); + storage.put(token, serialized, -1); + + String secondErrorTicket = requestIdValidationStragegy.generateExternalPendingRequestId(); + errorService.setErrorIdTokenForRedirect(secondErrorTicket); + errorService.setTicketType(ActionType.ERRORPAGE); + + // perform test + controller.errorHandling(httpReq, httpResp); + + //validate state + assertNull("Exception not removed from cache", storage.get( + requestIdValidationStragegy.getPendingRequestIdWithOutChecks(token))); + + assertNotNull("No gui builder request", guiBuilder.getConfig()); + assertFalse("No GUI form infos", guiBuilder.getConfig().getViewParameters().isEmpty()); + assertTrue("No GUI form infos", guiBuilder.getConfig().getViewParameters().containsKey("msg")); + Map<String, Object> params = ((Map<String, Object>) guiBuilder.getConfig().getViewParameters().get("msg")); + assertFalse("No GUI form infos", params.isEmpty()); + assertEquals("wrong intErrorCode", "internal.00", params.get("errorCode")); + assertTrue("wrong extErrorCode", ((String) params.get("extErrorCode")).contains("internal.00")); + + byte[] secondErrorSerialized = storage.get( + requestIdValidationStragegy.getPendingRequestIdWithOutChecks(secondErrorTicket), byte[].class); + assertNotNull("Exception not removed from cache", secondErrorSerialized); + ExceptionContainer secondError = (ExceptionContainer) SerializationUtils.deserialize(secondErrorSerialized); + assertEquals("wrong pengingReq", protocolRequest.getUniqueTransactionIdentifier(), + secondError.getPendingRequest().getUniqueTransactionIdentifier()); + assertEquals("wrong exception", throwable.getMessage(), secondError.getExceptionThrown().getMessage()); + + assertTrue("GUI sp redirect", guiBuilder.getConfig().getViewParameters() + .containsKey(DummyDefaultErrorService.JUNIT_EL_SPREDIRECT)); + + } + + private class DummyGuiBuilderConfig extends AbstractGuiFormBuilderConfiguration implements ModifyableGuiBuilderConfiguration { |