Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/docker/ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ http_check() {

php -r '
// The front end and the manager are the two entry points an installed
// site has to serve. The manager answers 404 without an Accept-Language
// header by design, hence the header on the second request.
// site has to serve. The manager request carries no Accept-Language
// header on purpose: the manager must fall back to English.
$port = $argv[1];
$expect = $argv[2];
$get = function (string $path, array $headers = []) use ($port): array {
Expand Down Expand Up @@ -125,7 +125,7 @@ http_check() {
$failures[] = "the front page rendered nothing";
}

[$status, $body] = $get("/manager/index.php", ["Accept-Language: en-US,en;q=0.9"]);
[$status, $body] = $get("/manager/index.php");
echo "manager: {$status}\n";
$status === 200 or $failures[] = "the manager answered {$status}";
stripos($body, "password") !== false or $failures[] = "the manager did not render its login form";
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ jobs:
curl -sf -o /dev/null http://127.0.0.1:8899/ && break
done
front=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8899/)
# The manager answers 404 without an Accept-Language header by design.
manager=$(curl -s -o /dev/null -w '%{http_code}' -H 'Accept-Language: en-US,en;q=0.9' http://127.0.0.1:8899/manager/index.php)
# No Accept-Language header on purpose: the manager must default to English.
manager=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8899/manager/index.php)
echo "front=$front manager=$manager"
test "$front" = "200" && test "$manager" = "200"

Expand Down Expand Up @@ -285,8 +285,8 @@ jobs:
curl -sf -o /dev/null http://127.0.0.1:8899/ && break
done
front=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8899/)
# The manager answers 404 without an Accept-Language header by design.
manager=$(curl -s -o /dev/null -w '%{http_code}' -H 'Accept-Language: en-US,en;q=0.9' http://127.0.0.1:8899/manager/index.php)
# No Accept-Language header on purpose: the manager must default to English.
manager=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8899/manager/index.php)
# A friendly URL has to be routed into index.php rather than answered
# by the web server itself. Whether the CMS then renders a page or an
# error is not the point — reaching PHP at all is — so this looks for
Expand Down
41 changes: 41 additions & 0 deletions core/tests/Unit/Manager/ManagerAcceptLanguageDefaultTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

function managerIndexSource(): string
{
return file_get_contents(dirname(__DIR__, 4) . '/manager/index.php');
}

function managerAcceptLanguageDefaultStatement(): string
{
preg_match('/^\$_SERVER\[\'HTTP_ACCEPT_LANGUAGE\'\]\s*\?\?=\s*[^;]+;/m', managerIndexSource(), $match);

return $match[0] ?? '';
}

it('does not answer 404 when the Accept-Language header is missing', function () {
$source = managerIndexSource();

expect($source)->not->toMatch('/if\s*\(\s*!\s*isset\(\$_SERVER\[\'HTTP_ACCEPT_LANGUAGE\'\]\)\s*\)\s*\{\s*header\([^)]*404/');
});

it('defaults a missing Accept-Language header to English', function () {
$statement = managerAcceptLanguageDefaultStatement();
expect($statement)->not->toBe('');

$backup = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? null;
try {
unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
eval($statement);
expect($_SERVER['HTTP_ACCEPT_LANGUAGE'])->toBe('en');

$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-DE,de;q=0.9';
eval($statement);
expect($_SERVER['HTTP_ACCEPT_LANGUAGE'])->toBe('de-DE,de;q=0.9');
} finally {
if ($backup === null) {
unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
} else {
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = $backup;
}
}
});
6 changes: 2 additions & 4 deletions manager/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@
exit;
}

if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
header('HTTP/1.0 404 Not Found');
exit;
}
// Clients that send no Accept-Language header (API clients, health checks) get English.
$_SERVER['HTTP_ACCEPT_LANGUAGE'] ??= 'en';

// send anti caching headers
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
Expand Down
Loading