diff options
author | Bjørn Erik Pedersen <[email protected]> | 2020-05-27 13:50:13 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-05-28 16:25:34 +0200 |
commit | 6a3e89743ccad58097a6dd203a63448946a2304d (patch) | |
tree | b360b4c713ddbaa7c55d486961a9c3e93e3aea8c /config/commonConfig_test.go | |
parent | 9613e3e8a81be934fc88db3f9f0d79d429aae1a2 (diff) | |
download | hugo-6a3e89743ccad58097a6dd203a63448946a2304d.tar.gz hugo-6a3e89743ccad58097a6dd203a63448946a2304d.zip |
Add redirect support to the server
Fixes #7323
Diffstat (limited to 'config/commonConfig_test.go')
-rw-r--r-- | config/commonConfig_test.go | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/config/commonConfig_test.go b/config/commonConfig_test.go index 41b2721bc..b8b6e6795 100644 --- a/config/commonConfig_test.go +++ b/config/commonConfig_test.go @@ -70,15 +70,73 @@ for = "/*.jpg" X-Frame-Options = "DENY" X-XSS-Protection = "1; mode=block" X-Content-Type-Options = "nosniff" + +[[server.redirects]] +from = "/foo/**" +to = "/foo/index.html" +status = 200 + +[[server.redirects]] +from = "/google/**" +to = "https://google.com/" +status = 301 + +[[server.redirects]] +from = "/**" +to = "/default/index.html" +status = 301 + + + `, "toml") c.Assert(err, qt.IsNil) - s := DecodeServer(cfg) + s, err := DecodeServer(cfg) + c.Assert(err, qt.IsNil) - c.Assert(s.Match("/foo.jpg"), qt.DeepEquals, []types.KeyValueStr{ + c.Assert(s.MatchHeaders("/foo.jpg"), qt.DeepEquals, []types.KeyValueStr{ {Key: "X-Content-Type-Options", Value: "nosniff"}, {Key: "X-Frame-Options", Value: "DENY"}, {Key: "X-XSS-Protection", Value: "1; mode=block"}}) + c.Assert(s.MatchRedirect("/foo/bar/baz"), qt.DeepEquals, Redirect{ + From: "/foo/**", + To: "/foo/", + Status: 200, + }) + + c.Assert(s.MatchRedirect("/someother"), qt.DeepEquals, Redirect{ + From: "/**", + To: "/default/", + Status: 301, + }) + + c.Assert(s.MatchRedirect("/google/foo"), qt.DeepEquals, Redirect{ + From: "/google/**", + To: "https://google.com/", + Status: 301, + }) + + // No redirect loop, please. + c.Assert(s.MatchRedirect("/default/index.html"), qt.DeepEquals, Redirect{}) + c.Assert(s.MatchRedirect("/default/"), qt.DeepEquals, Redirect{}) + + for _, errorCase := range []string{`[[server.redirects]] +from = "/**" +to = "/file" +status = 301`, + `[[server.redirects]] +from = "/**" +to = "/foo/file.html" +status = 301`, + } { + + cfg, err := FromConfigString(errorCase, "toml") + c.Assert(err, qt.IsNil) + _, err = DecodeServer(cfg) + c.Assert(err, qt.Not(qt.IsNil)) + + } + } |