Пример #1
0
        public async Task ShouldGoToTheNextRewriteRuleIfTheCurrentDoesNottMatches()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a /b [L]", "/b /c" }));

            var request = OwinHelper.CreateRequest("http://test.com/b");

            await middleware.Invoke(request.Context);

            request.Path.ShouldBe(new PathString("/c"));
        }
Пример #2
0
        public async Task ShouldNotRewriteIfThePatternMatch()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "!/a /b [L]", "/b /c" }));

            var request = OwinHelper.CreateRequest("http://test.com/b");

            await middleware.Invoke(request.Context);

            request.Path.ShouldNotBe(new PathString("/c"));
        }
Пример #3
0
        public async Task ShouldSetStatusCodeTo403()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a [F]" }));
            var request    = OwinHelper.CreateRequest("http://test.com/a");

            var context = request.Context;
            await middleware.Invoke(context);

            context.Response.StatusCode.ShouldBe((int)HttpStatusCode.Forbidden);
        }
Пример #4
0
        public async Task ShouldLeaveTheUrlUnrewrittenIfThereIsNoMatch()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a /b [L]", "/a /c" }));

            var request = OwinHelper.CreateRequest("http://test.com/d");

            await middleware.Invoke(request.Context);

            request.Path.ShouldBe(new PathString("/d"));
        }
Пример #5
0
        public async Task ShouldKeepNestedQueryParameters()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a /b [L]", "/a /c" }));

            var request = OwinHelper.CreateRequest("http://test.com/d?foo[0]=bar&foo[1]=baz&q");

            await middleware.Invoke(request.Context);

            request.QueryString.ShouldBe(new QueryString("foo[0]=bar&foo[1]=baz&q"));
        }
Пример #6
0
        public async Task ShouldBeAbleToParseWithOtherFlags()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a /b [H=(.+)\\.webview\\..*, L]" }));

            var request = OwinHelper.CreateRequest("http://ios.webview.test.com/a");
            var context = request.Context;

            await middleware.Invoke(context);

            request.Path.ShouldBe(new PathString("/b"));
        }
Пример #7
0
        public async Task ShouldUseTheCurrentRuleIfTheHostMatch()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a /b [H=(.+)\\.webview\\..*]" }));

            var request = OwinHelper.CreateRequest("http://ios.webview.test.com/a");
            var context = request.Context;

            await middleware.Invoke(context);

            request.Path.ShouldBe(new PathString("/b"));
        }
Пример #8
0
        public async Task ShouldNotDoAnythingIfGoneFlagIsNotSet()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a [F]" }));

            var request = OwinHelper.CreateRequest("http://test.com/d");
            var context = request.Context;

            await middleware.Invoke(context);

            context.Response.StatusCode.ShouldBe((int)HttpStatusCode.OK);
        }
Пример #9
0
        public async Task Monkey()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "!\\.\\w+$ /index.html [L]" }));

            var request = OwinHelper.CreateRequest("http://test.com/notifications.json");
            var context = request.Context;

            await middleware.Invoke(context);

            request.Path.ShouldBe(new PathString("/notifications.json"));
        }
Пример #10
0
        public async Task ShouldSetCustomStatusCodeIfRewriteCustomFlagIsSet()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a /b [R=307]" }));

            var request = OwinHelper.CreateRequest("http://test.com/a");
            var context = request.Context;

            await middleware.Invoke(context);

            context.Response.StatusCode.ShouldBe(307);
        }
Пример #11
0
        public async Task ShouldUseTheCurrentRuleIfTheHostMatch()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "^/a - [L]" }));

            var request = OwinHelper.CreateRequest("http://test.com/a/foo/bar/woot");

            var context = request.Context;
            await middleware.Invoke(context);

            request.Path.ShouldBe(new PathString("/a/foo/bar/woot"));
        }
Пример #12
0
        public async Task ShouldBeAbleToSetARewriteWithHostnameAndProtocol()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/(.*) http://localhost/$1 [R]" }));

            var request = OwinHelper.CreateRequest("http://localhost/a");
            var context = request.Context;

            await middleware.Invoke(context);

            context.Response.StatusCode.ShouldBe((int)HttpStatusCode.Redirect);
            //context.Response.Received(1).Redirect(Arg.Is("http://localhost/b"));
        }
Пример #13
0
        public async Task ShouldSetDefaultStatusCodeTo301IfRewriteFlagIsSet()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a /b [R]" }));

            var request = OwinHelper.CreateRequest("http://test.com/a");
            var context = request.Context;

            await middleware.Invoke(context);

            context.Response.StatusCode.ShouldBe((int)HttpStatusCode.Redirect);
            //context.Response.Received(1).Redirect(Arg.Is("http://test.com/b"));
        }
Пример #14
0
        public async Task ShouldNotDoAnythingTheTypeFlagIsNotSet()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "/a /b [L]" }));

            var request = OwinHelper.CreateRequest("http://test.com/a");

            var context = request.Context;
            await middleware.Invoke(context);

            var header = context.Response.Headers["Content-Type"];

            header.ShouldBeNullOrEmpty();
        }
Пример #15
0
        public async Task ShouldSetContentTypeHeaderIfTypeFlagIsSet()
        {
            var middleware = new UrlRewriterMiddleware(new VoidOwinMiddleware(), new UrlRewriterOptions(new[] { "!/ /b [T=image/jpeg]" }));

            var request = OwinHelper.CreateRequest("http://test.com/b");

            var context = request.Context;
            await middleware.Invoke(context);

            var header = context.Response.Headers["Content-Type"];

            header.ShouldBe("image/jpeg");
        }