8114860: Behavior of java.net.URLPermission.getActions() contradicts spec

Reviewed-by: chegar, prappo
This commit is contained in:
Vyom Tewari 2016-06-21 16:52:16 +01:00
parent bb15c9c8bf
commit 6ae11043e9
2 changed files with 60 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2016, 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
@ -455,15 +455,11 @@ public final class URLPermission extends Permission {
}
private String actions() {
StringBuilder b = new StringBuilder();
for (String s : methods) {
b.append(s);
String b = String.join(",", methods);
if (!requestHeaders.isEmpty()) {
b += ":" + String.join(",", requestHeaders);
}
b.append(":");
for (String s : requestHeaders) {
b.append(s);
}
return b.toString();
return b;
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2016, 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
@ -26,7 +26,7 @@ import java.io.*;
/**
* @test
* @bug 8010464 8027570 8027687 8029354
* @bug 8010464 8027570 8027687 8029354 8114860
*/
public class URLPermissionTest {
@ -129,6 +129,28 @@ public class URLPermissionTest {
}
}
static ActionsStringTest actionstest(String arg, String expectedActions) {
return new ActionsStringTest(arg, expectedActions);
}
static class ActionsStringTest extends Test {
String expectedActions;
String arg;
public ActionsStringTest(String arg, String expectedActions) {
this.arg = arg;
this.expectedActions = expectedActions;
}
@Override
boolean execute() {
String url = "http://www.foo.com/";
URLPermission urlp = new URLPermission(url, arg);
return (expectedActions.equals(urlp.getActions()));
}
}
static ActionImpliesTest actest(String arg1, String arg2, boolean expected) {
return new ActionImpliesTest(arg1, arg2, expected);
}
@ -308,6 +330,20 @@ public class URLPermissionTest {
actest("*:*", "GET:x-bar,x-foo", true)
};
static Test[] actionsStringTest = {
actionstest("", ""),
actionstest(":X-Bar", ":X-Bar"),
actionstest("GET", "GET"),
actionstest("get", "GET"),
actionstest("GET,POST", "GET,POST"),
actionstest("GET,post", "GET,POST"),
actionstest("get,post", "GET,POST"),
actionstest("get,post,DELETE", "DELETE,GET,POST"),
actionstest("GET,POST:", "GET,POST"),
actionstest("GET:X-Foo,X-bar", "GET:X-Bar,X-Foo"),
actionstest("GET,POST,DELETE:X-Bar,X-Foo,X-Bar,Y-Foo", "DELETE,GET,POST:X-Bar,X-Bar,X-Foo,Y-Foo")
};
static Test[] equalityTests = {
eqtest("http://www.foo.com", "http://www.FOO.CoM", true),
eqtest("http://[fe80:0:0::]:1-2", "HTTP://[FE80::]:1-2", true),
@ -449,6 +485,23 @@ public class URLPermissionTest {
System.out.println ("action test " + i + " OK");
}
for (int i = 0; i < actionsStringTest.length; i++) {
ActionsStringTest test = (ActionsStringTest) actionsStringTest[i];
Exception caught = null;
boolean result = false;
try {
result = test.execute();
} catch (Exception e) {
caught = e;
}
if (!result) {
failed = true;
System.out.println("test failed: " + test.arg + ": "
+ test.expectedActions + " Exception: " + caught);
}
System.out.println("Actions String test " + i + " OK");
}
serializationTest("http://www.foo.com/-", "GET,DELETE:*");
serializationTest("https://www.foo.com/-", "POST:X-Foo");
serializationTest("https:*", "*:*");