Skip to content

Commit

Permalink
Merge branch 'MDL-40050-master' of git://github.com/FMCorz/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Oct 2, 2013
2 parents 766c640 + 26422a6 commit 0880a52
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions admin/webservice/service.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
$params = array(
'objectid' => $servicedata->id
);
$event = \core\event\webservice_service_updated::create($params);
$event = \core\event\webservice_service_created::create($params);
$event->add_record_snapshot('external_services', $servicedata);
$event->trigger();

Expand All @@ -98,7 +98,7 @@
$params = array(
'objectid' => $servicedata->id
);
$event = \core\event\webservice_service_created::create($params);
$event = \core\event\webservice_service_updated::create($params);
$event->add_record_snapshot('external_services', $servicedata);
$event->trigger();
}
Expand Down
13 changes: 11 additions & 2 deletions lib/classes/event/webservice_login_failed.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ public function set_legacy_logdata($logdata) {
/**
* Custom validation.
*
* It is recommended to set the properties:
* - $other['tokenid']
* - $other['username']
*
* However they are not mandatory as they are not always known.
*
* Please note that the token CANNOT be specified, it is considered
* as a password and should never be displayed.
*
* @throws \coding_exception
* @return void
*/
Expand All @@ -100,8 +109,8 @@ protected function validate_data() {
throw new \coding_exception('The key \'reason\' needs to be set in $other.');
} else if (!isset($this->other['method'])) {
throw new \coding_exception('The key \'method\' needs to be set in $other.');
} else if (!isset($this->other['token']) && !isset($this->other['tokenid']) && !isset($this->other['username'])) {
throw new \coding_exception('The keys \'username\', \'token\' or \'tokenid\' need to be set in $other.');
} else if (isset($this->other['token'])) {
throw new \coding_exception('The token cannot be set in $other.');
}
}
}
6 changes: 2 additions & 4 deletions webservice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,7 @@ protected function authenticate_user() {
'context' => context_system::instance(),
'other' => array(
'method' => $this->authmethod,
'reason' => null,
'token' => $this->token
'reason' => null
)
);

Expand Down Expand Up @@ -1015,8 +1014,7 @@ protected function authenticate_by_token($tokentype){
'context' => context_system::instance(),
'other' => array(
'method' => $this->authmethod,
'reason' => null,
'token' => $this->token
'reason' => null
)
);

Expand Down
14 changes: 11 additions & 3 deletions webservice/tests/events.php → webservice/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class webservice_events_testcase extends advanced_testcase {
class core_webservice_events_testcase extends advanced_testcase {

public function setUp() {
$this->resetAfterTest();
Expand Down Expand Up @@ -77,7 +77,7 @@ public function test_login_failed() {
'other' => array(
'reason' => 'Unit Test',
'method' => 'Some method',
'token' => 'A fake token'
'tokenid' => '123'
)
);
$event = \core\event\webservice_login_failed::create($params);
Expand All @@ -91,8 +91,16 @@ public function test_login_failed() {
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals($params['other']['reason'], $event->other['reason']);
$this->assertEquals($params['other']['method'], $event->other['method']);
$this->assertEquals($params['other']['token'], $event->other['token']);
$this->assertEquals($params['other']['tokenid'], $event->other['tokenid']);
$this->assertEventLegacyLogData($fakelogdata, $event);

// We cannot set the token in the other properties.
$params['other']['token'] = 'I should not be set';
try {
$event = \core\event\webservice_login_failed::create($params);
$this->fail('The token cannot be allowed in \core\event\webservice_login_failed');
} catch (coding_exception $e) {
}
}

public function test_service_created() {
Expand Down

0 comments on commit 0880a52

Please sign in to comment.