use of com.yahoo.athenz.auth.impl.RoleAuthority in project athenz by yahoo.
the class RoleAuthorityTest method testIsWriteOperationNull.
@Test
public void testIsWriteOperationNull() throws IOException {
RoleAuthority roleAuthority = new RoleAuthority();
roleAuthority.initialize();
KeyStore keyStore = new KeyStoreMock();
roleAuthority.setKeyStore(keyStore);
// Add some roles
List<String> roles = new ArrayList<String>();
roles.add("storage.tenant.weather.updater");
// Create and sign token with keyVersion = 0
RoleToken roleToken = new RoleToken.Builder(rolVersion, svcDomain, roles).salt(salt).ip("127.0.0.1").expirationWindow(expirationTime).principal(".").keyId(testKeyVersionK0).build();
roleToken.sign(ztsPrivateKeyStringK0);
Principal principal = roleAuthority.authenticate(roleToken.getSignedToken(), "127.0.0.2", null, null);
assertNotNull(principal);
}
use of com.yahoo.athenz.auth.impl.RoleAuthority in project athenz by yahoo.
the class RoleAuthorityTest method testAuthenticateIlligal.
@Test
public void testAuthenticateIlligal() throws IOException {
RoleAuthority roleAuthority = new RoleAuthority();
roleAuthority.initialize();
Principal principal = roleAuthority.authenticate("", "10.72.118.45", "GET", null);
assertNull(principal);
KeyStore keyStore = new KeyStoreMock();
roleAuthority.setKeyStore(keyStore);
// Add some roles
List<String> roles = new ArrayList<String>();
roles.add("storage.tenant.weather.updater");
// Create and sign token with keyVersion = 0
RoleToken roleToken = new RoleToken.Builder(rolVersion, svcDomain, roles).salt(salt).ip("127.0.0.1").expirationWindow(expirationTime).principal(".").keyId(testKeyVersionK0).build();
roleToken.sign(ztsPrivateKeyStringK0);
principal = roleAuthority.authenticate(roleToken.getSignedToken(), "127.0.0.2", "DELETE", null);
assertNull(principal);
roleToken = new RoleToken.Builder(rolVersion, svcDomain, roles).salt(salt).ip("127.0.0.1").expirationWindow(expirationTime).principal("illigal.joe").keyId(testKeyVersionK0).build();
roleToken.sign(ztsPrivateKeyStringK0);
principal = roleAuthority.authenticate(roleToken.getSignedToken(), "127.0.0.2", "DELETE", null);
assertNotNull(principal);
}
use of com.yahoo.athenz.auth.impl.RoleAuthority in project athenz by yahoo.
the class RoleAuthorityTest method testInitialize.
@Test
public void testInitialize() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Class<RoleAuthority> c = RoleAuthority.class;
RoleAuthority roleAuthority = new RoleAuthority();
System.setProperty(RoleAuthority.ATHENZ_PROP_TOKEN_OFFSET, "-1");
roleAuthority.initialize();
Field f1 = c.getDeclaredField("allowedOffset");
f1.setAccessible(true);
int m = (Integer) f1.get(roleAuthority);
assertEquals(m, 300);
assertEquals(roleAuthority.userDomain, "user");
}
Aggregations