use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.
the class ZTSImplTest method testGetRoleTokenNoRoleMatchAuditLog.
@Test
public void testGetRoleTokenNoRoleMatchAuditLog() {
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.getRemoteAddr()).thenReturn("99.88.77.66");
Mockito.when(servletRequest.isSecure()).thenReturn(true);
final java.util.Set<String> aLogMsgs = new java.util.HashSet<String>();
AuditLogger alogger = new AuditLogger() {
public void log(String logMsg, String msgVersionTag) {
aLogMsgs.add(logMsg);
}
public void log(AuditLogMsgBuilder msgBldr) {
String msg = msgBldr.build();
aLogMsgs.add(msg);
}
@Override
public AuditLogMsgBuilder getMsgBuilder() {
return new DefaultAuditLogMsgBuilder();
}
};
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);
ztsImpl.auditLogger = alogger;
ZTSImpl.serverHostName = "localhost";
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
store.processDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "invalidUser", "v=U1;d=user_domain;n=invalidUser;s=signature", 0, null);
ResourceContext context = createResourceContext(principal, servletRequest);
try {
ztsImpl.getRoleToken(context, "coretech", null, Integer.valueOf(600), Integer.valueOf(1200), null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 403);
}
for (String msg : aLogMsgs) {
assertTrue(msg.contains("ERROR=(Principal Has No Access to Domain)"));
assertTrue(msg.contains("CLIENT-IP=(99.88.77.66)"));
assertTrue(msg.contains("WHO=(who-name=invalidUser,who-domain=user_domain,who-fullname=user_domain.invalidUser)"));
break;
}
}
use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.
the class ZTSImplTest method testGetRoleTokenCertInvalidRequests.
@Test
public void testGetRoleTokenCertInvalidRequests() throws Exception {
// this csr is for sports:role.readers role
RoleCertificateRequest req = new RoleCertificateRequest().setCsr(ROLE_CERT_CORETECH_REQUEST).setExpiryTime(Long.valueOf(3600));
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
store.processDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user;s=signature", 0, null);
ResourceContext context = createResourceContext(principal);
try {
zts.postRoleCertificateRequest(context, "coretech", "unknownrole", req);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 403);
}
try {
zts.postRoleCertificateRequest(context, "coretech", "writers", req);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
}
try {
zts.postRoleCertificateRequest(context, "unknown-domain", "readers", req);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 404);
}
}
use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.
the class ZTSImplTest method testGetRoleTokenAuthorizedService.
@Test
public void testGetRoleTokenAuthorizedService() {
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
signedDomain.domain.setApplicationId("application_id");
store.processDomain(signedDomain, false);
// success
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
principal.setApplicationId("coretech.api");
ResourceContext context = createResourceContext(principal);
RoleToken roleToken = zts.getRoleToken(context, "coretech", null, Integer.valueOf(600), Integer.valueOf(1200), null);
com.yahoo.athenz.auth.token.RoleToken token = new com.yahoo.athenz.auth.token.RoleToken(roleToken.getToken());
assertEquals(token.getRoles().size(), 1);
// success - no authorized service available
principal = (SimplePrincipal) SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
context = createResourceContext(principal);
token = new com.yahoo.athenz.auth.token.RoleToken(roleToken.getToken());
assertEquals(token.getRoles().size(), 1);
// failure - domain name and principal authorized service doesn't match
principal = (SimplePrincipal) SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
principal.setAuthorizedService("sports.hockey.api");
context = createResourceContext(principal);
try {
zts.getRoleToken(context, "coretech", null, Integer.valueOf(600), Integer.valueOf(1200), null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 403);
}
}
use of com.yahoo.athenz.zms.SignedDomain 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.zms.SignedDomain in project athenz by yahoo.
the class ZTSImplTest method testVerifyAWSAssumeRole.
@Test
public void testVerifyAWSAssumeRole() {
SignedDomain signedDomain = createAwsSignedDomain("athenz.product", "1234");
store.processDomain(signedDomain, false);
// our group includes user100 and user101
assertTrue(zts.verifyAWSAssumeRole("athenz.product", "athenz.product:aws_role_name", "user_domain.user100"));
assertTrue(zts.verifyAWSAssumeRole("athenz.product", "athenz.product:aws_role_name", "user_domain.user101"));
assertFalse(zts.verifyAWSAssumeRole("athenz.product", "athenz.product:aws_role_name", "user_domain.user102"));
}
Aggregations