test/jdk/java/net/CookieHandler/CookieManagerTest.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58108 5302477c8285
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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
58108
5302477c8285 8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents: 55399
diff changeset
    29
 *          java.logging
5302477c8285 8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents: 55399
diff changeset
    30
 * @run main/othervm -ea -esa CookieManagerTest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @author Edward Wang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    34
import com.sun.net.httpserver.*;
51724
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
    35
import java.util.Collections;
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
    36
import java.util.LinkedList;
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
    37
import java.util.List;
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    38
import java.io.IOException;
18148
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    39
import java.net.*;
58108
5302477c8285 8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents: 55399
diff changeset
    40
import java.util.logging.Level;
5302477c8285 8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents: 55399
diff changeset
    41
import java.util.logging.Logger;
38780
fa8bf2d62d36 8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents: 23010
diff changeset
    42
import static java.net.Proxy.NO_PROXY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class CookieManagerTest {
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    45
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    46
    static CookieTransactionHandler httpTrans;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    47
    static HttpServer server;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
38780
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 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
    50
fa8bf2d62d36 8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents: 23010
diff changeset
    51
    /** 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
    52
    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
    53
        try {
fa8bf2d62d36 8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents: 23010
diff changeset
    54
            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
    55
            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
    56
            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
    57
                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
    58
                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
    59
            }
fa8bf2d62d36 8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents: 23010
diff changeset
    60
        } 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
    61
            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
    62
        }
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 51724
diff changeset
    63
        InetAddress loopback = InetAddress.getLoopbackAddress();
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 51724
diff changeset
    64
        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
    65
        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
    66
    }
fa8bf2d62d36 8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents: 23010
diff changeset
    67
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static void main(String[] args) throws Exception {
58108
5302477c8285 8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents: 55399
diff changeset
    69
        // logs everything...
5302477c8285 8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents: 55399
diff changeset
    70
        Logger root = Logger.getLogger("");
5302477c8285 8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents: 55399
diff changeset
    71
        root.setLevel(Level.ALL);
5302477c8285 8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents: 55399
diff changeset
    72
        root.getHandlers()[0].setLevel(Level.ALL);
5302477c8285 8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents: 55399
diff changeset
    73
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        startHttpServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        makeHttpCall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (httpTrans.badRequest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new RuntimeException("Test failed : bad cookie header");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
18148
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    80
        checkCookiePolicy();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
18148
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    83
   public static void startHttpServer() throws IOException {
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    84
        httpTrans = new CookieTransactionHandler();
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 51724
diff changeset
    85
        server = HttpServer.create(new InetSocketAddress(hostAddress, 0), 0);
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    86
        server.createContext("/", httpTrans);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    87
        server.start();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
18148
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    90
    /*
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    91
     * Checks if CookiePolicy.ACCEPT_ORIGINAL_SERVER#shouldAccept()
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    92
     * returns false for null arguments
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    93
     */
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    94
    private static void checkCookiePolicy() throws Exception {
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    95
        CookiePolicy cp = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    96
        boolean retVal;
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    97
        retVal = cp.shouldAccept(null, null);
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    98
        checkValue(retVal);
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
    99
        retVal = cp.shouldAccept(null, new HttpCookie("CookieName", "CookieVal"));
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   100
        checkValue(retVal);
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   101
        retVal = cp.shouldAccept((new URL("http", "localhost", 2345, "/")).toURI(),
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   102
                                  null);
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   103
        checkValue(retVal);
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   104
    }
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   105
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   106
    private static void checkValue(boolean val) {
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   107
        if (val)
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   108
            throw new RuntimeException("Return value is not false!");
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   109
    }
d641a1b31205 7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER
khazra
parents: 17489
diff changeset
   110
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   111
    public static void makeHttpCall() throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        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
   113
            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
   114
            System.out.println("http server listenining on: " + port);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            // install CookieManager to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            CookieHandler.setDefault(new CookieManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   119
            for (int i = 0; i < CookieTransactionHandler.testCount; i++) {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   120
                System.out.println("====== CookieManager test " + (i+1)
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   121
                                    + " ======");
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   122
                ((CookieManager)CookieHandler.getDefault())
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   123
                    .setCookiePolicy(CookieTransactionHandler.testPolicies[i]);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   124
                ((CookieManager)CookieHandler.getDefault())
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   125
                    .getCookieStore().removeAll();
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   126
                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
   127
                                  hostAddress,
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   128
                                  server.getAddress().getPort(),
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   129
                                  CookieTransactionHandler.testCases[i][0]
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   130
                                                          .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
   131
                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
   132
                HttpURLConnection uc = (HttpURLConnection)url.openConnection(NO_PROXY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                uc.getResponseCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                uc.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        } finally {
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   137
            server.stop(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   142
class CookieTransactionHandler implements HttpHandler {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   143
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   144
    private int testcaseDone = 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   145
    private int testDone = 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   146
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static boolean badRequest = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    // the main test control logic will also loop exactly this number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    // to send http request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public static final int testCount = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   152
    @Override
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   153
    public void handle(HttpExchange exchange) throws IOException {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   154
        if (testDone < testCases[testcaseDone].length) {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   155
            // still have other tests to run,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   156
            // check the Cookie header and then redirect it
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   157
            if (testDone > 0) checkRequest(exchange.getRequestHeaders());
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   158
            exchange.getResponseHeaders().add("Location",
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   159
                    testCases[testcaseDone][testDone].serverPath);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   160
            exchange.getResponseHeaders()
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   161
                    .add(testCases[testcaseDone][testDone].headerToken,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   162
                         testCases[testcaseDone][testDone].cookieToSend);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   163
            exchange.sendResponseHeaders(302, -1);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   164
            testDone++;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   165
        } else {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   166
            // the last test of this test case
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   167
            if (testDone > 0) checkRequest(exchange.getRequestHeaders());
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   168
            testcaseDone++;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   169
            testDone = 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   170
            exchange.sendResponseHeaders(200, -1);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   171
        }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   172
        exchange.close();
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   173
    }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   174
51724
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   175
    private static String trim(String s) {
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   176
        StringBuilder sb = new StringBuilder();
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   177
        for (int i=0; i<s.length(); i++) {
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   178
            char c = s.charAt(i);
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   179
            if (!Character.isWhitespace(c))
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   180
                sb.append(c);
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   181
        }
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   182
        return sb.toString();
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   183
    }
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   184
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   185
    private static boolean cookieEquals(String s1, String s2) {
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   186
        s1 = trim(s1);
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   187
        s2 = trim(s2);
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   188
        String[] s1a = s1.split(";");
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   189
        String[] s2a = s2.split(";");
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   190
        List<String> l1 = new LinkedList(List.of(s1a));
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   191
        List<String> l2 = new LinkedList(List.of(s2a));
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   192
        Collections.sort(l1);
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   193
        Collections.sort(l2);
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   194
        int i = 0;
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   195
        for (String s : l1) {
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   196
            if (!s.equals(l2.get(i++))) {
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   197
                return false;
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   198
            }
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   199
        }
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   200
        return true;
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   201
    }
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   202
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   203
    private void checkRequest(Headers hdrs) {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   204
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   205
        assert testDone > 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   206
        String cookieHeader = hdrs.getFirst("Cookie");
51724
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   207
        if (cookieHeader != null && cookieEquals(
8abb0fa2c334 8210311: IllegalArgumentException in CookieManager - Comparison method violates its general contract
michaelm
parents: 47216
diff changeset
   208
                cookieHeader, testCases[testcaseDone][testDone-1].cookieToRecv))
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   209
        {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   210
            System.out.printf("%15s %s\n", "PASSED:", cookieHeader);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   211
        } else {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   212
            System.out.printf("%15s %s\n", "FAILED:", cookieHeader);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   213
            System.out.printf("%15s %s\n\n", "should be:",
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   214
                    testCases[testcaseDone][testDone-1].cookieToRecv);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   215
            badRequest = true;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   216
        }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   217
    }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   218
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    // test cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public static class CookieTestCase {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        public String headerToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        public String cookieToSend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        public String cookieToRecv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        public String serverPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        public CookieTestCase(String h, String cts, String ctr, String sp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            headerToken = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            cookieToSend = cts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            cookieToRecv = ctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            serverPath = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   234
    /*
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   235
     * these two must match each other,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   236
     * i.e. testCases.length == testPolicies.length
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   237
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   239
    // the test cases to run; each test case may contain multiple roundtrips
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   240
    public static CookieTestCase[][] testCases = null;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   241
    // indicates what CookiePolicy to use with each test cases
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   242
    public static CookiePolicy[] testPolicies = null;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   243
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   244
    CookieTransactionHandler() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        testCases = new CookieTestCase[testCount][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        testPolicies = new CookiePolicy[testCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
38780
fa8bf2d62d36 8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents: 23010
diff changeset
   248
        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
   249
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        // an http session with Netscape cookies exchanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                new CookieTestCase("Set-Cookie",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   256
                "CUSTOMER=WILE:BOB; " +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   257
                "path=/; expires=Sat, 09-Nov-2030 23:12:40 GMT;" + "domain=." +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   258
                localHostAddr,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                "CUSTOMER=WILE:BOB",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                "PART_NUMBER=ROCKET_LAUNCHER_0001; path=/;" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   264
                "CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                "SHIPPING=FEDEX; path=/foo;" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   269
                "CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                "SHIPPING=FEDEX; path=/foo;" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   274
                "CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                "/foo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        // check whether or not path rule is applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                "PART_NUMBER=ROCKET_LAUNCHER_0001; path=/;" + "domain=." + localHostAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                "PART_NUMBER=ROCKET_LAUNCHER_0001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                "PART_NUMBER=RIDING_ROCKET_0023; path=/ammo;" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   289
                "PART_NUMBER=RIDING_ROCKET_0023; PART_NUMBER=ROCKET_LAUNCHER_0001",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                "/ammo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // an http session with rfc2965 cookies exchanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                "Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   299
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                "/acme/login"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                "Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\";" + "domain=." + localHostAddr,
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   304
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   305
                    localHostAddr  + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$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/pickitem"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                "Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   311
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr  +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   312
                    "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"."
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   313
                    + localHostAddr  + "\"" + "; Shipping=\"FedEx\";$Path=\"/acme\";" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   314
                    "$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                "/acme/shipping"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        // check whether or not the path rule is applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                "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
   324
                "$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$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("Set-Cookie2",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   328
                "Part_Number=\"Riding_Rocket_0023\"; Version=\"1\"; Path=\"/acme/ammo\";" + "domain=."
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   329
                    + localHostAddr,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   330
                "$Version=\"1\"; Part_Number=\"Riding_Rocket_0023\";$Path=\"/acme/ammo\";$Domain=\"."
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   331
                    + localHostAddr  + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";"
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   332
                    + "$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                "/acme/ammo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                new CookieTestCase("",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                "",
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   337
                "$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                "/acme/parts"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // new cookie should overwrite old cookie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                "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
   347
                "$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                "/acme"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                "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
   352
                "$Version=\"1\"; Part_Number=\"Rocket_Launcher_2000\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                "/acme"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // cookies without domain attributes
2924
a67f12d92bdd 6349566: java.net.CookieManager doesn't set default domain
jccollet
parents: 715
diff changeset
   358
        // RFC 2965 states that domain should default to host
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        testPolicies[count] = CookiePolicy.ACCEPT_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                "Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\"",
2924
a67f12d92bdd 6349566: java.net.CookieManager doesn't set default domain
jccollet
parents: 715
diff changeset
   363
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                "/acme/login"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                "Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\"",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   368
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   369
                    "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                "/acme/pickitem"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                "Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\"",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   374
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   375
                    "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   376
                    "; Shipping=\"FedEx\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                "/acme/shipping"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        assert count == testCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
}