Exemplo n.º 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"));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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();
        }
Exemplo n.º 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");
        }