use of com.yahoo.athenz.zpe.AuthZpeClient.AccessCheckStatus in project athenz by yahoo.
the class TestAuthZpe method testAllowAccessMatchStartsWithAllowed.
@Test
public void testAllowAccessMatchStartsWithAllowed() {
String action = "startswith";
String resource = "angler:startswithgreat";
StringBuilder roleName = new StringBuilder();
AccessCheckStatus status = AuthZpeClient.allowAccess(rToken0AnglerRegex, resource, action, roleName);
Assert.assertEquals(status, AccessCheckStatus.ALLOW);
Assert.assertEquals(roleName.toString(), "matchstarts");
// multi tokens test
List<String> tokenList = new ArrayList<>();
tokenList.add(rToken0AnglerExpirePublic.getSignedToken());
tokenList.add(rToken0AnglerRegex.getSignedToken());
tokenList.add(rToken0AnglerPublic.getSignedToken());
roleName = new StringBuilder();
status = AuthZpeClient.allowAccess(tokenList, resource, action, roleName);
Assert.assertEquals(status, AccessCheckStatus.ALLOW);
Assert.assertEquals(roleName.toString(), "matchstarts");
}
use of com.yahoo.athenz.zpe.AuthZpeClient.AccessCheckStatus in project athenz by yahoo.
the class TestAuthZpe method testPublicReadInvalidRoleToken.
@Test
public void testPublicReadInvalidRoleToken() {
String action = "read";
String angResource = "angler:stuff";
// make the token invalid by adding chars to the signature
String roleToken = rToken0AnglerPublic.getSignedToken();
roleToken = roleToken.replace(";s=", ";s=ab");
AccessCheckStatus status = AuthZpeClient.allowAccess(roleToken, angResource, action);
Assert.assertEquals(status, AccessCheckStatus.DENY_ROLETOKEN_INVALID);
// multi tokens test
List<String> tokenList = new ArrayList<>();
tokenList.add(rToken0AnglerPublic.getSignedToken());
// add the bad one in
tokenList.add(roleToken);
StringBuilder roleName = new StringBuilder();
status = AuthZpeClient.allowAccess(tokenList, angResource, action, roleName);
Assert.assertEquals(status, AccessCheckStatus.ALLOW);
Assert.assertEquals(roleName.toString(), "public");
}
use of com.yahoo.athenz.zpe.AuthZpeClient.AccessCheckStatus in project athenz by yahoo.
the class TestAuthZpe method testPublicReadInvalidParameters.
@Test
public void testPublicReadInvalidParameters() {
String action = "read";
String angResource = "anglerTest:stuff";
AccessCheckStatus status = AuthZpeClient.allowAccess(rToken0AnglerPublic.getSignedToken(), "", action);
Assert.assertEquals(status, AccessCheckStatus.DENY_INVALID_PARAMETERS);
status = AuthZpeClient.allowAccess(rToken0AnglerPublic.getSignedToken(), angResource, "");
Assert.assertEquals(status, AccessCheckStatus.DENY_INVALID_PARAMETERS);
}
use of com.yahoo.athenz.zpe.AuthZpeClient.AccessCheckStatus in project athenz by yahoo.
the class TestAuthZpe method testAllowAccessExpiredAccessToken.
@Test
public void testAllowAccessExpiredAccessToken() {
String action = "all";
String resource = "angler:stuff";
StringBuilder roleName = new StringBuilder();
long now = System.currentTimeMillis() / 1000;
AccessToken accessToken = new AccessToken();
accessToken.setIssueTime(now - 3600);
accessToken.setExpiryTime(now - 3000);
accessToken.setAudience("angler");
accessToken.setScope(Collections.singletonList("matchall"));
AccessCheckStatus status = AuthZpeClient.allowAccess(accessToken, resource, action, roleName);
Assert.assertEquals(status, AccessCheckStatus.DENY_ROLETOKEN_EXPIRED);
}
use of com.yahoo.athenz.zpe.AuthZpeClient.AccessCheckStatus in project athenz by yahoo.
the class TestAuthZpe method testPublicWriteAllowed.
@Test
public void testPublicWriteAllowed() {
String action = "write";
String angResource = "angler:stuff";
StringBuilder roleName = new StringBuilder();
AccessCheckStatus status = AuthZpeClient.allowAccess(rToken0AnglerPublic, angResource, action, roleName);
Assert.assertEquals(status, AccessCheckStatus.ALLOW);
Assert.assertEquals(roleName.toString(), "public");
}
Aggregations