Exemplo n.º 1
0
        public void Test_AddNullThreshold()
        {
            IntrusionDetector detector = Esapi.IntrusionDetector as IntrusionDetector;

            Assert.IsNotNull(detector);

            detector.AddThreshold(null);
        }
Exemplo n.º 2
0
        public void Test_AddThresholdMissingAction()
        {
            string evtName = Guid.NewGuid().ToString();

            IntrusionDetector detector = Esapi.IntrusionDetector as IntrusionDetector;

            Assert.IsNotNull(detector);

            Threshold threshold = new Threshold(evtName, 1, 1, new[] { Guid.NewGuid().ToString() });

            detector.AddThreshold(threshold);
        }
Exemplo n.º 3
0
        public void Test_IntrusionDetected()
        {
            string evtName = Guid.NewGuid().ToString();

            IntrusionDetector detector = Esapi.IntrusionDetector as IntrusionDetector;

            Assert.IsNotNull(detector);

            Threshold threshold = new Threshold(evtName, 1, 1, new[] { "log" });

            detector.AddThreshold(threshold);

            Esapi.IntrusionDetector.AddEvent(evtName);
        }
Exemplo n.º 4
0
        public void Test_RemoveThreshold()
        {
            string evtName = Guid.NewGuid().ToString();

            IntrusionDetector detector = Esapi.IntrusionDetector as IntrusionDetector;

            Assert.IsNotNull(detector);

            Threshold threshold = new Threshold(evtName, 1, 1, new[] { "logout" });

            detector.AddThreshold(threshold);

            Assert.IsTrue(detector.RemoveThreshold(evtName));
        }
Exemplo n.º 5
0
        public void Test_AddExceptionSecurityEvent()
        {
            string evtName = typeof(ArgumentException).FullName;

            IntrusionDetector detector = Esapi.IntrusionDetector as IntrusionDetector;

            Assert.IsNotNull(detector);

            Threshold threshold = new Threshold(evtName, 1, 1, new[] { "log" });

            detector.AddThreshold(threshold);

            ArgumentException arg = new ArgumentException();

            detector.AddException(arg);
        }
Exemplo n.º 6
0
        public void Test_AddDuplicateThreshold()
        {
            string evtName = Guid.NewGuid().ToString();

            IntrusionDetector detector = Esapi.IntrusionDetector as IntrusionDetector;

            Assert.IsNotNull(detector);

            Threshold threshold = new Threshold(evtName, 1, 1, new[] { BuiltinActions.FormsAuthenticationLogout });

            detector.AddThreshold(threshold);

            Threshold dup = new Threshold(evtName, 2, 2, null);

            detector.AddThreshold(dup);
        }
        public void Test_Execute()
        {
            IntrusionDetector detector = Esapi.IntrusionDetector as IntrusionDetector;

            Assert.IsNotNull(detector);

            // Should be loaded by default
            BlockAction action = new BlockAction();

            // Set context
            MockHttpContext.InitializeCurrentContext();
            SurrogateWebPage page = new SurrogateWebPage();

            HttpContext.Current.Handler = page;

            // Block
            Assert.AreNotEqual(HttpContext.Current.Response.StatusCode, action.StatusCode);

            action.Execute(ActionArgs.Empty);
            Assert.AreEqual(HttpContext.Current.Response.StatusCode, action.StatusCode);
        }