From b47c3eb5dd2add4ecb75149ba063e9ae67f3e0de Mon Sep 17 00:00:00 2001 From: megala21 Date: Tue, 10 Oct 2017 22:15:54 +0530 Subject: [PATCH] Webapp authenticator framework test cases --- .../WebappAuthenticatorConfigTest.java | 2 +- .../WebappAuthenticatorFrameworkUtilTest.java | 2 +- .../WebappAuthenticatorRepositoryTest.java | 7 ++-- .../BasicAuthAuthenticatorTest.java | 41 +++++++++++++++++++ .../util/MalformedAuthenticator.java | 2 +- .../util/TestWebappAuthenticator.java | 2 +- .../src/test/resources/testng.xml | 19 +++------ 7 files changed, 53 insertions(+), 22 deletions(-) rename components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/{test => }/WebappAuthenticatorConfigTest.java (97%) rename components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/{test => }/WebappAuthenticatorFrameworkUtilTest.java (98%) rename components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/{test => }/WebappAuthenticatorRepositoryTest.java (87%) create mode 100644 components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticatorTest.java rename components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/{test => }/util/MalformedAuthenticator.java (96%) rename components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/{test => }/util/TestWebappAuthenticator.java (96%) diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/WebappAuthenticatorConfigTest.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorConfigTest.java similarity index 97% rename from components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/WebappAuthenticatorConfigTest.java rename to components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorConfigTest.java index 8ea931a8eb..637a46598a 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/WebappAuthenticatorConfigTest.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorConfigTest.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.webapp.authenticator.framework.test; +package org.wso2.carbon.webapp.authenticator.framework; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/WebappAuthenticatorFrameworkUtilTest.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkUtilTest.java similarity index 98% rename from components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/WebappAuthenticatorFrameworkUtilTest.java rename to components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkUtilTest.java index 1ad1975b08..8fc0a4f3c9 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/WebappAuthenticatorFrameworkUtilTest.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkUtilTest.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.webapp.authenticator.framework.test; +package org.wso2.carbon.webapp.authenticator.framework; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/WebappAuthenticatorRepositoryTest.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepositoryTest.java similarity index 87% rename from components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/WebappAuthenticatorRepositoryTest.java rename to components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepositoryTest.java index edb094b3e3..410f75976c 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/WebappAuthenticatorRepositoryTest.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepositoryTest.java @@ -16,14 +16,13 @@ * under the License. * */ -package org.wso2.carbon.webapp.authenticator.framework.test; +package org.wso2.carbon.webapp.authenticator.framework; import org.testng.Assert; import org.testng.annotations.Test; -import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorRepository; import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; -import org.wso2.carbon.webapp.authenticator.framework.test.util.MalformedAuthenticator; -import org.wso2.carbon.webapp.authenticator.framework.test.util.TestWebappAuthenticator; +import org.wso2.carbon.webapp.authenticator.framework.util.MalformedAuthenticator; +import org.wso2.carbon.webapp.authenticator.framework.util.TestWebappAuthenticator; public class WebappAuthenticatorRepositoryTest { diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticatorTest.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticatorTest.java new file mode 100644 index 0000000000..7f26a10c00 --- /dev/null +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticatorTest.java @@ -0,0 +1,41 @@ +package org.wso2.carbon.webapp.authenticator.framework.authenticator; + +import org.apache.catalina.Context; +import org.apache.catalina.connector.Request; +import org.apache.catalina.core.StandardContext; +import org.apache.tomcat.util.buf.MessageBytes; +import org.apache.tomcat.util.http.MimeHeaders; +import org.testng.annotations.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; + +public class BasicAuthAuthenticatorTest { + @Test + public void testCanHandle() + throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, + InvocationTargetException, InstantiationException { + Request request = new Request(); + Context context = new StandardContext(); + context.addParameter("basicAuth", "true"); + request.setContext(context); + org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request(); + Field headers = org.apache.coyote.Request.class.getDeclaredField("headers"); + headers.setAccessible(true); + + Field mimeHeaderField = MimeHeaders.class.getDeclaredField("headers"); + mimeHeaderField.setAccessible(true); + + + MimeHeaders mimeHeaders = new MimeHeaders(); + MessageBytes bytes = mimeHeaders.addValue("Authorization"); + bytes.setString("test"); +// mimeHeaders.setValue() + headers.set(coyoteRequest, mimeHeaders); + + request.setCoyoteRequest(coyoteRequest); + BasicAuthAuthenticator basicAuthAuthenticator = new BasicAuthAuthenticator(); + basicAuthAuthenticator.canHandle(request); + } +} diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/util/MalformedAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/util/MalformedAuthenticator.java similarity index 96% rename from components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/util/MalformedAuthenticator.java rename to components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/util/MalformedAuthenticator.java index cfa6afe6de..fb7db6a5bb 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/util/MalformedAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/util/MalformedAuthenticator.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.webapp.authenticator.framework.test.util; +package org.wso2.carbon.webapp.authenticator.framework.util; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/util/TestWebappAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/util/TestWebappAuthenticator.java similarity index 96% rename from components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/util/TestWebappAuthenticator.java rename to components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/util/TestWebappAuthenticator.java index aebe1bbcc6..1f4c3abce2 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/test/util/TestWebappAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/util/TestWebappAuthenticator.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.webapp.authenticator.framework.test.util; +package org.wso2.carbon.webapp.authenticator.framework.util; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/resources/testng.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/resources/testng.xml index a73f1df2d3..bbaf6827fa 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/resources/testng.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/resources/testng.xml @@ -22,21 +22,12 @@ - + - - - - - - - - - - - - - + + + +