15 Commits

Author SHA1 Message Date
ScottVerbeek
f1cff274fe Updated README.md with new branch 2021-01-07 10:59:53 +10:00
Dan Marsden
b9baa58252 update readme to cover branch versions. 2021-01-07 09:36:59 +10:00
Brendan Heywood
1eb509d458 Merge pull request #199 from ledship/totara-10-time
Accept unix time for --start CLI option to totara-10 branch
2020-07-24 09:59:24 +10:00
Dan Marsden
03d33cb5c3 Remove incorrect usage of example.com in tests.
remove http part of test - site might be https.
2020-07-15 20:29:55 +12:00
Alexander
ee94917bf4 Accept unix time for --start CLI option 2020-07-07 10:12:03 +12:00
kristian-94
76f6523577 Merge pull request #202 from catalyst/WR336891
Issue 189 Unable to find Class 'core\ip_utils'
2020-07-03 13:43:40 +10:00
Heena Agheda
ab26bae579 Add services: mysql 2020-07-03 10:41:01 +10:00
Heena Agheda
be259f6ee5 Upgrade PHP version 2020-07-03 10:19:26 +10:00
Heena Agheda
186c75b00b Fix failing tests 2020-07-03 09:47:21 +10:00
Heena Agheda
c56025bcdd Upgrade postgresql version 2020-07-02 15:03:58 +10:00
katcher
3375ef6fea Issue 189 Unable to find Class 'core\ip_utils'
Following upgrade of moodle to 3.5.11, error above prevented moodle from
displaying on the web.  The class ip_utils was for somereason not loaded
and through an error preventing the site from displaying when in
maintenance mod.  Adding the require class appears to have fixed the
issue.
2020-07-02 11:14:14 +10:00
Nathan Nguyen
c234a70476 Fix problem with loading stylesheet in preview mode 2019-10-16 12:01:51 +11:00
Dan Marsden
21ff2fbd3b Fix resetAfterTest(false) in events_test file for Totara tests. 2019-07-22 10:41:44 +12:00
Dan Marsden
4cf8d12aa4 Fix #161 - make unit tests distinct. 2019-07-22 10:41:34 +12:00
Kristian Ringer
c8f99a7bf3 Fix unit tests in totara 10
- Change outagelib_test to use the auth_outage_base_testcase base class
  - Remove outages from test table in tearDown function after each test.
2019-05-08 13:30:08 +10:00
11 changed files with 96 additions and 24 deletions

View File

@@ -5,11 +5,14 @@ cache:
- $HOME/.composer/cache
addons:
postgresql: "9.3"
postgresql: "9.5"
php:
- 7.0
services:
- mysql
env:
- DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE
@@ -17,9 +20,9 @@ env:
matrix:
include:
- php: 5.5
- php: 5.6
env: DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
- php: 5.5
- php: 5.6
env: DB=mysqli MOODLE_BRANCH=MOODLE_30_STABLE
before_install:

View File

@@ -39,6 +39,16 @@ If you have an older version of Moodle you can still make it work but you will
need to manually add one extra plugin, please check:
* https://github.com/catalyst/moodle-local_outage
Branches
--------
| Moodle version | Branch | PHP |
| ----------------- | ----------- | ---- |
| Moodle 2.7 to 3.2 | MOODLE_32_STABLE | 5.5+ |
| Totara up to 10 | TOTARA_10 | 5.5+ |
| Moodle 3.3 to 3.9 | MOODLE_39_STABLE | 7.0+ |
| Totara 11 to 12 | MOODLE_39_STABLE | 7.0+ |
| Moodle 3.10 | master | 7.2+ |
| Totara 13+ | master | 7.2+ |
Screenshots
-----------
@@ -99,7 +109,7 @@ Creates a new outage.
-c, --clone clone another outage except for the start time.
-a, --autostart must be Y or N, sets if the outage automatically triggers maintenance mode.
-w, --warn how many seconds before it starts to display a warning.
-s, --start in how many seconds should this outage start. Required.
-s, --start in how many seconds should this outage start or unix time to start outage. Required.
-d, --duration how many seconds should the outage last.
-t, --title the title of the outage.
-e, --description the description of the outage.

View File

@@ -170,7 +170,9 @@ class create extends clibase {
$this->become_admin_user();
// Create the outage.
$start = $this->time + $options['start'];
// If time is above 1500000000 then it must be a unix time timestamp, otherwise they are trying to create
// an outage 47 years in advance.
$start = $options['start'] > 1500000000 ? $options['start'] : $this->time + $options['start'];
$outage = new outage([
'autostart' => $options['autostart'],
'warntime' => $start - $options['warn'],

View File

@@ -253,6 +253,7 @@ class outagelib {
if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
define('MOODLE_INTERNAL', true);
require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
if (!remoteip_in_list('{{ALLOWEDIPS}}')) {
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
header('Status: 503 Moodle under maintenance');

View File

@@ -34,7 +34,7 @@ $string['clicreateparamdescription'] = 'the description of the outage.';
$string['clicreateparamduration'] = 'how many seconds should the outage last.';
$string['clicreateparamhelp'] = 'shows parameters help.';
$string['clicreateparamonlyid'] = 'only outputs the new outage id, useful for scripts.';
$string['clicreateparamstart'] = 'in how many seconds should this outage start. Required.';
$string['clicreateparamstart'] = 'in how many seconds should this outage start or unix time to start outage. Required.';
$string['clicreateparamtitle'] = 'the title of the outage.';
$string['clicreateparamwarn'] = 'how many seconds before it starts to display a warning.';
$string['clifinishhelp'] = 'Finishes an ongoing outage.';

View File

@@ -75,7 +75,7 @@ function auth_outage_get_climaintenance_resource_file($file) {
// Protect against path traversal attacks.
$basename = basename($file);
if ($basename !== $file) {
if ($basename !== $file && $file !== 'preview/' . $basename) {
// @codingStandardsIgnoreStart
if (!PHPUNIT_TEST) {
error_log('Possible attempt for Path Traversal Attack (only filename expected): '.$file);

View File

@@ -69,9 +69,10 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
parent::setUp();
$this->resetAfterTest(true);
}
// Do not use https.
$CFG->wwwroot = 'http://www.example.com/moodle';
$CFG->httpswwwroot = $CFG->wwwroot;
public function tearDown() {
global $DB;
$DB->delete_records('auth_outage');
}
}

View File

@@ -49,8 +49,8 @@ class calendar_test extends advanced_testcase {
* Creates an outage and checks if its in the calendar.
*/
public function test_create() {
$this->resetAfterTest(true);
self::setAdminUser();
$this->resetAfterTest(false);
$time = time();
self::$outage = new outage([
@@ -70,8 +70,20 @@ class calendar_test extends advanced_testcase {
* Updates an outage and checks the calendar.
*/
public function test_update() {
$this->resetAfterTest(true);
self::setAdminUser();
$this->resetAfterTest(false);
$time = time();
self::$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $time - 100,
'starttime' => $time,
'stoptime' => $time + (2 * 60 * 60),
'title' => 'Title',
'description' => 'Description',
]);
calendar::create(self::$outage);
self::$outage->title = 'New Title';
calendar::update(self::$outage);
@@ -82,8 +94,22 @@ class calendar_test extends advanced_testcase {
* Deletes an outage and checks the calendar.
*/
public function test_delete() {
self::setAdminUser();
$this->resetAfterTest(true);
self::setAdminUser();
$time = time();
self::$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $time - 100,
'starttime' => $time,
'stoptime' => $time + (2 * 60 * 60),
'title' => 'Title',
'description' => 'Description',
]);
calendar::create(self::$outage);
$this->check_calendar();
calendar::delete(self::$outage->id);
self::assertNull(calendar::load(self::$outage->id));
@@ -93,8 +119,8 @@ class calendar_test extends advanced_testcase {
* Try to update a non existing outage.
*/
public function test_update_notfound() {
self::setAdminUser();
$this->resetAfterTest(true);
self::setAdminUser();
$time = time();
$outage = new outage([
@@ -116,8 +142,9 @@ class calendar_test extends advanced_testcase {
* Try to delete a non existing outage.
*/
public function test_delete_notfound() {
self::setAdminUser();
$this->resetAfterTest(true);
self::setAdminUser();
calendar::delete(1);
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();

View File

@@ -57,7 +57,7 @@ class events_test extends advanced_testcase {
public function test_save() {
global $DB;
self::setAdminUser();
$this->resetAfterTest(false);
$this->resetAfterTest(true);
// Save new outage.
$now = time();
@@ -90,7 +90,20 @@ class events_test extends advanced_testcase {
global $DB;
self::setAdminUser();
$this->resetAfterTest(false);
$this->resetAfterTest(true);
// Save new outage.
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 60,
'starttime' => 60,
'stoptime' => 120,
'title' => 'Title',
'description' => 'Description',
]);
$outage->id = outagedb::save($outage);
self::$outage = $outage;
self::$outage->starttime += 10;
outagedb::save(self::$outage);
@@ -117,6 +130,19 @@ class events_test extends advanced_testcase {
self::setAdminUser();
$this->resetAfterTest(true);
// Save new outage.
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 60,
'starttime' => 60,
'stoptime' => 120,
'title' => 'Title',
'description' => 'Description',
]);
$outage->id = outagedb::save($outage);
self::$outage = $outage;
outagedb::delete(self::$outage->id);
// Should not exist.

View File

@@ -87,7 +87,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
'<body>Content<link rel="stylesheet" href="'.$externalcsslink.'"></body></html>';
$generated = $this->generated_page_html($html);
self::assertContains('http://www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertNotContains($localcsslink, $generated);
self::assertContains($externalcsslink, $generated);
}
@@ -145,7 +145,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
'<body><img src="'.$localimglink.'">Content<img src="'.$externalimglink.'" /></body></html>';
$generated = $this->generated_page_html($html);
self::assertContains('http://www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertNotContains($localimglink, $generated);
self::assertContains($externalimglink, $generated);
}
@@ -158,7 +158,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
$generated = $this->generated_page_html($html);
self::assertNotContains($link, $generated);
self::assertContains('http://www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
}
public function test_previewpath() {
@@ -172,7 +172,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
$generated = trim(file_get_contents($page->get_io()->get_template_file()));
self::assertNotContains($link, $generated);
self::assertContains('http://www.example.com/moodle/auth/outage/file.php?file=preview%2F', $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=preview%2F', $generated);
}
/**
@@ -256,7 +256,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
public function test_get_url_for_file() {
$io = new maintenance_static_page_io();
self::assertSame('http://www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png'));
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png'));
}
public function test_is_url() {

View File

@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir.'/adminlib.php');
require_once(__DIR__.'/../base_testcase.php');
/**
* outagelib_test test class.
*
@@ -41,7 +41,7 @@ require_once($CFG->libdir.'/adminlib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class outagelib_test extends advanced_testcase {
class outagelib_test extends auth_outage_base_testcase {
/**
* Check if maintenance message is disabled as needed.
*/
@@ -293,6 +293,7 @@ class outagelib_test extends advanced_testcase {
if ((time() >= 123) && (time() < 456)) {
define('MOODLE_INTERNAL', true);
require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
if (!remoteip_in_list('heyyou
a.b.c.d
e.e.e.e/20')) {
@@ -333,6 +334,7 @@ EOT;
if ((time() >= 123) && (time() < 456)) {
define('MOODLE_INTERNAL', true);
require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
if (!remoteip_in_list('127.0.0.1')) {
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
header('Status: 503 Moodle under maintenance');