use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class RoleAuthorityTest method testRoleAuthorityMismatchIPNonWrite.
@Test
public void testRoleAuthorityMismatchIPNonWrite() throws IOException, CryptoException {
RoleAuthority rollAuthority = new RoleAuthority();
KeyStore keyStore = new KeyStoreMock();
rollAuthority.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("" + userDomain + ".joe").keyId(testKeyVersionK0).build();
roleToken.sign(ztsPrivateKeyStringK0);
// mismatch IP but should be OK since it's not write operation
StringBuilder errMsg = new StringBuilder();
Principal principal = rollAuthority.authenticate(roleToken.getSignedToken(), "127.0.0.2", "GET", errMsg);
assertNotNull(principal);
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class SimplePrincipalTest method testSimplePrincipalToStringZToken.
@Test
public void testSimplePrincipalToStringZToken() {
List<String> roles = new ArrayList<String>();
roles.add("updater");
UserAuthority userAuthority = new UserAuthority();
userAuthority.initialize();
Principal p = SimplePrincipal.create("user", fakeCreds, roles, userAuthority);
assertEquals(p.toString(), "ZToken_user~updater");
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class SimplePrincipalTest method testSimplePrincipalNullDomainAuthorityDomainNotNull.
@Test
public void testSimplePrincipalNullDomainAuthorityDomainNotNull() {
Principal p = SimplePrincipal.create("user", "jdoe", fakeCreds, 0, null);
assertNotNull(p);
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class SimplePrincipalTest method testFullName.
@Test
public void testFullName() {
Principal p = SimplePrincipal.create("user", "jdoe", fakeCreds, null);
assertEquals(p.getFullName(), "user.jdoe");
assertEquals(p.getFullName(), "user.jdoe");
assertNotNull(SimplePrincipal.create(null, "jdoe", fakeCreds));
assertNotNull(SimplePrincipal.create("user", null, fakeCreds));
List<String> roles = new ArrayList<String>();
roles.add("role1");
p = SimplePrincipal.create("user", fakeCreds, roles, null);
assertEquals(p.getFullName(), "user");
p = SimplePrincipal.create("appid", fakeCreds, (Authority) null);
assertEquals(p.getFullName(), "appid");
Authority authority = null;
assertNull(SimplePrincipal.create(null, null, authority));
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class SimplePrincipalTest method testSimplePrincipalExtraFields.
@Test
public void testSimplePrincipalExtraFields() {
UserAuthority userAuthority = new UserAuthority();
userAuthority.initialize();
Principal p = SimplePrincipal.create("user", "jdoe", fakeCreds, 101, userAuthority);
((SimplePrincipal) p).setOriginalRequestor("athenz.ci");
((SimplePrincipal) p).setKeyService("zts");
((SimplePrincipal) p).setKeyId("v1");
X509Certificate cert = Mockito.mock(X509Certificate.class);
((SimplePrincipal) p).setX509Certificate(cert);
assertEquals(p.toString(), "user.jdoe");
assertEquals(p.getOriginalRequestor(), "athenz.ci");
assertEquals(p.getKeyService(), "zts");
assertEquals(p.getKeyId(), "v1");
assertEquals(p.getX509Certificate(), cert);
}
Aggregations