author | dfuchs |
Mon, 17 Jun 2019 20:03:34 +0100 | |
changeset 55399 | 46049b8a5658 |
parent 51724 | 8abb0fa2c334 |
child 58108 | 5302477c8285 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55399
46049b8a5658
8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents:
51724
diff
changeset
|
2 |
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @summary Unit test for java.net.CookieManager |
|
18148
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
27 |
* @bug 6244040 7150552 7051862 |
38780
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
28 |
* @modules jdk.httpserver |
2 | 29 |
* @run main/othervm -ea CookieManagerTest |
30 |
* @author Edward Wang |
|
31 |
*/ |
|
32 |
||
17489 | 33 |
import com.sun.net.httpserver.*; |
51724
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
34 |
import java.util.Collections; |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
35 |
import java.util.LinkedList; |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
36 |
import java.util.List; |
17489 | 37 |
import java.io.IOException; |
18148
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
38 |
import java.net.*; |
38780
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
39 |
import static java.net.Proxy.NO_PROXY; |
2 | 40 |
|
41 |
public class CookieManagerTest { |
|
17489 | 42 |
|
43 |
static CookieTransactionHandler httpTrans; |
|
44 |
static HttpServer server; |
|
2 | 45 |
|
38780
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
46 |
static final String hostAddress = getAddr(); |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
47 |
|
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
48 |
/** Returns an IP literal suitable for use by the test. */ |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
49 |
static String getAddr() { |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
50 |
try { |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
51 |
InetAddress lh = InetAddress.getLocalHost(); |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
52 |
System.out.println("Trying: " + lh); |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
53 |
if (lh.isReachable(5_000)) { |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
54 |
System.out.println("Using: " + lh); |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
55 |
return lh.getHostAddress(); |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
56 |
} |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
57 |
} catch (IOException x) { |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
58 |
System.out.println("Debug: caught:" + x); |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
59 |
} |
55399
46049b8a5658
8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents:
51724
diff
changeset
|
60 |
InetAddress loopback = InetAddress.getLoopbackAddress(); |
46049b8a5658
8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents:
51724
diff
changeset
|
61 |
System.out.println("Using: \"" + loopback.getHostAddress() + "\""); |
46049b8a5658
8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents:
51724
diff
changeset
|
62 |
return loopback.getHostAddress(); |
38780
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
63 |
} |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
64 |
|
2 | 65 |
public static void main(String[] args) throws Exception { |
66 |
startHttpServer(); |
|
67 |
makeHttpCall(); |
|
68 |
||
69 |
if (httpTrans.badRequest) { |
|
70 |
throw new RuntimeException("Test failed : bad cookie header"); |
|
71 |
} |
|
18148
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
72 |
checkCookiePolicy(); |
2 | 73 |
} |
74 |
||
18148
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
75 |
public static void startHttpServer() throws IOException { |
17489 | 76 |
httpTrans = new CookieTransactionHandler(); |
55399
46049b8a5658
8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents:
51724
diff
changeset
|
77 |
server = HttpServer.create(new InetSocketAddress(hostAddress, 0), 0); |
17489 | 78 |
server.createContext("/", httpTrans); |
79 |
server.start(); |
|
2 | 80 |
} |
81 |
||
18148
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
82 |
/* |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
83 |
* Checks if CookiePolicy.ACCEPT_ORIGINAL_SERVER#shouldAccept() |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
84 |
* returns false for null arguments |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
85 |
*/ |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
86 |
private static void checkCookiePolicy() throws Exception { |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
87 |
CookiePolicy cp = CookiePolicy.ACCEPT_ORIGINAL_SERVER; |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
88 |
boolean retVal; |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
89 |
retVal = cp.shouldAccept(null, null); |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
90 |
checkValue(retVal); |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
91 |
retVal = cp.shouldAccept(null, new HttpCookie("CookieName", "CookieVal")); |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
92 |
checkValue(retVal); |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
93 |
retVal = cp.shouldAccept((new URL("http", "localhost", 2345, "/")).toURI(), |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
94 |
null); |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
95 |
checkValue(retVal); |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
96 |
} |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
97 |
|
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
98 |
private static void checkValue(boolean val) { |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
99 |
if (val) |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
100 |
throw new RuntimeException("Return value is not false!"); |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
101 |
} |
d641a1b31205
7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents:
17489
diff
changeset
|
102 |
|
17489 | 103 |
public static void makeHttpCall() throws IOException { |
2 | 104 |
try { |
38780
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
105 |
int port = server.getAddress().getPort(); |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
106 |
System.out.println("http server listenining on: " + port); |
2 | 107 |
|
108 |
// install CookieManager to use |
|
109 |
CookieHandler.setDefault(new CookieManager()); |
|
110 |
||
17489 | 111 |
for (int i = 0; i < CookieTransactionHandler.testCount; i++) { |
112 |
System.out.println("====== CookieManager test " + (i+1) |
|
113 |
+ " ======"); |
|
114 |
((CookieManager)CookieHandler.getDefault()) |
|
115 |
.setCookiePolicy(CookieTransactionHandler.testPolicies[i]); |
|
116 |
((CookieManager)CookieHandler.getDefault()) |
|
117 |
.getCookieStore().removeAll(); |
|
118 |
URL url = new URL("http" , |
|
38780
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
119 |
hostAddress, |
17489 | 120 |
server.getAddress().getPort(), |
121 |
CookieTransactionHandler.testCases[i][0] |
|
122 |
.serverPath); |
|
38780
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
123 |
System.out.println("Requesting " + url); |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
124 |
HttpURLConnection uc = (HttpURLConnection)url.openConnection(NO_PROXY); |
2 | 125 |
uc.getResponseCode(); |
126 |
uc.disconnect(); |
|
127 |
} |
|
128 |
} finally { |
|
17489 | 129 |
server.stop(0); |
2 | 130 |
} |
131 |
} |
|
132 |
} |
|
133 |
||
17489 | 134 |
class CookieTransactionHandler implements HttpHandler { |
135 |
||
136 |
private int testcaseDone = 0; |
|
137 |
private int testDone = 0; |
|
138 |
||
2 | 139 |
public static boolean badRequest = false; |
140 |
// the main test control logic will also loop exactly this number |
|
141 |
// to send http request |
|
142 |
public static final int testCount = 6; |
|
143 |
||
17489 | 144 |
@Override |
145 |
public void handle(HttpExchange exchange) throws IOException { |
|
146 |
if (testDone < testCases[testcaseDone].length) { |
|
147 |
// still have other tests to run, |
|
148 |
// check the Cookie header and then redirect it |
|
149 |
if (testDone > 0) checkRequest(exchange.getRequestHeaders()); |
|
150 |
exchange.getResponseHeaders().add("Location", |
|
151 |
testCases[testcaseDone][testDone].serverPath); |
|
152 |
exchange.getResponseHeaders() |
|
153 |
.add(testCases[testcaseDone][testDone].headerToken, |
|
154 |
testCases[testcaseDone][testDone].cookieToSend); |
|
155 |
exchange.sendResponseHeaders(302, -1); |
|
156 |
testDone++; |
|
157 |
} else { |
|
158 |
// the last test of this test case |
|
159 |
if (testDone > 0) checkRequest(exchange.getRequestHeaders()); |
|
160 |
testcaseDone++; |
|
161 |
testDone = 0; |
|
162 |
exchange.sendResponseHeaders(200, -1); |
|
163 |
} |
|
164 |
exchange.close(); |
|
165 |
} |
|
166 |
||
51724
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
167 |
private static String trim(String s) { |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
168 |
StringBuilder sb = new StringBuilder(); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
169 |
for (int i=0; i<s.length(); i++) { |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
170 |
char c = s.charAt(i); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
171 |
if (!Character.isWhitespace(c)) |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
172 |
sb.append(c); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
173 |
} |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
174 |
return sb.toString(); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
175 |
} |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
176 |
|
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
177 |
private static boolean cookieEquals(String s1, String s2) { |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
178 |
s1 = trim(s1); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
179 |
s2 = trim(s2); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
180 |
String[] s1a = s1.split(";"); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
181 |
String[] s2a = s2.split(";"); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
182 |
List<String> l1 = new LinkedList(List.of(s1a)); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
183 |
List<String> l2 = new LinkedList(List.of(s2a)); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
184 |
Collections.sort(l1); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
185 |
Collections.sort(l2); |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
186 |
int i = 0; |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
187 |
for (String s : l1) { |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
188 |
if (!s.equals(l2.get(i++))) { |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
189 |
return false; |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
190 |
} |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
191 |
} |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
192 |
return true; |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
193 |
} |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
194 |
|
17489 | 195 |
private void checkRequest(Headers hdrs) { |
196 |
||
197 |
assert testDone > 0; |
|
198 |
String cookieHeader = hdrs.getFirst("Cookie"); |
|
51724
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
199 |
if (cookieHeader != null && cookieEquals( |
8abb0fa2c334
8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents:
47216
diff
changeset
|
200 |
cookieHeader, testCases[testcaseDone][testDone-1].cookieToRecv)) |
17489 | 201 |
{ |
202 |
System.out.printf("%15s %s\n", "PASSED:", cookieHeader); |
|
203 |
} else { |
|
204 |
System.out.printf("%15s %s\n", "FAILED:", cookieHeader); |
|
205 |
System.out.printf("%15s %s\n\n", "should be:", |
|
206 |
testCases[testcaseDone][testDone-1].cookieToRecv); |
|
207 |
badRequest = true; |
|
208 |
} |
|
209 |
} |
|
210 |
||
2 | 211 |
// test cases |
212 |
public static class CookieTestCase { |
|
213 |
public String headerToken; |
|
214 |
public String cookieToSend; |
|
215 |
public String cookieToRecv; |
|
216 |
public String serverPath; |
|
217 |
||
218 |
public CookieTestCase(String h, String cts, String ctr, String sp) { |
|
219 |
headerToken = h; |
|
220 |
cookieToSend = cts; |
|
221 |
cookieToRecv = ctr; |
|
222 |
serverPath = sp; |
|
223 |
} |
|
224 |
}; |
|
225 |
||
17489 | 226 |
/* |
227 |
* these two must match each other, |
|
228 |
* i.e. testCases.length == testPolicies.length |
|
229 |
*/ |
|
2 | 230 |
|
17489 | 231 |
// the test cases to run; each test case may contain multiple roundtrips |
232 |
public static CookieTestCase[][] testCases = null; |
|
233 |
// indicates what CookiePolicy to use with each test cases |
|
234 |
public static CookiePolicy[] testPolicies = null; |
|
235 |
||
236 |
CookieTransactionHandler() { |
|
2 | 237 |
testCases = new CookieTestCase[testCount][]; |
238 |
testPolicies = new CookiePolicy[testCount]; |
|
239 |
||
38780
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
240 |
String localHostAddr = CookieManagerTest.hostAddress; |
fa8bf2d62d36
8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents:
23010
diff
changeset
|
241 |
|
2 | 242 |
int count = 0; |
243 |
||
244 |
// an http session with Netscape cookies exchanged |
|
245 |
testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER; |
|
246 |
testCases[count++] = new CookieTestCase[]{ |
|
247 |
new CookieTestCase("Set-Cookie", |
|
17489 | 248 |
"CUSTOMER=WILE:BOB; " + |
249 |
"path=/; expires=Sat, 09-Nov-2030 23:12:40 GMT;" + "domain=." + |
|
250 |
localHostAddr, |
|
2 | 251 |
"CUSTOMER=WILE:BOB", |
252 |
"/" |
|
253 |
), |
|
254 |
new CookieTestCase("Set-Cookie", |
|
255 |
"PART_NUMBER=ROCKET_LAUNCHER_0001; path=/;" + "domain=." + localHostAddr, |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
256 |
"CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001", |
2 | 257 |
"/" |
258 |
), |
|
259 |
new CookieTestCase("Set-Cookie", |
|
260 |
"SHIPPING=FEDEX; path=/foo;" + "domain=." + localHostAddr, |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
261 |
"CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001", |
2 | 262 |
"/" |
263 |
), |
|
264 |
new CookieTestCase("Set-Cookie", |
|
265 |
"SHIPPING=FEDEX; path=/foo;" + "domain=." + localHostAddr, |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
266 |
"CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX", |
2 | 267 |
"/foo" |
268 |
) |
|
269 |
}; |
|
270 |
||
271 |
// check whether or not path rule is applied |
|
272 |
testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER; |
|
273 |
testCases[count++] = new CookieTestCase[]{ |
|
274 |
new CookieTestCase("Set-Cookie", |
|
275 |
"PART_NUMBER=ROCKET_LAUNCHER_0001; path=/;" + "domain=." + localHostAddr, |
|
276 |
"PART_NUMBER=ROCKET_LAUNCHER_0001", |
|
277 |
"/" |
|
278 |
), |
|
279 |
new CookieTestCase("Set-Cookie", |
|
280 |
"PART_NUMBER=RIDING_ROCKET_0023; path=/ammo;" + "domain=." + localHostAddr, |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
281 |
"PART_NUMBER=RIDING_ROCKET_0023; PART_NUMBER=ROCKET_LAUNCHER_0001", |
2 | 282 |
"/ammo" |
283 |
) |
|
284 |
}; |
|
285 |
||
286 |
// an http session with rfc2965 cookies exchanged |
|
287 |
testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER; |
|
288 |
testCases[count++] = new CookieTestCase[]{ |
|
289 |
new CookieTestCase("Set-Cookie2", |
|
290 |
"Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr, |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
291 |
"$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"", |
2 | 292 |
"/acme/login" |
293 |
), |
|
294 |
new CookieTestCase("Set-Cookie2", |
|
295 |
"Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\";" + "domain=." + localHostAddr, |
|
17489 | 296 |
"$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." + |
297 |
localHostAddr + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" |
|
298 |
+ "$Domain=\"." + localHostAddr + "\"", |
|
2 | 299 |
"/acme/pickitem" |
300 |
), |
|
301 |
new CookieTestCase("Set-Cookie2", |
|
302 |
"Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr, |
|
17489 | 303 |
"$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + |
304 |
"\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." |
|
305 |
+ localHostAddr + "\"" + "; Shipping=\"FedEx\";$Path=\"/acme\";" + |
|
306 |
"$Domain=\"." + localHostAddr + "\"", |
|
2 | 307 |
"/acme/shipping" |
308 |
) |
|
309 |
}; |
|
310 |
||
311 |
// check whether or not the path rule is applied |
|
312 |
testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER; |
|
313 |
testCases[count++] = new CookieTestCase[]{ |
|
314 |
new CookieTestCase("Set-Cookie2", |
|
315 |
"Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr, |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
316 |
"$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"", |
2 | 317 |
"/acme/ammo" |
318 |
), |
|
319 |
new CookieTestCase("Set-Cookie2", |
|
17489 | 320 |
"Part_Number=\"Riding_Rocket_0023\"; Version=\"1\"; Path=\"/acme/ammo\";" + "domain=." |
321 |
+ localHostAddr, |
|
322 |
"$Version=\"1\"; Part_Number=\"Riding_Rocket_0023\";$Path=\"/acme/ammo\";$Domain=\"." |
|
323 |
+ localHostAddr + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" |
|
324 |
+ "$Domain=\"." + localHostAddr + "\"", |
|
2 | 325 |
"/acme/ammo" |
326 |
), |
|
327 |
new CookieTestCase("", |
|
328 |
"", |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
329 |
"$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"", |
2 | 330 |
"/acme/parts" |
331 |
) |
|
332 |
}; |
|
333 |
||
334 |
// new cookie should overwrite old cookie |
|
335 |
testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER; |
|
336 |
testCases[count++] = new CookieTestCase[]{ |
|
337 |
new CookieTestCase("Set-Cookie2", |
|
338 |
"Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr, |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
339 |
"$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"", |
2 | 340 |
"/acme" |
341 |
), |
|
342 |
new CookieTestCase("Set-Cookie2", |
|
343 |
"Part_Number=\"Rocket_Launcher_2000\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr, |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
344 |
"$Version=\"1\"; Part_Number=\"Rocket_Launcher_2000\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"", |
2 | 345 |
"/acme" |
346 |
) |
|
347 |
}; |
|
348 |
||
349 |
// cookies without domain attributes |
|
2924
a67f12d92bdd
6349566: java.net.CookieManager doesn't set default domain
jccollet
parents:
715
diff
changeset
|
350 |
// RFC 2965 states that domain should default to host |
2 | 351 |
testPolicies[count] = CookiePolicy.ACCEPT_ALL; |
352 |
testCases[count++] = new CookieTestCase[]{ |
|
353 |
new CookieTestCase("Set-Cookie2", |
|
354 |
"Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\"", |
|
2924
a67f12d92bdd
6349566: java.net.CookieManager doesn't set default domain
jccollet
parents:
715
diff
changeset
|
355 |
"$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"", |
2 | 356 |
"/acme/login" |
357 |
), |
|
358 |
new CookieTestCase("Set-Cookie2", |
|
359 |
"Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\"", |
|
17489 | 360 |
"$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" + |
361 |
"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"", |
|
2 | 362 |
"/acme/pickitem" |
363 |
), |
|
364 |
new CookieTestCase("Set-Cookie2", |
|
365 |
"Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\"", |
|
17489 | 366 |
"$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" + |
367 |
"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" + |
|
368 |
"; Shipping=\"FedEx\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"", |
|
2 | 369 |
"/acme/shipping" |
370 |
) |
|
371 |
}; |
|
372 |
||
373 |
assert count == testCount; |
|
374 |
} |
|
375 |
} |