You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2011/10/20 13:56:54 UTC

svn commit: r1186750 - /tomcat/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java

Author: kkolinko
Date: Thu Oct 20 11:56:54 2011
New Revision: 1186750

URL: http://svn.apache.org/viewvc?rev=1186750&view=rev
Log:
Expand the test to cover regression fixed in 7.0.23:
check that parameters in the original request have reached the protected page.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51940#c9

Modified:
    tomcat/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java

Modified: tomcat/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java?rev=1186750&r1=1186749&r2=1186750&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java (original)
+++ tomcat/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java Thu Oct 20 11:56:54 2011
@@ -19,6 +19,7 @@ package org.apache.catalina.authenticato
 import java.io.File;
 
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import org.junit.Test;
 
@@ -123,7 +124,11 @@ public class TestFormAuthenticator exten
             StringBuilder requestHead = new StringBuilder(128);
             String requestTail;
             requestHead.append(method).append(" ").append(protectedLocation)
-                    .append(protectedPage).append(" HTTP/1.1").append(CRLF);
+                    .append(protectedPage);
+            if ("GET".equals(method)) {
+                requestHead.append("?role=bar");
+            }
+            requestHead.append(" HTTP/1.1").append(CRLF);
             requestHead.append("Host: localhost").append(CRLF);
             requestHead.append("Connection: close").append(CRLF);
             if (getUseContinue()) {
@@ -137,9 +142,9 @@ public class TestFormAuthenticator exten
                 requestHead.append(
                         "Content-Type: application/x-www-form-urlencoded")
                         .append(CRLF);
-                requestHead.append("Content-length: 7").append(CRLF);
+                requestHead.append("Content-length: 8").append(CRLF);
                 requestHead.append(CRLF);
-                requestTail = "foo=bar";
+                requestTail = "role=bar";
             } else {
                 requestTail = CRLF;
             }
@@ -190,20 +195,32 @@ public class TestFormAuthenticator exten
 
         @Override
         public boolean isResponseBodyOK() {
-            String expected;
-
             if (requestCount == 1) {
                 // First request should result in the login page
-                expected = "<title>Login Page for Examples</title>";
+                assertContains(getResponseBody(),
+                        "<title>Login Page for Examples</title>");
+                return true;
             } else if (requestCount == 2) {
                 // Second request should result in a redirect
                 return true;
             } else {
                 // Subsequent requests should result in the protected page
-                expected = "<title>Protected Page for Examples</title>";
+                // The role parameter should have reached the page
+                String body = getResponseBody();
+                assertContains(body,
+                        "<title>Protected Page for Examples</title>");
+                assertContains(body,
+                        "<input type=\"text\" name=\"role\" value=\"bar\"");
+                return true;
             }
-            return getResponseBody().contains(expected);
         }
 
+        private void assertContains(String body, String expected) {
+            if (!body.contains(expected)) {
+                fail("Response body check failure.\n"
+                        + "Expected to contain substring: [" + expected
+                        + "]\nActual: [" + body + "]");
+            }
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org