jdk/test/sun/net/www/protocol/http/DigestTest.java
author chegar
Fri, 16 Dec 2011 16:09:41 +0000
changeset 11284 2750cfd2352c
parent 7668 d4a77089c587
child 30820 0d4717a011d3
permissions -rw-r--r--
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies Reviewed-by: michaelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6115
diff changeset
     2
 * Copyright (c) 2001, 2010, 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: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
 * @bug 4432213
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @run main/othervm -Dhttp.auth.digest.validateServer=true DigestTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary  Need to support Digest Authentication for Proxies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.net.www.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/* This is one simple test of the RFC2617 digest authentication behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * It specifically tests that the client correctly checks the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Authentication-Info header field from the server and throws an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * if the password is wrong
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class DigestServer extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    ServerSocket s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    Socket   s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    InputStream  is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    OutputStream os;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    String reply1 = "HTTP/1.1 401 Unauthorized\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        "WWW-Authenticate: Digest realm=\""+realm+"\" domain=/ "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        "nonce=\""+nonce+"\" qop=\"auth\"\r\n\r\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    String reply2 = "HTTP/1.1 200 OK\r\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        "Server: Apache/1.3.14 (Unix)\r\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        "Content-Type: text/html; charset=iso-8859-1\r\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        "Transfer-encoding: chunked\r\n\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        "B\r\nHelloWorld1\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        "B\r\nHelloWorld2\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        "B\r\nHelloWorld3\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        "B\r\nHelloWorld4\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        "B\r\nHelloWorld5\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        "0\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        "Authentication-Info: ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    DigestServer (ServerSocket y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        s = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        port = s.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public void run () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                s1 = s.accept ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                is = s1.getInputStream ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                os = s1.getOutputStream ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                is.read ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                os.write (reply1.getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                Thread.sleep (2000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                s1.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                s1 = s.accept ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                is = s1.getInputStream ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                os = s1.getOutputStream ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                is.read ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                // need to get the cnonce out of the response
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                MessageHeader header = new MessageHeader (is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                String raw = header.findValue ("Authorization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                HeaderParser parser = new HeaderParser (raw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                String cnonce = parser.findValue ("cnonce");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                String cnstring = parser.findValue ("nc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                String reply = reply2 + getAuthorization (uri, "GET", cnonce, cnstring) +"\r\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                os.write (reply.getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                Thread.sleep (2000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                s1.close ();
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    98
        } catch (Exception e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            System.out.println (e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            e.printStackTrace();
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   101
        } finally {
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   102
            try { s.close(); } catch (IOException unused) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    static char[] passwd = "password".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    static String username = "user";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    static String nonce = "abcdefghijklmnopqrstuvwxyz";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    static String realm = "wallyworld";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    static String uri = "/foo.html";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private String getAuthorization (String uri, String method, String cnonce, String cnstring) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        String response;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            response = computeDigest(false, username,passwd,realm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                        method, uri, nonce, cnonce, cnstring);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } catch (NoSuchAlgorithmException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        String value = "Digest"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                        + " qop=auth\""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                        + "\", cnonce=\"" + cnonce
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                        + "\", rspauth=\"" + response
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                        + "\", nc=\"" + cnstring + "\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return (value+ "\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private String computeDigest(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        boolean isRequest, String userName, char[] password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                        String realm, String connMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                        String requestURI, String nonceString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                        String cnonce, String ncValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    ) throws NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        String A1, HashA1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        MessageDigest md = MessageDigest.getInstance("MD5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            A1 = userName + ":" + realm + ":";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            HashA1 = encode(A1, password, md);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        String A2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (isRequest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            A2 = connMethod + ":" + requestURI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            A2 = ":" + requestURI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        String HashA2 = encode(A2, null, md);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        String combo, finalHash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        { /* RRC2617 when qop=auth */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            combo = HashA1+ ":" + nonceString + ":" + ncValue + ":" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        cnonce + ":auth:" +HashA2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        finalHash = encode(combo, null, md);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return finalHash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private final static char charArray[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        '0', '1', '2', '3', '4', '5', '6', '7',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private String encode(String src, char[] passwd, MessageDigest md) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        md.update(src.getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (passwd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            byte[] passwdBytes = new byte[passwd.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            for (int i=0; i<passwd.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                passwdBytes[i] = (byte)passwd[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            md.update(passwdBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            Arrays.fill(passwdBytes, (byte)0x00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        byte[] digest = md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        StringBuffer res = new StringBuffer(digest.length * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        for (int i = 0; i < digest.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            int hashchar = ((digest[i] >>> 4) & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            res.append(charArray[hashchar]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            hashchar = (digest[i] & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            res.append(charArray[hashchar]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return res.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
public class DigestTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    static class MyAuthenticator extends Authenticator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        public MyAuthenticator () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            super ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        public PasswordAuthentication getPasswordAuthentication ()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return (new PasswordAuthentication ("user", "Wrongpassword".toCharArray()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public static void main(String[] args) throws Exception {
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   208
        int port;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        DigestServer server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        ServerSocket sock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        try {
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   213
            sock = new ServerSocket (0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            port = sock.getLocalPort ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            System.out.println ("Exception: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        server = new DigestServer(sock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        server.start ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        boolean passed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        try  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            Authenticator.setDefault (new MyAuthenticator ());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            String s = "http://localhost:" + port + DigestServer.uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            URL url = new URL(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            java.net.URLConnection conURL =  url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            InputStream in = conURL.getInputStream();
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   232
            while (in.read () != -1) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            in.close ();
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   234
        } catch(ProtocolException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            passed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   237
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (!passed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            throw new RuntimeException ("Expected a ProtocolException from wrong password");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
}