use of com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder 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.common.server.log.impl.DefaultAuditLogMsgBuilder in project athenz by yahoo.
the class ZTSImplTest method testGetRoleTokenAddrLoopbackXFFMultipleValuesAuditLog.
@Test
public void testGetRoleTokenAddrLoopbackXFFMultipleValuesAuditLog() {
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.getRemoteAddr()).thenReturn("127.0.0.1");
Mockito.when(servletRequest.getHeader("X-Forwarded-For")).thenReturn("10.10.10.11, 10.11.11.11, 10.12.12.12");
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.12.12.12)"));
break;
}
}
use of com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder in project athenz by yahoo.
the class ZTSImplTest method testGetRoleTokenAddrLoopbackXFFSingeValueAuditLog.
@Test
public void testGetRoleTokenAddrLoopbackXFFSingeValueAuditLog() {
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.getRemoteAddr()).thenReturn("127.0.0.1");
Mockito.when(servletRequest.getHeader("X-Forwarded-For")).thenReturn("10.10.10.12");
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.12)"));
break;
}
}
use of com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder in project athenz by yahoo.
the class AuditLogMsgBuilderTest method testWhenString.
@Test
public void testWhenString() {
DefaultAuditLogMsgBuilder msgBldr = starter("testWhenString");
String dataStr = "now?";
msgBldr.when(dataStr);
Assert.assertTrue(msgBldr.when().equals(dataStr), "when string=" + msgBldr.when());
}
use of com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder in project athenz by yahoo.
the class AuditLogMsgBuilderTest method testWho.
@Test
public void testWho() {
DefaultAuditLogMsgBuilder msgBldr = starter("testWho");
String dataStr = "me?";
msgBldr.who(dataStr);
Assert.assertTrue(msgBldr.who().equals(dataStr), "who string=" + msgBldr.who());
}
Aggregations