8284353: Update java/net and sun/net/www tests to eliminate dependency on sun.net.www.MessageHeader

Reviewed-by: dfuchs
This commit is contained in:
Mahendra Chhipa 2022-04-07 10:19:12 +00:00 committed by Daniel Fuchs
parent 8e58d4a589
commit ec73c61d8f
12 changed files with 98 additions and 64 deletions

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,7 @@
/**
* @test
* @bug 6870935
* @library /test/lib
* @modules java.base/sun.net.www
* @run main/othervm -Dhttp.auth.digest.reEnabledAlgorithms=MD5
* -Dhttp.nonProxyHosts="" -Dhttp.auth.digest.validateProxy=true B6870935
@ -36,6 +37,8 @@ import java.io.*;
import java.util.*;
import java.net.*;
import java.security.*;
import jdk.test.lib.net.HttpHeaderParser;
import sun.net.www.*;
/* This is one simple test of the RFC2617 digest authentication behavior
@ -100,8 +103,9 @@ public class B6870935 {
os = s1.getOutputStream ();
// is.read ();
// need to get the cnonce out of the response
MessageHeader header = new MessageHeader (is);
String raw = header.findValue ("Proxy-Authorization");
HttpHeaderParser header = new HttpHeaderParser (is);
String raw = header.getHeaderValue("Proxy-Authorization") != null ?
header.getHeaderValue("Proxy-Authorization").get(0) : null;
HeaderParser parser = new HeaderParser (raw);
String cnonce = parser.findValue ("cnonce");
String cnstring = parser.findValue ("nc");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,6 @@
* @summary Add support for HTTP_CONNECT proxy in Socket class.
* This test uses the wildcard address and is susceptible to fail intermittently.
* @key intermittent
* @modules java.base/sun.net.www
* @run main HttpProxy
* @run main/othervm -Djava.net.preferIPv4Stack=true HttpProxy
* @run main/othervm -Djava.net.preferIPv6Addresses=true HttpProxy
@ -38,7 +37,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import static java.lang.System.out;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
@ -47,8 +45,10 @@ import java.net.Socket;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.List;
import static java.lang.System.out;
import jdk.test.lib.net.HttpHeaderParser;
import jdk.test.lib.net.IPSupport;
import sun.net.www.MessageHeader;
public class HttpProxy {
final String proxyHost;
@ -244,8 +244,8 @@ public class HttpProxy {
* Processes the CONNECT request
*/
private void processRequest(Socket clientSocket) throws Exception {
MessageHeader mheader = new MessageHeader(clientSocket.getInputStream());
String statusLine = mheader.getValue(0);
HttpHeaderParser mheader = new HttpHeaderParser(clientSocket.getInputStream());
String statusLine = mheader.getRequestDetails();
if (!statusLine.startsWith("CONNECT")) {
out.println("proxy server: processes only "

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,8 +24,7 @@
/*
* @test
* @bug 8163561
* @modules java.base/sun.net.www
* java.net.http
* @library /test/lib
* @summary Verify that Proxy-Authenticate header is correctly handled
* @run main/othervm ProxyAuthTest
*/
@ -52,7 +51,8 @@ import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.Base64;
import java.util.List;
import sun.net.www.MessageHeader;
import jdk.test.lib.net.HttpHeaderParser;
public class ProxyAuthTest {
private static final String AUTH_USER = "user";
@ -156,10 +156,11 @@ public class ProxyAuthTest {
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os));
PrintWriter out = new PrintWriter(writer);) {
MessageHeader headers = new MessageHeader(in);
HttpHeaderParser headers = new HttpHeaderParser(in);
System.out.println("Proxy: received " + headers);
String authInfo = headers.findValue("Proxy-Authorization");
String authInfo = headers.getHeaderValue("Proxy-Authorization") != null ?
headers.getHeaderValue("Proxy-Authorization").get(0) : null;
if (authInfo != null) {
authenticate(authInfo);
out.print("HTTP/1.1 404 Not found\r\n");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
* @test
* @bug 4432213
* @modules java.base/sun.net.www
* @library /test/lib
* @run main/othervm -Dhttp.auth.digest.reEnabledAlgorithms=MD5
* -Dhttp.auth.digest.validateServer=true DigestTest
* @run main/othervm -Dhttp.auth.digest.reEnabledAlgorithms=MD5
@ -44,7 +45,9 @@ import java.io.*;
import java.util.*;
import java.net.*;
import java.security.*;
import sun.net.www.*;
import sun.net.www.HeaderParser;
import jdk.test.lib.net.HttpHeaderParser;
/* This is one simple test of the RFC2617 digest authentication behavior
* It specifically tests that the client correctly checks the returned
@ -99,8 +102,9 @@ class DigestServer extends Thread {
os = s1.getOutputStream ();
//is.read ();
// need to get the cnonce out of the response
MessageHeader header = new MessageHeader (is);
String raw = header.findValue ("Authorization");
HttpHeaderParser header = new HttpHeaderParser (is);
String raw = header.getHeaderValue("Authorization") != null ?
header.getHeaderValue("Authorization").get(0) : null;
HeaderParser parser = new HeaderParser (raw);
String cnonce = parser.findValue ("cnonce");
String cnstring = parser.findValue ("nc");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
/*
* @test
* @bug 8270290
* @modules java.base/sun.net.www
* @library /test/lib
* @run main/othervm NTLMHeadTest SERVER
* @run main/othervm NTLMHeadTest PROXY
@ -52,7 +51,8 @@
import java.net.*;
import java.io.*;
import java.util.*;
import sun.net.www.MessageHeader;
import jdk.test.lib.net.HttpHeaderParser;
import jdk.test.lib.net.URIBuilder;
public class NTLMHeadTest {
@ -264,36 +264,36 @@ public class NTLMHeadTest {
static void doServer(InputStream is, OutputStream os, boolean doing2ndStageNTLM) throws IOException {
if (!doing2ndStageNTLM) {
new MessageHeader(is);
new HttpHeaderParser(is);
os.write(RESP_SERVER_AUTH.getBytes("ASCII"));
} else {
new MessageHeader(is);
new HttpHeaderParser(is);
os.write(RESP_SERVER_NTLM.getBytes("ASCII"));
new MessageHeader(is);
new HttpHeaderParser(is);
os.write(RESP_SERVER_OR_PROXY_DEST.getBytes("ASCII"));
}
}
static void doProxy(InputStream is, OutputStream os, boolean doing2ndStageNTLM) throws IOException {
if (!doing2ndStageNTLM) {
new MessageHeader(is);
new HttpHeaderParser(is);
os.write(RESP_PROXY_AUTH.getBytes("ASCII"));
} else {
new MessageHeader(is);
new HttpHeaderParser(is);
os.write(RESP_PROXY_NTLM.getBytes("ASCII"));
new MessageHeader(is);
new HttpHeaderParser(is);
os.write(RESP_SERVER_OR_PROXY_DEST.getBytes("ASCII"));
}
}
static void doTunnel(InputStream is, OutputStream os, boolean doing2ndStageNTLM) throws IOException {
if (!doing2ndStageNTLM) {
new MessageHeader(is);
new HttpHeaderParser(is);
os.write(RESP_TUNNEL_AUTH.getBytes("ASCII"));
} else {
new MessageHeader(is);
new HttpHeaderParser(is);
os.write(RESP_TUNNEL_NTLM.getBytes("ASCII"));
new MessageHeader(is);
new HttpHeaderParser(is);
os.write(RESP_TUNNEL_ESTABLISHED.getBytes("ASCII"));
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,12 +29,17 @@
* It is used by the TunnelThroughProxy test.
*/
import java.io.*;
import java.net.*;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Base64;
import javax.net.ssl.*;
import javax.net.ServerSocketFactory;
import sun.net.www.*;
import jdk.test.lib.net.HttpHeaderParser;
public class ProxyTunnelServer extends Thread {
@ -129,8 +134,8 @@ public class ProxyTunnelServer extends Thread {
*/
private void processRequests(boolean makeTunnel) throws Exception {
InputStream in = clientSocket.getInputStream();
MessageHeader mheader = new MessageHeader(in);
String statusLine = mheader.getValue(0);
HttpHeaderParser mheader = new HttpHeaderParser(in);
String statusLine = mheader.getRequestDetails();
System.out.printf("Proxy: Processing request from '%s'%n", clientSocket);
@ -139,8 +144,9 @@ public class ProxyTunnelServer extends Thread {
// retrieveConnectInfo(statusLine);
if (needAuth) {
String authInfo;
if ((authInfo = mheader.findValue("Proxy-Authorization"))
!= null) {
if ((authInfo = (mheader.getHeaderValue("Proxy-Authorization") != null ?
mheader.getHeaderValue("Proxy-Authorization").get(0) : null))
!= null) {
if (authenticate(authInfo)) {
needAuth = false;
System.out.println(

@ -24,6 +24,7 @@
/**
* @test
* @bug 4620362
* @library /test/lib
* @modules java.base/sun.net.www
* @build ProxyTunnelServer
* @run main/othervm TunnelThroughProxy

@ -33,7 +33,7 @@
* Incorrect checking of proxy server response
* @modules jdk.crypto.ec
* java.base/sun.net.www
* @library /javax/net/ssl/templates
* @library /test/lib /javax/net/ssl/templates
* @run main/othervm ProxyAuthTest fail
* @run main/othervm -Djdk.http.auth.tunneling.disabledSchemes=Basic
* ProxyAuthTest fail

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,13 +28,20 @@
* is accepted.
* It is used by the regression test for the bug fixes: 4323990, 4413069
*/
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import javax.net.ServerSocketFactory;
import sun.net.www.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Base64;
import javax.net.ServerSocketFactory;
import jdk.test.lib.net.HttpHeaderParser;
public class ProxyTunnelServer extends Thread {
private static ServerSocket ss = null;
@ -113,15 +120,16 @@ public class ProxyTunnelServer extends Thread {
private void processRequests() throws Exception {
InputStream in = clientSocket.getInputStream();
MessageHeader mheader = new MessageHeader(in);
String statusLine = mheader.getValue(0);
HttpHeaderParser mheader = new HttpHeaderParser(in);
String statusLine = mheader.getRequestDetails();
if (statusLine.startsWith("CONNECT")) {
// retrieve the host and port info from the status-line
retrieveConnectInfo(statusLine);
if (needAuth) {
String authInfo;
if ((authInfo = mheader.findValue("Proxy-Authorization"))
if ((authInfo = (mheader.getHeaderValue("Proxy-Authorization") != null) ?
mheader.getHeaderValue("Proxy-Authorization").get(0) : null)
!= null) {
if (authenticate(authInfo)) {
needAuth = false;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -30,12 +30,20 @@
* followed by the corresponding tunnel data.
*/
import java.io.*;
import java.net.*;
import javax.net.ServerSocketFactory;
import sun.net.www.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.Base64;
import javax.net.ServerSocketFactory;
import jdk.test.lib.net.HttpHeaderParser;
public class ProxyTunnelServer extends Thread {
private static final int TIMEOUT = 30000;
@ -130,8 +138,8 @@ public class ProxyTunnelServer extends Thread {
private void processRequests() throws Exception {
InputStream in = clientSocket.getInputStream();
MessageHeader mheader = new MessageHeader(in);
String statusLine = mheader.getValue(0);
HttpHeaderParser mheader = new HttpHeaderParser(in);
String statusLine = mheader.getRequestDetails();
if (statusLine.startsWith("CONNECT")) {
synchronized(this) { connectCount++; }
@ -139,8 +147,9 @@ public class ProxyTunnelServer extends Thread {
retrieveConnectInfo(statusLine);
if (needAuth) {
String authInfo;
if ((authInfo = mheader.findValue("Proxy-Authorization"))
!= null) {
if ((authInfo = (mheader.getHeaderValue("Proxy-Authorization") != null ?
mheader.getHeaderValue("Proxy-Authorization").get(0) : null))
!= null) {
if (authenticate(authInfo)) {
needAuth = false;
System.out.println(

@ -24,6 +24,7 @@
/*
* @test
* @bug 4432868
* @library /test/lib
* @summary A client-hello message may not always be read correctly
* @modules java.base/sun.net.www
* @run main/othervm ClientHelloRead

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,7 @@ import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import javax.net.ServerSocketFactory;
import sun.net.www.MessageHeader;
import jdk.test.lib.net.HttpHeaderParser;
public class ProxyTunnelServer extends Thread {
@ -82,8 +82,8 @@ public class ProxyTunnelServer extends Thread {
private void processRequests() throws Exception {
InputStream in = clientSocket.getInputStream();
MessageHeader response = new MessageHeader(in);
String statusLine = response.getValue(0);
HttpHeaderParser response = new HttpHeaderParser(in);
String statusLine = response.getRequestDetails();
if (statusLine.startsWith("CONNECT")) {
// retrieve the host and port info from the response line