Beispiel #1
0
        /// <summary>Test the AuditLog format for successful events.</summary>
        private void TestSuccessLogFormat(bool checkIP)
        {
            // check without the IP
            string        sLog   = AuditLogger.CreateSuccessLog(User, Operation, Target);
            StringBuilder expLog = new StringBuilder();

            expLog.Append("USER=test\t");
            if (checkIP)
            {
                IPAddress ip = Server.GetRemoteIp();
                expLog.Append(AuditLogger.Keys.Ip.ToString() + "=" + ip.GetHostAddress() + "\t");
            }
            expLog.Append("OPERATION=oper\tTARGET=tgt\tRESULT=SUCCESS");
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), sLog);
        }
Beispiel #2
0
        /// <summary>Test the AuditLog format for failure events.</summary>
        private void TestFailureLogFormat(bool checkIP, string perm)
        {
            string        fLog   = AuditLogger.CreateFailureLog(User, Operation, perm, Target, Desc);
            StringBuilder expLog = new StringBuilder();

            expLog.Append("USER=test\t");
            if (checkIP)
            {
                IPAddress ip = Server.GetRemoteIp();
                expLog.Append(AuditLogger.Keys.Ip.ToString() + "=" + ip.GetHostAddress() + "\t");
            }
            expLog.Append("OPERATION=oper\tTARGET=tgt\tRESULT=FAILURE\t");
            expLog.Append("DESCRIPTION=description of an audit log\t");
            expLog.Append("PERMISSIONS=" + perm);
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), fLog);
        }
Beispiel #3
0
        /// <summary>Test the AuditLog format with key-val pair.</summary>
        public virtual void TestKeyValLogFormat()
        {
            StringBuilder actLog = new StringBuilder();
            StringBuilder expLog = new StringBuilder();

            // add the first k=v pair and check
            AuditLogger.Start(AuditLogger.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
            AuditLogger.Add(AuditLogger.Keys.Operation, Operation, actLog);
            expLog.Append("\tOPERATION=oper");
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), actLog.ToString());
            // append another k1=null pair and test
            AuditLogger.Add(AuditLogger.Keys.Permissions, (string)null, actLog);
            expLog.Append("\tPERMISSIONS=null");
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), actLog.ToString());
            // now add the target and check of the final string
            AuditLogger.Add(AuditLogger.Keys.Target, Target, actLog);
            expLog.Append("\tTARGET=tgt");
            NUnit.Framework.Assert.AreEqual(expLog.ToString(), actLog.ToString());
        }