feature/appm-store/pbac
inoshperera 5 years ago
parent b7de3225a1
commit 2e265fcb3d

@ -55,8 +55,9 @@ public class WebappAuthenticationValveTest {
@Test(description = "This method tests the invoke method of the WebAppAuthenticationValve with the context path " @Test(description = "This method tests the invoke method of the WebAppAuthenticationValve with the context path "
+ "starting with carbon") + "starting with carbon")
public void testInvokeWithContextSkippedScenario1() { public void testInvokeWithContextSkippedScenario1() throws NoSuchFieldException, IllegalAccessException {
Request request = new Request(); Request request = new Request();
getCoyoteRequest(request);
Context context = new StandardContext(); Context context = new StandardContext();
context.setPath("carbon"); context.setPath("carbon");
CompositeValve compositeValve = Mockito.mock(CompositeValve.class); CompositeValve compositeValve = Mockito.mock(CompositeValve.class);
@ -64,6 +65,7 @@ public class WebappAuthenticationValveTest {
request.setContext(context); request.setContext(context);
webappAuthenticationValve.invoke(request, null, compositeValve); webappAuthenticationValve.invoke(request, null, compositeValve);
request = new TestRequest("", "test"); request = new TestRequest("", "test");
getCoyoteRequest(request);
context = new StandardContext(); context = new StandardContext();
compositeValve = Mockito.mock(CompositeValve.class); compositeValve = Mockito.mock(CompositeValve.class);
Mockito.doNothing().when(compositeValve).continueInvocation(Mockito.any(), Mockito.any()); Mockito.doNothing().when(compositeValve).continueInvocation(Mockito.any(), Mockito.any());
@ -73,8 +75,9 @@ public class WebappAuthenticationValveTest {
@Test(description = "This method tests the behaviour of the invoke method of WebAuthenticationValve when " @Test(description = "This method tests the behaviour of the invoke method of WebAuthenticationValve when "
+ "un-secured endpoints are invoked.") + "un-secured endpoints are invoked.")
public void testInvokeUnSecuredEndpoints() { public void testInvokeUnSecuredEndpoints() throws IllegalAccessException, NoSuchFieldException {
Request request = new TestRequest("", "test"); Request request = new TestRequest("", "test");
getCoyoteRequest(request);
Context context = new StandardContext(); Context context = new StandardContext();
context.setPath("carbon1"); context.setPath("carbon1");
context.addParameter("doAuthentication", String.valueOf(true)); context.addParameter("doAuthentication", String.valueOf(true));
@ -85,6 +88,22 @@ public class WebappAuthenticationValveTest {
webappAuthenticationValve.invoke(request, null, compositeValve); webappAuthenticationValve.invoke(request, null, compositeValve);
} }
private void getCoyoteRequest(Request request) throws
IllegalAccessException,
NoSuchFieldException {
Field headersField = org.apache.coyote.Request.class.getDeclaredField("headers");
headersField.setAccessible(true);
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
MimeHeaders mimeHeaders = new MimeHeaders();
MessageBytes bytes = mimeHeaders.addValue("content-type");
bytes.setString("test");
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
}
@Test(description = "This method tests the behaviour of the invoke method of WebAuthenticationValve when " @Test(description = "This method tests the behaviour of the invoke method of WebAuthenticationValve when "
+ "secured endpoints are invoked.") + "secured endpoints are invoked.")
public void testInvokeSecuredEndpoints() throws NoSuchFieldException, IllegalAccessException { public void testInvokeSecuredEndpoints() throws NoSuchFieldException, IllegalAccessException {

Loading…
Cancel
Save