-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fallback idp/mdl attribute mapping
Used when the primary mapping does not match against any particular user. This can be used in the case where attributes used for id management are transitioned from one field to another, and allows for a gradual non-disruptive rollover.
- Loading branch information
Showing
4 changed files
with
102 additions
and
22 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
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 |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
* @copyright 2021 Moodle Pty Ltd <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class auth_saml2_test extends \advanced_testcase { | ||
class auth_test extends \advanced_testcase { | ||
/** | ||
* Set up | ||
*/ | ||
|
@@ -435,6 +435,41 @@ public function test_saml_login_complete_missing_idpattr(): void { | |
$this->assertEquals(AUTH_LOGIN_NOUSER, $event->get_data()['other']['reason']); | ||
} | ||
|
||
public function test_saml_login_complete_secondary_mapping_used(): void { | ||
global $USER; | ||
|
||
$attribs = [ | ||
'uid' => ['doesnotmatch'], | ||
'email' => ['[email protected]'], | ||
'someidfield' => ['must-match-12345'], | ||
]; | ||
|
||
$user = $this->getDataGenerator()->create_user([ | ||
'auth' => 'saml2', | ||
'email' => '[email protected]', | ||
'idnumber' => 'must-match-12345', | ||
]); | ||
|
||
// The primary was set up to fail. | ||
set_config('idpattr', 'uid', 'auth_saml2'); | ||
set_config('mdlattr', 'email', 'auth_saml2'); | ||
// The secondary mapping should match and map to the generated user. | ||
set_config('idpattrsecondary', 'someidfield', 'auth_saml2'); | ||
set_config('mdlattrsecondary', 'idnumber', 'auth_saml2'); | ||
|
||
// Sanity check. | ||
$this->assertFalse(isloggedin()); | ||
$this->assertNotEquals($attribs['email'][0], $user->email); | ||
|
||
// Try to login, suppress output. | ||
$auth = new \auth_saml2\auth(); | ||
@$auth->saml_login_complete($attribs); | ||
|
||
// Check global object, make sure the created user is the one logged in, despite other non-matching attributes provided. | ||
$this->assertEquals($user->id, $USER->id); | ||
$this->assertEquals($user->username, $USER->username); | ||
} | ||
|
||
public function test_saml_login_complete_group_restriction(): void { | ||
$attribs = [ | ||
'uid' => ['samlu1'], | ||
|