Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 22... Línea 22...
22
 * @package    auth_lti
22
 * @package    auth_lti
23
 * @copyright  2021 Jake Dallimore <jrhdallimore@gmail.com>
23
 * @copyright  2021 Jake Dallimore <jrhdallimore@gmail.com>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @coversDefaultClass \auth_plugin_lti
25
 * @coversDefaultClass \auth_plugin_lti
26
 */
26
 */
27
class auth_test extends \advanced_testcase {
27
final class auth_test extends \advanced_testcase {
Línea 28... Línea 28...
28
 
28
 
29
    /** @var string issuer URL used for test cases. */
29
    /** @var string issuer URL used for test cases. */
Línea 30... Línea 30...
30
    protected $issuer = 'https://lms.example.org';
30
    protected static string $issuer = 'https://lms.example.org';
31
 
31
 
Línea 32... Línea 32...
32
    /** @var int const representing cases where no PII is present. */
32
    /** @var int const representing cases where no PII is present. */
Línea 68... Línea 68...
68
     * @param bool $includenames whether to include the firstname and lastname of the user
68
     * @param bool $includenames whether to include the firstname and lastname of the user
69
     * @param bool $includeemail whether to include the email of the user
69
     * @param bool $includeemail whether to include the email of the user
70
     * @param bool $includepicture whether to include a profile picture or not (slows tests, so defaults to false).
70
     * @param bool $includepicture whether to include a profile picture or not (slows tests, so defaults to false).
71
     * @return array the users list.
71
     * @return array the users list.
72
     */
72
     */
73
    protected function get_mock_users_with_ids(array $ids,
73
    protected static function get_mock_users_with_ids(
-
 
74
        array $ids,
74
            string $role = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor', bool $includenames = true,
75
        string $role = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
-
 
76
        bool $includenames = true,
-
 
77
        bool $includeemail = true,
75
            bool $includeemail = true, bool $includepicture = false): array {
78
        bool $includepicture = false,
76
 
79
    ): array {
77
        $users = [];
80
        $users = [];
78
        foreach ($ids as $id) {
81
        foreach ($ids as $id) {
79
            $user = [
82
            $user = [
80
                'user_id' => $id,
83
                'user_id' => $id,
81
                'given_name' => 'Firstname' . $id,
84
                'given_name' => 'Firstname' . $id,
Línea 89... Línea 92...
89
            }
92
            }
90
            if (!$includeemail) {
93
            if (!$includeemail) {
91
                unset($user['email']);
94
                unset($user['email']);
92
            }
95
            }
93
            if ($includepicture) {
96
            if ($includepicture) {
94
                $user['picture'] = $this->getExternalTestFileUrl('/test.jpg');
97
                $user['picture'] = self::getExternalTestFileUrl('/test.jpg');
95
            }
98
            }
96
            $users[] = $user;
99
            $users[] = $user;
97
        }
100
        }
98
        return $users;
101
        return $users;
99
    }
102
    }
Línea 135... Línea 138...
135
     * @param array $mockmigration information needed to mock the migration claim
138
     * @param array $mockmigration information needed to mock the migration claim
136
     * @return array the mock JWT data
139
     * @return array the mock JWT data
137
     */
140
     */
138
    protected function get_mock_launchdata_for_user(array $mockuser, array $mockmigration = []): array {
141
    protected function get_mock_launchdata_for_user(array $mockuser, array $mockmigration = []): array {
139
        $data = [
142
        $data = [
140
            'iss' => $this->issuer, // Must match registration in create_test_environment.
143
            'iss' => self::$issuer, // Must match registration in create_test_environment.
141
            'aud' => '123', // Must match registration in create_test_environment.
144
            'aud' => '123', // Must match registration in create_test_environment.
142
            'sub' => $mockuser['user_id'], // User id on the platform site.
145
            'sub' => $mockuser['user_id'], // User id on the platform site.
143
            'exp' => time() + 60,
146
            'exp' => time() + 60,
144
            'nonce' => 'some-nonce-value-123',
147
            'nonce' => 'some-nonce-value-123',
145
            'https://purl.imsglobal.org/spec/lti/claim/deployment_id' => '1', // Must match registration.
148
            'https://purl.imsglobal.org/spec/lti/claim/deployment_id' => '1', // Must match registration.
Línea 206... Línea 209...
206
    }
209
    }
Línea 207... Línea 210...
207
 
210
 
208
    /**
211
    /**
209
     * Test which verifies a user account can be created/found using the find_or_create_user_from_launch() method.
212
     * Test which verifies a user account can be created/found using the find_or_create_user_from_launch() method.
210
     *
213
     *
211
     * @dataProvider launch_data_provider
214
     * @dataProvider launchdata_provider
212
     * @param array|null $legacydata legacy user and tool data, if testing migration cases.
215
     * @param array|null $legacydata legacy user and tool data, if testing migration cases.
213
     * @param array $launchdata data describing the launch, including user data and migration claim data.
216
     * @param array $launchdata data describing the launch, including user data and migration claim data.
214
     * @param array $expected the test case expectations.
217
     * @param array $expected the test case expectations.
215
     * @covers ::find_or_create_user_from_launch
218
     * @covers ::find_or_create_user_from_launch
Línea 284... Línea 287...
284
    /**
287
    /**
285
     * Data provider for testing launch-based authentication.
288
     * Data provider for testing launch-based authentication.
286
     *
289
     *
287
     * @return array the test case data.
290
     * @return array the test case data.
288
     */
291
     */
289
    public function launch_data_provider(): array {
292
    public static function launchdata_provider(): array {
290
        return [
293
        return [
291
            'New (unlinked) platform learner including PII, no legacy user, no migration claim' => [
294
            'New (unlinked) platform learner including PII, no legacy user, no migration claim' => [
292
                'legacy_data' => null,
295
                'legacydata' => null,
293
                'launch_data' => [
296
                'launchdata' => [
294
                    'user' => $this->get_mock_users_with_ids(
297
                    'user' => self::get_mock_users_with_ids(
295
                        ['1'],
298
                        ['1'],
296
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
299
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
297
                    )[0],
300
                    )[0],
298
                    'migration_claim' => null
301
                    'migration_claim' => null
299
                ],
302
                ],
300
            ],
303
            ],
301
            'New (unlinked) platform learner excluding names, no legacy user, no migration claim' => [
304
            'New (unlinked) platform learner excluding names, no legacy user, no migration claim' => [
302
                'legacy_data' => null,
305
                'legacydata' => null,
303
                'launch_data' => [
306
                'launchdata' => [
304
                    'user' => $this->get_mock_users_with_ids(
307
                    'user' => self::get_mock_users_with_ids(
305
                        ['1'],
308
                        ['1'],
306
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
309
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
307
                        false
310
                        false
308
                    )[0],
311
                    )[0],
309
                    'migration_claim' => null
312
                    'migration_claim' => null
310
                ],
313
                ],
311
            ],
314
            ],
312
            'New (unlinked) platform learner excluding emails, no legacy user, no migration claim' => [
315
            'New (unlinked) platform learner excluding emails, no legacy user, no migration claim' => [
313
                'legacy_data' => null,
316
                'legacydata' => null,
314
                'launch_data' => [
317
                'launchdata' => [
315
                    'user' => $this->get_mock_users_with_ids(
318
                    'user' => self::get_mock_users_with_ids(
316
                        ['1'],
319
                        ['1'],
317
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
320
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
318
                        true,
321
                        true,
319
                        false
322
                        false
320
                    )[0],
323
                    )[0],
321
                    'migration_claim' => null
324
                    'migration_claim' => null
322
                ],
325
                ],
323
            ],
326
            ],
324
            'New (unlinked) platform learner excluding all PII, no legacy user, no migration claim' => [
327
            'New (unlinked) platform learner excluding all PII, no legacy user, no migration claim' => [
325
                'legacy_data' => null,
328
                'legacydata' => null,
326
                'launch_data' => [
329
                'launchdata' => [
327
                    'user' => $this->get_mock_users_with_ids(
330
                    'user' => self::get_mock_users_with_ids(
328
                        ['1'],
331
                        ['1'],
329
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
332
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
330
                        false,
333
                        false,
331
                        false
334
                        false
332
                    )[0],
335
                    )[0],
333
                    'migration_claim' => null
336
                    'migration_claim' => null
334
                ],
337
                ],
335
            ],
338
            ],
336
            'New (unlinked) platform learner including PII, existing legacy user, valid migration claim' => [
339
            'New (unlinked) platform learner including PII, existing legacy user, valid migration claim' => [
337
                'legacy_data' => [
340
                'legacydata' => [
338
                    'users' => [
341
                    'users' => [
339
                        ['user_id' => '123-abc'],
342
                        ['user_id' => '123-abc'],
340
                    ],
343
                    ],
341
                    'consumer_key' => 'CONSUMER_1',
344
                    'consumer_key' => 'CONSUMER_1',
342
                    'tools' => [
345
                    'tools' => [
343
                        ['secret' => 'toolsecret1'],
346
                        ['secret' => 'toolsecret1'],
344
                        ['secret' => 'toolsecret2'],
347
                        ['secret' => 'toolsecret2'],
345
                    ]
348
                    ]
346
                ],
349
                ],
347
                'launch_data' => [
350
                'launchdata' => [
348
                    'user' => $this->get_mock_users_with_ids(
351
                    'user' => self::get_mock_users_with_ids(
349
                        ['1'],
352
                        ['1'],
350
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
353
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
351
                    )[0],
354
                    )[0],
352
                    'migration_claim' => [
355
                    'migration_claim' => [
353
                        'consumer_key' => 'CONSUMER_1',
356
                        'consumer_key' => 'CONSUMER_1',
Línea 361... Línea 364...
361
                'expected' => [
364
                'expected' => [
362
                    'migrated' => true
365
                    'migrated' => true
363
                ]
366
                ]
364
            ],
367
            ],
365
            'New (unlinked) platform learner including PII, existing legacy user, no migration claim' => [
368
            'New (unlinked) platform learner including PII, existing legacy user, no migration claim' => [
366
                'legacy_data' => [
369
                'legacydata' => [
367
                    'users' => [
370
                    'users' => [
368
                        ['user_id' => '123-abc'],
371
                        ['user_id' => '123-abc'],
369
                    ],
372
                    ],
370
                    'consumer_key' => 'CONSUMER_1',
373
                    'consumer_key' => 'CONSUMER_1',
371
                    'tools' => [
374
                    'tools' => [
372
                        ['secret' => 'toolsecret1'],
375
                        ['secret' => 'toolsecret1'],
373
                        ['secret' => 'toolsecret2'],
376
                        ['secret' => 'toolsecret2'],
374
                    ]
377
                    ]
375
                ],
378
                ],
376
                'launch_data' => [
379
                'launchdata' => [
377
                    'user' => $this->get_mock_users_with_ids(
380
                    'user' => self::get_mock_users_with_ids(
378
                        ['1'],
381
                        ['1'],
379
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
382
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
380
                    )[0],
383
                    )[0],
381
                    'migration_claim' => null,
384
                    'migration_claim' => null,
382
                ],
385
                ],
383
                'expected' => [
386
                'expected' => [
384
                    'migrated' => false,
387
                    'migrated' => false,
385
                ]
388
                ]
386
            ],
389
            ],
387
            'New (unlinked) platform learner including PII, existing legacy user, migration missing consumer_key' => [
390
            'New (unlinked) platform learner including PII, existing legacy user, migration missing consumer_key' => [
388
                'legacy_data' => [
391
                'legacydata' => [
389
                    'users' => [
392
                    'users' => [
390
                        ['user_id' => '123-abc'],
393
                        ['user_id' => '123-abc'],
391
                    ],
394
                    ],
392
                    'consumer_key' => 'CONSUMER_1',
395
                    'consumer_key' => 'CONSUMER_1',
393
                    'tools' => [
396
                    'tools' => [
394
                        ['secret' => 'toolsecret1'],
397
                        ['secret' => 'toolsecret1'],
395
                        ['secret' => 'toolsecret2'],
398
                        ['secret' => 'toolsecret2'],
396
                    ]
399
                    ]
397
                ],
400
                ],
398
                'launch_data' => [
401
                'launchdata' => [
399
                    'user' => $this->get_mock_users_with_ids(
402
                    'user' => self::get_mock_users_with_ids(
400
                        ['1'],
403
                        ['1'],
401
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
404
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
402
                    )[0],
405
                    )[0],
403
                    'migration_claim' => [
406
                    'migration_claim' => [
404
                        'signing_secret' => 'toolsecret1',
407
                        'signing_secret' => 'toolsecret1',
Línea 412... Línea 415...
412
                    'migrated' => false,
415
                    'migrated' => false,
413
                    'migration_debugging' => true,
416
                    'migration_debugging' => true,
414
                ]
417
                ]
415
            ],
418
            ],
416
            'New (unlinked) platform learner including PII, existing legacy user, migration bad consumer_key' => [
419
            'New (unlinked) platform learner including PII, existing legacy user, migration bad consumer_key' => [
417
                'legacy_data' => [
420
                'legacydata' => [
418
                    'users' => [
421
                    'users' => [
419
                        ['user_id' => '123-abc'],
422
                        ['user_id' => '123-abc'],
420
                    ],
423
                    ],
421
                    'consumer_key' => 'CONSUMER_1',
424
                    'consumer_key' => 'CONSUMER_1',
422
                    'tools' => [
425
                    'tools' => [
423
                        ['secret' => 'toolsecret1'],
426
                        ['secret' => 'toolsecret1'],
424
                        ['secret' => 'toolsecret2'],
427
                        ['secret' => 'toolsecret2'],
425
                    ]
428
                    ]
426
                ],
429
                ],
427
                'launch_data' => [
430
                'launchdata' => [
428
                    'user' => $this->get_mock_users_with_ids(
431
                    'user' => self::get_mock_users_with_ids(
429
                        ['1'],
432
                        ['1'],
430
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
433
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
431
                    )[0],
434
                    )[0],
432
                    'migration_claim' => [
435
                    'migration_claim' => [
433
                        'consumer_key' => 'CONSUMER_BAD',
436
                        'consumer_key' => 'CONSUMER_BAD',
Línea 441... Línea 444...
441
                'expected' => [
444
                'expected' => [
442
                    'migrated' => false,
445
                    'migrated' => false,
443
                ]
446
                ]
444
            ],
447
            ],
445
            'New (unlinked) platform learner including PII, existing legacy user, migration user not matched' => [
448
            'New (unlinked) platform learner including PII, existing legacy user, migration user not matched' => [
446
                'legacy_data' => [
449
                'legacydata' => [
447
                    'users' => [
450
                    'users' => [
448
                        ['user_id' => '123-abc'],
451
                        ['user_id' => '123-abc'],
449
                    ],
452
                    ],
450
                    'consumer_key' => 'CONSUMER_1',
453
                    'consumer_key' => 'CONSUMER_1',
451
                    'tools' => [
454
                    'tools' => [
452
                        ['secret' => 'toolsecret1'],
455
                        ['secret' => 'toolsecret1'],
453
                        ['secret' => 'toolsecret2'],
456
                        ['secret' => 'toolsecret2'],
454
                    ]
457
                    ]
455
                ],
458
                ],
456
                'launch_data' => [
459
                'launchdata' => [
457
                    'user' => $this->get_mock_users_with_ids(
460
                    'user' => self::get_mock_users_with_ids(
458
                        ['1'],
461
                        ['1'],
459
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
462
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
460
                    )[0],
463
                    )[0],
461
                    'migration_claim' => [
464
                    'migration_claim' => [
462
                        'consumer_key' => 'CONSUMER_1',
465
                        'consumer_key' => 'CONSUMER_1',
Línea 470... Línea 473...
470
                'expected' => [
473
                'expected' => [
471
                    'migrated' => false
474
                    'migrated' => false
472
                ]
475
                ]
473
            ],
476
            ],
474
            'New (unlinked) platform learner including PII, existing legacy user, valid migration claim secret2' => [
477
            'New (unlinked) platform learner including PII, existing legacy user, valid migration claim secret2' => [
475
                'legacy_data' => [
478
                'legacydata' => [
476
                    'users' => [
479
                    'users' => [
477
                        ['user_id' => '123-abc'],
480
                        ['user_id' => '123-abc'],
478
                    ],
481
                    ],
479
                    'consumer_key' => 'CONSUMER_1',
482
                    'consumer_key' => 'CONSUMER_1',
480
                    'tools' => [
483
                    'tools' => [
481
                        ['secret' => 'toolsecret1'],
484
                        ['secret' => 'toolsecret1'],
482
                        ['secret' => 'toolsecret2'],
485
                        ['secret' => 'toolsecret2'],
483
                    ]
486
                    ]
484
                ],
487
                ],
485
                'launch_data' => [
488
                'launchdata' => [
486
                    'user' => $this->get_mock_users_with_ids(
489
                    'user' => self::get_mock_users_with_ids(
487
                        ['1'],
490
                        ['1'],
488
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
491
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
489
                    )[0],
492
                    )[0],
490
                    'migration_claim' => [
493
                    'migration_claim' => [
491
                        'consumer_key' => 'CONSUMER_1',
494
                        'consumer_key' => 'CONSUMER_1',
Línea 499... Línea 502...
499
                'expected' => [
502
                'expected' => [
500
                    'migrated' => true
503
                    'migrated' => true
501
                ]
504
                ]
502
            ],
505
            ],
503
            'New (unlinked) platform learner including PII, existing legacy user, migration claim bad secret' => [
506
            'New (unlinked) platform learner including PII, existing legacy user, migration claim bad secret' => [
504
                'legacy_data' => [
507
                'legacydata' => [
505
                    'users' => [
508
                    'users' => [
506
                        ['user_id' => '123-abc'],
509
                        ['user_id' => '123-abc'],
507
                    ],
510
                    ],
508
                    'consumer_key' => 'CONSUMER_1',
511
                    'consumer_key' => 'CONSUMER_1',
509
                    'tools' => [
512
                    'tools' => [
510
                        ['secret' => 'toolsecret1'],
513
                        ['secret' => 'toolsecret1'],
511
                        ['secret' => 'toolsecret2'],
514
                        ['secret' => 'toolsecret2'],
512
                    ]
515
                    ]
513
                ],
516
                ],
514
                'launch_data' => [
517
                'launchdata' => [
515
                    'user' => $this->get_mock_users_with_ids(
518
                    'user' => self::get_mock_users_with_ids(
516
                        ['1'],
519
                        ['1'],
517
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
520
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
518
                    )[0],
521
                    )[0],
519
                    'migration_claim' => [
522
                    'migration_claim' => [
520
                        'consumer_key' => 'CONSUMER_1',
523
                        'consumer_key' => 'CONSUMER_1',
Línea 529... Línea 532...
529
                    'migrated' => false,
532
                    'migrated' => false,
530
                    'migration_debugging' => true,
533
                    'migration_debugging' => true,
531
                ]
534
                ]
532
            ],
535
            ],
533
            'New (unlinked) platform learner including PII, no legacy user, valid migration claim' => [
536
            'New (unlinked) platform learner including PII, no legacy user, valid migration claim' => [
534
                'legacy_data' => [
537
                'legacydata' => [
535
                    'users' => [],
538
                    'users' => [],
536
                    'consumer_key' => 'CONSUMER_1',
539
                    'consumer_key' => 'CONSUMER_1',
537
                    'tools' => [
540
                    'tools' => [
538
                        ['secret' => 'toolsecret1'],
541
                        ['secret' => 'toolsecret1'],
539
                        ['secret' => 'toolsecret2'],
542
                        ['secret' => 'toolsecret2'],
540
                    ]
543
                    ]
541
                ],
544
                ],
542
                'launch_data' => [
545
                'launchdata' => [
543
                    'user' => $this->get_mock_users_with_ids(
546
                    'user' => self::get_mock_users_with_ids(
544
                        ['1'],
547
                        ['1'],
545
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
548
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
546
                    )[0],
549
                    )[0],
547
                    'migration_claim' => [
550
                    'migration_claim' => [
548
                        'consumer_key' => 'CONSUMER_1',
551
                        'consumer_key' => 'CONSUMER_1',
Línea 556... Línea 559...
556
                'expected' => [
559
                'expected' => [
557
                    'migrated' => false
560
                    'migrated' => false
558
                ]
561
                ]
559
            ],
562
            ],
560
            'New (unlinked) platform learner excluding PII, existing legacy user, valid migration claim' => [
563
            'New (unlinked) platform learner excluding PII, existing legacy user, valid migration claim' => [
561
                'legacy_data' => [
564
                'legacydata' => [
562
                    'users' => [
565
                    'users' => [
563
                        ['user_id' => '123-abc'],
566
                        ['user_id' => '123-abc'],
564
                    ],
567
                    ],
565
                    'consumer_key' => 'CONSUMER_1',
568
                    'consumer_key' => 'CONSUMER_1',
566
                    'tools' => [
569
                    'tools' => [
567
                        ['secret' => 'toolsecret1'],
570
                        ['secret' => 'toolsecret1'],
568
                        ['secret' => 'toolsecret2'],
571
                        ['secret' => 'toolsecret2'],
569
                    ]
572
                    ]
570
                ],
573
                ],
571
                'launch_data' => [
574
                'launchdata' => [
572
                    'user' => $this->get_mock_users_with_ids(
575
                    'user' => self::get_mock_users_with_ids(
573
                        ['1'],
576
                        ['1'],
574
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
577
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
575
                        false,
578
                        false,
576
                        false
579
                        false
577
                    )[0],
580
                    )[0],
Línea 587... Línea 590...
587
                'expected' => [
590
                'expected' => [
588
                    'migrated' => true
591
                    'migrated' => true
589
                ]
592
                ]
590
            ],
593
            ],
591
            'New (unlinked) platform instructor including PII, no legacy user, no migration claim' => [
594
            'New (unlinked) platform instructor including PII, no legacy user, no migration claim' => [
592
                'legacy_data' => null,
595
                'legacydata' => null,
593
                'launch_data' => [
596
                'launchdata' => [
594
                    'user' => $this->get_mock_users_with_ids(
597
                    'user' => self::get_mock_users_with_ids(
595
                        ['1'],
598
                        ['1'],
596
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'
599
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'
597
                    )[0],
600
                    )[0],
598
                    'migration_claim' => null
601
                    'migration_claim' => null
599
                ],
602
                ],
600
            ],
603
            ],
601
            'New (unlinked) platform instructor excluding PII, no legacy user, no migration claim' => [
604
            'New (unlinked) platform instructor excluding PII, no legacy user, no migration claim' => [
602
                'legacy_data' => null,
605
                'legacydata' => null,
603
                'launch_data' => [
606
                'launchdata' => [
604
                    'user' => $this->get_mock_users_with_ids(
607
                    'user' => self::get_mock_users_with_ids(
605
                        ['1'],
608
                        ['1'],
606
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
609
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
607
                        false,
610
                        false,
608
                        false
611
                        false
609
                    )[0],
612
                    )[0],
610
                    'migration_claim' => null
613
                    'migration_claim' => null
611
                ],
614
                ],
612
            ],
615
            ],
613
            'New (unlinked) platform instructor including PII, existing legacy user, valid migration claim' => [
616
            'New (unlinked) platform instructor including PII, existing legacy user, valid migration claim' => [
614
                'legacy_data' => [
617
                'legacydata' => [
615
                    'users' => [
618
                    'users' => [
616
                        ['user_id' => '123-abc'],
619
                        ['user_id' => '123-abc'],
617
                    ],
620
                    ],
618
                    'consumer_key' => 'CONSUMER_1',
621
                    'consumer_key' => 'CONSUMER_1',
619
                    'tools' => [
622
                    'tools' => [
620
                        ['secret' => 'toolsecret1'],
623
                        ['secret' => 'toolsecret1'],
621
                        ['secret' => 'toolsecret2'],
624
                        ['secret' => 'toolsecret2'],
622
                    ]
625
                    ]
623
                ],
626
                ],
624
                'launch_data' => [
627
                'launchdata' => [
625
                    'user' => $this->get_mock_users_with_ids(
628
                    'user' => self::get_mock_users_with_ids(
626
                        ['1'],
629
                        ['1'],
627
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'
630
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'
628
                    )[0],
631
                    )[0],
629
                    'migration_claim' => [
632
                    'migration_claim' => [
630
                        'consumer_key' => 'CONSUMER_1',
633
                        'consumer_key' => 'CONSUMER_1',
Línea 638... Línea 641...
638
                'expected' => [
641
                'expected' => [
639
                    'migrated' => true
642
                    'migrated' => true
640
                ]
643
                ]
641
            ],
644
            ],
642
            'Existing (linked) platform learner including PII, no legacy user, no migration claim' => [
645
            'Existing (linked) platform learner including PII, no legacy user, no migration claim' => [
643
                'legacy_data' => null,
646
                'legacydata' => null,
644
                'launch_data' => [
647
                'launchdata' => [
645
                    'has_authenticated_before' => true,
648
                    'has_authenticated_before' => true,
646
                    'user' => $this->get_mock_users_with_ids(
649
                    'user' => self::get_mock_users_with_ids(
647
                        ['1'],
650
                        ['1'],
648
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
651
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
649
                    )[0],
652
                    )[0],
650
                    'migration_claim' => null
653
                    'migration_claim' => null
651
                ],
654
                ],
652
            ],
655
            ],
653
            'Existing (linked) platform learner excluding PII, no legacy user, no migration claim' => [
656
            'Existing (linked) platform learner excluding PII, no legacy user, no migration claim' => [
654
                'legacy_data' => null,
657
                'legacydata' => null,
655
                'launch_data' => [
658
                'launchdata' => [
656
                    'has_authenticated_before' => true,
659
                    'has_authenticated_before' => true,
657
                    'user' => $this->get_mock_users_with_ids(
660
                    'user' => self::get_mock_users_with_ids(
658
                        ['1'],
661
                        ['1'],
659
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
662
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
660
                        false,
663
                        false,
661
                        false
664
                        false
662
                    )[0],
665
                    )[0],
663
                    'migration_claim' => null
666
                    'migration_claim' => null
664
                ],
667
                ],
665
            ],
668
            ],
666
            'Existing (linked) platform instructor including PII, no legacy user, no migration claim' => [
669
            'Existing (linked) platform instructor including PII, no legacy user, no migration claim' => [
667
                'legacy_data' => null,
670
                'legacydata' => null,
668
                'launch_data' => [
671
                'launchdata' => [
669
                    'has_authenticated_before' => true,
672
                    'has_authenticated_before' => true,
670
                    'user' => $this->get_mock_users_with_ids(
673
                    'user' => self::get_mock_users_with_ids(
671
                        ['1'],
674
                        ['1'],
672
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'
675
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'
673
                    )[0],
676
                    )[0],
674
                    'migration_claim' => null
677
                    'migration_claim' => null
675
                ],
678
                ],
676
            ],
679
            ],
677
            'Existing (linked) platform instructor excluding PII, no legacy user, no migration claim' => [
680
            'Existing (linked) platform instructor excluding PII, no legacy user, no migration claim' => [
678
                'legacy_data' => null,
681
                'legacydata' => null,
679
                'launch_data' => [
682
                'launchdata' => [
680
                    'has_authenticated_before' => true,
683
                    'has_authenticated_before' => true,
681
                    'user' => $this->get_mock_users_with_ids(
684
                    'user' => self::get_mock_users_with_ids(
682
                        ['1'],
685
                        ['1'],
683
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
686
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
684
                        false,
687
                        false,
685
                        false
688
                        false
686
                    )[0],
689
                    )[0],
687
                    'migration_claim' => null
690
                    'migration_claim' => null
688
                ],
691
                ],
689
            ],
692
            ],
690
            'New (unlinked) platform instructor excluding PII, picture included' => [
693
            'New (unlinked) platform instructor excluding PII, picture included' => [
691
                'legacy_data' => null,
694
                'legacydata' => null,
692
                'launch_data' => [
695
                'launchdata' => [
693
                    'has_authenticated_before' => false,
696
                    'has_authenticated_before' => false,
694
                    'user' => $this->get_mock_users_with_ids(
697
                    'user' => self::get_mock_users_with_ids(
695
                        ['1'],
698
                        ['1'],
696
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
699
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
697
                        false,
700
                        false,
698
                        false,
701
                        false,
699
                        true
702
                        true
Línea 808... Línea 811...
808
    /**
811
    /**
809
     * Data provider for testing membership-service-based authentication.
812
     * Data provider for testing membership-service-based authentication.
810
     *
813
     *
811
     * @return array the test case data.
814
     * @return array the test case data.
812
     */
815
     */
813
    public function membership_data_provider(): array {
816
    public static function membership_data_provider(): array {
814
        return [
817
        return [
815
            'New (unlinked) platform learner including PII, no legacy data, no consumer key bound, no legacy id' => [
818
            'New (unlinked) platform learner including PII, no legacy data, no consumer key bound, no legacy id' => [
816
                'legacy_data' => null,
819
                'legacydata' => null,
817
                'membership_data' => [
820
                'memberdata' => [
818
                    'user' => $this->get_mock_users_with_ids(
821
                    'user' => self::get_mock_users_with_ids(
819
                        ['1'],
822
                        ['1'],
820
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
823
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
821
                    )[0],
824
                    )[0],
822
                ],
825
                ],
823
                'iss' => $this->issuer,
826
                'iss' => self::$issuer,
824
                'legacy_consumer_key' => null,
827
                'legacyconsumerkey' => null,
825
                'expected' => [
828
                'expected' => [
826
                    'PII' => self::PII_ALL,
829
                    'PII' => self::PII_ALL,
827
                    'migrated' => false
830
                    'migrated' => false
828
                ]
831
                ]
829
            ],
832
            ],
830
            'New (unlinked) platform learner excluding PII, no legacy data, no consumer key bound, no legacy id' => [
833
            'New (unlinked) platform learner excluding PII, no legacy data, no consumer key bound, no legacy id' => [
831
                'legacy_data' => null,
834
                'legacydata' => null,
832
                'membership_data' => [
835
                'memberdata' => [
833
                    'user' => $this->get_mock_users_with_ids(
836
                    'user' => self::get_mock_users_with_ids(
834
                        ['1'],
837
                        ['1'],
835
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
838
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
836
                        false,
839
                        false,
837
                        false
840
                        false
838
                    )[0],
841
                    )[0],
839
                ],
842
                ],
840
                'iss' => $this->issuer,
843
                'iss' => self::$issuer,
841
                'legacy_consumer_key' => null,
844
                'legacyconsumerkey' => null,
842
                'expected' => [
845
                'expected' => [
843
                    'PII' => self::PII_NONE,
846
                    'PII' => self::PII_NONE,
844
                    'migrated' => false
847
                    'migrated' => false
845
                ]
848
                ]
846
            ],
849
            ],
847
            'New (unlinked) platform learner excluding names, no legacy data, no consumer key bound, no legacy id' => [
850
            'New (unlinked) platform learner excluding names, no legacy data, no consumer key bound, no legacy id' => [
848
                'legacy_data' => null,
851
                'legacydata' => null,
849
                'membership_data' => [
852
                'memberdata' => [
850
                    'user' => $this->get_mock_users_with_ids(
853
                    'user' => self::get_mock_users_with_ids(
851
                        ['1'],
854
                        ['1'],
852
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
855
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
853
                        false,
856
                        false,
854
                    )[0],
857
                    )[0],
855
                ],
858
                ],
856
                'iss' => $this->issuer,
859
                'iss' => self::$issuer,
857
                'legacy_consumer_key' => null,
860
                'legacyconsumerkey' => null,
858
                'expected' => [
861
                'expected' => [
859
                    'PII' => self::PII_EMAILS_ONLY,
862
                    'PII' => self::PII_EMAILS_ONLY,
860
                    'migrated' => false
863
                    'migrated' => false
861
                ]
864
                ]
862
            ],
865
            ],
863
            'New (unlinked) platform learner excluding email, no legacy data, no consumer key bound, no legacy id' => [
866
            'New (unlinked) platform learner excluding email, no legacy data, no consumer key bound, no legacy id' => [
864
                'legacy_data' => null,
867
                'legacydata' => null,
865
                'membership_data' => [
868
                'memberdata' => [
866
                    'user' => $this->get_mock_users_with_ids(
869
                    'user' => self::get_mock_users_with_ids(
867
                        ['1'],
870
                        ['1'],
868
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
871
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
869
                        true,
872
                        true,
870
                        false
873
                        false
871
                    )[0],
874
                    )[0],
872
                ],
875
                ],
873
                'iss' => $this->issuer,
876
                'iss' => self::$issuer,
874
                'legacy_consumer_key' => null,
877
                'legacyconsumerkey' => null,
875
                'expected' => [
878
                'expected' => [
876
                    'PII' => self::PII_NAMES_ONLY,
879
                    'PII' => self::PII_NAMES_ONLY,
877
                    'migrated' => false
880
                    'migrated' => false
878
                ]
881
                ]
879
            ],
882
            ],
880
            'New (unlinked) platform learner including PII, legacy user, consumer key bound, legacy user id sent' => [
883
            'New (unlinked) platform learner including PII, legacy user, consumer key bound, legacy user id sent' => [
881
                'legacy_data' => [
884
                'legacydata' => [
882
                    'users' => [
885
                    'users' => [
883
                        ['user_id' => '123-abc'],
886
                        ['user_id' => '123-abc'],
884
                    ],
887
                    ],
885
                    'consumer_key' => 'CONSUMER_1',
888
                    'consumer_key' => 'CONSUMER_1',
886
                ],
889
                ],
887
                'membership_data' => [
890
                'memberdata' => [
888
                    'user' => $this->get_mock_users_with_ids(
891
                    'user' => self::get_mock_users_with_ids(
889
                        ['1'],
892
                        ['1'],
890
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
893
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
891
                    )[0],
894
                    )[0],
892
                    'legacy_user_id' => '123-abc'
895
                    'legacy_user_id' => '123-abc'
893
                ],
896
                ],
894
                'iss' => $this->issuer,
897
                'iss' => self::$issuer,
895
                'legacy_consumer_key' => 'CONSUMER_1',
898
                'legacyconsumerkey' => 'CONSUMER_1',
896
                'expected' => [
899
                'expected' => [
897
                    'PII' => self::PII_ALL,
900
                    'PII' => self::PII_ALL,
898
                    'migrated' => true
901
                    'migrated' => true
899
                ]
902
                ]
900
            ],
903
            ],
901
            'New (unlinked) platform learner including PII, legacy user, consumer key bound, legacy user id omitted' => [
904
            'New (unlinked) platform learner including PII, legacy user, consumer key bound, legacy user id omitted' => [
902
                'legacy_data' => [
905
                'legacydata' => [
903
                    'users' => [
906
                    'users' => [
904
                        ['user_id' => '123-abc'],
907
                        ['user_id' => '123-abc'],
905
                    ],
908
                    ],
906
                    'consumer_key' => 'CONSUMER_1',
909
                    'consumer_key' => 'CONSUMER_1',
907
                ],
910
                ],
908
                'membership_data' => [
911
                'memberdata' => [
909
                    'user' => $this->get_mock_users_with_ids(
912
                    'user' => self::get_mock_users_with_ids(
910
                        ['1'],
913
                        ['1'],
911
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
914
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
912
                    )[0],
915
                    )[0],
913
                ],
916
                ],
914
                'iss' => $this->issuer,
917
                'iss' => self::$issuer,
915
                'legacy_consumer_key' => 'CONSUMER_1',
918
                'legacyconsumerkey' => 'CONSUMER_1',
916
                'expected' => [
919
                'expected' => [
917
                    'PII' => self::PII_ALL,
920
                    'PII' => self::PII_ALL,
918
                    'migrated' => false,
921
                    'migrated' => false,
919
                ]
922
                ]
920
            ],
923
            ],
921
            'New (unlinked) platform learner including PII, legacy user, consumer key bound, no change in user id' => [
924
            'New (unlinked) platform learner including PII, legacy user, consumer key bound, no change in user id' => [
922
                'legacy_data' => [
925
                'legacydata' => [
923
                    'users' => [
926
                    'users' => [
924
                        ['user_id' => '123-abc'],
927
                        ['user_id' => '123-abc'],
925
                    ],
928
                    ],
926
                    'consumer_key' => 'CONSUMER_1',
929
                    'consumer_key' => 'CONSUMER_1',
927
                ],
930
                ],
928
                'membership_data' => [
931
                'memberdata' => [
929
                    'user' => $this->get_mock_users_with_ids(
932
                    'user' => self::get_mock_users_with_ids(
930
                        ['123-abc'],
933
                        ['123-abc'],
931
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
934
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
932
                    )[0],
935
                    )[0],
933
                ],
936
                ],
934
                'iss' => $this->issuer,
937
                'iss' => self::$issuer,
935
                'legacy_consumer_key' => 'CONSUMER_1',
938
                'legacyconsumerkey' => 'CONSUMER_1',
936
                'expected' => [
939
                'expected' => [
937
                    'PII' => self::PII_ALL,
940
                    'PII' => self::PII_ALL,
938
                    'migrated' => true
941
                    'migrated' => true
939
                ]
942
                ]
940
            ],
943
            ],
941
            'New (unlinked) platform learner including PII, legacy user, unexpected consumer key bound, no change in user id' => [
944
            'New (unlinked) platform learner including PII, legacy user, unexpected consumer key bound, no change in user id' => [
942
                'legacy_data' => [
945
                'legacydata' => [
943
                    'users' => [
946
                    'users' => [
944
                        ['user_id' => '123-abc'],
947
                        ['user_id' => '123-abc'],
945
                    ],
948
                    ],
946
                    'consumer_key' => 'CONSUMER_1',
949
                    'consumer_key' => 'CONSUMER_1',
947
                ],
950
                ],
948
                'membership_data' => [
951
                'memberdata' => [
949
                    'user' => $this->get_mock_users_with_ids(
952
                    'user' => self::get_mock_users_with_ids(
950
                        ['123-abc'],
953
                        ['123-abc'],
951
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
954
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
952
                    )[0],
955
                    )[0],
953
                ],
956
                ],
954
                'iss' => $this->issuer,
957
                'iss' => self::$issuer,
955
                'legacy_consumer_key' => 'CONSUMER_ABCDEF',
958
                'legacyconsumerkey' => 'CONSUMER_ABCDEF',
956
                'expected' => [
959
                'expected' => [
957
                    'PII' => self::PII_ALL,
960
                    'PII' => self::PII_ALL,
958
                    'migrated' => false,
961
                    'migrated' => false,
959
                ]
962
                ]
960
            ],
963
            ],
961
            'New (unlinked) platform learner including PII, legacy user, consumer key not bound, legacy user id sent' => [
964
            'New (unlinked) platform learner including PII, legacy user, consumer key not bound, legacy user id sent' => [
962
                'legacy_data' => [
965
                'legacydata' => [
963
                    'users' => [
966
                    'users' => [
964
                        ['user_id' => '123-abc'],
967
                        ['user_id' => '123-abc'],
965
                    ],
968
                    ],
966
                    'consumer_key' => 'CONSUMER_1',
969
                    'consumer_key' => 'CONSUMER_1',
967
                ],
970
                ],
968
                'membership_data' => [
971
                'memberdata' => [
969
                    'user' => $this->get_mock_users_with_ids(
972
                    'user' => self::get_mock_users_with_ids(
970
                        ['1'],
973
                        ['1'],
971
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
974
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
972
                    )[0],
975
                    )[0],
973
                    'legacy_user_id' => '123-abc'
976
                    'legacy_user_id' => '123-abc'
974
                ],
977
                ],
975
                'iss' => $this->issuer,
978
                'iss' => self::$issuer,
976
                'legacy_consumer_key' => null,
979
                'legacyconsumerkey' => null,
977
                'expected' => [
980
                'expected' => [
978
                    'PII' => self::PII_ALL,
981
                    'PII' => self::PII_ALL,
979
                    'migrated' => false
982
                    'migrated' => false
980
                ]
983
                ]
981
            ],
984
            ],
982
            'New (unlinked) platform learner including PII, no legacy data, consumer key bound, legacy user id sent' => [
985
            'New (unlinked) platform learner including PII, no legacy data, consumer key bound, legacy user id sent' => [
983
                'legacy_data' => null,
986
                'legacydata' => null,
984
                'membership_data' => [
987
                'memberdata' => [
985
                    'user' => $this->get_mock_users_with_ids(
988
                    'user' => self::get_mock_users_with_ids(
986
                        ['1'],
989
                        ['1'],
987
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
990
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
988
                    )[0],
991
                    )[0],
989
                    'legacy_user_id' => '123-abc'
992
                    'legacy_user_id' => '123-abc'
990
                ],
993
                ],
991
                'iss' => $this->issuer,
994
                'iss' => self::$issuer,
992
                'legacy_consumer_key' => 'CONSUMER_1',
995
                'legacyconsumerkey' => 'CONSUMER_1',
993
                'expected' => [
996
                'expected' => [
994
                    'PII' => self::PII_ALL,
997
                    'PII' => self::PII_ALL,
995
                    'migrated' => false
998
                    'migrated' => false
996
                ]
999
                ]
997
            ],
1000
            ],
998
            'New (unlinked) platform instructor including PII, no legacy data, no consumer key bound, no legacy id' => [
1001
            'New (unlinked) platform instructor including PII, no legacy data, no consumer key bound, no legacy id' => [
999
                'legacy_data' => null,
1002
                'legacydata' => null,
1000
                'membership_data' => [
1003
                'memberdata' => [
1001
                    'user' => $this->get_mock_users_with_ids(
1004
                    'user' => self::get_mock_users_with_ids(
1002
                        ['1'],
1005
                        ['1'],
1003
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'
1006
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'
1004
                    )[0],
1007
                    )[0],
1005
                ],
1008
                ],
1006
                'iss' => $this->issuer,
1009
                'iss' => self::$issuer,
1007
                'legacy_consumer_key' => null,
1010
                'legacyconsumerkey' => null,
1008
                'expected' => [
1011
                'expected' => [
1009
                    'PII' => self::PII_ALL,
1012
                    'PII' => self::PII_ALL,
1010
                    'migrated' => false
1013
                    'migrated' => false
1011
                ]
1014
                ]
1012
            ],
1015
            ],
1013
            'New (unlinked) platform instructor excluding PII, no legacy data, no consumer key bound, no legacy id' => [
1016
            'New (unlinked) platform instructor excluding PII, no legacy data, no consumer key bound, no legacy id' => [
1014
                'legacy_data' => null,
1017
                'legacydata' => null,
1015
                'membership_data' => [
1018
                'memberdata' => [
1016
                    'user' => $this->get_mock_users_with_ids(
1019
                    'user' => self::get_mock_users_with_ids(
1017
                        ['1'],
1020
                        ['1'],
1018
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1021
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1019
                        false,
1022
                        false,
1020
                        false
1023
                        false
1021
                    )[0],
1024
                    )[0],
1022
                ],
1025
                ],
1023
                'iss' => $this->issuer,
1026
                'iss' => self::$issuer,
1024
                'legacy_consumer_key' => null,
1027
                'legacyconsumerkey' => null,
1025
                'expected' => [
1028
                'expected' => [
1026
                    'PII' => self::PII_NONE,
1029
                    'PII' => self::PII_NONE,
1027
                    'migrated' => false
1030
                    'migrated' => false
1028
                ]
1031
                ]
1029
            ],
1032
            ],
1030
            'Existing (linked) platform learner including PII, no legacy data, no consumer key bound, no legacy id' => [
1033
            'Existing (linked) platform learner including PII, no legacy data, no consumer key bound, no legacy id' => [
1031
                'legacy_data' => null,
1034
                'legacydata' => null,
1032
                'launch_data' => [
1035
                'memberdata' => [
1033
                    'has_authenticated_before' => true,
1036
                    'has_authenticated_before' => true,
1034
                    'user' => $this->get_mock_users_with_ids(
1037
                    'user' => self::get_mock_users_with_ids(
1035
                        ['1'],
1038
                        ['1'],
1036
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1039
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1037
                    )[0],
1040
                    )[0],
1038
                ],
1041
                ],
1039
                'iss' => $this->issuer,
1042
                'iss' => self::$issuer,
1040
                'legacy_consumer_key' => null,
1043
                'legacyconsumerkey' => null,
1041
                'expected' => [
1044
                'expected' => [
1042
                    'PII' => self::PII_ALL,
1045
                    'PII' => self::PII_ALL,
1043
                    'migrated' => false
1046
                    'migrated' => false
1044
                ]
1047
                ]
1045
            ],
1048
            ],
Línea 1054... Línea 1057...
1054
    public function test_create_user_binding(): void {
1057
    public function test_create_user_binding(): void {
1055
        $this->resetAfterTest();
1058
        $this->resetAfterTest();
1056
        global $DB;
1059
        global $DB;
1057
        $auth = get_auth_plugin('lti');
1060
        $auth = get_auth_plugin('lti');
1058
        $user = $this->getDataGenerator()->create_user();
1061
        $user = $this->getDataGenerator()->create_user();
1059
        $mockiss = $this->issuer;
1062
        $mockiss = self::$issuer;
1060
        $mocksub = '1';
1063
        $mocksub = '1';
Línea 1061... Línea 1064...
1061
 
1064
 
1062
        // Create a binding and verify it exists.
1065
        // Create a binding and verify it exists.
1063
        $this->assertFalse($DB->record_exists('auth_lti_linked_login', ['userid' => $user->id]));
1066
        $this->assertFalse($DB->record_exists('auth_lti_linked_login', ['userid' => $user->id]));
Línea 1066... Línea 1069...
1066
 
1069
 
1067
        // Now, try to get an authenticated user USING that binding. Verify the bound user is returned.
1070
        // Now, try to get an authenticated user USING that binding. Verify the bound user is returned.
1068
        $numusersbefore = $DB->count_records('user');
1071
        $numusersbefore = $DB->count_records('user');
1069
        $matcheduser = $auth->find_or_create_user_from_launch(
1072
        $matcheduser = $auth->find_or_create_user_from_launch(
1070
            $this->get_mock_launchdata_for_user(
1073
            $this->get_mock_launchdata_for_user(
1071
                $this->get_mock_users_with_ids([$mocksub])[0]
1074
                self::get_mock_users_with_ids([$mocksub])[0]
1072
            )
1075
            )
1073
        );
1076
        );
1074
        $numusersafter = $DB->count_records('user');
1077
        $numusersafter = $DB->count_records('user');
1075
        $this->assertEquals($numusersafter, $numusersbefore);
1078
        $this->assertEquals($numusersafter, $numusersbefore);
Línea 1146... Línea 1149...
1146
    /**
1149
    /**
1147
     * Data provider for testing user user_update_account.
1150
     * Data provider for testing user user_update_account.
1148
     *
1151
     *
1149
     * @return array the test case data.
1152
     * @return array the test case data.
1150
     */
1153
     */
1151
    public function update_user_account_provider(): array {
1154
    public static function update_user_account_provider(): array {
1152
        return [
1155
        return [
1153
            'Full PII included in both auths, no picture in either' => [
1156
            'Full PII included in both auths, no picture in either' => [
1154
                'first_launch_data' => [
1157
                'firstlaunchdata' => [
1155
                     'user' => $this->get_mock_users_with_ids(
1158
                     'user' => self::get_mock_users_with_ids(
1156
                        ['1'],
1159
                        ['1'],
1157
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1160
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1158
                    )[0]
1161
                    )[0]
1159
                ],
1162
                ],
1160
                'launch_data' => [
1163
                'launchdata' => [
1161
                    'user' => $this->get_mock_users_with_ids(
1164
                    'user' => self::get_mock_users_with_ids(
1162
                        ['1'],
1165
                        ['1'],
1163
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1166
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1164
                    )[0],
1167
                    )[0],
1165
                ],
1168
                ],
1166
                'expected' => [
1169
                'expected' => [
Línea 1168... Línea 1171...
1168
                    'user_updated' => false,
1171
                    'user_updated' => false,
1169
                    'picture_updated' => false
1172
                    'picture_updated' => false
1170
                ]
1173
                ]
1171
            ],
1174
            ],
1172
            'No PII included in both auths, no picture in either' => [
1175
            'No PII included in both auths, no picture in either' => [
1173
                'first_launch_data' => [
1176
                'firstlaunchdata' => [
1174
                    'user' => $this->get_mock_users_with_ids(
1177
                    'user' => self::get_mock_users_with_ids(
1175
                        ['1'],
1178
                        ['1'],
1176
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1179
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1177
                        false,
1180
                        false,
1178
                        false
1181
                        false
1179
                    )[0]
1182
                    )[0]
1180
                ],
1183
                ],
1181
                'launch_data' => [
1184
                'launchdata' => [
1182
                    'user' => $this->get_mock_users_with_ids(
1185
                    'user' => self::get_mock_users_with_ids(
1183
                        ['1'],
1186
                        ['1'],
1184
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1187
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1185
                        false,
1188
                        false,
1186
                        false
1189
                        false
1187
                    )[0],
1190
                    )[0],
Línea 1191... Línea 1194...
1191
                    'user_updated' => false,
1194
                    'user_updated' => false,
1192
                    'picture_updated' => false
1195
                    'picture_updated' => false
1193
                ]
1196
                ]
1194
            ],
1197
            ],
1195
            'First auth no PII, second auth including PII, no picture in either' => [
1198
            'First auth no PII, second auth including PII, no picture in either' => [
1196
                'first_launch_data' => [
1199
                'firstlaunchdata' => [
1197
                    'user' => $this->get_mock_users_with_ids(
1200
                    'user' => self::get_mock_users_with_ids(
1198
                        ['1'],
1201
                        ['1'],
1199
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1202
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1200
                        false,
1203
                        false,
1201
                        false
1204
                        false
1202
                    )[0]
1205
                    )[0]
1203
                ],
1206
                ],
1204
                'launch_data' => [
1207
                'launchdata' => [
1205
                    'user' => $this->get_mock_users_with_ids(
1208
                    'user' => self::get_mock_users_with_ids(
1206
                        ['1'],
1209
                        ['1'],
1207
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1210
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1208
                    )[0],
1211
                    )[0],
1209
                ],
1212
                ],
1210
                'expected' => [
1213
                'expected' => [
Línea 1212... Línea 1215...
1212
                    'user_updated' => true,
1215
                    'user_updated' => true,
1213
                    'picture_updated' => false
1216
                    'picture_updated' => false
1214
                ]
1217
                ]
1215
            ],
1218
            ],
1216
            'First auth full PII, second auth no PII, no picture in either' => [
1219
            'First auth full PII, second auth no PII, no picture in either' => [
1217
                'first_launch_data' => [
1220
                'firstlaunchdata' => [
1218
                    'user' => $this->get_mock_users_with_ids(
1221
                    'user' => self::get_mock_users_with_ids(
1219
                        ['1'],
1222
                        ['1'],
1220
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1223
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1221
                    )[0]
1224
                    )[0]
1222
                ],
1225
                ],
1223
                'launch_data' => [
1226
                'launchdata' => [
1224
                    'user' => $this->get_mock_users_with_ids(
1227
                    'user' => self::get_mock_users_with_ids(
1225
                        ['1'],
1228
                        ['1'],
1226
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1229
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1227
                        false,
1230
                        false,
1228
                        false
1231
                        false
1229
                    )[0],
1232
                    )[0],
Línea 1233... Línea 1236...
1233
                    'user_updated' => true,
1236
                    'user_updated' => true,
1234
                    'picture_updated' => false
1237
                    'picture_updated' => false
1235
                ]
1238
                ]
1236
            ],
1239
            ],
1237
            'First auth full PII, second auth emails only, no picture in either' => [
1240
            'First auth full PII, second auth emails only, no picture in either' => [
1238
                'first_launch_data' => [
1241
                'firstlaunchdata' => [
1239
                    'user' => $this->get_mock_users_with_ids(
1242
                    'user' => self::get_mock_users_with_ids(
1240
                        ['1'],
1243
                        ['1'],
1241
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1244
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1242
                    )[0]
1245
                    )[0]
1243
                ],
1246
                ],
1244
                'launch_data' => [
1247
                'launchdata' => [
1245
                    'user' => $this->get_mock_users_with_ids(
1248
                    'user' => self::get_mock_users_with_ids(
1246
                        ['1'],
1249
                        ['1'],
1247
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1250
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1248
                        false
1251
                        false
1249
                    )[0],
1252
                    )[0],
1250
                ],
1253
                ],
Línea 1253... Línea 1256...
1253
                    'user_updated' => true,
1256
                    'user_updated' => true,
1254
                    'picture_updated' => false
1257
                    'picture_updated' => false
1255
                ]
1258
                ]
1256
            ],
1259
            ],
1257
            'First auth full PII, second auth names only, no picture in either' => [
1260
            'First auth full PII, second auth names only, no picture in either' => [
1258
                'first_launch_data' => [
1261
                'firstlaunchdata' => [
1259
                    'user' => $this->get_mock_users_with_ids(
1262
                    'user' => self::get_mock_users_with_ids(
1260
                        ['1'],
1263
                        ['1'],
1261
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1264
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1262
                    )[0]
1265
                    )[0]
1263
                ],
1266
                ],
1264
                'launch_data' => [
1267
                'launchdata' => [
1265
                    'user' => $this->get_mock_users_with_ids(
1268
                    'user' => self::get_mock_users_with_ids(
1266
                        ['1'],
1269
                        ['1'],
1267
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1270
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1268
                        true,
1271
                        true,
1269
                        false
1272
                        false
1270
                    )[0],
1273
                    )[0],
Línea 1274... Línea 1277...
1274
                    'user_updated' => true,
1277
                    'user_updated' => true,
1275
                    'picture_updated' => false
1278
                    'picture_updated' => false
1276
                ]
1279
                ]
1277
            ],
1280
            ],
1278
            'Full PII included in both auths, picture included in the second auth' => [
1281
            'Full PII included in both auths, picture included in the second auth' => [
1279
                'first_launch_data' => [
1282
                'firstlaunchdata' => [
1280
                    'user' => $this->get_mock_users_with_ids(
1283
                    'user' => self::get_mock_users_with_ids(
1281
                        ['1'],
1284
                        ['1'],
1282
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1285
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1283
                    )[0]
1286
                    )[0]
1284
                ],
1287
                ],
1285
                'launch_data' => [
1288
                'launchdata' => [
1286
                    'user' => $this->get_mock_users_with_ids(
1289
                    'user' => self::get_mock_users_with_ids(
1287
                        ['1'],
1290
                        ['1'],
1288
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1291
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner',
1289
                        true,
1292
                        true,
1290
                        true,
1293
                        true,
1291
                        true
1294
                        true