Merge branch 'MDL-40050-master' of git://github.com/FMCorz/moodle
authorMarina Glancy <marina@moodle.com>
Wed, 2 Oct 2013 06:54:59 +0000 (16:54 +1000)
committerMarina Glancy <marina@moodle.com>
Wed, 2 Oct 2013 06:54:59 +0000 (16:54 +1000)
admin/webservice/service.php
lib/classes/event/webservice_login_failed.php
webservice/lib.php
webservice/tests/events_test.php [moved from webservice/tests/events.php with 95% similarity]

index 13f3c8d..0abf9d0 100644 (file)
@@ -83,7 +83,7 @@ if ($mform->is_cancelled()) {
         $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();
 
@@ -98,7 +98,7 @@ if ($mform->is_cancelled()) {
         $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();
     }
index 02c49a3..395e91b 100644 (file)
@@ -92,6 +92,15 @@ class webservice_login_failed extends \core\event\base {
     /**
      * 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
      */
@@ -100,8 +109,8 @@ class webservice_login_failed extends \core\event\base {
            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.');
         }
     }
 }
index 56d437a..9a867d2 100644 (file)
@@ -866,8 +866,7 @@ abstract class webservice_server implements webservice_server_interface {
             'context' => context_system::instance(),
             'other' => array(
                 'method' => $this->authmethod,
-                'reason' => null,
-                'token' => $this->token
+                'reason' => null
             )
         );
 
@@ -1015,8 +1014,7 @@ abstract class webservice_server implements webservice_server_interface {
             'context' => context_system::instance(),
             'other' => array(
                 'method' => $this->authmethod,
-                'reason' => null,
-                'token' => $this->token
+                'reason' => null
             )
         );
 
similarity index 95%
rename from webservice/tests/events.php
rename to webservice/tests/events_test.php
index b196100..7152077 100644 (file)
@@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
  * @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();
@@ -77,7 +77,7 @@ class webservice_events_testcase extends advanced_testcase {
             'other' => array(
                 'reason' => 'Unit Test',
                 'method' => 'Some method',
-                'token' => 'A fake token'
+                'tokenid' => '123'
             )
         );
         $event = \core\event\webservice_login_failed::create($params);
@@ -91,8 +91,16 @@ class webservice_events_testcase extends advanced_testcase {
         $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() {