Author: markt
Date: Mon Sep 14 15:36:35 2015
New Revision: 1702970
URL: http://svn.apache.org/r1702970
Log:
Fix various cookie related issues in Authenticator tests now the RFC6265 cookie
parser is used by default
Modified:
tomcat/trunk/test/org/apache/catalina/authenticator/TestNonLoginAndBasicAuthenticator.java
tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndBasicAuthenticator.java
tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndDigestAuthenticator.java
Modified:
tomcat/trunk/test/org/apache/catalina/authenticator/TestNonLoginAndBasicAuthenticator.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/TestNonLoginAndBasicAuthenticator.java?rev=1702970&r1=1702969&r2=1702970&view=diff
==============================================================================
---
tomcat/trunk/test/org/apache/catalina/authenticator/TestNonLoginAndBasicAuthenticator.java
(original)
+++
tomcat/trunk/test/org/apache/catalina/authenticator/TestNonLoginAndBasicAuthenticator.java
Mon Sep 14 15:36:35 2015
@@ -356,8 +356,8 @@ public class TestNonLoginAndBasicAuthent
Map<String,List<String>> reqHeaders = new HashMap<>();
Map<String,List<String>> respHeaders = new HashMap<>();
- if (useCookie && (cookies != null)) {
- reqHeaders.put(CLIENT_COOKIE_HEADER + ":", cookies);
+ if (useCookie) {
+ addCookies(reqHeaders);
}
ByteChunk bc = new ByteChunk();
@@ -379,8 +379,8 @@ public class TestNonLoginAndBasicAuthent
Map<String,List<String>> reqHeaders = new HashMap<>();
Map<String,List<String>> respHeaders = new HashMap<>();
- if (useCookie && (cookies != null)) {
- reqHeaders.put(CLIENT_COOKIE_HEADER + ":", cookies);
+ if (useCookie) {
+ addCookies(reqHeaders);
}
else {
if (credentials != null) {
@@ -415,7 +415,7 @@ public class TestNonLoginAndBasicAuthent
List<String> newCookies = respHeaders.get(SERVER_COOKIE_HEADER);
if (newCookies != null) {
// harvest cookies whenever the server sends some new ones
- cookies = newCookies;
+ saveCookies(respHeaders);
}
}
}
@@ -568,4 +568,41 @@ public class TestNonLoginAndBasicAuthent
return credentials;
}
}
+
+ /*
+ * extract and save the server cookies from the incoming response
+ */
+ protected void saveCookies(Map<String,List<String>> respHeaders) {
+ // we only save the Cookie values, not header prefix
+ List<String> cookieHeaders = respHeaders.get(SERVER_COOKIE_HEADER);
+ if (cookieHeaders == null) {
+ cookies = null;
+ } else {
+ cookies = new ArrayList<>(cookieHeaders.size());
+ for (String cookieHeader : cookieHeaders) {
+ cookies.add(cookieHeader.substring(0,
cookieHeader.indexOf(';')));
+ }
+ }
+ }
+
+ /*
+ * add all saved cookies to the outgoing request
+ */
+ protected void addCookies(Map<String,List<String>> reqHeaders) {
+ if ((cookies != null) && (cookies.size() > 0)) {
+ StringBuilder cookieHeader = new StringBuilder();
+ boolean first = true;
+ for (String cookie : cookies) {
+ if (!first) {
+ cookieHeader.append(';');
+ } else {
+ first = false;
+ }
+ cookieHeader.append(cookie);
+ }
+ List<String> cookieHeaderList = new ArrayList<>(1);
+ cookieHeaderList.add(cookieHeader.toString());
+ reqHeaders.put(CLIENT_COOKIE_HEADER, cookieHeaderList);
+ }
+ }
}
\ No newline at end of file
Modified:
tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndBasicAuthenticator.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndBasicAuthenticator.java?rev=1702970&r1=1702969&r2=1702970&view=diff
==============================================================================
---
tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndBasicAuthenticator.java
(original)
+++
tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndBasicAuthenticator.java
Mon Sep 14 15:36:35 2015
@@ -355,7 +355,7 @@ public class TestSSOnonLoginAndBasicAuth
Map<String,List<String>> respHeaders = new HashMap<>();
if (useCookie && (cookies != null)) {
- reqHeaders.put(CLIENT_COOKIE_HEADER + ":", cookies);
+ addCookies(reqHeaders);
}
ByteChunk bc = new ByteChunk();
@@ -379,7 +379,7 @@ public class TestSSOnonLoginAndBasicAuth
Map<String,List<String>> respHeaders = new HashMap<>();
if (useCookie && (cookies != null)) {
- reqHeaders.put(CLIENT_COOKIE_HEADER + ":", cookies);
+ addCookies(reqHeaders);
}
else {
if (credentials != null) {
@@ -554,18 +554,36 @@ public class TestSSOnonLoginAndBasicAuth
* extract and save the server cookies from the incoming response
*/
protected void saveCookies(Map<String,List<String>> respHeaders) {
-
// we only save the Cookie values, not header prefix
- cookies = respHeaders.get(SERVER_COOKIE_HEADER);
+ List<String> cookieHeaders = respHeaders.get(SERVER_COOKIE_HEADER);
+ if (cookieHeaders == null) {
+ cookies = null;
+ } else {
+ cookies = new ArrayList<>(cookieHeaders.size());
+ for (String cookieHeader : cookieHeaders) {
+ cookies.add(cookieHeader.substring(0,
cookieHeader.indexOf(';')));
+ }
+ }
}
/*
* add all saved cookies to the outgoing request
*/
protected void addCookies(Map<String,List<String>> reqHeaders) {
-
if ((cookies != null) && (cookies.size() > 0)) {
- reqHeaders.put(CLIENT_COOKIE_HEADER + ":", cookies);
+ StringBuilder cookieHeader = new StringBuilder();
+ boolean first = true;
+ for (String cookie : cookies) {
+ if (!first) {
+ cookieHeader.append(';');
+ } else {
+ first = false;
+ }
+ cookieHeader.append(cookie);
+ }
+ List<String> cookieHeaderList = new ArrayList<>(1);
+ cookieHeaderList.add(cookieHeader.toString());
+ reqHeaders.put(CLIENT_COOKIE_HEADER, cookieHeaderList);
}
}
Modified:
tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndDigestAuthenticator.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndDigestAuthenticator.java?rev=1702970&r1=1702969&r2=1702970&view=diff
==============================================================================
---
tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndDigestAuthenticator.java
(original)
+++
tomcat/trunk/test/org/apache/catalina/authenticator/TestSSOnonLoginAndDigestAuthenticator.java
Mon Sep 14 15:36:35 2015
@@ -470,16 +470,35 @@ public class TestSSOnonLoginAndDigestAut
protected void saveCookies(Map<String,List<String>> respHeaders) {
// we only save the Cookie values, not header prefix
- cookies = respHeaders.get(SERVER_COOKIES);
+ List<String> cookieHeaders = respHeaders.get(SERVER_COOKIES);
+ if (cookieHeaders == null) {
+ cookies = null;
+ } else {
+ cookies = new ArrayList<>(cookieHeaders.size());
+ for (String cookieHeader : cookieHeaders) {
+ cookies.add(cookieHeader.substring(0,
cookieHeader.indexOf(';')));
+ }
+ }
}
/*
* add all saved cookies to the outgoing request
*/
protected void addCookies(Map<String,List<String>> reqHeaders) {
-
if ((cookies != null) && (cookies.size() > 0)) {
- reqHeaders.put(BROWSER_COOKIES + ":", cookies);
+ StringBuilder cookieHeader = new StringBuilder();
+ boolean first = true;
+ for (String cookie : cookies) {
+ if (!first) {
+ cookieHeader.append(';');
+ } else {
+ first = false;
+ }
+ cookieHeader.append(cookie);
+ }
+ List<String> cookieHeaderList = new ArrayList<>(1);
+ cookieHeaderList.add(cookieHeader.toString());
+ reqHeaders.put(BROWSER_COOKIES, cookieHeaderList);
}
}
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]