BSTAuthenticator implements WebappAuthenticator { @Override public boolean canHandle(Request request) { String contentType = request.getContentType(); if (contentType != null && APPLICABLE_CONTENT_TYPES.contains(contentType)) { try { return isBSTHeaderExists(request); } catch (IOException | XMLStreamException e) { log.error("Error occurred while checking if BST authenticator can handle the incoming SOAP message"); } } return false; }  void init(); @Override boolean canHandle(Request request); @Override AuthenticationInfo authenticate(Request request, Response response); @Override String getName(); @Override void setProperties(Properties properties); @Override Properties getProperties(); @Override String getProperty(String name);  }
@Test(description = "This test case tests the canHandle method of the BSTAuthenticator under faulty conditions") public void testCanHandleWithFalseConditions() throws IllegalAccessException { Request request = new Request(); org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request(); request.setCoyoteRequest(coyoteRequest); Assert.assertFalse(bstAuthenticator.canHandle(request), "BST Authenticator can handle a request without content type"); MimeHeaders mimeHeaders = new MimeHeaders(); MessageBytes bytes = mimeHeaders.addValue("content-type"); bytes.setString("test"); headersField.set(coyoteRequest, mimeHeaders); request.setCoyoteRequest(coyoteRequest); Assert.assertFalse(bstAuthenticator.canHandle(request), "BST Authenticator can handle a request with content type test"); }
@Test(description = "This test case tests the canHandle method of the BSTAuthenticator under valid conditions") public void testCanHandleWithValidRequest() throws IOException, IllegalAccessException { Request request = createSoapRequest("CorrectBST.xml"); Assert.assertTrue(bstAuthenticator.canHandle(request), "BST Authenticator cannot handle a valid " + "authentication request"); }
@Test(description = "This test case tests the canHandle method of the BSTAuthenticator under missing soap headers") public void testCanHandleWithMissingHeaders() throws IOException, IllegalAccessException { Request request = createSoapRequest("WrongBST1.xml"); Assert.assertFalse(bstAuthenticator.canHandle(request), "BST Authenticator can handle a request with missing headers "); request = createSoapRequest("WrongBST2.xml"); Assert.assertFalse(bstAuthenticator.canHandle(request), "BST Authenticator can handle a request with missing headers "); }