use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshRequestHcaCNMismatch.
@Test
public void testPostInstanceRefreshRequestHcaCNMismatch() 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("abc", "xyz", "v=S1,d=abc;n=xyz;s=sig", 0, new PrincipalAuthority());
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.isSecure()).thenReturn(true);
ResourceContext context = createResourceContext(principal, servletRequest);
try {
zts.postInstanceRefreshRequest(context, "abc", "xyz", req);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
}
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testGetServiceIdentity.
@Test
public void testGetServiceIdentity() {
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);
com.yahoo.athenz.zts.ServiceIdentity svc = zts.getServiceIdentity(context, "coretech", "storage");
assertNotNull(svc);
assertEquals(svc.getName(), "coretech.storage");
svc = zts.getServiceIdentity(context, "coretech", "backup");
assertNotNull(svc);
assertEquals(svc.getName(), "coretech.backup");
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshInformationInvalidPrincipal.
@Test
public void testPostInstanceRefreshInformationInvalidPrincipal() throws IOException {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
Path path = Paths.get("src/test/resources/athenz.instanceid.csr");
String certCsr = new String(Files.readAllBytes(path));
InstanceRefreshInformation info = new InstanceRefreshInformation().setCsr(certCsr);
PrincipalAuthority authority = new PrincipalAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenzn=production;s=signature", 0, authority);
ResourceContext context = createResourceContext(principal);
try {
ztsImpl.postInstanceRefreshInformation(context, "athenz.provider", "athenz2", "production", "1001", info);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Principal mismatch"));
}
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testGetPublicKeyEntryInvalidDomain.
@Test
public void testGetPublicKeyEntryInvalidDomain() {
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, "nonexistentdomain", "storage", "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 testGetPublicKeyEntry.
@Test
public void testGetPublicKeyEntry() {
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);
PublicKeyEntry entry = zts.getPublicKeyEntry(context, "coretech", "storage", "0");
assertEquals(entry.getId(), "0");
assertEquals(entry.getKey(), ZTS_Y64_CERT0);
}
Aggregations