forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-59115 auth_oauth2: Set all mapped field of user
On account creation by Oauth2 all configured mapped user fields are now saved in the user profile on user creation. Co-Authored-By: SKOLL Learning Technologies
- Loading branch information
Matt Porritt
committed
Dec 1, 2021
1 parent
d5698ac
commit 1c77897
Showing
2 changed files
with
96 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,45 @@ public function test_clean_orphaned_linked_logins_with_issuer_id() { | |
$this->assertCount(1, $linkedlogins); | ||
} | ||
|
||
/** | ||
* Test creating a new confirmed account. | ||
* Including testing that user profile fields are correctly set. | ||
* | ||
* @covers \auth_oauth2\api::create_new_confirmed_account | ||
*/ | ||
public function test_create_new_confirmed_account() { | ||
global $DB; | ||
$this->resetAfterTest(); | ||
$this->setAdminUser(); | ||
|
||
$issuer = \core\oauth2\api::create_standard_issuer('microsoft'); | ||
|
||
$info = []; | ||
$info['username'] = 'apple'; | ||
$info['email'] = '[email protected]'; | ||
$info['firstname'] = 'Apple'; | ||
$info['lastname'] = 'Fruit'; | ||
$info['alternatename'] = 'Beatles'; | ||
$info['idnumber'] = '123456'; | ||
$info['city'] = 'Melbourne'; | ||
$info['country'] = 'AU'; | ||
$info['institution'] = 'ACME Inc'; | ||
$info['department'] = 'Misc Explosives'; | ||
|
||
$createduser = \auth_oauth2\api::create_new_confirmed_account($info, $issuer); | ||
|
||
// Get actual user record from DB to check. | ||
$userdata = $DB->get_record('user', ['id' => $createduser->id]); | ||
|
||
// Confirm each value supplied from issuers is saved into the user record. | ||
foreach ($info as $key => $value) { | ||
$this->assertEquals($value, $userdata->$key); | ||
} | ||
|
||
// Explicitly test the user is confirmed. | ||
$this->assertEquals(1, $userdata->confirmed); | ||
} | ||
|
||
/** | ||
* Test auto-confirming linked logins. | ||
*/ | ||
|
@@ -159,4 +198,43 @@ public function test_is_enabled_disabled() { | |
set_config('auth', 'manual'); | ||
$this->assertFalse(\auth_oauth2\api::is_enabled()); | ||
} | ||
|
||
/** | ||
* Test creating a user via the send confirm account email method. | ||
* Including testing that user profile fields are correctly set. | ||
* | ||
* @covers \auth_oauth2\api::send_confirm_account_email | ||
*/ | ||
public function test_send_confirm_account_email() { | ||
global $DB; | ||
$this->resetAfterTest(); | ||
$this->setAdminUser(); | ||
|
||
$issuer = \core\oauth2\api::create_standard_issuer('microsoft'); | ||
|
||
$info = []; | ||
$info['username'] = 'apple'; | ||
$info['email'] = '[email protected]'; | ||
$info['firstname'] = 'Apple'; | ||
$info['lastname'] = 'Fruit'; | ||
$info['alternatename'] = 'Beatles'; | ||
$info['idnumber'] = '123456'; | ||
$info['city'] = 'Melbourne'; | ||
$info['country'] = 'AU'; | ||
$info['institution'] = 'ACME Inc'; | ||
$info['department'] = 'Misc Explosives'; | ||
|
||
$createduser = \auth_oauth2\api::send_confirm_account_email($info, $issuer); | ||
|
||
// Get actual user record from DB to check. | ||
$userdata = $DB->get_record('user', ['id' => $createduser->id]); | ||
|
||
// Confirm each value supplied from issuers is saved into the user record. | ||
foreach ($info as $key => $value) { | ||
$this->assertEquals($value, $userdata->$key); | ||
} | ||
|
||
// Explicitly test the user is not yet confirmed. | ||
$this->assertEquals(0, $userdata->confirmed); | ||
} | ||
} |