提交 fc00d666 编写于 作者: K khazra

7051862: CookiePolicy spec conflicts with CookiePolicy.ACCEPT_ORIGINAL_SERVER

Summary: Return false for null arguments in ACCEPT_ORIGINAL_SERVER#shouldAccept()
Reviewed-by: chegar
上级 b8b3fa09
......@@ -59,6 +59,8 @@ public interface CookiePolicy {
*/
public static final CookiePolicy ACCEPT_ORIGINAL_SERVER = new CookiePolicy(){
public boolean shouldAccept(URI uri, HttpCookie cookie) {
if (uri == null || cookie == null)
return false;
return HttpCookie.domainMatches(cookie.getDomain(), uri.getHost());
}
};
......
......@@ -24,20 +24,14 @@
/*
* @test
* @summary Unit test for java.net.CookieManager
* @bug 6244040 7150552
* @bug 6244040 7150552 7051862
* @run main/othervm -ea CookieManagerTest
* @author Edward Wang
*/
import com.sun.net.httpserver.*;
import java.io.IOException;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URL;
import java.net.*;
public class CookieManagerTest {
......@@ -51,15 +45,37 @@ public class CookieManagerTest {
if (httpTrans.badRequest) {
throw new RuntimeException("Test failed : bad cookie header");
}
checkCookiePolicy();
}
public static void startHttpServer() throws IOException {
public static void startHttpServer() throws IOException {
httpTrans = new CookieTransactionHandler();
server = HttpServer.create(new InetSocketAddress(0), 0);
server.createContext("/", httpTrans);
server.start();
}
/*
* Checks if CookiePolicy.ACCEPT_ORIGINAL_SERVER#shouldAccept()
* returns false for null arguments
*/
private static void checkCookiePolicy() throws Exception {
CookiePolicy cp = CookiePolicy.ACCEPT_ORIGINAL_SERVER;
boolean retVal;
retVal = cp.shouldAccept(null, null);
checkValue(retVal);
retVal = cp.shouldAccept(null, new HttpCookie("CookieName", "CookieVal"));
checkValue(retVal);
retVal = cp.shouldAccept((new URL("http", "localhost", 2345, "/")).toURI(),
null);
checkValue(retVal);
}
private static void checkValue(boolean val) {
if (val)
throw new RuntimeException("Return value is not false!");
}
public static void makeHttpCall() throws IOException {
try {
System.out.println("http server listenining on: "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册