Skip to content

Commit

Permalink
Merge pull request #351 from catalyst/issue-350-MOODLE_39_STABLE-test…
Browse files Browse the repository at this point in the history
…-errors

Fix #350: Do not setcookie during unit tests
  • Loading branch information
brendanheywood authored Nov 27, 2024
2 parents 386a623 + 2a55769 commit 7f55f5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions classes/local/outagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ public static function create_climaintenancephp_code($starttime, $stoptime, $all
}
// Put access key as a cookie if given. This stops the need to put it as a url param on every request.
$urlaccesskey = optional_param('accesskey', null, PARAM_TEXT);
$isphpunit = defined('PHPUNIT_TEST');
if (!empty($urlaccesskey)) {
if (!empty($urlaccesskey) && !$isphpunit) {
setcookie('auth_outage_accesskey', $urlaccesskey, time() + 86400, '/', '', {{COOKIESECURE}}, {{COOKIEHTTPONLY}});
}
Expand All @@ -322,7 +323,6 @@ public static function create_climaintenancephp_code($starttime, $stoptime, $all
$ipblocked = !remoteip_in_list('{{ALLOWEDIPS}}');
$accesskeyblocked = $useraccesskey != '{{ACCESSKEY}}';
$allowed = ({{USEACCESSKEY}} && !$accesskeyblocked) || ({{USEALLOWEDIPS}} && !$ipblocked);
$isphpunit = defined('PHPUNIT_TEST');
if (!$allowed) {
if (!$isphpunit) {
Expand Down
8 changes: 4 additions & 4 deletions tests/local/outagelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,9 @@ public function test_createmaintenancephpcode() {
}
// Put access key as a cookie if given. This stops the need to put it as a url param on every request.
$urlaccesskey = optional_param('accesskey', null, PARAM_TEXT);
$isphpunit = defined('PHPUNIT_TEST');
if (!empty($urlaccesskey)) {
if (!empty($urlaccesskey) && !$isphpunit) {
setcookie('auth_outage_accesskey', $urlaccesskey, time() + 86400, '/', '', true, false);
}
Expand All @@ -336,7 +337,6 @@ public function test_createmaintenancephpcode() {
e.e.e.e/20');
$accesskeyblocked = $useraccesskey != '12345';
$allowed = (true && !$accesskeyblocked) || (true && !$ipblocked);
$isphpunit = defined('PHPUNIT_TEST');
if (!$allowed) {
if (!$isphpunit) {
Expand Down Expand Up @@ -404,8 +404,9 @@ public function test_createmaintenancephpcode_withoutage($configkey) {
}
// Put access key as a cookie if given. This stops the need to put it as a url param on every request.
$urlaccesskey = optional_param('accesskey', null, PARAM_TEXT);
$isphpunit = defined('PHPUNIT_TEST');
if (!empty($urlaccesskey)) {
if (!empty($urlaccesskey) && !$isphpunit) {
setcookie('auth_outage_accesskey', $urlaccesskey, time() + 86400, '/', '', true, false);
}
Expand All @@ -415,7 +416,6 @@ public function test_createmaintenancephpcode_withoutage($configkey) {
$ipblocked = !remoteip_in_list('127.0.0.1');
$accesskeyblocked = $useraccesskey != '5678';
$allowed = (true && !$accesskeyblocked) || (true && !$ipblocked);
$isphpunit = defined('PHPUNIT_TEST');
if (!$allowed) {
if (!$isphpunit) {
Expand Down

0 comments on commit 7f55f5d

Please sign in to comment.