From a3088068b6d3f6d6719ca5943eec556d01c0655d Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Thu, 1 Jul 2021 07:37:47 +0200 Subject: add new 'errorHandling' type that illustrate any error on application side before forwarding to SP --- .../ProtocolFinalizationControllerTest.java | 57 +++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'eaaf_core/src/test/java') 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 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 params = ((Map) 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 { -- cgit v1.2.3