0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

Add more tests.

This commit is contained in:
Abiola Ibrahim 2016-03-11 23:44:50 +01:00
parent 84845a66ab
commit e92a911e7d
2 changed files with 21 additions and 0 deletions

View file

@ -141,6 +141,7 @@ func (fh fileHandler) isHidden(name string) bool {
name = strings.TrimSpace(name) name = strings.TrimSpace(name)
for strings.HasSuffix(name, ".") { for strings.HasSuffix(name, ".") {
name = name[:len(name)-1] name = name[:len(name)-1]
name = strings.TrimSpace(name)
} }
} }
// If the file is supposed to be hidden, return a 404 // If the file is supposed to be hidden, return a 404

View file

@ -112,6 +112,26 @@ func TestServeHTTP(t *testing.T) {
expectedStatus: http.StatusMovedPermanently, expectedStatus: http.StatusMovedPermanently,
expectedBodyContent: movedPermanently, expectedBodyContent: movedPermanently,
}, },
// Test 11 - attempt to bypass hidden file
{
url: "https://foo/dir/hidden.html%20",
expectedStatus: http.StatusNotFound,
},
// Test 12 - attempt to bypass hidden file
{
url: "https://foo/dir/hidden.html.",
expectedStatus: http.StatusNotFound,
},
// Test 13 - attempt to bypass hidden file
{
url: "https://foo/dir/hidden.html.%20",
expectedStatus: http.StatusNotFound,
},
// Test 14 - attempt to bypass hidden file
{
url: "https://foo/dir/hidden.html%20.",
expectedStatus: http.StatusNotFound,
},
} }
for i, test := range tests { for i, test := range tests {