Skip to content

Commit

Permalink
use php_sapi_name() instead of manual flag for cli authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Field committed Jul 12, 2017
1 parent 7d131a9 commit 8836db0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 4 additions & 3 deletions admin/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,11 @@ function authorized() {

global $lang;

# special case for test scripts
if (isset($_SERVER['PHP_CLI_TESTING'])) {
# if they're running php from the command prompt,
# that's considered authorized
if (php_sapi_name() == "cli") {
return true;
}
}

# if we've got a good cookie, return true
if (isset($_COOKIE['rachel-auth']) && $_COOKIE['rachel-auth'] == "admin") {
Expand Down
6 changes: 2 additions & 4 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@
unlink("admin/admin.sqlite") or error("Couldn't remove test db file");

testmsg("Testing admin/modules.php with two modules, no db");
$html = shell_exec("PHP_CLI_TESTING=1 php admin/modules.php");
$html = shell_exec("php admin/modules.php");
passfail(preg_match("/<!DOCTYPE.+mod_one - Test Module 1.+mod_two - Test Module 2.+<\/html>/s", $html) == 1);

testmsg("Testing admin/modules.php created db");
passfail(file_exists("admin/admin.sqlite"));

testmsg("Testing admin/modules.php saving module order");
$html = shell_exec(
"PHP_CLI_TESTING=1 " .
"php -e -r '\$_GET[\"moddirs\"] = \"mod_two,mod_one\"; " .
"include \"admin/modules.php\";'"
);
passfail($html == "");

testmsg("Testing admin/modules.php reading saved module order");
$html = shell_exec("PHP_CLI_TESTING=1 php admin/modules.php");
$html = shell_exec("php admin/modules.php");
passfail(preg_match("/<!DOCTYPE.+mod_two - Test Module 2.+mod_one - Test Module 1.+<\/html>/s", $html) == 1);

testmsg("Testing index.php reading saved module order");
Expand All @@ -50,7 +49,6 @@

testmsg("Testing admin/modules.php hiding both modules");
$html = shell_exec(
"PHP_CLI_TESTING=1 " .
"php -e -r '\$_GET[\"moddirs\"] = \"mod_one,mod_two\"; " .
"\$_GET[\"hidden\"] = \"mod_one,mod_two\"; " .
"include \"admin/modules.php\";'"
Expand Down

0 comments on commit 8836db0

Please sign in to comment.