[FIX] SAML login crashing when receiving an array of roles (#18224)

pull/18240/head
pierre-lehnen-rc 6 years ago committed by GitHub
parent af8c879f6b
commit 2e2c4cc2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/meteor-accounts-saml/server/lib/Utils.ts
  2. 11
      app/meteor-accounts-saml/tests/server.tests.ts

@ -451,7 +451,12 @@ export class SAMLUtils {
}
if (roleAttributeName && profile[roleAttributeName]) {
userObject.roles = this.ensureArray<string>((profile[roleAttributeName] || '').split(','));
let value = profile[roleAttributeName] || '';
if (typeof value === 'string') {
value = value.split(',');
}
userObject.roles = this.ensureArray<string>(value);
}
if (profile.language) {

@ -722,6 +722,17 @@ describe('SAML', () => {
expect(userObject).to.have.property('username').that.is.equal('[username]');
});
it('should load multiple roles from the roleAttributeName when it has multiple values', () => {
const multipleRoles = {
...profile,
roles: ['role1', 'role2'],
};
const userObject = SAMLUtils.mapProfileToUserObject(multipleRoles);
expect(userObject).to.be.an('object').that.have.property('roles').that.is.an('array').with.members(['role1', 'role2']);
});
it('should assign the default role when the roleAttributeName is missing', () => {
const { globalSettings } = SAMLUtils;
globalSettings.roleAttributeName = '';

Loading…
Cancel
Save