Ejemplo 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"));
        }
Ejemplo 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"));
        }
Ejemplo 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);
        }
Ejemplo 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"));
        }
Ejemplo 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"));
        }
Ejemplo 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"));
        }
Ejemplo 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"));
        }
Ejemplo 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);
        }
Ejemplo 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"));
        }
Ejemplo 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);
        }
Ejemplo 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"));
        }
Ejemplo 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"));
        }
Ejemplo 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"));
        }
Ejemplo 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();
        }
Ejemplo 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");
        }