commit
61b624aa80
4 changed files with 37 additions and 32 deletions
|
@ -14,6 +14,15 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
namespace auth_userkey;
|
||||||
|
|
||||||
|
use advanced_testcase;
|
||||||
|
use auth_plugin_userkey;
|
||||||
|
use stdClass;
|
||||||
|
use invalid_parameter_exception;
|
||||||
|
use moodle_exception;
|
||||||
|
use external_value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for auth_plugin_userkey class.
|
* Tests for auth_plugin_userkey class.
|
||||||
*
|
*
|
||||||
|
@ -21,14 +30,7 @@
|
||||||
* @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net)
|
* @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net)
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
class auth_plugin_test extends advanced_testcase {
|
||||||
/**
|
|
||||||
* Tests for auth_plugin_userkey class.
|
|
||||||
*
|
|
||||||
* @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net)
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
class auth_plugin_userkey_testcase extends advanced_testcase {
|
|
||||||
/**
|
/**
|
||||||
* An instance of auth_plugin_userkey class.
|
* An instance of auth_plugin_userkey class.
|
||||||
* @var auth_plugin_userkey
|
* @var auth_plugin_userkey
|
||||||
|
@ -48,7 +50,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
require_once($CFG->libdir . "/externallib.php");
|
require_once($CFG->libdir . "/externallib.php");
|
||||||
require_once($CFG->dirroot . '/auth/userkey/tests/phpunit/fake_userkey_manager.php');
|
require_once($CFG->dirroot . '/auth/userkey/tests/fake_userkey_manager.php');
|
||||||
require_once($CFG->dirroot . '/auth/userkey/auth.php');
|
require_once($CFG->dirroot . '/auth/userkey/auth.php');
|
||||||
require_once($CFG->dirroot . '/user/lib.php');
|
require_once($CFG->dirroot . '/user/lib.php');
|
||||||
|
|
||||||
|
@ -262,7 +264,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
|
|
||||||
self::getDataGenerator()->create_user($user);
|
self::getDataGenerator()->create_user($user);
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
$expected = $CFG->wwwroot . '/auth/userkey/login.php?key=FaKeKeyFoRtEsTiNg';
|
$expected = $CFG->wwwroot . '/auth/userkey/login.php?key=FaKeKeyFoRtEsTiNg';
|
||||||
|
@ -283,7 +285,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
|
|
||||||
self::getDataGenerator()->create_user($user);
|
self::getDataGenerator()->create_user($user);
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
$expected = $CFG->wwwroot . '/auth/userkey/login.php?key=FaKeKeyFoRtEsTiNg';
|
$expected = $CFG->wwwroot . '/auth/userkey/login.php?key=FaKeKeyFoRtEsTiNg';
|
||||||
|
@ -305,7 +307,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
|
|
||||||
self::getDataGenerator()->create_user($user);
|
self::getDataGenerator()->create_user($user);
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
$expected = $CFG->wwwroot . '/auth/userkey/login.php?key=FaKeKeyFoRtEsTiNg';
|
$expected = $CFG->wwwroot . '/auth/userkey/login.php?key=FaKeKeyFoRtEsTiNg';
|
||||||
|
@ -323,7 +325,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
set_config('createuser', true, 'auth_userkey');
|
set_config('createuser', true, 'auth_userkey');
|
||||||
$this->auth = new auth_plugin_userkey();
|
$this->auth = new auth_plugin_userkey();
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
$user = new stdClass();
|
$user = new stdClass();
|
||||||
|
@ -355,7 +357,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
set_config('createuser', true, 'auth_userkey');
|
set_config('createuser', true, 'auth_userkey');
|
||||||
$this->auth = new auth_plugin_userkey();
|
$this->auth = new auth_plugin_userkey();
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
$user = new stdClass();
|
$user = new stdClass();
|
||||||
|
@ -375,7 +377,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
set_config('createuser', true, 'auth_userkey');
|
set_config('createuser', true, 'auth_userkey');
|
||||||
$this->auth = new auth_plugin_userkey();
|
$this->auth = new auth_plugin_userkey();
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
$originaluser = new stdClass();
|
$originaluser = new stdClass();
|
||||||
|
@ -405,7 +407,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
set_config('mappingfield', 'username', 'auth_userkey');
|
set_config('mappingfield', 'username', 'auth_userkey');
|
||||||
$this->auth = new auth_plugin_userkey();
|
$this->auth = new auth_plugin_userkey();
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
$originaluser = new stdClass();
|
$originaluser = new stdClass();
|
||||||
|
@ -436,7 +438,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
set_config('updateuser', true, 'auth_userkey');
|
set_config('updateuser', true, 'auth_userkey');
|
||||||
$this->auth = new auth_plugin_userkey();
|
$this->auth = new auth_plugin_userkey();
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
$originaluser = new stdClass();
|
$originaluser = new stdClass();
|
||||||
|
@ -477,7 +479,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
set_config('mappingfield', 'username', 'auth_userkey');
|
set_config('mappingfield', 'username', 'auth_userkey');
|
||||||
$this->auth = new auth_plugin_userkey();
|
$this->auth = new auth_plugin_userkey();
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
self::getDataGenerator()->create_user(['email' => 'trytoduplicate@test.com']);
|
self::getDataGenerator()->create_user(['email' => 'trytoduplicate@test.com']);
|
||||||
|
@ -504,7 +506,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
|
||||||
set_config('updateuser', true, 'auth_userkey');
|
set_config('updateuser', true, 'auth_userkey');
|
||||||
$this->auth = new auth_plugin_userkey();
|
$this->auth = new auth_plugin_userkey();
|
||||||
|
|
||||||
$userkeymanager = new \auth_userkey\fake_userkey_manager();
|
$userkeymanager = new fake_userkey_manager();
|
||||||
$this->auth->set_userkey_manager($userkeymanager);
|
$this->auth->set_userkey_manager($userkeymanager);
|
||||||
|
|
||||||
self::getDataGenerator()->create_user(['username' => 'trytoduplicate']);
|
self::getDataGenerator()->create_user(['username' => 'trytoduplicate']);
|
|
@ -14,15 +14,7 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
namespace auth_userkey;
|
||||||
* Tests for core_userkey_manager class.
|
|
||||||
*
|
|
||||||
* @package auth_userkey
|
|
||||||
* @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net)
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
use auth_userkey\core_userkey_manager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for core_userkey_manager class.
|
* Tests for core_userkey_manager class.
|
||||||
|
@ -30,10 +22,11 @@ use auth_userkey\core_userkey_manager;
|
||||||
* Key validation is fully covered in auth_plugin_test.php file.
|
* Key validation is fully covered in auth_plugin_test.php file.
|
||||||
* TODO: write tests for validate_key() function.
|
* TODO: write tests for validate_key() function.
|
||||||
*
|
*
|
||||||
|
* @package auth_userkey
|
||||||
* @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net)
|
* @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net)
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class core_userkey_manager_testcase extends advanced_testcase {
|
class core_userkey_manager_test extends \advanced_testcase {
|
||||||
/**
|
/**
|
||||||
* Test user object.
|
* Test user object.
|
||||||
* @var
|
* @var
|
||||||
|
@ -57,7 +50,7 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
$this->resetAfterTest();
|
$this->resetAfterTest();
|
||||||
$CFG->getremoteaddrconf = GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR;
|
$CFG->getremoteaddrconf = GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR;
|
||||||
$this->user = self::getDataGenerator()->create_user();
|
$this->user = self::getDataGenerator()->create_user();
|
||||||
$this->config = new stdClass();
|
$this->config = new \stdClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,7 +159,7 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$_SERVER['HTTP_CLIENT_IP'] = '193.168.1.2';
|
$_SERVER['HTTP_CLIENT_IP'] = '193.168.1.2';
|
||||||
|
|
||||||
$this->expectException(moodle_exception::class);
|
$this->expectException(\moodle_exception::class);
|
||||||
$this->expectExceptionMessage('Client IP address mismatch');
|
$this->expectExceptionMessage('Client IP address mismatch');
|
||||||
|
|
||||||
$manager->validate_key($value);
|
$manager->validate_key($value);
|
|
@ -14,6 +14,16 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
namespace auth_userkey;
|
||||||
|
|
||||||
|
use advanced_testcase;
|
||||||
|
use webservice_access_exception;
|
||||||
|
use auth_userkey_external;
|
||||||
|
use external_api;
|
||||||
|
use invalid_parameter_exception;
|
||||||
|
use required_capability_exception;
|
||||||
|
use context_system;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for externallib.php.
|
* Tests for externallib.php.
|
||||||
*
|
*
|
||||||
|
@ -21,7 +31,7 @@
|
||||||
* @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net)
|
* @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net)
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class auth_userkey_externallib_testcase extends advanced_testcase {
|
class externallib_test extends advanced_testcase {
|
||||||
/**
|
/**
|
||||||
* User object.
|
* User object.
|
||||||
*
|
*
|
Loading…
Reference in a new issue