use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSClientTest method testLookupRoleTokenServiceProvider.
@SuppressWarnings("static-access")
@Test
public void testLookupRoleTokenServiceProvider() {
String domName = "svcdomtest";
Long expiryTime = (System.currentTimeMillis() / 1000) + 3500L;
String token = "v=Z1;d=" + domName + ";r=admin;p=sports.hockey;h=localhost;a=f10bc905071a72d1;t=1448045776;e=" + expiryTime.toString() + ";k=0;i=10.11.12.13;s=pujvQuvaLa2jgE3k24bCw5Hm7AP9dUQkmkwNfX2bPhVXyhdRkOlbttF4exJm9V571sJXid6vsihgopCdxqW_qA--";
RoleToken roleToken = new RoleToken().setToken(token).setExpiryTime((System.currentTimeMillis() / 1000) + 3500L);
java.util.ServiceLoader<ZTSClientService> providers = java.util.ServiceLoader.load(ZTSClientService.class);
for (ZTSClientService provider : providers) {
if (provider instanceof ZTSClientServiceProvider) {
ZTSClientServiceProvider sprov = (ZTSClientServiceProvider) provider;
sprov.setToken(roleToken, domName, null, null);
roleToken = null;
break;
}
}
// means it found the test service provider
assertNull(roleToken);
// now get role token for that domain
Authority principalAuthority = new PrincipalAuthority();
Principal principal = SimplePrincipal.create("sports", "hockey", "v=S1;d=sports;n=hockey;s=sig", principalAuthority);
ZTSRDLClientMock ztsClientMock = new ZTSRDLClientMock();
ztsClientMock.setRoleName("role1");
ZTSClient client = new ZTSClient("http://localhost:4080", principal);
client.setZTSRDLGeneratedClient(ztsClientMock);
// purposely ignoring cache so 1st thing it will do is check in the providers
RoleToken rToken = client.getRoleToken(domName, null, null, null, true, null);
assertNotNull(rToken);
// not in cache
String cacheKey = client.getRoleTokenCacheKey(domName, null, null);
rToken = client.lookupRoleTokenInCache(cacheKey, null, null);
assertNull(rToken);
// don't ignore cache so 1st thing it will do is check in the cache
// before it checks the providers
rToken = client.getRoleToken(domName, null, null, null, false, null);
assertNotNull(rToken);
client.close();
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testGetPublicKeyEntryInvalidService.
@Test
public void testGetPublicKeyEntryInvalidService() {
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
store.processDomain(signedDomain, false);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority());
ResourceContext context = createResourceContext(principal);
try {
zts.getPublicKeyEntry(context, "coretech", "nonexistentservice", "0");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 404);
}
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshRequestPrincipalMismatch.
@Test
public void testPostInstanceRefreshRequestPrincipalMismatch() throws IOException {
Path path = Paths.get("src/test/resources/valid.csr");
String certCsr = new String(Files.readAllBytes(path));
InstanceRefreshRequest req = new InstanceRefreshRequest().setCsr(certCsr);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority());
ResourceContext context = createResourceContext(principal);
try {
zts.postInstanceRefreshRequest(context, "basketbal", "kings", req);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Principal mismatch"), ex.getMessage());
}
try {
zts.postInstanceRefreshRequest(context, "hockey", "bruins", req);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Principal mismatch"), ex.getMessage());
}
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testGetTenantDomainsInvalidUser.
@Test
public void testGetTenantDomainsInvalidUser() {
SignedDomain signedDomain = createSignedDomain("athenz.product", "weather.frontpage", "storage", true);
store.processDomain(signedDomain, false);
signedDomain = createTenantSignedDomain("weather.frontpage", "athenz.product", "storage");
store.processDomain(signedDomain, false);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority());
ResourceContext context = createResourceContext(principal);
TenantDomains tenantDomains = zts.getTenantDomains(context, "athenz.product", "user1099", null, null);
assertNotNull(tenantDomains);
assertEquals(tenantDomains.getTenantDomainNames().size(), 0);
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testGetAWSTemporaryCredentialsNoCloudStore.
@Test
public void testGetAWSTemporaryCredentialsNoCloudStore() {
SignedDomain signedDomain = createAwsSignedDomain("athenz.product", "1234");
store.processDomain(signedDomain, false);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority());
ResourceContext context = createResourceContext(principal);
try {
zts.getAWSTemporaryCredentials(context, "athenz.product", "aws_role_name");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
}
}
Aggregations