Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 27... Línea 27...
27
 * Tests for oauth2 apis (\core\oauth2\*).
27
 * Tests for oauth2 apis (\core\oauth2\*).
28
 *
28
 *
29
 * @package    core
29
 * @package    core
30
 * @copyright  2017 Damyon Wiese
30
 * @copyright  2017 Damyon Wiese
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
32
 * @coversDefaultClass \core\oauth2\api
32
 * @covers \core\oauth2\api
33
 */
33
 */
34
class oauth2_test extends \advanced_testcase {
34
final class oauth2_test extends \advanced_testcase {
Línea 35... Línea 35...
35
 
35
 
36
    /**
36
    /**
37
     * Tests the crud operations on oauth2 issuers.
37
     * Tests the crud operations on oauth2 issuers.
38
     */
38
     */
Línea 117... Línea 117...
117
    /**
117
    /**
118
     * Data provider for \core_oauth2_testcase::test_get_system_oauth_client().
118
     * Data provider for \core_oauth2_testcase::test_get_system_oauth_client().
119
     *
119
     *
120
     * @return array
120
     * @return array
121
     */
121
     */
122
    public function system_oauth_client_provider() {
122
    public static function system_oauth_client_provider(): array {
123
        return [
123
        return [
124
            [
124
            [
125
                (object) [
125
                (object) [
126
                    'access_token' => 'fdas...',
126
                    'access_token' => 'fdas...',
127
                    'token_type' => 'Bearer',
127
                    'token_type' => 'Bearer',
Línea 254... Línea 254...
254
 
254
 
255
    /**
255
    /**
256
     * Test endpoints creation for issuers.
256
     * Test endpoints creation for issuers.
257
     * @dataProvider create_endpoints_for_standard_issuer_provider
257
     * @dataProvider create_endpoints_for_standard_issuer_provider
258
     *
-
 
259
     * @covers ::create_endpoints_for_standard_issuer
-
 
260
     *
258
     *
261
     * @param string $type Issuer type to create.
259
     * @param string $type Issuer type to create.
262
     * @param string|null $discoveryurl Expected discovery URL or null if this endpoint doesn't exist.
260
     * @param string|null $discoveryurl Expected discovery URL or null if this endpoint doesn't exist.
263
     * @param bool $hasmappingfields True if it's expected the issuer to create has mapping fields.
261
     * @param bool $hasmappingfields True if it's expected the issuer to create has mapping fields.
264
     * @param string|null $baseurl The service URL (mandatory parameter for some issuers, such as NextCloud or IMS OBv2.1).
262
     * @param string|null $baseurl The service URL (mandatory parameter for some issuers, such as NextCloud or IMS OBv2.1).
Línea 304... Línea 302...
304
    /**
302
    /**
305
     * Data provider for test_create_endpoints_for_standard_issuer.
303
     * Data provider for test_create_endpoints_for_standard_issuer.
306
     *
304
     *
307
     * @return array
305
     * @return array
308
     */
306
     */
309
    public function create_endpoints_for_standard_issuer_provider(): array {
307
    public static function create_endpoints_for_standard_issuer_provider(): array {
310
        return [
308
        return [
311
            'Google' => [
309
            'Google' => [
312
                'type' => 'google',
310
                'type' => 'google',
313
                'discoveryurl' => '.well-known/openid-configuration',
311
                'discoveryurl' => '.well-known/openid-configuration',
314
            ],
312
            ],
Línea 337... Línea 335...
337
                'baseurl' => null,
335
                'baseurl' => null,
338
                'expectedexception' => \moodle_exception::class,
336
                'expectedexception' => \moodle_exception::class,
339
            ],
337
            ],
340
            'Microsoft' => [
338
            'Microsoft' => [
341
                'type' => 'microsoft',
339
                'type' => 'microsoft',
-
 
340
                'discoveryurl' => '.well-known/openid-configuration',
342
            ],
341
            ],
343
            'Facebook' => [
342
            'Facebook' => [
344
                'type' => 'facebook',
343
                'type' => 'facebook',
345
            ],
344
            ],
346
            'NextCloud' => [
345
            'NextCloud' => [
Línea 419... Línea 418...
419
        $googleissuer->set('showonloginpage', issuer::SERVICEONLY);
418
        $googleissuer->set('showonloginpage', issuer::SERVICEONLY);
420
        $googleissuer->update();
419
        $googleissuer->update();
Línea 421... Línea 420...
421
 
420
 
Línea -... Línea 421...
-
 
421
        $this->assertFalse($googleissuer->is_available_for_login());
-
 
422
 
-
 
423
        // Set showonloginpage to SMTP with XOAUTH2 only.
-
 
424
        $googleissuer->set('showonloginpage', issuer::SMTPWITHXOAUTH2);
-
 
425
        $googleissuer->update();
-
 
426
 
422
        $this->assertFalse($googleissuer->is_available_for_login());
427
        $this->assertFalse($googleissuer->is_available_for_login());
423
 
428
 
424
        // Set showonloginpage to everywhere (service and login) and disable issuer.
429
        // Set showonloginpage to everywhere (service and login) and disable issuer.
425
        $googleissuer->set('showonloginpage', issuer::EVERYWHERE);
430
        $googleissuer->set('showonloginpage', issuer::EVERYWHERE);
Línea 447... Línea 452...
447
    /**
452
    /**
448
     * Data provider for test_get_internalfield_list and test_get_internalfields.
453
     * Data provider for test_get_internalfield_list and test_get_internalfields.
449
     *
454
     *
450
     * @return array
455
     * @return array
451
     */
456
     */
452
    public function create_custom_profile_fields(): array {
457
    public static function create_custom_profile_fields(): array {
453
        return [
458
        return [
454
            'data' =>
459
            'data' =>
455
            [
460
            [
456
                'given' => [
461
                'given' => [
457
                    'Hobbies' => [
462
                    'Hobbies' => [
Línea 493... Línea 498...
493
 
498
 
494
    /**
499
    /**
495
     * Test getting the list of internal fields.
500
     * Test getting the list of internal fields.
496
     *
501
     *
497
     * @dataProvider create_custom_profile_fields
502
     * @dataProvider create_custom_profile_fields
498
     * @covers ::get_internalfield_list
503
     * @covers \core\oauth2\user_field_mapping::get_internalfield_list
499
     * @param array $given Categories and profile fields.
504
     * @param array $given Categories and profile fields.
500
     * @param array $expected Expected value.
505
     * @param array $expected Expected value.
501
     */
506
     */
502
    public function test_get_internalfield_list(array $given, array $expected): void {
507
    public function test_get_internalfield_list(array $given, array $expected): void {
Línea 520... Línea 525...
520
 
525
 
521
    /**
526
    /**
522
     * Test getting the list of internal fields with flat array.
527
     * Test getting the list of internal fields with flat array.
523
     *
528
     *
524
     * @dataProvider create_custom_profile_fields
529
     * @dataProvider create_custom_profile_fields
525
     * @covers ::get_internalfields
530
     * @covers \core\oauth2\user_field_mapping::get_internalfields
526
     * @param array $given Categories and profile fields.
531
     * @param array $given Categories and profile fields.
527
     * @param array $expected Expected value.
532
     * @param array $expected Expected value.
528
     */
533
     */
529
    public function test_get_internalfields(array $given, array $expected): void {
534
    public function test_get_internalfields(array $given, array $expected): void {
Línea 540... Línea 545...
540
    }
545
    }
Línea 541... Línea 546...
541
 
546
 
542
    /**
547
    /**
543
     * Test getting the list of empty external/custom profile fields.
548
     * Test getting the list of empty external/custom profile fields.
544
     *
549
     *
545
     * @covers ::get_internalfields
550
     * @covers \core\oauth2\user_field_mapping::get_internalfields
546
     */
551
     */
Línea 547... Línea 552...
547
    public function test_get_empty_internalfield_list(): void {
552
    public function test_get_empty_internalfield_list(): void {
548
 
553