Ejemplo n.º 1
0
        /// <summary>Test the AuditLog format for successful events.</summary>
        private void TestSuccessLogFormatHelper(bool checkIP, ApplicationId appId, ContainerId
                                                containerId)
        {
            // check without the IP
            string sLog = NMAuditLogger.CreateSuccessLog(User, Operation, Target, appId, containerId
                                                         );
            StringBuilder expLog = new StringBuilder();

            expLog.Append("USER=test\t");
            if (checkIP)
            {
                IPAddress ip = Org.Apache.Hadoop.Ipc.Server.GetRemoteIp();
                expLog.Append(NMAuditLogger.Keys.Ip.ToString() + "=" + ip.GetHostAddress() + "\t"
                              );
            }
            expLog.Append("OPERATION=oper\tTARGET=tgt\tRESULT=SUCCESS");
            if (appId != null)
            {
                expLog.Append("\tAPPID=app_1");
            }
            if (containerId != null)
            {
                expLog.Append("\tCONTAINERID=container_1");
            }
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), sLog);
        }
Ejemplo n.º 2
0
        /// <summary>Test the AuditLog format for failure events.</summary>
        private void TestFailureLogFormatHelper(bool checkIP, ApplicationId appId, ContainerId
                                                containerId)
        {
            string fLog = NMAuditLogger.CreateFailureLog(User, Operation, Target, Desc, appId
                                                         , containerId);
            StringBuilder expLog = new StringBuilder();

            expLog.Append("USER=test\t");
            if (checkIP)
            {
                IPAddress ip = Org.Apache.Hadoop.Ipc.Server.GetRemoteIp();
                expLog.Append(NMAuditLogger.Keys.Ip.ToString() + "=" + ip.GetHostAddress() + "\t"
                              );
            }
            expLog.Append("OPERATION=oper\tTARGET=tgt\tRESULT=FAILURE\t");
            expLog.Append("DESCRIPTION=description of an audit log");
            if (appId != null)
            {
                expLog.Append("\tAPPID=app_1");
            }
            if (containerId != null)
            {
                expLog.Append("\tCONTAINERID=container_1");
            }
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), fLog);
        }
Ejemplo n.º 3
0
        /// <summary>Test the AuditLog format for successful events passing nulls.</summary>
        private void TestSuccessLogNulls(bool checkIP)
        {
            string        sLog   = NMAuditLogger.CreateSuccessLog(null, null, null, null, null);
            StringBuilder expLog = new StringBuilder();

            expLog.Append("USER=null\t");
            if (checkIP)
            {
                IPAddress ip = Org.Apache.Hadoop.Ipc.Server.GetRemoteIp();
                expLog.Append(NMAuditLogger.Keys.Ip.ToString() + "=" + ip.GetHostAddress() + "\t"
                              );
            }
            expLog.Append("OPERATION=null\tTARGET=null\tRESULT=SUCCESS");
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), sLog);
        }
Ejemplo n.º 4
0
        public virtual void TestKeyValLogFormat()
        {
            StringBuilder actLog = new StringBuilder();
            StringBuilder expLog = new StringBuilder();

            // add the first k=v pair and check
            NMAuditLogger.Start(NMAuditLogger.Keys.User, User, actLog);
            expLog.Append("USER=test");
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), actLog.ToString());
            // append another k1=v1 pair to already added k=v and test
            NMAuditLogger.Add(NMAuditLogger.Keys.Operation, Operation, actLog);
            expLog.Append("\tOPERATION=oper");
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), actLog.ToString());
            // append another k1=null pair and test
            NMAuditLogger.Add(NMAuditLogger.Keys.Appid, (string)null, actLog);
            expLog.Append("\tAPPID=null");
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), actLog.ToString());
            // now add the target and check of the final string
            NMAuditLogger.Add(NMAuditLogger.Keys.Target, Target, actLog);
            expLog.Append("\tTARGET=tgt");
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), actLog.ToString());
        }