From: maxcooper Date: Mon, 9 Jun 2003 11:00:55 +0000 (+0000) Subject: refactored test class organization, X-Git-Tag: rel-2_0-alpha1~83 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=cf899e3c113e3480426ffa9432212b075259817e;p=securityfilter.git refactored test class organization, completed JustInTime login test --- diff --git a/src/test/org/securityfilter/test/http/LoginTest.java b/src/test/org/securityfilter/test/http/LoginTest.java deleted file mode 100644 index a973f3c..0000000 --- a/src/test/org/securityfilter/test/http/LoginTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/Attic/LoginTest.java,v 1.3 2003/05/06 13:58:26 maxcooper Exp $ - * $Revision: 1.3 $ - * $Date: 2003/05/06 13:58:26 $ - * - * ==================================================================== - * The SecurityFilter Software License, Version 1.1 - * - * (this license is derived and fully compatible with the Apache Software - * License - see http://www.apache.org/LICENSE.txt) - * - * Copyright (c) 2002 SecurityFilter.org. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by - * SecurityFilter.org (http://www.securityfilter.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The name "SecurityFilter" must not be used to endorse or promote - * products derived from this software without prior written permission. - * For written permission, please contact license@securityfilter.org . - * - * 5. Products derived from this software may not be called "SecurityFilter", - * nor may "SecurityFilter" appear in their name, without prior written - * permission of SecurityFilter.org. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE SECURITY FILTER PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - */ - -package org.securityfilter.test.http; - -import com.meterware.httpunit.*; -import junit.framework.TestCase; - -/** - * LoginTest - */ -public class LoginTest extends TestCase { - - private String baseUrl; - - /** - * Constructor - * - * @param name - */ - public LoginTest(String name) { - super(name); - } - - /** - * - */ - public void setUp() { - baseUrl = System.getProperty("base.url"); - HttpUnitOptions.setExceptionsThrownOnErrorStatus(true); - HttpUnitOptions.setMatchesIgnoreCase(true); - } - - /** - * - */ - public void testLogin() throws Exception { - assertNotNull("base.url is null", baseUrl); - WebConversation session = new WebConversation(); - WebRequest request = new GetMethodWebRequest(baseUrl + "/securePage.jsp"); - System.out.println("--------------------------------------------------------------------------------"); - System.out.println("Request URL: " + request.getURL()); - WebResponse response = session.getResponse(request); - System.out.println("Response:"); - System.out.println("\tResponse Code: " + response.getResponseCode()); - System.out.println("\tTitle: " + response.getTitle()); - String[] headerNames = response.getHeaderFieldNames(); - for (int i = 0; i < headerNames.length; i++) { - System.out.println("\tHeader: \"" + headerNames[i] + "\" = \"" + response.getHeaderField(headerNames[i]) + "\""); - } - } -} diff --git a/src/test/org/securityfilter/test/http/TestBase.java b/src/test/org/securityfilter/test/http/TestBase.java new file mode 100644 index 0000000..6127869 --- /dev/null +++ b/src/test/org/securityfilter/test/http/TestBase.java @@ -0,0 +1,88 @@ +/* + * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/TestBase.java,v 1.1 2003/06/09 11:00:55 maxcooper Exp $ + * $Revision: 1.1 $ + * $Date: 2003/06/09 11:00:55 $ + * + * ==================================================================== + * The SecurityFilter Software License, Version 1.1 + * + * (this license is derived and fully compatible with the Apache Software + * License - see http://www.apache.org/LICENSE.txt) + * + * Copyright (c) 2002 SecurityFilter.org. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by + * SecurityFilter.org (http://www.securityfilter.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The name "SecurityFilter" must not be used to endorse or promote + * products derived from this software without prior written permission. + * For written permission, please contact license@securityfilter.org . + * + * 5. Products derived from this software may not be called "SecurityFilter", + * nor may "SecurityFilter" appear in their name, without prior written + * permission of SecurityFilter.org. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE SECURITY FILTER PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + */ + +package org.securityfilter.test.http; + +import com.meterware.httpunit.HttpUnitOptions; +import junit.framework.TestCase; + +/** + * TestBase + * + * @author Max Cooper (max@maxcooper.com) + * @version $Revision: 1.1 $ $Date: 2003/06/09 11:00:55 $ + */ +public class TestBase extends TestCase { + + protected String baseUrl; + + /** + * Constructor + * + * @param name + */ + public TestBase(String name) { + super(name); + } + + /** + * Initialize test environment + */ + public void setUp() { + baseUrl = System.getProperty("base.url"); + HttpUnitOptions.setExceptionsThrownOnErrorStatus(true); + HttpUnitOptions.setMatchesIgnoreCase(true); + } +} diff --git a/src/test/org/securityfilter/test/http/form/JustInTimeTest.java b/src/test/org/securityfilter/test/http/form/JustInTimeTest.java new file mode 100644 index 0000000..a2beab1 --- /dev/null +++ b/src/test/org/securityfilter/test/http/form/JustInTimeTest.java @@ -0,0 +1,117 @@ +/* + * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/form/JustInTimeTest.java,v 1.1 2003/06/09 11:00:55 maxcooper Exp $ + * $Revision: 1.1 $ + * $Date: 2003/06/09 11:00:55 $ + * + * ==================================================================== + * The SecurityFilter Software License, Version 1.1 + * + * (this license is derived and fully compatible with the Apache Software + * License - see http://www.apache.org/LICENSE.txt) + * + * Copyright (c) 2002 SecurityFilter.org. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by + * SecurityFilter.org (http://www.securityfilter.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The name "SecurityFilter" must not be used to endorse or promote + * products derived from this software without prior written permission. + * For written permission, please contact license@securityfilter.org . + * + * 5. Products derived from this software may not be called "SecurityFilter", + * nor may "SecurityFilter" appear in their name, without prior written + * permission of SecurityFilter.org. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE SECURITY FILTER PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + */ + +package org.securityfilter.test.http.form; + +import com.meterware.httpunit.*; +import org.securityfilter.example.Constants; +import org.securityfilter.test.http.TestBase; + +/** + * JustInTimeTest - This tests basic just-in-time login behavior. + * + * Sequence of events: + * 1. ASSERT: baseUrl (set from base.url system property) is not null + * 2. request securePage.jsp + * 3. ASSERT: response should be the login page (after auto-redirect) + * 4. submit valid login credentials + * 5. ASSERT: response should be the secure page (after auto-redirect) + * + * @author Max Cooper (max@maxcooper.com) + * @version $Revision: 1.1 $ $Date: 2003/06/09 11:00:55 $ + */ +public class JustInTimeTest extends TestBase { + + /** + * Constructor + * + * @param name + */ + public JustInTimeTest(String name) { + super(name); + } + + public void testJustInTime() throws Exception { + // make sure the baseUrl was set + assertNotNull("base.url is null", baseUrl); + + // request the secure page + WebConversation session = new WebConversation(); + WebRequest request = new GetMethodWebRequest(baseUrl + "/securePage.jsp"); + WebResponse response = session.getResponse(request); + + // make sure the response leads us to login page + String title = response.getTitle(); + assertEquals( + "On request for secure page, expected login page, got:" + title, + Constants.LOGIN_TITLE, + title + ); + + // submit valid login credentials + WebForm loginForm = response.getFormWithID(Constants.LOGIN_FORM_ID); + loginForm.setParameter(Constants.LOGIN_USERNAME_FIELD, Constants.VALID_USERNAME); + loginForm.setParameter(Constants.LOGIN_PASSWORD_FIELD, Constants.VALID_PASSWORD); + response = session.getResponse(loginForm.getRequest()); + + // make sure the response leads to the secure page + title = response.getTitle(); + assertEquals( + "Expected secure page, got:" + title, + Constants.SECURE_TITLE, + title + ); + } +}