URLTest.java 文件源码

java
阅读 37 收藏 0 点赞 0 评论 0

项目:openjdk-jdk10 作者:
static void test1() throws IOException {
    System.out.println("\n--- Test 1 ---");

    boolean expectException = false;
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        expectException = true;
        Policy.setPolicy(new CustomPolicy(
            new URLPermission("http://127.0.0.1:"+httpPort+"/foo.html", "GET:X-Foo,Z-Bar"),
            new URLPermission("https://127.0.0.1:"+httpsPort+"/foo.html", "POST:X-Fob,T-Bar")));
    }

    String url1 = "http://127.0.0.1:"+httpPort+"/foo.html";
    String url2 = "https://127.0.0.1:"+httpsPort+"/foo.html";
    String url3 = "http://127.0.0.1:"+httpPort+"/bar.html";
    String url4 = "https://127.0.0.1:"+httpsPort+"/bar.html";

    // simple positive test. Should succeed
    test(url1, "GET", "X-Foo");
    test(url1, "GET", "Z-Bar", "X-Foo");
    test(url1, "GET", "X-Foo", "Z-Bar");
    test(url1, "GET", "Z-Bar");
    test(url2, "POST", "X-Fob");

    // reverse the methods, should fail
    test(url1, "POST", "X-Foo", expectException);
    test(url2, "GET", "X-Fob", expectException);

    // different URLs, should fail
    test(url3, "GET", "X-Foo", expectException);
    test(url4, "POST", "X-Fob", expectException);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号