You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This one is interesting — though I’m not sure the best way to provide a
test. I will have to look into maybe an integration test because it is a
careful dance between how we resolve paths in the Caddy module vs.
workers. I looked into making a proper change (literally using the same
logic everywhere), but I think it is best to wait until #1646 is merged.
But anyway, this change deals with some interesting edge cases. I will
use gherkin to describe them:
```gherkin
Feature: FrankenPHP symlinked edge cases
Background:
Given a `test` folder
And a `public` folder linked to `test`
And a worker script located at `test/index.php`
And a `test/nested` folder
And a worker script located at `test/nested/index.php`
Scenario: neighboring worker script
Given frankenphp located in the test folder
When I execute `frankenphp php-server --listen localhost:8080 -w index.php` from `public`
Then I expect to see the worker script executed successfully
Scenario: nested worker script
Given frankenphp located in the test folder
When I execute `frankenphp --listen localhost:8080 -w nested/index.php` from `public`
Then I expect to see the worker script executed successfully
Scenario: outside the symlinked folder
Given frankenphp located in the root folder
When I execute `frankenphp --listen localhost:8080 -w public/index.php` from the root folder
Then I expect to see the worker script executed successfully
Scenario: specified root directory
Given frankenphp located in the root folder
When I execute `frankenphp --listen localhost:8080 -w public/index.php -r public` from the root folder
Then I expect to see the worker script executed successfully
```
Trying to write that out in regular English would be more complex IMHO.
These scenarios should all pass now with this PR.
---------
Signed-off-by: Marc <m@pyc.ac>
Co-authored-by: henderkes <m@pyc.ac>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
// Tests that accessing a worker-only script without configuring it as a worker actually results in an error
1704
+
tester:=caddytest.NewTester(t)
1705
+
tester.InitServer(`
1706
+
{
1707
+
skip_install_trust
1708
+
admin localhost:2999
1709
+
http_port `+testPort+`
1710
+
}
1711
+
1712
+
localhost:`+testPort+` {
1713
+
route {
1714
+
php {
1715
+
root `+publicDir+`
1716
+
}
1717
+
}
1718
+
}
1719
+
`, "caddyfile")
1720
+
1721
+
// Accessing the worker script without worker configuration MUST fail
1722
+
// The script checks $_SERVER['FRANKENPHP_WORKER'] and dies if not set
1723
+
tester.AssertGetResponse("http://localhost:"+testPort+"/index.php", http.StatusOK, "Error: This script must be run in worker mode (FRANKENPHP_WORKER not set to '1')\n")
1724
+
})
1725
+
1726
+
t.Run("MultipleRequests", func(t*testing.T) {
1727
+
// Tests that symlinked workers handle multiple requests correctly
1728
+
tester:=caddytest.NewTester(t)
1729
+
tester.InitServer(`
1730
+
{
1731
+
skip_install_trust
1732
+
admin localhost:2999
1733
+
http_port `+testPort+`
1734
+
}
1735
+
1736
+
localhost:`+testPort+` {
1737
+
route {
1738
+
php {
1739
+
root `+publicDir+`
1740
+
resolve_root_symlink true
1741
+
worker index.php 1
1742
+
}
1743
+
}
1744
+
}
1745
+
`, "caddyfile")
1746
+
1747
+
// Make multiple requests - each should increment the counter
0 commit comments