Ejemplo n.º 1
0
        public void UseCase_SuppressExistingPast_Test()
        {
            RuleProcessor processor = new RuleProcessor(@"rules\valid");

            processor.AddRules(@"rules\custom");

            string     testString = "MD5 hash = new MD5CryptoServiceProvider(); //DevSkim: ignore DS126858,DS168931 until 1980-07-15";
            Suppressor sup        = new Suppressor(testString, "csharp");

            Assert.IsFalse(sup.IsRuleSuppressed("DS126858"), "Is suppressed DS126858 should be True");
            Assert.IsFalse(sup.IsRuleSuppressed("DS168931"), "Is suppressed DS168931 should be True");

            // Suppress multiple
            string suppressedString = sup.SuppressRule("DS196098");
            string expected         = "MD5 hash = new MD5CryptoServiceProvider(); //DevSkim: ignore DS126858,DS168931,DS196098 until 1980-07-15";

            Assert.AreEqual(expected, suppressedString, "Suppress multiple failed");

            // Suppress multiple new date
            DateTime expirationDate = DateTime.Now.AddDays(10);

            suppressedString = sup.SuppressRule("DS196098", expirationDate);
            expected         = "MD5 hash = new MD5CryptoServiceProvider(); //DevSkim: ignore DS126858,DS168931,DS196098 until {0:yyyy}-{0:MM}-{0:dd}";
            Assert.AreEqual(string.Format(expected, expirationDate), suppressedString, "Suppress multiple new date failed");

            // Suppress multiple to all
            suppressedString = sup.SuppressAll();
            expected         = "MD5 hash = new MD5CryptoServiceProvider(); //DevSkim: ignore all until 1980-07-15";
            Assert.AreEqual(string.Format(expected, expirationDate), suppressedString, "Suppress multiple to all failed");

            // Suppress multiple to all new date
            suppressedString = sup.SuppressAll(expirationDate);
            expected         = "MD5 hash = new MD5CryptoServiceProvider(); //DevSkim: ignore all until {0:yyyy}-{0:MM}-{0:dd}";
            Assert.AreEqual(string.Format(expected, expirationDate), suppressedString, "Suppress multiple to all new date failed");
        }
Ejemplo n.º 2
0
        public void UseCase_Suppress_Test()
        {
            RuleProcessor processor = new RuleProcessor(@"rules\valid");

            processor.AddRules(@"rules\custom");

            // Is supressed test
            string testString = "md5.new()";
            Match  match      = processor.IsMatch(testString, 0, "python");

            Assert.IsTrue(match.Success, "Is suppressed should ve flagged");

            string     ruleId = match.Rule.Id;
            Suppressor sup    = new Suppressor(testString, "python");

            Assert.IsFalse(sup.IsRuleSuppressed(ruleId), "Is suppressed should be false");

            // Suppress Rule test
            string suppressedString = sup.SuppressRule(ruleId);
            string expected         = "md5.new() #DevSkim: ignore DS196098";

            Assert.AreEqual(expected, suppressedString, "Supress Rule failed ");

            // Suppress Rule Until test
            DateTime expirationDate = DateTime.Now.AddDays(5);

            suppressedString = sup.SuppressRule(ruleId, expirationDate);
            expected         = string.Format("md5.new() #DevSkim: ignore DS196098 until {0:yyyy}-{0:MM}-{0:dd}", expirationDate);
            Assert.AreEqual(expected, suppressedString, "Supress Rule Until failed ");

            // Suppress All test
            suppressedString = sup.SuppressAll();
            expected         = "md5.new() #DevSkim: ignore all";
            Assert.AreEqual(expected, suppressedString, "Supress All failed");

            // Suppress All Until test
            suppressedString = sup.SuppressAll(expirationDate);
            expected         = string.Format("md5.new() #DevSkim: ignore all until {0:yyyy}-{0:MM}-{0:dd}", expirationDate);
            Assert.AreEqual(expected, suppressedString, "Supress All Until failed ");
        }