|
| 1 | +package caddy_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + "os" |
| 6 | + "strconv" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/caddyserver/caddy/v2/caddytest" |
| 10 | +) |
| 11 | + |
| 12 | +func TestRootBehavesTheSameOutsideAndInsidePhpServer(t *testing.T) { |
| 13 | + tester := caddytest.NewTester(t) |
| 14 | + testPortNum, _ := strconv.Atoi(testPort) |
| 15 | + testPortTwo := strconv.Itoa(testPortNum + 1) |
| 16 | + expectedFileResponse, _ := os.ReadFile("../testdata/files/static.txt") |
| 17 | + hostWithRootOutside := "http://localhost:" + testPort |
| 18 | + hostWithRootInside := "http://localhost:" + testPortTwo |
| 19 | + tester.InitServer(` |
| 20 | + { |
| 21 | + skip_install_trust |
| 22 | + admin localhost:2999 |
| 23 | + } |
| 24 | +
|
| 25 | + `+hostWithRootOutside+` { |
| 26 | + root ../testdata |
| 27 | + php_server |
| 28 | + } |
| 29 | +
|
| 30 | + `+hostWithRootInside+` { |
| 31 | + php_server { |
| 32 | + root ../testdata |
| 33 | + } |
| 34 | + } |
| 35 | + `, "caddyfile") |
| 36 | + |
| 37 | + // serve a static file |
| 38 | + tester.AssertGetResponse(hostWithRootOutside+"/files/static.txt", http.StatusOK, string(expectedFileResponse)) |
| 39 | + tester.AssertGetResponse(hostWithRootInside+"/files/static.txt", http.StatusOK, string(expectedFileResponse)) |
| 40 | + |
| 41 | + // serve a php file |
| 42 | + tester.AssertGetResponse(hostWithRootOutside+"/hello.php", http.StatusOK, "Hello from PHP") |
| 43 | + tester.AssertGetResponse(hostWithRootInside+"/hello.php", http.StatusOK, "Hello from PHP") |
| 44 | + |
| 45 | + // fallback to index.php |
| 46 | + tester.AssertGetResponse(hostWithRootOutside+"/some-path", http.StatusOK, "I am by birth a Genevese (i not set)") |
| 47 | + tester.AssertGetResponse(hostWithRootInside+"/some-path", http.StatusOK, "I am by birth a Genevese (i not set)") |
| 48 | + |
| 49 | + // fallback to directory index ('dirIndex' in module.go) |
| 50 | + tester.AssertGetResponse(hostWithRootOutside+"/dirindex/", http.StatusOK, "Hello from directory index.php") |
| 51 | + tester.AssertGetResponse(hostWithRootInside+"/dirindex/", http.StatusOK, "Hello from directory index.php") |
| 52 | +} |
0 commit comments