diff --git a/services/web/app/src/Features/Errors/Errors.js b/services/web/app/src/Features/Errors/Errors.js index f432657e29..abdf8108cd 100644 --- a/services/web/app/src/Features/Errors/Errors.js +++ b/services/web/app/src/Features/Errors/Errors.js @@ -105,15 +105,6 @@ class SAMLSessionDataMissing extends BackwardCompatibleError { } } -class SAMLUserNotFoundError extends BackwardCompatibleError { - constructor(arg) { - super(arg) - if (!this.message) { - this.message = 'user not found for SAML provider and external id' - } - } -} - class ThirdPartyIdentityExistsError extends BackwardCompatibleError { constructor(arg) { super(arg) @@ -201,7 +192,6 @@ module.exports = { NotInV2Error, SAMLIdentityExistsError, SAMLSessionDataMissing, - SAMLUserNotFoundError, SLInV2Error, ThirdPartyIdentityExistsError, ThirdPartyUserNotFoundError, diff --git a/services/web/app/src/Features/User/SAMLIdentityManager.js b/services/web/app/src/Features/User/SAMLIdentityManager.js index ecda8ee8f1..72150c4f02 100644 --- a/services/web/app/src/Features/User/SAMLIdentityManager.js +++ b/services/web/app/src/Features/User/SAMLIdentityManager.js @@ -65,16 +65,6 @@ async function _addIdentifier( } } -function _getUserQuery(providerId, externalUserId) { - externalUserId = externalUserId.toString() - providerId = providerId.toString() - const query = { - 'samlIdentifiers.externalUserId': externalUserId, - 'samlIdentifiers.providerId': providerId - } - return query -} - async function _addInstitutionEmail(userId, email, providerId) { const user = await UserGetter.promises.getUser(userId) const query = { @@ -134,18 +124,16 @@ function _sendUnlinkedEmail(primaryEmail, providerName) { } async function getUser(providerId, externalUserId) { - if (providerId == null || externalUserId == null) { + if (!providerId || !externalUserId) { throw new Error( `invalid arguments: providerId: ${providerId}, externalUserId: ${externalUserId}` ) } - providerId = providerId.toString() - externalUserId = externalUserId.toString() - const query = _getUserQuery(providerId, externalUserId) - let user = await User.findOne(query).exec() - if (!user) { - throw new Errors.SAMLUserNotFoundError() - } + const user = await User.findOne({ + 'samlIdentifiers.externalUserId': externalUserId.toString(), + 'samlIdentifiers.providerId': providerId.toString() + }).exec() + return user } diff --git a/services/web/app/src/util/promises.js b/services/web/app/src/util/promises.js index 7c96472d03..7dc36a06c3 100644 --- a/services/web/app/src/util/promises.js +++ b/services/web/app/src/util/promises.js @@ -2,6 +2,7 @@ const { promisify } = require('util') const pLimit = require('p-limit') module.exports = { + promisify, promisifyAll, promisifyMultiResult, callbackifyMultiResult, diff --git a/services/web/test/unit/src/User/SAMLIdentityManagerTests.js b/services/web/test/unit/src/User/SAMLIdentityManagerTests.js index 9d8756e57e..db8bde435a 100644 --- a/services/web/test/unit/src/User/SAMLIdentityManagerTests.js +++ b/services/web/test/unit/src/User/SAMLIdentityManagerTests.js @@ -9,8 +9,7 @@ describe('SAMLIdentityManager', function() { this.Errors = { EmailExistsError: sinon.stub(), NotFoundError: sinon.stub(), - SAMLIdentityExistsError: sinon.stub(), - SAMLUserNotFoundError: sinon.stub() + SAMLIdentityExistsError: sinon.stub() } this.user = { _id: 'user-id-1',