diff options
Diffstat (limited to 'modules/caddyhttp/fileserver/staticfiles_test.go')
| -rw-r--r-- | modules/caddyhttp/fileserver/staticfiles_test.go | 50 | 
1 files changed, 42 insertions, 8 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles_test.go b/modules/caddyhttp/fileserver/staticfiles_test.go index 1bbd77b..690f46a 100644 --- a/modules/caddyhttp/fileserver/staticfiles_test.go +++ b/modules/caddyhttp/fileserver/staticfiles_test.go @@ -17,6 +17,8 @@ package fileserver  import (  	"net/url"  	"path/filepath" +	"runtime" +	"strings"  	"testing"  ) @@ -44,7 +46,7 @@ func TestSanitizedPathJoin(t *testing.T) {  		},  		{  			inputPath: "/foo/", -			expect:    "foo" + string(filepath.Separator), +			expect:    "foo" + separator,  		},  		{  			inputPath: "/foo/bar", @@ -77,7 +79,7 @@ func TestSanitizedPathJoin(t *testing.T) {  		{  			inputRoot: "/a/b",  			inputPath: "/%2e%2e%2f%2e%2e%2f", -			expect:    filepath.Join("/", "a", "b") + string(filepath.Separator), +			expect:    filepath.Join("/", "a", "b") + separator,  		},  		{  			inputRoot: "C:\\www", @@ -155,6 +157,26 @@ func TestFileHidden(t *testing.T) {  			expect:    true,  		},  		{ +			inputHide: []string{"*.txt"}, +			inputPath: "/foo/bar.txt", +			expect:    true, +		}, +		{ +			inputHide: []string{"/foo/bar/*.txt"}, +			inputPath: "/foo/bar/baz.txt", +			expect:    true, +		}, +		{ +			inputHide: []string{"/foo/bar/*.txt"}, +			inputPath: "/foo/bar.txt", +			expect:    false, +		}, +		{ +			inputHide: []string{"/foo/bar/*.txt"}, +			inputPath: "/foo/bar/index.html", +			expect:    false, +		}, +		{  			inputHide: []string{"/foo"},  			inputPath: "/foo",  			expect:    true, @@ -164,17 +186,29 @@ func TestFileHidden(t *testing.T) {  			inputPath: "/foobar",  			expect:    false,  		}, +		{ +			inputHide: []string{"first", "second"}, +			inputPath: "/second", +			expect:    true, +		},  	} { -		// for Windows' sake -		tc.inputPath = filepath.FromSlash(tc.inputPath) -		for i := range tc.inputHide { -			tc.inputHide[i] = filepath.FromSlash(tc.inputHide[i]) +		if runtime.GOOS == "windows" { +			if strings.HasPrefix(tc.inputPath, "/") { +				tc.inputPath, _ = filepath.Abs(tc.inputPath) +			} +			tc.inputPath = filepath.FromSlash(tc.inputPath) +			for i := range tc.inputHide { +				if strings.HasPrefix(tc.inputHide[i], "/") { +					tc.inputHide[i], _ = filepath.Abs(tc.inputHide[i]) +				} +				tc.inputHide[i] = filepath.FromSlash(tc.inputHide[i]) +			}  		}  		actual := fileHidden(tc.inputPath, tc.inputHide)  		if actual != tc.expect { -			t.Errorf("Test %d: Is %s hidden in %v? Got %t but expected %t", -				i, tc.inputPath, tc.inputHide, actual, tc.expect) +			t.Errorf("Test %d: Does %v hide %s? Got %t but expected %t", +				i, tc.inputHide, tc.inputPath, actual, tc.expect)  		}  	}  }  | 
