use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZTSImplTest method testGetRoleTokenTrustDomainWildCard.
@Test
public void testGetRoleTokenTrustDomainWildCard() {
SignedDomain signedDomain = createSignedDomainWildCard("weather", "netops");
store.processDomain(signedDomain, false);
signedDomain = createTenantSignedDomainWildCard("netops", "weather");
store.processDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "siteops_user_1", "v=U1;d=user_domain;n=siteops_user_1;s=signature", 0, null);
ResourceContext context = createResourceContext(principal);
RoleToken roleToken = zts.getRoleToken(context, "weather", null, null, null, null);
com.yahoo.athenz.auth.token.RoleToken token = new com.yahoo.athenz.auth.token.RoleToken(roleToken.getToken());
assertEquals(token.getRoles().size(), 1);
assertTrue(token.getRoles().contains("netops_superusers"));
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZTSImplTest method testRoleTokenAddrNoLoopbackAuditLog.
@Test
public void testRoleTokenAddrNoLoopbackAuditLog() {
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.getRemoteAddr()).thenReturn("10.10.10.11");
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", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
ResourceContext context = createResourceContext(principal, servletRequest);
RoleToken roleToken = ztsImpl.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());
assertNotNull(token);
String unsignToken = token.getUnsignedToken();
for (String msg : aLogMsgs) {
assertTrue(msg.contains("SUCCESS ROLETOKEN=(" + unsignToken));
assertTrue(msg.contains("CLIENT-IP=(10.10.10.11)"));
break;
}
}
use of com.yahoo.athenz.auth.Principal 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.auth.Principal 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.auth.Principal in project athenz by yahoo.
the class ZTSImplTest method testGetRoleAccess.
@Test
public void testGetRoleAccess() {
SignedDomain signedDomain = createSignedDomain("roleaccess", "tenantrole", "storage", true);
store.processDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=sig", 0, null);
ResourceContext context = createResourceContext(principal);
RoleAccess roleAccess = zts.getRoleAccess(context, "roleaccess", "user_domain.user");
assertEquals(roleAccess.getRoles().size(), 1);
assertTrue(roleAccess.getRoles().contains("writers"));
Principal principal1 = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user1;s=sig", 0, null);
ResourceContext context1 = createResourceContext(principal1);
roleAccess = zts.getRoleAccess(context1, "roleaccess", "user_domain.user1");
assertEquals(roleAccess.getRoles().size(), 2);
assertTrue(roleAccess.getRoles().contains("readers"));
assertTrue(roleAccess.getRoles().contains("writers"));
Principal principal4 = SimplePrincipal.create("user_domain", "user4", "v=U1;d=user_domain;n=user1;s=sig", 0, null);
ResourceContext context4 = createResourceContext(principal4);
roleAccess = zts.getRoleAccess(context4, "roleaccess", "user_domain.user4");
assertEquals(roleAccess.getRoles().size(), 1);
assertTrue(roleAccess.getRoles().contains("readers"));
try {
roleAccess = zts.getRoleAccess(context4, "unknowndomain", "user_domain.user4");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 404);
}
}
Aggregations