示例#1
0
        public void Test_Execute()
        {
            IIntrusionDetector detector = Esapi.IntrusionDetector;

            string         url    = Guid.NewGuid().ToString();
            RedirectAction action = new RedirectAction(url);

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

            HttpContext.Current.Handler = page;

            // Block
            try {
                Assert.AreNotEqual(HttpContext.Current.Request.RawUrl, action.Url);
                action.Execute(ActionArgs.Empty);

                Assert.Fail("Request not terminated");
            }
            catch (Exception exp) {
                // FIXME : so far there is no other way to test the redirect except to check
                // the stack of the exception. Ideally we should be able to mock the request
                // redirect itself
                Assert.IsTrue(exp.StackTrace.Contains("at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)"));
            }
        }
        public void Execute_WithNullContext_Throws()
        {
            // Arrange
            RedirectAction action = new RedirectAction("/", true);
            IRewriteContext context = null;

            // Act/Assert
            ExceptionAssert.Throws<ArgumentNullException>(() => action.Execute(context));
        }
示例#3
0
        public void Execute_WithNullContext_Throws()
        {
            // Arrange
            RedirectAction  action  = new RedirectAction("/", true);
            IRewriteContext context = null;

            // Act/Assert
            ExceptionAssert.Throws <ArgumentNullException>(() => action.Execute(context));
        }
        public void Execute_WhenTemporary_SetsStatusCodeAndLocation_ReturnsStopProcessing()
        {
            // Arrange
            string location = "/NewLocation";
            bool permanent = false;
            RedirectAction action = new RedirectAction(location, permanent);
            action.Conditions.Add(new MockRewriteCondition(true));
            IRewriteContext context = new MockRewriteContext();

            // Act
            RewriteProcessing result = action.Execute(context);

            // Assert
            Assert.AreEqual(RewriteProcessing.StopProcessing, result);
            Assert.AreEqual(HttpStatusCode.Found, context.StatusCode);
            Assert.AreEqual(location, context.Location);
        }
示例#5
0
        public void Execute_WhenTemporary_SetsStatusCodeAndLocation_ReturnsStopProcessing()
        {
            // Arrange
            string         location  = "/NewLocation";
            bool           permanent = false;
            RedirectAction action    = new RedirectAction(location, permanent);

            action.Conditions.Add(new MockRewriteCondition(true));
            IRewriteContext context = new MockRewriteContext();

            // Act
            RewriteProcessing result = action.Execute(context);

            // Assert
            Assert.AreEqual(RewriteProcessing.StopProcessing, result);
            Assert.AreEqual(HttpStatusCode.Found, context.StatusCode);
            Assert.AreEqual(location, context.Location);
        }