jdk/test/sun/net/www/MessageHeaderTest.java
author michaelm
Mon, 10 Dec 2012 14:56:44 +0000
changeset 14766 1f22dd6f2658
child 30820 0d4717a011d3
permissions -rw-r--r--
8003948: NTLM/Negotiate authentication problem Reviewed-by: chegar, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14766
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
     1
/*
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
     4
 *
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
     8
 *
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    13
 * accompanied this code).
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    14
 *
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    18
 *
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    21
 * questions.
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    22
 */
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    23
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    24
/**
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    25
 * @test
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    26
 * @bug 8003948
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    27
 * @run main MessageHeaderTest
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    28
 */
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    29
import java.io.*;
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    30
import sun.net.www.MessageHeader;
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    31
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    32
public class MessageHeaderTest {
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    33
    public static void main (String[] args) throws Exception {
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    34
        for (int i=0; i<7; i++) {
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    35
            ByteArrayInputStream bis = new ByteArrayInputStream(headers[i].getBytes());
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    36
            MessageHeader h = new MessageHeader(bis);
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    37
            String before = h.toString();
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    38
            before = before.substring(before.indexOf('{'));
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    39
            boolean result = h.filterNTLMResponses("WWW-Authenticate");
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    40
            String after = h.toString();
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    41
            after = after.substring(after.indexOf('{'));
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    42
            if (!expected[i].equals(after)) {
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    43
                throw new RuntimeException(Integer.toString(i) + " expected != after");
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    44
            }
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    45
            if (result != expectedResult[i]) {
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    46
                throw new RuntimeException(Integer.toString(i) + " result != expectedResult");
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    47
            }
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    48
        }
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    49
    }
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    50
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    51
    static String expected[] = {
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    52
        "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    53
        "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: }",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    54
        "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    55
        "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    56
        "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}{Bar: foo}",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    57
        "{null: HTTP/1.1 200 Ok}{WWW-Authenticate: Negotiate}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM}{Bar: foo}{WWW-Authenticate: Kerberos}",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    58
        "{null: HTTP/1.1 200 Ok}{Foo: foo}{Bar: }{WWW-Authenticate: NTLM blob}{Bar: foo blob}"
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    59
    };
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    60
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    61
    static boolean[] expectedResult = {
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    62
        false, false, true, true, true, false, false
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    63
    };
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    64
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    65
    static String[] headers = {
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    66
        "HTTP/1.1 200 Ok\r\nFoo: bar\r\nBar: foo\r\nWWW-Authenticate: NTLM sdsds",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    67
        "HTTP/1.1 200 Ok\r\nFoo: bar\r\nBar: foo\r\nWWW-Authenticate:",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    68
        "HTTP/1.1 200 Ok\r\nFoo: bar\r\nBar: foo\r\nWWW-Authenticate: NTLM sdsds\r\nWWW-Authenticate: Negotiate",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    69
        "HTTP/1.1 200 Ok\r\nFoo: bar\r\nBar: foo\r\nWWW-Authenticate: NTLM sdsds\r\nWWW-Authenticate: Negotiate\r\nWWW-Authenticate: Kerberos",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    70
        "HTTP/1.1 200 Ok\r\nWWW-Authenticate: Negotiate\r\nFoo: bar\r\nBar: foo\r\nWWW-Authenticate: NTLM sdsds\r\nBar: foo\r\nWWW-Authenticate: Kerberos",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    71
        "HTTP/1.1 200 Ok\r\nWWW-Authenticate: Negotiate\r\nFoo: bar\r\nBar: foo\r\nWWW-Authenticate: NTLM\r\nBar: foo\r\nWWW-Authenticate: Kerberos",
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    72
        "HTTP/1.1 200 Ok\r\nFoo: foo\r\nBar:\r\nWWW-Authenticate: NTLM blob\r\nBar: foo blob"
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    73
    };
1f22dd6f2658 8003948: NTLM/Negotiate authentication problem
michaelm
parents:
diff changeset
    74
}