use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class SimpleServiceIdentityProviderTest method testSimpleIdentityDefaultV1.
@Test
public void testSimpleIdentityDefaultV1() {
PrivateKey key = Crypto.loadPrivateKey(servicePrivateKeyStringK1);
SimpleServiceIdentityProvider provider = new SimpleServiceIdentityProvider("coretech", "athenz", key, "1");
Principal user = provider.getIdentity("coretech", "athenz");
assertNotNull(user);
assertTrue(user.getIssueTime() != 0);
String token = user.getCredentials();
PrincipalToken prToken = new PrincipalToken(token);
assertTrue(prToken.validate(servicePublicKeyStringK1, 0, false));
assertEquals(prToken.getKeyId(), "1");
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class SimpleServiceIdentityProviderTest method testSimpleIdentityPrivateKeyDomainMismatch.
@Test
public void testSimpleIdentityPrivateKeyDomainMismatch() {
PrivateKey key = Crypto.loadPrivateKey(servicePrivateKeyStringK1);
SimpleServiceIdentityProvider provider = new SimpleServiceIdentityProvider("coretech", "athenz", key, "1");
Principal user = provider.getIdentity("coretech2", "athenz");
assertNull(user);
user = provider.getIdentity("coretech", "athenz2");
assertNull(user);
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class PrincipalAuthorityTest method testAuthenticateIlligal.
@Test
public void testAuthenticateIlligal() throws IOException {
PrincipalAuthority serviceAuthority = new PrincipalAuthority();
Principal principal = serviceAuthority.authenticate("aaaa", null, "GET", null);
assertNull(principal);
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class PrincipalAuthorityTest method testPrincipalAuthorityAuthenticateIlligal.
@Test
public void testPrincipalAuthorityAuthenticateIlligal() throws IOException, CryptoException {
PrincipalAuthority serviceAuthority = new PrincipalAuthority();
KeyStore keyStore = Mockito.mock(KeyStore.class);
serviceAuthority.setKeyStore(keyStore);
String t = "v=S1;d=domain;n=hoge;bs=aaaa;s=signatur";
Principal check = serviceAuthority.authenticate(t, "10", "10", null);
assertNull(check);
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class PrincipalAuthorityTest method testPrincipalAuthority_TamperedToken.
@Test
public void testPrincipalAuthority_TamperedToken() throws IOException, CryptoException {
PrincipalAuthority serviceAuthority = new PrincipalAuthority();
KeyStore keyStore = new KeyStoreMock();
serviceAuthority.setKeyStore(keyStore);
// Create and sign token
PrincipalToken serviceToken = new PrincipalToken.Builder(svcVersion, svcDomain, svcName).host(host).salt(salt).expirationWindow(expirationTime).build();
serviceToken.sign(servicePrivateKeyStringK0);
String tokenToTamper = serviceToken.getSignedToken();
StringBuilder errMsg = new StringBuilder();
Principal principal = serviceAuthority.authenticate(tamperWithServiceToken(tokenToTamper), null, "GET", errMsg);
// Service Authority should return null when authenticate() fails
assertNull(principal);
assertTrue(!errMsg.toString().isEmpty());
assertTrue(errMsg.toString().contains("authenticate"));
principal = serviceAuthority.authenticate(tamperWithServiceToken(tokenToTamper), null, "GET", null);
assertNull(principal);
}
Aggregations