Commit 38e65e28 authored by Matt Holt's avatar Matt Holt Committed by GitHub

tls: Fix tests on Windows (#2093)

parent 73b61af5
...@@ -14,7 +14,10 @@ ...@@ -14,7 +14,10 @@
package caddytls package caddytls
import "testing" import (
"path/filepath"
"testing"
)
// *********************************** NOTE ******************************** // *********************************** NOTE ********************************
// Due to circular package dependencies with the storagetest sub package and // Due to circular package dependencies with the storagetest sub package and
...@@ -22,33 +25,47 @@ import "testing" ...@@ -22,33 +25,47 @@ import "testing"
// the tests for file storage are done in the storagetest package. // the tests for file storage are done in the storagetest package.
func TestPathBuilders(t *testing.T) { func TestPathBuilders(t *testing.T) {
fs := FileStorage{Path: "/test"} fs := FileStorage{Path: "test"}
for i, testcase := range []struct { for i, testcase := range []struct {
in, folder, certFile, keyFile, metaFile string in, folder, certFile, keyFile, metaFile string
}{ }{
{ {
in: "example.com", in: "example.com",
folder: "/test/sites/example.com", folder: filepath.Join("test", "sites", "example.com"),
certFile: "/test/sites/example.com/example.com.crt", certFile: filepath.Join("test", "sites", "example.com", "example.com.crt"),
keyFile: "/test/sites/example.com/example.com.key", keyFile: filepath.Join("test", "sites", "example.com", "example.com.key"),
metaFile: "/test/sites/example.com/example.com.json", metaFile: filepath.Join("test", "sites", "example.com", "example.com.json"),
}, },
{ {
in: "*.example.com", in: "*.example.com",
folder: "/test/sites/wildcard_.example.com", folder: filepath.Join("test", "sites", "wildcard_.example.com"),
certFile: "/test/sites/wildcard_.example.com/wildcard_.example.com.crt", certFile: filepath.Join("test", "sites", "wildcard_.example.com", "wildcard_.example.com.crt"),
keyFile: "/test/sites/wildcard_.example.com/wildcard_.example.com.key", keyFile: filepath.Join("test", "sites", "wildcard_.example.com", "wildcard_.example.com.key"),
metaFile: "/test/sites/wildcard_.example.com/wildcard_.example.com.json", metaFile: filepath.Join("test", "sites", "wildcard_.example.com", "wildcard_.example.com.json"),
}, },
{ {
// prevent directory traversal! very important, esp. with on-demand TLS // prevent directory traversal! very important, esp. with on-demand TLS
// see issue #2092 // see issue #2092
in: "a/../../../foo", in: "a/../../../foo",
folder: "/test/sites/afoo", folder: filepath.Join("test", "sites", "afoo"),
certFile: "/test/sites/afoo/afoo.crt", certFile: filepath.Join("test", "sites", "afoo", "afoo.crt"),
keyFile: "/test/sites/afoo/afoo.key", keyFile: filepath.Join("test", "sites", "afoo", "afoo.key"),
metaFile: "/test/sites/afoo/afoo.json", metaFile: filepath.Join("test", "sites", "afoo", "afoo.json"),
},
{
in: "b\\..\\..\\..\\foo",
folder: filepath.Join("test", "sites", "bfoo"),
certFile: filepath.Join("test", "sites", "bfoo", "bfoo.crt"),
keyFile: filepath.Join("test", "sites", "bfoo", "bfoo.key"),
metaFile: filepath.Join("test", "sites", "bfoo", "bfoo.json"),
},
{
in: "c/foo",
folder: filepath.Join("test", "sites", "cfoo"),
certFile: filepath.Join("test", "sites", "cfoo", "cfoo.crt"),
keyFile: filepath.Join("test", "sites", "cfoo", "cfoo.key"),
metaFile: filepath.Join("test", "sites", "cfoo", "cfoo.json"),
}, },
} { } {
if actual := fs.site(testcase.in); actual != testcase.folder { if actual := fs.site(testcase.in); actual != testcase.folder {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment