prevent calls to UserGetter.getUser with null query

This commit is contained in:
Tim Alby 2018-09-13 17:31:35 +01:00
parent b14fe82c1c
commit 41b92d4647
2 changed files with 6 additions and 0 deletions

View file

@ -8,6 +8,7 @@ Errors = require("../Errors/Errors")
module.exports = UserGetter = module.exports = UserGetter =
getUser: (query, projection, callback = (error, user) ->) -> getUser: (query, projection, callback = (error, user) ->) ->
return callback(new Error("no query provided")) unless query?
if query?.email? if query?.email?
return callback(new Error("Don't use getUser to find user by email"), null) return callback(new Error("Don't use getUser to find user by email"), null)
if arguments.length == 2 if arguments.length == 2

View file

@ -48,6 +48,11 @@ describe "UserGetter", ->
error.should.exist error.should.exist
done() done()
it "should not allow null query", (done)->
@UserGetter.getUser null, {}, (error, user) =>
error.should.exist
done()
describe "getUserFullEmails", -> describe "getUserFullEmails", ->
it "should get user", (done)-> it "should get user", (done)->
@UserGetter.getUser = sinon.stub().callsArgWith(2, null, @fakeUser) @UserGetter.getUser = sinon.stub().callsArgWith(2, null, @fakeUser)