aboutsummaryrefslogtreecommitdiff
path: root/fs_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-04 17:16:43 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-04 17:16:43 +0200
commite0cd149b5e802db804484c7cd16da5eb5efe7753 (patch)
treef03dea5b1ccb7d57a58f551b45bf1736e4bfd6fd /fs_test.go
parentFS: verify that the path doesn't contain '/../' only if PathRewriter is used (diff)
downloadfasthttp-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.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/fs_test.go b/fs_test.go
index d138c60..3aa856b 100644
--- a/fs_test.go
+++ b/fs_test.go
@@ -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