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