Skip to content

Commit

Permalink
8179880: Refactor javax/security shell tests to plain java tests
Browse files Browse the repository at this point in the history
Reviewed-by: mdoerr
Backport-of: 7f55dc1
  • Loading branch information
GoeLin committed Sep 30, 2021
1 parent 11659aa commit 2baf9ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 93 deletions.
27 changes: 19 additions & 8 deletions test/jdk/javax/security/auth/Subject/doAs/Test.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, 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
Expand All @@ -21,35 +21,46 @@
* questions.
*/

/*
* @test
* @bug 4399067 8179880
* @summary Subject.doAs(null, action) does not clear the executing subject
* @run main/othervm/policy=policy Test
*/
import javax.security.auth.Subject;
import javax.security.auth.x500.X500Principal;
import java.security.*;
import java.util.*;

public class Test {

public static Subject get(String name) {

return new Subject(true,
Collections.singleton(new X500Principal(name)),
new HashSet(),
Collections.singleton(Boolean.TRUE));
Collections.singleton(new X500Principal(name)),
new HashSet(),
Collections.singleton(Boolean.TRUE));
}

public static void main(String[] args) {

System.setSecurityManager(new SecurityManager());
try {
Subject.doAsPrivileged(get("CN=joe"), new PrivilegedAction() {
public Object run() {
return Subject.doAs(null, new PrivilegedAction() {
public Object run() {
return System.getProperty("foobar");
return System.getProperty("foobar");
}
});
}
}, null);
throw new RuntimeException
("Access control exception should have occcured");
throw new RuntimeException(
"AccessControlException should have occcured");
} catch (java.security.AccessControlException e) {
// Expected exception occured
// Expected exception occurred
e.printStackTrace(System.out);
System.out.println("Expected exception occurred");
}
}
}
85 changes: 0 additions & 85 deletions test/jdk/javax/security/auth/Subject/doAs/Test.sh

This file was deleted.

1 comment on commit 2baf9ea

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.