You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2010/07/28 23:00:15 UTC

svn commit: r980210 - in /geronimo/server/trunk/testsuite/security-testsuite/test-security: pom.xml src/test/java/org/apache/geronimo/testsuite/security/TestConsoleSecurity.java src/test/java/org/apache/geronimo/testsuite/security/TestSecurity.java

Author: gawor
Date: Wed Jul 28 21:00:14 2010
New Revision: 980210

URL: http://svn.apache.org/viewvc?rev=980210&view=rev
Log:
use HttpClient for console security tests as selenium is not working quite right

Modified:
    geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml
    geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestConsoleSecurity.java
    geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestSecurity.java

Modified: geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml?rev=980210&r1=980209&r2=980210&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml (original)
+++ geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml Wed Jul 28 21:00:14 2010
@@ -70,6 +70,14 @@
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.bundles</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.0.1_1</version>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
     <profiles>
@@ -88,11 +96,6 @@
                     </plugin>
 
                     <plugin>
-                        <groupId>org.codehaus.mojo</groupId>
-                        <artifactId>selenium-maven-plugin</artifactId>
-                    </plugin>
-
-                    <plugin>
                         <groupId>org.apache.geronimo.buildsupport</groupId>
                         <artifactId>geronimo-maven-plugin</artifactId>
                         <executions>

Modified: geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestConsoleSecurity.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestConsoleSecurity.java?rev=980210&r1=980209&r2=980210&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestConsoleSecurity.java (original)
+++ geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestConsoleSecurity.java Wed Jul 28 21:00:14 2010
@@ -19,25 +19,35 @@
 
 package org.apache.geronimo.testsuite.security;
 
-
-import org.apache.geronimo.testsupport.SeleniumTestSupport;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.geronimo.testsupport.TestSupport;
 import org.testng.annotations.Test;
 
-public class TestConsoleSecurity extends SeleniumTestSupport {
+public class TestConsoleSecurity extends TestSupport {
     
     @Test
     public void testLogin() throws Exception {
-        selenium.open("/console");
-        waitForPageLoad();
-        assertFalse(selenium.isTextPresent("Deploy New"));
-        selenium.type("j_username", "system");
-        selenium.type("j_password", "manager");
-        selenium.click("submit");
-        waitForPageLoad();
-        assertTrue(selenium.isTextPresent("Deploy New"));
-        selenium.click("//a[contains(@href, '/console/logout.jsp')]");
-        waitForPageLoad();
-        assertEquals("Geronimo Console Login", selenium.getTitle());
+        HttpClient httpClient = new HttpClient();
+        
+        PostMethod postMethod = login(httpClient, "system", "manager");
+        
+        int statusCode = httpClient.executeMethod(postMethod);
+        assertTrue(statusCode >= 300 || statusCode < 310);
+        
+        postMethod.releaseConnection();         
+        Header locationHeader = postMethod.getResponseHeader("location");
+        assertNotNull("Expected location header is not present", locationHeader);
+
+        String response;
+        
+        response = doGet(httpClient, locationHeader.getValue());
+        assertTrue(response.contains("Deployer"));
+        
+        response = doGet(httpClient, "http://localhost:8080/console/logout.jsp");
+        assertTrue(response.contains("Geronimo Console Login"));
     }
 
     @Test
@@ -69,20 +79,42 @@ public class TestConsoleSecurity extends
     public void testEmptyCredentialsLogin() throws Exception {        
         testFailure("", "");
     }
-    
+        
     private void testFailure(String username, String password) throws Exception {
-        selenium.open("/console");
-        waitForPageLoad();
+        HttpClient httpClient = new HttpClient();
+                
+        PostMethod postMethod = login(httpClient, username, password);
+        
+        assertEquals(200, httpClient.executeMethod(postMethod));
+        String response = postMethod.getResponseBodyAsString();
+        postMethod.releaseConnection();  
+        
+        boolean authError = response.contains("Invalid User Name and");              
+        assertTrue("Expected authentication error", authError);
+    }
+
+    private PostMethod login(HttpClient httpClient, String username, String password) throws Exception {
+        String response = doGet(httpClient, "http://localhost:8080/console");
+        assertTrue("Expected login form", response.contains("Geronimo Console Login"));
+        
+        PostMethod postMethod = new PostMethod("http://localhost:8080/console/j_security_check");
         if (username != null) {
-            selenium.type("j_username", username);
+            postMethod.addParameter("j_username", username);
         }
         if (password != null) {
-            selenium.type("j_password", password);
+            postMethod.addParameter("j_password", password);
         }
-        selenium.click("submit");
-        waitForPageLoad();
         
-        assertTrue(selenium.isTextPresent("Invalid User Name and"));
+        return postMethod;        
     }
     
+    private String doGet(HttpClient httpClient, String url) throws Exception {
+        GetMethod getMethod = new GetMethod(url);
+        getMethod.setFollowRedirects(true);
+        
+        assertEquals(200, httpClient.executeMethod(getMethod));
+        String response = getMethod.getResponseBodyAsString();
+        getMethod.releaseConnection();
+        return response;
+    }
 }

Modified: geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestSecurity.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestSecurity.java?rev=980210&r1=980209&r2=980210&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestSecurity.java (original)
+++ geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestSecurity.java Wed Jul 28 21:00:14 2010
@@ -19,29 +19,39 @@
 
 package org.apache.geronimo.testsuite.security;
 
-
-import org.apache.geronimo.testsupport.SeleniumTestSupport;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.geronimo.testsupport.TestSupport;
 import org.testng.annotations.Test;
 
-public class TestSecurity extends SeleniumTestSupport {
+public class TestSecurity extends TestSupport {
     
     @Test
     public void testLogin() throws Exception {
-        selenium.open("/demo/protect/hello.html");
-        selenium.type("j_username", "george");
-        selenium.type("j_password", "bone");
-        selenium.click("submit");
-        waitForPageLoad();
-        assertEquals("hello world.", selenium.getText("xpath=/html"));
-        selenium.deleteAllVisibleCookies();
-        selenium.refresh();
-    }
+        HttpClient httpClient = new HttpClient();
+                
+        PostMethod postMethod = login(httpClient, "george", "bone");
+        
+        int statusCode = httpClient.executeMethod(postMethod);
+        assertTrue(statusCode >= 300 || statusCode < 310);
+        
+        postMethod.releaseConnection();         
+        Header locationHeader = postMethod.getResponseHeader("location");
+        assertNotNull("Expected location header is not present", locationHeader);
 
+        String response;
+        
+        response = doGet(httpClient, locationHeader.getValue());
+        assertTrue(response.contains("hello world"));
+    }
+   
     @Test
     public void testBadPasswordLogin() throws Exception {   
         testFailure("george", "bonee");
     }
-    
+
     @Test
     public void testBadUser() throws Exception {  
         testFailure("doesnotexist", "bonee");
@@ -68,18 +78,40 @@ public class TestSecurity extends Seleni
     }
     
     private void testFailure(String username, String password) throws Exception {
-        selenium.open("/demo/protect/hello.html");
-        waitForPageLoad();
+        HttpClient httpClient = new HttpClient();
+                
+        PostMethod postMethod = login(httpClient, username, password);
+        
+        assertEquals(200, httpClient.executeMethod(postMethod));
+        String response = postMethod.getResponseBodyAsString();
+        postMethod.releaseConnection();  
+        
+        boolean authError = response.contains("Authentication ERROR");              
+        assertTrue("Expected authentication error", authError);
+    }
+
+    private PostMethod login(HttpClient httpClient, String username, String password) throws Exception {
+        String response = doGet(httpClient, "http://localhost:8080/demo/protect/hello.html");
+        assertTrue("Expected authentication form", response.contains("FORM Authentication demo"));
+        
+        PostMethod postMethod = new PostMethod("http://localhost:8080/demo/j_security_check");
         if (username != null) {
-            selenium.type("j_username", username);
+            postMethod.addParameter("j_username", username);
         }
         if (password != null) {
-            selenium.type("j_password", password);
+            postMethod.addParameter("j_password", password);
         }
-        selenium.click("submit");
-        waitForPageLoad();
         
-        assertTrue(selenium.isTextPresent("Authentication ERROR"));
+        return postMethod;        
     }
     
+    private String doGet(HttpClient httpClient, String url) throws Exception {
+        GetMethod getMethod = new GetMethod(url);
+        getMethod.setFollowRedirects(true);
+        
+        assertEquals(200, httpClient.executeMethod(getMethod));
+        String response = getMethod.getResponseBodyAsString();
+        getMethod.releaseConnection();
+        return response;
+    }
 }