jdk/test/java/net/CookieHandler/CookieManagerTest.java
author khazra
Thu, 16 May 2013 10:58:20 -0700
changeset 17489 a74a13b9aa93
parent 14787 54eb3f090934
child 18148 d641a1b31205
permissions -rw-r--r--
7150552: network test hangs [macosx] Summary: Remove usage of test/sun/net/www/httptest Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13788
diff changeset
     2
 * Copyright (c) 2005, 2012, 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
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    27
 * @bug 6244040 7150552
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @run main/othervm -ea CookieManagerTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Edward Wang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    32
import com.sun.net.httpserver.*;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    33
import java.io.IOException;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    34
import java.net.CookieHandler;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    35
import java.net.CookieManager;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    36
import java.net.CookiePolicy;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    37
import java.net.HttpURLConnection;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    38
import java.net.InetAddress;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    39
import java.net.InetSocketAddress;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    40
import java.net.URL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class CookieManagerTest {
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    43
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    44
    static CookieTransactionHandler httpTrans;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    45
    static HttpServer server;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        startHttpServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        makeHttpCall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (httpTrans.badRequest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            throw new RuntimeException("Test failed : bad cookie header");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    56
    public static void startHttpServer() throws IOException {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    57
        httpTrans = new CookieTransactionHandler();
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    58
        server = HttpServer.create(new InetSocketAddress(0), 0);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    59
        server.createContext("/", httpTrans);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    60
        server.start();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    63
    public static void makeHttpCall() throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        try {
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    65
            System.out.println("http server listenining on: "
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    66
                    + server.getAddress().getPort());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            // install CookieManager to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            CookieHandler.setDefault(new CookieManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    71
            for (int i = 0; i < CookieTransactionHandler.testCount; i++) {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    72
                System.out.println("====== CookieManager test " + (i+1)
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    73
                                    + " ======");
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    74
                ((CookieManager)CookieHandler.getDefault())
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    75
                    .setCookiePolicy(CookieTransactionHandler.testPolicies[i]);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    76
                ((CookieManager)CookieHandler.getDefault())
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    77
                    .getCookieStore().removeAll();
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    78
                URL url = new URL("http" ,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    79
                                  InetAddress.getLocalHost().getHostAddress(),
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    80
                                  server.getAddress().getPort(),
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    81
                                  CookieTransactionHandler.testCases[i][0]
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    82
                                                          .serverPath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                HttpURLConnection uc = (HttpURLConnection)url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                uc.getResponseCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                uc.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } finally {
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    88
            server.stop(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    93
class CookieTransactionHandler implements HttpHandler {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    94
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    95
    private int testcaseDone = 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    96
    private int testDone = 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
    97
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static boolean badRequest = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // the main test control logic will also loop exactly this number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // to send http request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public static final int testCount = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private String localHostAddr = "127.0.0.1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   105
    @Override
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   106
    public void handle(HttpExchange exchange) throws IOException {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   107
        if (testDone < testCases[testcaseDone].length) {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   108
            // still have other tests to run,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   109
            // check the Cookie header and then redirect it
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   110
            if (testDone > 0) checkRequest(exchange.getRequestHeaders());
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   111
            exchange.getResponseHeaders().add("Location",
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   112
                    testCases[testcaseDone][testDone].serverPath);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   113
            exchange.getResponseHeaders()
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   114
                    .add(testCases[testcaseDone][testDone].headerToken,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   115
                         testCases[testcaseDone][testDone].cookieToSend);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   116
            exchange.sendResponseHeaders(302, -1);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   117
            testDone++;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   118
        } else {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   119
            // the last test of this test case
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   120
            if (testDone > 0) checkRequest(exchange.getRequestHeaders());
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   121
            testcaseDone++;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   122
            testDone = 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   123
            exchange.sendResponseHeaders(200, -1);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   124
        }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   125
        exchange.close();
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   126
    }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   127
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   128
    private void checkRequest(Headers hdrs) {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   129
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   130
        assert testDone > 0;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   131
        String cookieHeader = hdrs.getFirst("Cookie");
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   132
        if (cookieHeader != null &&
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   133
            cookieHeader
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   134
                .equalsIgnoreCase(testCases[testcaseDone][testDone-1]
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   135
                                  .cookieToRecv))
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   136
        {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   137
            System.out.printf("%15s %s\n", "PASSED:", cookieHeader);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   138
        } else {
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   139
            System.out.printf("%15s %s\n", "FAILED:", cookieHeader);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   140
            System.out.printf("%15s %s\n\n", "should be:",
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   141
                    testCases[testcaseDone][testDone-1].cookieToRecv);
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   142
            badRequest = true;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   143
        }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   144
    }
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   145
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    // test cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static class CookieTestCase {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        public String headerToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        public String cookieToSend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        public String cookieToRecv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        public String serverPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        public CookieTestCase(String h, String cts, String ctr, String sp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            headerToken = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            cookieToSend = cts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            cookieToRecv = ctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            serverPath = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   161
    /*
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   162
     * these two must match each other,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   163
     * i.e. testCases.length == testPolicies.length
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   164
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   166
    // the test cases to run; each test case may contain multiple roundtrips
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   167
    public static CookieTestCase[][] testCases = null;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   168
    // indicates what CookiePolicy to use with each test cases
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   169
    public static CookiePolicy[] testPolicies = null;
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   170
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   171
    CookieTransactionHandler() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        testCases = new CookieTestCase[testCount][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        testPolicies = new CookiePolicy[testCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            localHostAddr = InetAddress.getLocalHost().getHostAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        } catch (Exception ignored) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        // an http session with Netscape cookies exchanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                new CookieTestCase("Set-Cookie",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   185
                "CUSTOMER=WILE:BOB; " +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   186
                "path=/; expires=Sat, 09-Nov-2030 23:12:40 GMT;" + "domain=." +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   187
                localHostAddr,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                "CUSTOMER=WILE:BOB",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                "PART_NUMBER=ROCKET_LAUNCHER_0001; path=/;" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   193
                "CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                "SHIPPING=FEDEX; path=/foo;" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   198
                "CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                "SHIPPING=FEDEX; path=/foo;" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   203
                "CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                "/foo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // check whether or not path rule is applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                "PART_NUMBER=ROCKET_LAUNCHER_0001; path=/;" + "domain=." + localHostAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                "PART_NUMBER=ROCKET_LAUNCHER_0001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                new CookieTestCase("Set-Cookie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                "PART_NUMBER=RIDING_ROCKET_0023; path=/ammo;" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   218
                "PART_NUMBER=RIDING_ROCKET_0023; PART_NUMBER=ROCKET_LAUNCHER_0001",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                "/ammo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // an http session with rfc2965 cookies exchanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                "Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   228
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                "/acme/login"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                "Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\";" + "domain=." + localHostAddr,
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   233
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   234
                    localHostAddr  + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";"
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   235
                    + "$Domain=\"." + localHostAddr +  "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                "/acme/pickitem"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                "Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   240
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr  +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   241
                    "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"."
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   242
                    + localHostAddr  + "\"" + "; Shipping=\"FedEx\";$Path=\"/acme\";" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   243
                    "$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                "/acme/shipping"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        // check whether or not the path rule is applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        testPolicies[count] = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                "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
   253
                "$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                "/acme/ammo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                new CookieTestCase("Set-Cookie2",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   257
                "Part_Number=\"Riding_Rocket_0023\"; Version=\"1\"; Path=\"/acme/ammo\";" + "domain=."
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   258
                    + localHostAddr,
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   259
                "$Version=\"1\"; Part_Number=\"Riding_Rocket_0023\";$Path=\"/acme/ammo\";$Domain=\"."
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   260
                    + localHostAddr  + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";"
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   261
                    + "$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                "/acme/ammo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                new CookieTestCase("",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                "",
74
068494063b1b 6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents: 2
diff changeset
   266
                "$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                "/acme/parts"
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
        // new cookie should overwrite old cookie
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-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                "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
   276
                "$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                "/acme"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                "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
   281
                "$Version=\"1\"; Part_Number=\"Rocket_Launcher_2000\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                "/acme"
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
        // cookies without domain attributes
2924
a67f12d92bdd 6349566: java.net.CookieManager doesn't set default domain
jccollet
parents: 715
diff changeset
   287
        // RFC 2965 states that domain should default to host
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        testPolicies[count] = CookiePolicy.ACCEPT_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        testCases[count++] = new CookieTestCase[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                "Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\"",
2924
a67f12d92bdd 6349566: java.net.CookieManager doesn't set default domain
jccollet
parents: 715
diff changeset
   292
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                "/acme/login"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                new CookieTestCase("Set-Cookie2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                "Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\"",
17489
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   297
                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   298
                    "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$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\"",
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=\""+localHostAddr+"\"" +
a74a13b9aa93 7150552: network test hangs [macosx]
khazra
parents: 14787
diff changeset
   305
                    "; Shipping=\"FedEx\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                "/acme/shipping"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        assert count == testCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
}