Search in sources :

Example 21 with AuditLogMsgBuilder

use of com.yahoo.athenz.common.server.log.AuditLogMsgBuilder in project athenz by yahoo.

the class AuditLogMsgBuilderTest method testBuild.

/**
 * Test method for {@link com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder#build()}.
 */
@Test
public void testBuild() {
    AuditLogMsgBuilder msgBldr = starter("testBuild");
    String msg = msgBldr.build();
    Assert.assertTrue(msg.contains("WHAT-api=(testBuild)"), "Test string=" + msg);
}
Also used : AuditLogMsgBuilder(com.yahoo.athenz.common.server.log.AuditLogMsgBuilder) DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) Test(org.testng.annotations.Test)

Example 22 with AuditLogMsgBuilder

use of com.yahoo.athenz.common.server.log.AuditLogMsgBuilder 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;
    }
}
Also used : DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) DefaultAuditLogger(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogger) AuditLogger(com.yahoo.athenz.common.server.log.AuditLogger) DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) AuditLogMsgBuilder(com.yahoo.athenz.common.server.log.AuditLogMsgBuilder) HttpServletRequest(javax.servlet.http.HttpServletRequest) ChangeLogStore(com.yahoo.athenz.zts.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 23 with AuditLogMsgBuilder

use of com.yahoo.athenz.common.server.log.AuditLogMsgBuilder 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;
    }
}
Also used : DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) DefaultAuditLogger(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogger) AuditLogger(com.yahoo.athenz.common.server.log.AuditLogger) DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) AuditLogMsgBuilder(com.yahoo.athenz.common.server.log.AuditLogMsgBuilder) HttpServletRequest(javax.servlet.http.HttpServletRequest) ChangeLogStore(com.yahoo.athenz.zts.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 24 with AuditLogMsgBuilder

use of com.yahoo.athenz.common.server.log.AuditLogMsgBuilder in project athenz by yahoo.

the class ZMSImplTest method testGetAuditLogMsgBuilderTokenSigMissing.

@Test
public void testGetAuditLogMsgBuilderTokenSigMissing() {
    Authority principalAuthority = new com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority();
    String userId = "user1";
    String unsignedCreds = "v=U1;d=user;n=user1";
    Principal principal = SimplePrincipal.create("user", userId, unsignedCreds, 0, principalAuthority);
    ResourceContext ctx = createResourceContext(principal);
    AuditLogMsgBuilder msgBldr = ZMSUtils.getAuditLogMsgBuilder(ctx, auditLogger, "mydomain", auditRef, "myapi", "PUT");
    assertNotNull(msgBldr);
    String who = msgBldr.who();
    assertNotNull(who);
    assertTrue(who.contains(userId));
}
Also used : DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) AuditLogMsgBuilder(com.yahoo.athenz.common.server.log.AuditLogMsgBuilder) Authority(com.yahoo.athenz.auth.Authority) PrincipalAuthority(com.yahoo.athenz.auth.impl.PrincipalAuthority) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal)

Aggregations

AuditLogMsgBuilder (com.yahoo.athenz.common.server.log.AuditLogMsgBuilder)24 DefaultAuditLogMsgBuilder (com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder)14 Principal (com.yahoo.athenz.auth.Principal)13 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)12 AuditLogger (com.yahoo.athenz.common.server.log.AuditLogger)8 Test (org.testng.annotations.Test)8 HashSet (java.util.HashSet)7 DefaultAuditLogger (com.yahoo.athenz.common.server.log.impl.DefaultAuditLogger)6 SignedDomain (com.yahoo.athenz.zms.SignedDomain)6 ChangeLogStore (com.yahoo.athenz.zts.store.ChangeLogStore)6 DataStore (com.yahoo.athenz.zts.store.DataStore)6 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)6 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 X509Certificate (java.security.cert.X509Certificate)4 Authority (com.yahoo.athenz.auth.Authority)3 CryptoException (com.yahoo.athenz.auth.util.CryptoException)3 X509CertRequest (com.yahoo.athenz.zts.cert.X509CertRequest)3 PrincipalAuthority (com.yahoo.athenz.auth.impl.PrincipalAuthority)2 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)2