Skip to content

Commit

Permalink
Fix test failing on Java 11 (fixes takari#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
guw committed Dec 31, 2019
1 parent 12cc266 commit 0f46e79
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import java.io.FilePermission;
import java.net.SocketPermission;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.List;
import java.util.PropertyPermission;
Expand All @@ -16,9 +19,6 @@

import org.junit.Test;

import io.takari.builder.enforcer.ComposableSecurityManagerPolicy;
import io.takari.builder.enforcer.Policy;

public class ComposableSecurityManagerPolicyTest {

private static ComposableSecurityManagerPolicy newPolicy(Policy... policies) {
Expand Down Expand Up @@ -104,12 +104,16 @@ public void checkPropertyPermission(String action, String name) {
getWork("allowed"), //
getWork("not.allowed"), //
getWork("allowed"));

AccessControlContext accessControlContext = AccessController.getContext();
List<String> exs1 = work.parallelStream().map(x -> {
try {
return x.call();
} catch (Exception e) {
return e;
}
return AccessController.doPrivileged((PrivilegedAction<Exception>) () -> {
try {
return x.call();
} catch (Exception e) {
return e;
}
}, accessControlContext);
}).map(e -> e != null ? e.getMessage() : null).collect(Collectors.toList());

assertThat(exs1).containsExactly("nope", null, "nope", null, "nope", null);
Expand Down

0 comments on commit 0f46e79

Please sign in to comment.