diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2016-02-04 17:16:43 +0200 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2016-02-04 17:16:43 +0200 |
commit | e0cd149b5e802db804484c7cd16da5eb5efe7753 (patch) | |
tree | f03dea5b1ccb7d57a58f551b45bf1736e4bfd6fd /fs_test.go | |
parent | FS: verify that the path doesn't contain '/../' only if PathRewriter is used (diff) | |
download | fasthttp-e0cd149b5e802db804484c7cd16da5eb5efe7753.tar.gz fasthttp-e0cd149b5e802db804484c7cd16da5eb5efe7753.tar.bz2 fasthttp-e0cd149b5e802db804484c7cd16da5eb5efe7753.zip |
Enabled virtual hosting support in example fileserver
Diffstat (limited to 'fs_test.go')
-rw-r--r-- | fs_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -12,6 +12,45 @@ import ( "time" ) +func TestNewVHostPathRewriter(t *testing.T) { + var ctx RequestCtx + var req Request + req.Header.SetHost("foobar.com") + req.SetRequestURI("/foo/bar/baz") + ctx.Init(&req, nil, nil) + + f := NewVHostPathRewriter(0) + path := f(&ctx) + expectedPath := "/foobar.com/foo/bar/baz" + if string(path) != expectedPath { + t.Fatalf("unexpected path %q. Expecting %q", path, expectedPath) + } + + ctx.Request.Reset() + ctx.Request.SetRequestURI("https://aaa.bbb.cc/one/two/three/four?asdf=dsf") + f = NewVHostPathRewriter(2) + path = f(&ctx) + expectedPath = "/aaa.bbb.cc/three/four" + if string(path) != expectedPath { + t.Fatalf("unexpected path %q. Expecting %q", path, expectedPath) + } +} + +func TestNewVHostPathRewriterMaliciousHost(t *testing.T) { + var ctx RequestCtx + var req Request + req.Header.SetHost("/../../../etc/passwd") + req.SetRequestURI("/foo/bar/baz") + ctx.Init(&req, nil, nil) + + f := NewVHostPathRewriter(0) + path := f(&ctx) + expectedPath := "/invalid-host/foo/bar/baz" + if string(path) != expectedPath { + t.Fatalf("unexpected path %q. Expecting %q", path, expectedPath) + } +} + func TestServeFileHead(t *testing.T) { var ctx RequestCtx var req Request |