catalyst / moodle-auth_saml2

SAML done 100% in Moodle, fast, simple, secure
https://moodle.org/plugins/auth_saml2
71 stars 133 forks source link

fix random notice when autocreating users #734

Closed skodak closed 1 year ago

skodak commented 1 year ago

Sometimes when autocreating users the method \auth_saml2\auth::update_user_record_from_attribute_map() may first try to validate email before adding username property to empty $user object resulting in "Notice: Undefined property: stdClass::$username in [dirroot]/auth/saml2/classes/auth.php on line 963".

This is annoying because it happens for me repeatedly in my behat tests for SAML2 support in our multi-tenancy code.

skodak commented 1 year ago

The real cause is unpredictable property order returned from $mapconfig = get_config('auth_saml2');, but I decided to do a minimal patch because the order does not matter. When autocreating users the new username does not exist, so we might as well just fall back to null.