RequestHandler { String handleSAMLRequest(String samlRequestBase64, boolean isPost) { return handleSAMLRequest(null, samlRequestBase64, isPost); } RequestHandler(SessionStore store,
                        ConfigHolder configHolder,
                        ServiceProviderConfig serviceProviderConfig); String handleSAMLRequest(String relayState, String samlRequestBase64, boolean isPost); String getTcTokenURL(String sessionId); static final String CANNOT_PARSE_SAML_REQUEST; }
@Test void testMissingParameters() { RequestHandler requestHandler = new RequestHandler(mockSessionStore, mockConfigHolder, mockServiceProviderConfig); RequestProcessingException requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(null, null, true)); Assertions.assertEquals(requestProcessingException.getCause().getClass(), ErrorCodeException.class); requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(null, null, false)); Assertions.assertEquals(requestProcessingException.getCause().getClass(), ErrorCodeException.class); requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(RELAY_STATE, null, true)); Assertions.assertEquals(requestProcessingException.getCause().getClass(), ErrorCodeException.class); requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(RELAY_STATE, null, false)); Assertions.assertEquals(requestProcessingException.getCause().getClass(), ErrorCodeException.class); requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest("", "", true)); Assertions.assertEquals(requestProcessingException.getCause().getClass(), SAXParseException.class); requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest("", "", false)); Assertions.assertEquals(requestProcessingException.getCause().getClass(), SAXParseException.class); requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(RELAY_STATE, "", true)); Assertions.assertEquals(requestProcessingException.getCause().getClass(), SAXParseException.class); requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(RELAY_STATE, "", false)); Assertions.assertEquals(requestProcessingException.getCause().getClass(), SAXParseException.class); }
@Test void testWrongSignatureCertificate() throws URISyntaxException { RequestingServiceProvider sp = new RequestingServiceProvider("http: URL resource = RequestHandlerTest.class.getResource("/de/governikus/eumw/eidasmiddleware/bos-test-tctoken.saml-encr.p12"); File keystoreFile = new File(resource.toURI()); KeyStore signatureKeystore = KeyStoreSupporter.readKeyStore(keystoreFile, DEFAULT_PASSWORD); sp.setSignatureCert((X509Certificate)KeyStoreSupporter.getCertificate(signatureKeystore, "bos-test-tctoken.saml-encr") .get()); Mockito.when(mockServiceProviderConfig.getProviderByEntityID("http: .thenReturn(sp); RequestHandler requestHandler = new RequestHandler(mockSessionStore, mockConfigHolder, mockServiceProviderConfig); RequestProcessingException requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(RELAY_STATE, GET_REQUEST, false)); Assertions.assertEquals(requestProcessingException.getCause().getClass(), ErrorCodeException.class, "ErrorCodeException expected as cause"); Assertions.assertEquals(RequestHandler.CANNOT_PARSE_SAML_REQUEST, requestProcessingException.getMessage()); }
@Test void testManipulatedXML() { String wrongDigest = "1VhZk+JGEn72/IoOJmJfCEYXAsEO7SjdAiSQAAl42RBS6Wh0oQOBfr1LHD1t79ie3fCD3S9NlbKyvvoyKyszv/58iaOXM8yLME0mHeIL3nmBiZO6YeJPOpu12GM6P79+Lew4IrMxqMogMeCpgkX5ghYmxfj+ZdKp8mSc2kVYjBM7hsW4dMYroM7H5Bd8nOVpmTpp1HmsgaFrF5NOUJbZGMNuoy+wytPMRv+wVmMPXkqYtJiKzguPdgsTu7whfCyKUseOgrQoxwzO4BhUeLDiYZyCLItC5yaLabA2oANDdLoVzM8RLDsvYpo78HaMSafMK9h5UfhJ5z996OADwhn2oOsyvf6Bgj37QHo9h6E8GvYPA88jkWixtIsC6Zt0PDsq2sVFUUElKUo7KScdEieYHkH0CGpN9Mc4Pe7TX3CG2Hdelnl6Dl2Ya4ibSYeHnl1F5XOy82I++UdsdR5sj2+68480/zHLCBrM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yioHT9dN91jYGBHfnvZrcjtQKKXsrnNZ15sUwSRRVlJYYxq7oKgmwmVJBr4/XVuo/jHwP0+eQ/trch70H++1bdX4b3qEN5rgddPL4+/r7eqYbxarq8ZfM2qA8r6v95Liefkb2UfdQt0QVnm4aEqIUq1fvrpp4eq RequestHandler requestHandler = new RequestHandler(mockSessionStore, mockConfigHolder, mockServiceProviderConfig); RequestProcessingException requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(RELAY_STATE, wrongDigest, false)); Assertions.assertEquals(ErrorCodeException.class, requestProcessingException.getCause().getClass(), "ErrorCodeException expected as cause"); Assertions.assertEquals(RequestHandler.CANNOT_PARSE_SAML_REQUEST, requestProcessingException.getMessage()); }
@Test void testGeneratedRequest() throws URISyntaxException { RequestHandler requestHandler = new RequestHandler(mockSessionStore, mockConfigHolder, mockServiceProviderConfig); File keystoreFile = new File(RequestHandlerTest.class.getResource("/de/governikus/eumw/eidasmiddleware/bos-test-tctoken.saml-sign.p12") .toURI()); KeyStore keyStore = KeyStoreSupporter.readKeyStore(keystoreFile, DEFAULT_PASSWORD); String request = createSAMLRequest(keyStore, DEFAULT_PASSWORD, "bos-test-tctoken.saml-sign", "http: "http: String tcTokenURL = requestHandler.handleSAMLRequest(RELAY_STATE, request, false); Assertions.assertNotNull(tcTokenURL); }
@Test void testGeneratedRequestWithoutRelayState() throws URISyntaxException { RequestHandler requestHandler = new RequestHandler(mockSessionStore, mockConfigHolder, mockServiceProviderConfig); File keystoreFile = new File(RequestHandlerTest.class.getResource("/de/governikus/eumw/eidasmiddleware/bos-test-tctoken.saml-sign.p12") .toURI()); KeyStore keyStore = KeyStoreSupporter.readKeyStore(keystoreFile, DEFAULT_PASSWORD); String request = createSAMLRequest(keyStore, DEFAULT_PASSWORD, "bos-test-tctoken.saml-sign", "http: "http: String tcTokenURL = requestHandler.handleSAMLRequest(request, false); Assertions.assertNotNull(tcTokenURL); }
@Test void testWrongIssuer() throws URISyntaxException { RequestHandler requestHandler = new RequestHandler(mockSessionStore, mockConfigHolder, mockServiceProviderConfig); File keystoreFile = new File(RequestHandlerTest.class.getResource("/de/governikus/eumw/eidasmiddleware/bos-test-tctoken.saml-sign.p12") .toURI()); KeyStore keyStore = KeyStoreSupporter.readKeyStore(keystoreFile, DEFAULT_PASSWORD); String wrongIssuer = "http: String request = createSAMLRequest(keyStore, DEFAULT_PASSWORD, "bos-test-tctoken.saml-sign", wrongIssuer, "http: RequestProcessingException requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(RELAY_STATE, request, false)); Assertions.assertEquals(ErrorCodeException.class, requestProcessingException.getCause().getClass(), "ErrorCodeException expected as cause"); Assertions.assertEquals(RequestHandler.CANNOT_PARSE_SAML_REQUEST, requestProcessingException.getMessage()); }
@Test void testInvalidBase64() { RequestHandler requestHandler = new RequestHandler(mockSessionStore, mockConfigHolder, mockServiceProviderConfig); RequestProcessingException requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(RELAY_STATE, INVALID_BASE64, false)); Assertions.assertEquals(DataFormatException.class, requestProcessingException.getCause().getClass(), "ErrorCodeException expected as cause"); Assertions.assertEquals(RequestHandler.CANNOT_PARSE_SAML_REQUEST, requestProcessingException.getMessage()); }
@Test void testInvalidXML() { RequestHandler requestHandler = new RequestHandler(mockSessionStore, mockConfigHolder, mockServiceProviderConfig); RequestProcessingException requestProcessingException = Assertions.assertThrows(RequestProcessingException.class, () -> requestHandler.handleSAMLRequest(RELAY_STATE, INVALID_SIGNED_XML, false)); Assertions.assertEquals(SAXParseException.class, requestProcessingException.getCause().getClass(), "ErrorCodeException expected as cause"); Assertions.assertEquals(RequestHandler.CANNOT_PARSE_SAML_REQUEST, requestProcessingException.getMessage()); }
@Test void testPOST() { RequestHandler requestHandler = new RequestHandler(mockSessionStore, mockConfigHolder, mockServiceProviderConfig); String tcTokenURL = requestHandler.handleSAMLRequest(RELAY_STATE, POST_REQUEST, true); Assertions.assertNotNull(tcTokenURL); }