test/jdk/java/net/CookieHandler/CookieManagerTest.java
author dfuchs
Mon, 17 Jun 2019 20:03:34 +0100
changeset 55399 46049b8a5658
parent 51724 8abb0fa2c334
child 58108 5302477c8285
permissions -rw-r--r--
8225578: Replace wildcard address with loopback or local host in tests - part 16 Summary: Fixes java/net/Authenticator and java/net/CookieHandler to stop depending on the wildcard address, wherever possible. Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2924
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2924
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2924
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @run main/othervm -ea CookieManagerTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @author Edward Wang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    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
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class CookieManagerTest {
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    42
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    43
    static CookieTransactionHandler httpTrans;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    44
    static HttpServer server;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        startHttpServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        makeHttpCall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (httpTrans.badRequest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            throw new RuntimeException("Test failed : bad cookie header");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
18148
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    72
        checkCookiePolicy();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    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
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    78
        server.createContext("/", httpTrans);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    79
        server.start();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   103
    public static void makeHttpCall() throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            // install CookieManager to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            CookieHandler.setDefault(new CookieManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   111
            for (int i = 0; i < CookieTransactionHandler.testCount; i++) {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   112
                System.out.println("====== CookieManager test " + (i+1)
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   113
                                    + " ======");
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   114
                ((CookieManager)CookieHandler.getDefault())
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   115
                    .setCookiePolicy(CookieTransactionHandler.testPolicies[i]);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   116
                ((CookieManager)CookieHandler.getDefault())
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   117
                    .getCookieStore().removeAll();
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   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
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   120
                                  server.getAddress().getPort(),
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   121
                                  CookieTransactionHandler.testCases[i][0]
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                uc.getResponseCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                uc.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } finally {
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   129
            server.stop(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   134
class CookieTransactionHandler implements HttpHandler {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   135
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   136
    private int testcaseDone = 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   137
    private int testDone = 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   138
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static boolean badRequest = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    // the main test control logic will also loop exactly this number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    // to send http request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public static final int testCount = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   144
    @Override
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   145
    public void handle(HttpExchange exchange) throws IOException {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   146
        if (testDone < testCases[testcaseDone].length) {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   147
            // still have other tests to run,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   148
            // check the Cookie header and then redirect it
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   149
            if (testDone > 0) checkRequest(exchange.getRequestHeaders());
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   150
            exchange.getResponseHeaders().add("Location",
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   151
                    testCases[testcaseDone][testDone].serverPath);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   152
            exchange.getResponseHeaders()
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   153
                    .add(testCases[testcaseDone][testDone].headerToken,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   154
                         testCases[testcaseDone][testDone].cookieToSend);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   155
            exchange.sendResponseHeaders(302, -1);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   156
            testDone++;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   157
        } else {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   158
            // the last test of this test case
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   159
            if (testDone > 0) checkRequest(exchange.getRequestHeaders());
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   160
            testcaseDone++;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   161
            testDone = 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   162
            exchange.sendResponseHeaders(200, -1);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   163
        }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   164
        exchange.close();
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   165
    }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   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
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   195
    private void checkRequest(Headers hdrs) {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   196
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   197
        assert testDone > 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   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
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   201
        {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   202
            System.out.printf("%15s %s\n", "PASSED:", cookieHeader);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   203
        } else {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   204
            System.out.printf("%15s %s\n", "FAILED:", cookieHeader);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   205
            System.out.printf("%15s %s\n\n", "should be:",
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   206
                    testCases[testcaseDone][testDone-1].cookieToRecv);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   207
            badRequest = true;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   208
        }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   209
    }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   210
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // test cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public static class CookieTestCase {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        public String headerToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        public String cookieToSend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        public String cookieToRecv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        public String serverPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        public CookieTestCase(String h, String cts, String ctr, String sp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            headerToken = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            cookieToSend = cts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            cookieToRecv = ctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            serverPath = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   226
    /*
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   227
     * these two must match each other,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   228
     * i.e. testCases.length == testPolicies.length
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   229
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   231
    // the test cases to run; each test case may contain multiple roundtrips
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   232
    public static CookieTestCase[][] testCases = null;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   233
    // indicates what CookiePolicy to use with each test cases
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   234
    public static CookiePolicy[] testPolicies = null;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   235
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   236
    CookieTransactionHandler() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        testCases = new CookieTestCase[testCount][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        testPolicies = new CookiePolicy[testCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // an http session with Netscape cookies exchanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                new CookieTestCase("Set-Cookie",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   248
                "CUSTOMER=WILE:BOB; " +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   249
                "path=/; expires=Sat, 09-Nov-2030 23:12:40 GMT;" + "domain=." +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   250
                localHostAddr,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                "CUSTOMER=WILE:BOB",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                "/foo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // check whether or not path rule is applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                "PART_NUMBER=ROCKET_LAUNCHER_0001; path=/;" + "domain=." + localHostAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                "PART_NUMBER=ROCKET_LAUNCHER_0001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                "/ammo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        // an http session with rfc2965 cookies exchanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                "/acme/login"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                "Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\";" + "domain=." + localHostAddr,
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   296
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   297
                    localHostAddr  + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";"
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   298
                    + "$Domain=\"." + localHostAddr +  "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                "/acme/pickitem"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                "Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   303
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr  +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   304
                    "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"."
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   305
                    + localHostAddr  + "\"" + "; Shipping=\"FedEx\";$Path=\"/acme\";" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   306
                    "$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                "/acme/shipping"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        // check whether or not the path rule is applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                "/acme/ammo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                new CookieTestCase("Set-Cookie2",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   320
                "Part_Number=\"Riding_Rocket_0023\"; Version=\"1\"; Path=\"/acme/ammo\";" + "domain=."
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   321
                    + localHostAddr,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   322
                "$Version=\"1\"; Part_Number=\"Riding_Rocket_0023\";$Path=\"/acme/ammo\";$Domain=\"."
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   323
                    + localHostAddr  + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";"
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   324
                    + "$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                "/acme/ammo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                new CookieTestCase("",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                "/acme/parts"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // new cookie should overwrite old cookie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                "/acme"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                "/acme"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        testPolicies[count] = CookiePolicy.ACCEPT_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                "/acme/login"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                "Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\"",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   360
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   361
                    "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                "/acme/pickitem"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                "Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\"",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   366
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   367
                    "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   368
                    "; Shipping=\"FedEx\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                "/acme/shipping"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        assert count == testCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
}