@Test public void testAuthorize() throws VException { Call call = VSecurity.newCall( new CallParams() .withLocalPrincipal(SERVER_PRINCIPAL) .withLocalBlessings(SERVER_BLESSINGS) .withRemoteBlessings(clientBlessings) .withMethod(methodName) .withMethodTags(methodTags)); try { AUTHORIZER.authorize(CONTEXT, call); if (!shouldAccept) { fail(String.format("Access granted for method %s to %s", methodName, clientBlessings)); } } catch (VException e) { if (shouldAccept) { throw e; } } }
public PermissionsAuthorizerTest( String methodName, VdlValue methodTag, List<String> clientBlessingNames, boolean isAccepted) throws VException { this.methodName = methodName; this.methodTags = new VdlValue[] {methodTag}; this.clientBlessings = VSecurity.unionOfBlessings( Lists.transform( clientBlessingNames, new Function<String, Blessings>() { @Override public Blessings apply(String name) { try { return CLIENT_PRINCIPAL.blessSelf(name); } catch (VException e) { throw new RuntimeException(e); } } }) .toArray(new Blessings[0])); this.shouldAccept = isAccepted; }
private static VPrincipal newPrincipal() throws VException { VSigner signer = VSecurity.newInMemorySigner(); return VSecurity.newPrincipal(signer, null, new TrustAllRoots()); }