Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/net/httpserver/bugs/B6341616.java
41154 views
1
/*
2
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 6341616
27
* @library /test/lib
28
* @run main B6341616
29
* @run main/othervm -Djava.net.preferIPv6Addresses=true B6341616
30
* @summary Server doesnt send response if there is a RuntimeException in validate of BasicAuthFilter
31
*/
32
33
import com.sun.net.httpserver.*;
34
35
import java.util.*;
36
import java.util.concurrent.*;
37
import java.io.*;
38
import java.net.*;
39
import java.security.*;
40
import java.security.cert.*;
41
import javax.net.ssl.*;
42
import jdk.test.lib.net.URIBuilder;
43
44
public class B6341616 {
45
46
public static void main (String[] args) throws Exception {
47
Handler handler = new Handler();
48
InetAddress loopback = InetAddress.getLoopbackAddress();
49
InetSocketAddress addr = new InetSocketAddress (loopback, 0);
50
HttpServer server = HttpServer.create (addr, 0);
51
HttpContext ctx = server.createContext ("/test", handler);
52
BasicAuthenticator filter = new BasicAuthenticator ("[email protected]") {
53
public boolean checkCredentials (String username, String pw) {
54
throw new RuntimeException ("");
55
}
56
};
57
58
ctx.setAuthenticator (filter);
59
ExecutorService executor = Executors.newCachedThreadPool();
60
server.setExecutor (executor);
61
server.start ();
62
java.net.Authenticator.setDefault (new MyAuthenticator());
63
64
URL url = URIBuilder.newBuilder()
65
.scheme("http")
66
.loopback()
67
.port(server.getAddress().getPort())
68
.path("/test/foo.html")
69
.toURL();
70
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
71
try {
72
InputStream is = urlc.getInputStream();
73
int c = 0;
74
while (is.read()!= -1) {
75
c ++;
76
}
77
} catch (IOException e) {
78
server.stop(2);
79
executor.shutdown();
80
System.out.println ("OK");
81
}
82
}
83
84
public static boolean error = false;
85
86
static class MyAuthenticator extends java.net.Authenticator {
87
public PasswordAuthentication getPasswordAuthentication () {
88
PasswordAuthentication pw;
89
if (!getRequestingPrompt().equals ("[email protected]")) {
90
B6341616.error = true;
91
}
92
pw = new PasswordAuthentication ("fred", "xyz".toCharArray());
93
return pw;
94
}
95
}
96
97
static class Handler implements HttpHandler {
98
int invocation = 1;
99
public void handle (HttpExchange t)
100
throws IOException
101
{
102
InputStream is = t.getRequestBody();
103
Headers map = t.getRequestHeaders();
104
Headers rmap = t.getResponseHeaders();
105
while (is.read () != -1) ;
106
is.close();
107
t.sendResponseHeaders (200, -1);
108
t.close();
109
}
110
}
111
}
112
113