@accounts/server
Advanced tools
Comparing version 0.0.9 to 0.0.10-alpha.b575b352
@@ -63,6 +63,6 @@ 'use strict'; | ||
this.db = db; | ||
if (options.sendMail) { | ||
this.email = { sendMail: options.sendMail }; | ||
if (this._options.sendMail) { | ||
this.email = { sendMail: this._options.sendMail }; | ||
} else { | ||
this.email = new _email2.default(_config3.default.email); | ||
this.email = new _email2.default(this._options.email); | ||
} | ||
@@ -220,3 +220,3 @@ this.emailTemplates = _emailTemplates2.default; | ||
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(user, password) { | ||
var _ref4, username, email, id, foundUser, hash, isPasswordValid; | ||
var _ref4, username, email, id, foundUser, hash, hashAlgorithm, pass, isPasswordValid; | ||
@@ -292,10 +292,12 @@ return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
case 25: | ||
_context3.next = 27; | ||
return (0, _encryption.verifyPassword)(password, hash); | ||
hashAlgorithm = this._options.passwordHashAlgorithm; | ||
pass = hashAlgorithm ? (0, _encryption.hashPassword)(password, hashAlgorithm) : password; | ||
_context3.next = 29; | ||
return (0, _encryption.verifyPassword)(pass, hash); | ||
case 27: | ||
case 29: | ||
isPasswordValid = _context3.sent; | ||
if (isPasswordValid) { | ||
_context3.next = 30; | ||
_context3.next = 32; | ||
break; | ||
@@ -306,6 +308,6 @@ } | ||
case 30: | ||
case 32: | ||
return _context3.abrupt('return', foundUser); | ||
case 31: | ||
case 33: | ||
case 'end': | ||
@@ -539,4 +541,6 @@ return _context3.stop(); | ||
var _options = this._options, | ||
tokenSecret = _options.tokenSecret, | ||
tokenConfigs = _options.tokenConfigs; | ||
_options$tokenSecret = _options.tokenSecret, | ||
tokenSecret = _options$tokenSecret === undefined ? _config3.default.tokenSecret : _options$tokenSecret, | ||
_options$tokenConfigs = _options.tokenConfigs, | ||
tokenConfigs = _options$tokenConfigs === undefined ? _config3.default.tokenConfigs : _options$tokenConfigs; | ||
@@ -548,7 +552,7 @@ var accessToken = (0, _tokens.generateAccessToken)({ | ||
secret: tokenSecret, | ||
config: tokenConfigs.accessToken | ||
config: tokenConfigs.accessToken || {} | ||
}); | ||
var refreshToken = (0, _tokens.generateRefreshToken)({ | ||
secret: tokenSecret, | ||
config: tokenConfigs.refreshToken | ||
config: tokenConfigs.refreshToken || {} | ||
}); | ||
@@ -1100,3 +1104,3 @@ return { accessToken: accessToken, refreshToken: refreshToken }; | ||
var _ref14 = _asyncToGenerator(regeneratorRuntime.mark(function _callee13(userId, address) { | ||
var user, email, emails, token, verifyEmailUrl; | ||
var user, email, emails, token, siteUrl, verifyEmailUrl; | ||
return regeneratorRuntime.wrap(function _callee13$(_context13) { | ||
@@ -1146,4 +1150,5 @@ while (1) { | ||
case 12: | ||
verifyEmailUrl = this._options.siteUrl + '/verify-email/' + token; | ||
_context13.next = 15; | ||
siteUrl = this._options.siteUrl || _config3.default.siteUrl; | ||
verifyEmailUrl = siteUrl + '/verify-email/' + token; | ||
_context13.next = 16; | ||
return this.email.sendMail({ | ||
@@ -1156,3 +1161,3 @@ from: this.emailTemplates.verifyEmail.from ? this.emailTemplates.verifyEmail.from : this.emailTemplates.from, | ||
case 15: | ||
case 16: | ||
case 'end': | ||
@@ -1185,3 +1190,3 @@ return _context13.stop(); | ||
var _ref15 = _asyncToGenerator(regeneratorRuntime.mark(function _callee14(userId, address) { | ||
var user, token, resetPasswordUrl; | ||
var user, token, siteUrl, resetPasswordUrl; | ||
return regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
@@ -1211,4 +1216,5 @@ while (1) { | ||
case 9: | ||
resetPasswordUrl = this._options.siteUrl + '/reset-password/' + token; | ||
_context14.next = 12; | ||
siteUrl = this._options.siteUrl || _config3.default.siteUrl; | ||
resetPasswordUrl = siteUrl + '/reset-password/' + token; | ||
_context14.next = 13; | ||
return this.email.sendMail({ | ||
@@ -1221,3 +1227,3 @@ from: this.emailTemplates.resetPassword.from ? this.emailTemplates.resetPassword.from : this.emailTemplates.from, | ||
case 12: | ||
case 13: | ||
case 'end': | ||
@@ -1250,3 +1256,3 @@ return _context14.stop(); | ||
var _ref16 = _asyncToGenerator(regeneratorRuntime.mark(function _callee15(userId, address) { | ||
var user, token, enrollAccountUrl; | ||
var user, token, siteUrl, enrollAccountUrl; | ||
return regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
@@ -1276,4 +1282,5 @@ while (1) { | ||
case 9: | ||
enrollAccountUrl = this._options.siteUrl + '/enroll-account/' + token; | ||
_context15.next = 12; | ||
siteUrl = this._options.siteUrl || _config3.default.siteUrl; | ||
enrollAccountUrl = siteUrl + '/enroll-account/' + token; | ||
_context15.next = 13; | ||
return this.email.sendMail({ | ||
@@ -1286,3 +1293,3 @@ from: this.emailTemplates.enrollAccount.from ? this.emailTemplates.enrollAccount.from : this.emailTemplates.from, | ||
case 12: | ||
case 13: | ||
case 'end': | ||
@@ -1289,0 +1296,0 @@ return _context15.stop(); |
@@ -215,2 +215,3 @@ 'use strict'; | ||
}); | ||
describe('loginWithPassword - errors', function () { | ||
@@ -244,2 +245,3 @@ it('throws error if user is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee5() { | ||
}))); | ||
it('throws error if password is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee6() { | ||
@@ -272,2 +274,3 @@ var message; | ||
}))); | ||
it('throws error if user is not a string or an object', _asyncToGenerator(regeneratorRuntime.mark(function _callee7() { | ||
@@ -300,2 +303,3 @@ var message; | ||
}))); | ||
it('throws error if password is not a string', _asyncToGenerator(regeneratorRuntime.mark(function _callee8() { | ||
@@ -328,2 +332,3 @@ var message; | ||
}))); | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee9() { | ||
@@ -364,2 +369,3 @@ var message; | ||
}))); | ||
it('throws error if password not set', _asyncToGenerator(regeneratorRuntime.mark(function _callee10() { | ||
@@ -403,2 +409,3 @@ var message; | ||
}))); | ||
it('throws error if password is incorrect', _asyncToGenerator(regeneratorRuntime.mark(function _callee11() { | ||
@@ -445,2 +452,3 @@ var message; | ||
}))); | ||
it('should use custom password authenticator when specified', _asyncToGenerator(regeneratorRuntime.mark(function _callee12() { | ||
@@ -484,714 +492,745 @@ var user, authenticator, result; | ||
}))); | ||
describe('loginWithUser', function () { | ||
it('login using id', _asyncToGenerator(regeneratorRuntime.mark(function _callee13() { | ||
var hash, user, findUserById, res, _res$tokens, accessToken, refreshToken, decodedAccessToken; | ||
return regeneratorRuntime.wrap(function _callee13$(_context13) { | ||
while (1) { | ||
switch (_context13.prev = _context13.next) { | ||
case 0: | ||
hash = (0, _encryption.hashPassword)('1234567'); | ||
user = { | ||
id: '123', | ||
username: 'username', | ||
email: 'email@email.com', | ||
profile: { | ||
bio: 'bio' | ||
} | ||
}; | ||
findUserById = jest.fn(function () { | ||
it('return user with custom validation method', _asyncToGenerator(regeneratorRuntime.mark(function _callee13() { | ||
var resumeSessionValidator, user, _Accounts$createToken, accessToken; | ||
return regeneratorRuntime.wrap(function _callee13$(_context13) { | ||
while (1) { | ||
switch (_context13.prev = _context13.next) { | ||
case 0: | ||
resumeSessionValidator = jest.fn(function () { | ||
return Promise.resolve({}); | ||
}); | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
Accounts.config({ resumeSessionValidator: resumeSessionValidator }, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}); | ||
} | ||
}); | ||
Accounts.config({}, { | ||
findUserById: findUserById, | ||
findPasswordHash: function findPasswordHash() { | ||
return Promise.resolve(hash); | ||
}, | ||
createSession: function createSession() { | ||
return Promise.resolve('sessionId'); | ||
} | ||
}); | ||
_context13.next = 6; | ||
return Accounts.loginWithPassword({ id: '123' }, '1234567'); | ||
_Accounts$createToken = Accounts.createTokens('456'), accessToken = _Accounts$createToken.accessToken; | ||
_context13.next = 6; | ||
return Accounts.resumeSession(accessToken); | ||
case 6: | ||
res = _context13.sent; | ||
case 6: | ||
expect(findUserById.mock.calls[0][0]).toEqual('123'); | ||
expect(res.user).toEqual(user); | ||
_res$tokens = res.tokens, accessToken = _res$tokens.accessToken, refreshToken = _res$tokens.refreshToken; | ||
decodedAccessToken = (0, _jwtDecode2.default)(accessToken); | ||
expect(resumeSessionValidator.mock.calls.length).toBe(1); | ||
expect(decodedAccessToken.data.sessionId).toEqual('sessionId'); | ||
expect(accessToken).toBeTruthy(); | ||
expect(refreshToken).toBeTruthy(); | ||
case 14: | ||
case 'end': | ||
return _context13.stop(); | ||
} | ||
case 7: | ||
case 'end': | ||
return _context13.stop(); | ||
} | ||
}, _callee13, undefined); | ||
}))); | ||
}); | ||
describe('refreshTokens', function () { | ||
it('updates session and returns new tokens and user', _asyncToGenerator(regeneratorRuntime.mark(function _callee14() { | ||
var updateSession, user, _Accounts$createToken, accessToken, refreshToken, res; | ||
} | ||
}, _callee13, undefined); | ||
}))); | ||
return regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
while (1) { | ||
switch (_context14.prev = _context14.next) { | ||
case 0: | ||
updateSession = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
it('throw when custom validation method rejects', _asyncToGenerator(regeneratorRuntime.mark(function _callee14() { | ||
var resumeSessionValidator, user, _Accounts$createToken2, accessToken; | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
updateSession: updateSession | ||
}); | ||
_Accounts$createToken = Accounts.createTokens('456'), accessToken = _Accounts$createToken.accessToken, refreshToken = _Accounts$createToken.refreshToken; | ||
return regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
while (1) { | ||
switch (_context14.prev = _context14.next) { | ||
case 0: | ||
resumeSessionValidator = jest.fn(function () { | ||
return Promise.reject('Custom session error'); | ||
}); | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
Accounts.createTokens = function () { | ||
return { | ||
accessToken: 'newAccessToken', | ||
refreshToken: 'newRefreshToken' | ||
}; | ||
}; | ||
_context14.next = 7; | ||
return Accounts.refreshTokens(accessToken, refreshToken, 'ip', 'user agent'); | ||
Accounts.config({ resumeSessionValidator: resumeSessionValidator }, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
} | ||
}); | ||
case 7: | ||
res = _context14.sent; | ||
_Accounts$createToken2 = Accounts.createTokens('456'), accessToken = _Accounts$createToken2.accessToken; | ||
_context14.prev = 4; | ||
_context14.next = 7; | ||
return Accounts.resumeSession(accessToken); | ||
expect(updateSession.mock.calls[0]).toEqual(['456', 'ip', 'user agent']); | ||
expect(res.user).toEqual({ | ||
userId: '123', | ||
username: 'username' | ||
}); | ||
case 7: | ||
throw new Error(); | ||
case 10: | ||
case 'end': | ||
return _context14.stop(); | ||
} | ||
case 10: | ||
_context14.prev = 10; | ||
_context14.t0 = _context14['catch'](4); | ||
expect(resumeSessionValidator.mock.calls.length).toBe(1); | ||
expect(_context14.t0.message).toEqual('Custom session error'); | ||
case 14: | ||
case 'end': | ||
return _context14.stop(); | ||
} | ||
}, _callee14, undefined); | ||
}))); | ||
} | ||
}, _callee14, undefined, [[4, 10]]); | ||
}))); | ||
}); | ||
it('requires access and refresh tokens', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() { | ||
return regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
case 0: | ||
Accounts.config({}, {}); | ||
_context15.prev = 1; | ||
_context15.next = 4; | ||
return Accounts.refreshTokens(); | ||
describe('loginWithUser', function () { | ||
it('login using id', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() { | ||
var hash, user, findUserById, res, _res$tokens, accessToken, refreshToken, decodedAccessToken; | ||
case 4: | ||
throw new Error(); | ||
return regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
case 0: | ||
hash = (0, _encryption.bcryptPassword)('1234567'); | ||
user = { | ||
id: '123', | ||
username: 'username', | ||
email: 'email@email.com', | ||
profile: { | ||
bio: 'bio' | ||
} | ||
}; | ||
findUserById = jest.fn(function () { | ||
return Promise.resolve(user); | ||
}); | ||
case 7: | ||
_context15.prev = 7; | ||
_context15.t0 = _context15['catch'](1); | ||
Accounts.config({}, { | ||
findUserById: findUserById, | ||
findPasswordHash: function findPasswordHash() { | ||
return Promise.resolve(hash); | ||
}, | ||
createSession: function createSession() { | ||
return Promise.resolve('sessionId'); | ||
} | ||
}); | ||
_context15.next = 6; | ||
return Accounts.loginWithPassword({ id: '123' }, '1234567'); | ||
expect(_context15.t0.message).toEqual('An accessToken and refreshToken are required'); | ||
case 6: | ||
res = _context15.sent; | ||
case 10: | ||
case 'end': | ||
return _context15.stop(); | ||
} | ||
expect(findUserById.mock.calls[0][0]).toEqual('123'); | ||
expect(res.user).toEqual(user); | ||
_res$tokens = res.tokens, accessToken = _res$tokens.accessToken, refreshToken = _res$tokens.refreshToken; | ||
decodedAccessToken = (0, _jwtDecode2.default)(accessToken); | ||
expect(decodedAccessToken.data.sessionId).toEqual('sessionId'); | ||
expect(accessToken).toBeTruthy(); | ||
expect(refreshToken).toBeTruthy(); | ||
case 14: | ||
case 'end': | ||
return _context15.stop(); | ||
} | ||
}, _callee15, undefined, [[1, 7]]); | ||
}))); | ||
it('throws error if tokens are not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() { | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
case 0: | ||
Accounts.config({}, {}); | ||
_context16.prev = 1; | ||
_context16.next = 4; | ||
return Accounts.refreshTokens('bad access token', 'bad refresh token'); | ||
} | ||
}, _callee15, undefined); | ||
}))); | ||
case 4: | ||
throw new Error(); | ||
it('supports hashed password from the client', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() { | ||
var hash, user, findUserById, res, _res$tokens2, accessToken, refreshToken, decodedAccessToken; | ||
case 7: | ||
_context16.prev = 7; | ||
_context16.t0 = _context16['catch'](1); | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
case 0: | ||
hash = (0, _encryption.bcryptPassword)((0, _encryption.hashPassword)('1234567', 'sha256')); | ||
user = { | ||
id: '123', | ||
username: 'username', | ||
email: 'email@email.com', | ||
profile: { | ||
bio: 'bio' | ||
} | ||
}; | ||
findUserById = jest.fn(function () { | ||
return Promise.resolve(user); | ||
}); | ||
expect(_context16.t0.message).toEqual('Tokens are not valid'); | ||
Accounts.config({ | ||
passwordHashAlgorithm: 'sha256' | ||
}, { | ||
findUserById: findUserById, | ||
findPasswordHash: function findPasswordHash() { | ||
return Promise.resolve(hash); | ||
}, | ||
createSession: function createSession() { | ||
return Promise.resolve('sessionId'); | ||
} | ||
}); | ||
case 10: | ||
case 'end': | ||
return _context16.stop(); | ||
} | ||
} | ||
}, _callee16, undefined, [[1, 7]]); | ||
}))); | ||
it('throws error if session not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() { | ||
var _Accounts$createToken2, accessToken, refreshToken; | ||
_context16.next = 6; | ||
return Accounts.loginWithPassword({ id: '123' }, '1234567'); | ||
return regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
while (1) { | ||
switch (_context17.prev = _context17.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context17.prev = 1; | ||
_Accounts$createToken2 = Accounts.createTokens(), accessToken = _Accounts$createToken2.accessToken, refreshToken = _Accounts$createToken2.refreshToken; | ||
_context17.next = 5; | ||
return Accounts.refreshTokens(accessToken, refreshToken); | ||
case 6: | ||
res = _context16.sent; | ||
case 5: | ||
throw new Error(); | ||
expect(findUserById.mock.calls[0][0]).toEqual('123'); | ||
expect(res.user).toEqual(user); | ||
case 8: | ||
_context17.prev = 8; | ||
_context17.t0 = _context17['catch'](1); | ||
_res$tokens2 = res.tokens, accessToken = _res$tokens2.accessToken, refreshToken = _res$tokens2.refreshToken; | ||
decodedAccessToken = (0, _jwtDecode2.default)(accessToken); | ||
expect(_context17.t0.message).toEqual('Session not found'); | ||
expect(decodedAccessToken.data.sessionId).toEqual('sessionId'); | ||
expect(accessToken).toBeTruthy(); | ||
expect(refreshToken).toBeTruthy(); | ||
case 11: | ||
case 'end': | ||
return _context17.stop(); | ||
} | ||
case 14: | ||
case 'end': | ||
return _context16.stop(); | ||
} | ||
}, _callee17, undefined, [[1, 8]]); | ||
}))); | ||
it('throws error if session not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
var _Accounts$createToken3, accessToken, refreshToken; | ||
} | ||
}, _callee16, undefined); | ||
}))); | ||
}); | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
while (1) { | ||
switch (_context18.prev = _context18.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
valid: false | ||
}); | ||
} | ||
}); | ||
_context18.prev = 1; | ||
_Accounts$createToken3 = Accounts.createTokens(), accessToken = _Accounts$createToken3.accessToken, refreshToken = _Accounts$createToken3.refreshToken; | ||
_context18.next = 5; | ||
return Accounts.refreshTokens(accessToken, refreshToken); | ||
describe('refreshTokens', function () { | ||
it('updates session and returns new tokens and user', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() { | ||
var updateSession, user, _Accounts$createToken3, accessToken, refreshToken, res; | ||
case 5: | ||
throw new Error(); | ||
return regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
while (1) { | ||
switch (_context17.prev = _context17.next) { | ||
case 0: | ||
updateSession = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
case 8: | ||
_context18.prev = 8; | ||
_context18.t0 = _context18['catch'](1); | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
updateSession: updateSession | ||
}); | ||
_Accounts$createToken3 = Accounts.createTokens('456'), accessToken = _Accounts$createToken3.accessToken, refreshToken = _Accounts$createToken3.refreshToken; | ||
expect(_context18.t0.message).toEqual('Session is no longer valid'); | ||
Accounts.createTokens = function () { | ||
return { | ||
accessToken: 'newAccessToken', | ||
refreshToken: 'newRefreshToken' | ||
}; | ||
}; | ||
_context17.next = 7; | ||
return Accounts.refreshTokens(accessToken, refreshToken, 'ip', 'user agent'); | ||
case 11: | ||
case 'end': | ||
return _context18.stop(); | ||
} | ||
case 7: | ||
res = _context17.sent; | ||
expect(updateSession.mock.calls[0]).toEqual(['456', 'ip', 'user agent']); | ||
expect(res.user).toEqual({ | ||
userId: '123', | ||
username: 'username' | ||
}); | ||
case 10: | ||
case 'end': | ||
return _context17.stop(); | ||
} | ||
}, _callee18, undefined, [[1, 8]]); | ||
}))); | ||
}); | ||
describe('logout', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() { | ||
var _Accounts$createToken4, accessToken, message; | ||
} | ||
}, _callee17, undefined); | ||
}))); | ||
return regeneratorRuntime.wrap(function _callee19$(_context19) { | ||
while (1) { | ||
switch (_context19.prev = _context19.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context19.prev = 1; | ||
_Accounts$createToken4 = Accounts.createTokens('456'), accessToken = _Accounts$createToken4.accessToken; | ||
_context19.next = 5; | ||
return Accounts.logout(accessToken); | ||
it('requires access and refresh tokens', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
while (1) { | ||
switch (_context18.prev = _context18.next) { | ||
case 0: | ||
Accounts.config({}, {}); | ||
_context18.prev = 1; | ||
_context18.next = 4; | ||
return Accounts.refreshTokens(); | ||
case 5: | ||
throw new Error(); | ||
case 4: | ||
throw new Error(); | ||
case 8: | ||
_context19.prev = 8; | ||
_context19.t0 = _context19['catch'](1); | ||
message = _context19.t0.message; | ||
case 7: | ||
_context18.prev = 7; | ||
_context18.t0 = _context18['catch'](1); | ||
expect(message).toEqual('User not found'); | ||
expect(_context18.t0.message).toEqual('An accessToken and refreshToken are required'); | ||
case 12: | ||
case 'end': | ||
return _context19.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context18.stop(); | ||
} | ||
}, _callee19, undefined, [[1, 8]]); | ||
}))); | ||
} | ||
}, _callee18, undefined, [[1, 7]]); | ||
}))); | ||
it('throws error if tokens are not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() { | ||
return regeneratorRuntime.wrap(function _callee19$(_context19) { | ||
while (1) { | ||
switch (_context19.prev = _context19.next) { | ||
case 0: | ||
Accounts.config({}, {}); | ||
_context19.prev = 1; | ||
_context19.next = 4; | ||
return Accounts.refreshTokens('bad access token', 'bad refresh token'); | ||
it('invalidates session', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
var invalidateSession, user, _Accounts$createToken5, accessToken; | ||
case 4: | ||
throw new Error(); | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
while (1) { | ||
switch (_context20.prev = _context20.next) { | ||
case 0: | ||
invalidateSession = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
case 7: | ||
_context19.prev = 7; | ||
_context19.t0 = _context19['catch'](1); | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
invalidateSession: invalidateSession | ||
}); | ||
_Accounts$createToken5 = Accounts.createTokens('456'), accessToken = _Accounts$createToken5.accessToken; | ||
_context20.next = 6; | ||
return Accounts.logout(accessToken); | ||
expect(_context19.t0.message).toEqual('Tokens are not valid'); | ||
case 6: | ||
expect(invalidateSession.mock.calls[0]).toEqual(['456']); | ||
case 7: | ||
case 'end': | ||
return _context20.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context19.stop(); | ||
} | ||
}, _callee20, undefined); | ||
}))); | ||
}); | ||
describe('findSessionByAccessToken', function () { | ||
it('requires access token', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() { | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
while (1) { | ||
switch (_context21.prev = _context21.next) { | ||
case 0: | ||
Accounts.config({}, {}); | ||
_context21.prev = 1; | ||
_context21.next = 4; | ||
return Accounts.logout(); | ||
} | ||
}, _callee19, undefined, [[1, 7]]); | ||
}))); | ||
it('throws error if session not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
var _Accounts$createToken4, accessToken, refreshToken; | ||
case 4: | ||
throw new Error(); | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
while (1) { | ||
switch (_context20.prev = _context20.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context20.prev = 1; | ||
_Accounts$createToken4 = Accounts.createTokens(), accessToken = _Accounts$createToken4.accessToken, refreshToken = _Accounts$createToken4.refreshToken; | ||
_context20.next = 5; | ||
return Accounts.refreshTokens(accessToken, refreshToken); | ||
case 7: | ||
_context21.prev = 7; | ||
_context21.t0 = _context21['catch'](1); | ||
case 5: | ||
throw new Error(); | ||
expect(_context21.t0.message).toEqual('An accessToken is required'); | ||
case 8: | ||
_context20.prev = 8; | ||
_context20.t0 = _context20['catch'](1); | ||
case 10: | ||
case 'end': | ||
return _context21.stop(); | ||
} | ||
expect(_context20.t0.message).toEqual('Session not found'); | ||
case 11: | ||
case 'end': | ||
return _context20.stop(); | ||
} | ||
}, _callee21, undefined, [[1, 7]]); | ||
}))); | ||
it('throws error if tokens are not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() { | ||
return regeneratorRuntime.wrap(function _callee22$(_context22) { | ||
while (1) { | ||
switch (_context22.prev = _context22.next) { | ||
case 0: | ||
Accounts.config({}, {}); | ||
_context22.prev = 1; | ||
_context22.next = 4; | ||
return Accounts.logout('bad access token'); | ||
} | ||
}, _callee20, undefined, [[1, 8]]); | ||
}))); | ||
it('throws error if session not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() { | ||
var _Accounts$createToken5, accessToken, refreshToken; | ||
case 4: | ||
throw new Error(); | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
while (1) { | ||
switch (_context21.prev = _context21.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
valid: false | ||
}); | ||
} | ||
}); | ||
_context21.prev = 1; | ||
_Accounts$createToken5 = Accounts.createTokens(), accessToken = _Accounts$createToken5.accessToken, refreshToken = _Accounts$createToken5.refreshToken; | ||
_context21.next = 5; | ||
return Accounts.refreshTokens(accessToken, refreshToken); | ||
case 7: | ||
_context22.prev = 7; | ||
_context22.t0 = _context22['catch'](1); | ||
case 5: | ||
throw new Error(); | ||
expect(_context22.t0.message).toEqual('Tokens are not valid'); | ||
case 8: | ||
_context21.prev = 8; | ||
_context21.t0 = _context21['catch'](1); | ||
case 10: | ||
case 'end': | ||
return _context22.stop(); | ||
} | ||
expect(_context21.t0.message).toEqual('Session is no longer valid'); | ||
case 11: | ||
case 'end': | ||
return _context21.stop(); | ||
} | ||
}, _callee22, undefined, [[1, 7]]); | ||
}))); | ||
it('throws error if session not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() { | ||
var _Accounts$createToken6, accessToken; | ||
} | ||
}, _callee21, undefined, [[1, 8]]); | ||
}))); | ||
}); | ||
return regeneratorRuntime.wrap(function _callee23$(_context23) { | ||
while (1) { | ||
switch (_context23.prev = _context23.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context23.prev = 1; | ||
_Accounts$createToken6 = Accounts.createTokens(), accessToken = _Accounts$createToken6.accessToken; | ||
_context23.next = 5; | ||
return Accounts.logout(accessToken); | ||
describe('logout', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() { | ||
var _Accounts$createToken6, accessToken, message; | ||
case 5: | ||
throw new Error(); | ||
return regeneratorRuntime.wrap(function _callee22$(_context22) { | ||
while (1) { | ||
switch (_context22.prev = _context22.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context22.prev = 1; | ||
_Accounts$createToken6 = Accounts.createTokens('456'), accessToken = _Accounts$createToken6.accessToken; | ||
_context22.next = 5; | ||
return Accounts.logout(accessToken); | ||
case 8: | ||
_context23.prev = 8; | ||
_context23.t0 = _context23['catch'](1); | ||
case 5: | ||
throw new Error(); | ||
expect(_context23.t0.message).toEqual('Session not found'); | ||
case 8: | ||
_context22.prev = 8; | ||
_context22.t0 = _context22['catch'](1); | ||
message = _context22.t0.message; | ||
case 11: | ||
case 'end': | ||
return _context23.stop(); | ||
} | ||
expect(message).toEqual('User not found'); | ||
case 12: | ||
case 'end': | ||
return _context22.stop(); | ||
} | ||
}, _callee23, undefined, [[1, 8]]); | ||
}))); | ||
it('throws error if session not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee24() { | ||
var _Accounts$createToken7, accessToken; | ||
} | ||
}, _callee22, undefined, [[1, 8]]); | ||
}))); | ||
return regeneratorRuntime.wrap(function _callee24$(_context24) { | ||
while (1) { | ||
switch (_context24.prev = _context24.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
valid: false | ||
}); | ||
} | ||
}); | ||
_context24.prev = 1; | ||
_Accounts$createToken7 = Accounts.createTokens(), accessToken = _Accounts$createToken7.accessToken; | ||
_context24.next = 5; | ||
return Accounts.logout(accessToken); | ||
it('invalidates session', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() { | ||
var invalidateSession, user, _Accounts$createToken7, accessToken; | ||
case 5: | ||
throw new Error(); | ||
return regeneratorRuntime.wrap(function _callee23$(_context23) { | ||
while (1) { | ||
switch (_context23.prev = _context23.next) { | ||
case 0: | ||
invalidateSession = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
case 8: | ||
_context24.prev = 8; | ||
_context24.t0 = _context24['catch'](1); | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
invalidateSession: invalidateSession | ||
}); | ||
_Accounts$createToken7 = Accounts.createTokens('456'), accessToken = _Accounts$createToken7.accessToken; | ||
_context23.next = 6; | ||
return Accounts.logout(accessToken); | ||
expect(_context24.t0.message).toEqual('Session is no longer valid'); | ||
case 6: | ||
expect(invalidateSession.mock.calls[0]).toEqual(['456']); | ||
case 11: | ||
case 'end': | ||
return _context24.stop(); | ||
} | ||
case 7: | ||
case 'end': | ||
return _context23.stop(); | ||
} | ||
}, _callee24, undefined, [[1, 8]]); | ||
}))); | ||
}); | ||
} | ||
}, _callee23, undefined); | ||
}))); | ||
}); | ||
describe('findUserByEmail', function () { | ||
it('call this.db.findUserByEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee25() { | ||
var findUserByEmail, user; | ||
return regeneratorRuntime.wrap(function _callee25$(_context25) { | ||
while (1) { | ||
switch (_context25.prev = _context25.next) { | ||
case 0: | ||
findUserByEmail = jest.fn(function () { | ||
return Promise.resolve('user'); | ||
}); | ||
describe('findSessionByAccessToken', function () { | ||
it('requires access token', _asyncToGenerator(regeneratorRuntime.mark(function _callee24() { | ||
return regeneratorRuntime.wrap(function _callee24$(_context24) { | ||
while (1) { | ||
switch (_context24.prev = _context24.next) { | ||
case 0: | ||
Accounts.config({}, {}); | ||
_context24.prev = 1; | ||
_context24.next = 4; | ||
return Accounts.logout(); | ||
Accounts.config({}, { findUserByEmail: findUserByEmail }); | ||
_context25.next = 4; | ||
return Accounts.findUserByEmail('email'); | ||
case 4: | ||
throw new Error(); | ||
case 4: | ||
user = _context25.sent; | ||
case 7: | ||
_context24.prev = 7; | ||
_context24.t0 = _context24['catch'](1); | ||
expect(findUserByEmail.mock.calls[0]).toEqual(['email']); | ||
expect(user).toEqual('user'); | ||
expect(_context24.t0.message).toEqual('An accessToken is required'); | ||
case 7: | ||
case 'end': | ||
return _context25.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context24.stop(); | ||
} | ||
}, _callee25, undefined); | ||
}))); | ||
}); | ||
} | ||
}, _callee24, undefined, [[1, 7]]); | ||
}))); | ||
it('throws error if tokens are not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee25() { | ||
return regeneratorRuntime.wrap(function _callee25$(_context25) { | ||
while (1) { | ||
switch (_context25.prev = _context25.next) { | ||
case 0: | ||
Accounts.config({}, {}); | ||
_context25.prev = 1; | ||
_context25.next = 4; | ||
return Accounts.logout('bad access token'); | ||
describe('findUserByUsername', function () { | ||
it('call this.db.findUserByUsername', _asyncToGenerator(regeneratorRuntime.mark(function _callee26() { | ||
var findUserByUsername, user; | ||
return regeneratorRuntime.wrap(function _callee26$(_context26) { | ||
while (1) { | ||
switch (_context26.prev = _context26.next) { | ||
case 0: | ||
findUserByUsername = jest.fn(function () { | ||
return Promise.resolve('user'); | ||
}); | ||
case 4: | ||
throw new Error(); | ||
Accounts.config({}, { findUserByUsername: findUserByUsername }); | ||
_context26.next = 4; | ||
return Accounts.findUserByUsername('username'); | ||
case 7: | ||
_context25.prev = 7; | ||
_context25.t0 = _context25['catch'](1); | ||
case 4: | ||
user = _context26.sent; | ||
expect(_context25.t0.message).toEqual('Tokens are not valid'); | ||
expect(findUserByUsername.mock.calls[0]).toEqual(['username']); | ||
expect(user).toEqual('user'); | ||
case 7: | ||
case 'end': | ||
return _context26.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context25.stop(); | ||
} | ||
}, _callee26, undefined); | ||
}))); | ||
}); | ||
} | ||
}, _callee25, undefined, [[1, 7]]); | ||
}))); | ||
it('throws error if session not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee26() { | ||
var _Accounts$createToken8, accessToken; | ||
describe('findUserById', function () { | ||
it('call this.db.findUserById', _asyncToGenerator(regeneratorRuntime.mark(function _callee27() { | ||
var findUserById, user; | ||
return regeneratorRuntime.wrap(function _callee27$(_context27) { | ||
while (1) { | ||
switch (_context27.prev = _context27.next) { | ||
case 0: | ||
findUserById = jest.fn(function () { | ||
return Promise.resolve('user'); | ||
}); | ||
return regeneratorRuntime.wrap(function _callee26$(_context26) { | ||
while (1) { | ||
switch (_context26.prev = _context26.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context26.prev = 1; | ||
_Accounts$createToken8 = Accounts.createTokens(), accessToken = _Accounts$createToken8.accessToken; | ||
_context26.next = 5; | ||
return Accounts.logout(accessToken); | ||
Accounts.config({}, { findUserById: findUserById }); | ||
_context27.next = 4; | ||
return Accounts.findUserById('id'); | ||
case 5: | ||
throw new Error(); | ||
case 4: | ||
user = _context27.sent; | ||
case 8: | ||
_context26.prev = 8; | ||
_context26.t0 = _context26['catch'](1); | ||
expect(findUserById.mock.calls[0]).toEqual(['id']); | ||
expect(user).toEqual('user'); | ||
expect(_context26.t0.message).toEqual('Session not found'); | ||
case 7: | ||
case 'end': | ||
return _context27.stop(); | ||
} | ||
case 11: | ||
case 'end': | ||
return _context26.stop(); | ||
} | ||
}, _callee27, undefined); | ||
}))); | ||
}); | ||
} | ||
}, _callee26, undefined, [[1, 8]]); | ||
}))); | ||
it('throws error if session not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee27() { | ||
var _Accounts$createToken9, accessToken; | ||
describe('addEmail', function () { | ||
it('call this.db.addEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee28() { | ||
var addEmail; | ||
return regeneratorRuntime.wrap(function _callee28$(_context28) { | ||
while (1) { | ||
switch (_context28.prev = _context28.next) { | ||
case 0: | ||
addEmail = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
return regeneratorRuntime.wrap(function _callee27$(_context27) { | ||
while (1) { | ||
switch (_context27.prev = _context27.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
valid: false | ||
}); | ||
} | ||
}); | ||
_context27.prev = 1; | ||
_Accounts$createToken9 = Accounts.createTokens(), accessToken = _Accounts$createToken9.accessToken; | ||
_context27.next = 5; | ||
return Accounts.logout(accessToken); | ||
Accounts.config({}, { addEmail: addEmail }); | ||
_context28.next = 4; | ||
return Accounts.addEmail('id', 'email', true); | ||
case 5: | ||
throw new Error(); | ||
case 4: | ||
expect(addEmail.mock.calls[0]).toEqual(['id', 'email', true]); | ||
case 8: | ||
_context27.prev = 8; | ||
_context27.t0 = _context27['catch'](1); | ||
case 5: | ||
case 'end': | ||
return _context28.stop(); | ||
} | ||
expect(_context27.t0.message).toEqual('Session is no longer valid'); | ||
case 11: | ||
case 'end': | ||
return _context27.stop(); | ||
} | ||
}, _callee28, undefined); | ||
}))); | ||
}); | ||
} | ||
}, _callee27, undefined, [[1, 8]]); | ||
}))); | ||
}); | ||
describe('removeEmail', function () { | ||
it('call this.db.removeEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee29() { | ||
var removeEmail; | ||
return regeneratorRuntime.wrap(function _callee29$(_context29) { | ||
while (1) { | ||
switch (_context29.prev = _context29.next) { | ||
case 0: | ||
removeEmail = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
describe('findUserByEmail', function () { | ||
it('call this.db.findUserByEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee28() { | ||
var findUserByEmail, user; | ||
return regeneratorRuntime.wrap(function _callee28$(_context28) { | ||
while (1) { | ||
switch (_context28.prev = _context28.next) { | ||
case 0: | ||
findUserByEmail = jest.fn(function () { | ||
return Promise.resolve('user'); | ||
}); | ||
Accounts.config({}, { removeEmail: removeEmail }); | ||
_context29.next = 4; | ||
return Accounts.removeEmail('id', 'email'); | ||
Accounts.config({}, { findUserByEmail: findUserByEmail }); | ||
_context28.next = 4; | ||
return Accounts.findUserByEmail('email'); | ||
case 4: | ||
expect(removeEmail.mock.calls[0]).toEqual(['id', 'email']); | ||
case 4: | ||
user = _context28.sent; | ||
case 5: | ||
case 'end': | ||
return _context29.stop(); | ||
} | ||
expect(findUserByEmail.mock.calls[0]).toEqual(['email']); | ||
expect(user).toEqual('user'); | ||
case 7: | ||
case 'end': | ||
return _context28.stop(); | ||
} | ||
}, _callee29, undefined); | ||
}))); | ||
}); | ||
} | ||
}, _callee28, undefined); | ||
}))); | ||
}); | ||
describe('resumeSession', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee30() { | ||
var _Accounts$createToken8, accessToken, message; | ||
describe('findUserByUsername', function () { | ||
it('call this.db.findUserByUsername', _asyncToGenerator(regeneratorRuntime.mark(function _callee29() { | ||
var findUserByUsername, user; | ||
return regeneratorRuntime.wrap(function _callee29$(_context29) { | ||
while (1) { | ||
switch (_context29.prev = _context29.next) { | ||
case 0: | ||
findUserByUsername = jest.fn(function () { | ||
return Promise.resolve('user'); | ||
}); | ||
return regeneratorRuntime.wrap(function _callee30$(_context30) { | ||
while (1) { | ||
switch (_context30.prev = _context30.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context30.prev = 1; | ||
_Accounts$createToken8 = Accounts.createTokens('456'), accessToken = _Accounts$createToken8.accessToken; | ||
_context30.next = 5; | ||
return Accounts.resumeSession(accessToken); | ||
Accounts.config({}, { findUserByUsername: findUserByUsername }); | ||
_context29.next = 4; | ||
return Accounts.findUserByUsername('username'); | ||
case 5: | ||
throw new Error(); | ||
case 4: | ||
user = _context29.sent; | ||
case 8: | ||
_context30.prev = 8; | ||
_context30.t0 = _context30['catch'](1); | ||
message = _context30.t0.message; | ||
expect(findUserByUsername.mock.calls[0]).toEqual(['username']); | ||
expect(user).toEqual('user'); | ||
expect(message).toEqual('User not found'); | ||
case 12: | ||
case 'end': | ||
return _context30.stop(); | ||
} | ||
case 7: | ||
case 'end': | ||
return _context29.stop(); | ||
} | ||
}, _callee30, undefined, [[1, 8]]); | ||
}))); | ||
} | ||
}, _callee29, undefined); | ||
}))); | ||
}); | ||
it('return false if session is not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee31() { | ||
var user, _Accounts$createToken9, accessToken, ret; | ||
describe('findUserById', function () { | ||
it('call this.db.findUserById', _asyncToGenerator(regeneratorRuntime.mark(function _callee30() { | ||
var findUserById, user; | ||
return regeneratorRuntime.wrap(function _callee30$(_context30) { | ||
while (1) { | ||
switch (_context30.prev = _context30.next) { | ||
case 0: | ||
findUserById = jest.fn(function () { | ||
return Promise.resolve('user'); | ||
}); | ||
return regeneratorRuntime.wrap(function _callee31$(_context31) { | ||
while (1) { | ||
switch (_context31.prev = _context31.next) { | ||
case 0: | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
Accounts.config({}, { findUserById: findUserById }); | ||
_context30.next = 4; | ||
return Accounts.findUserById('id'); | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: false, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
} | ||
}); | ||
_Accounts$createToken9 = Accounts.createTokens('456'), accessToken = _Accounts$createToken9.accessToken; | ||
_context31.next = 5; | ||
return Accounts.resumeSession(accessToken); | ||
case 4: | ||
user = _context30.sent; | ||
case 5: | ||
ret = _context31.sent; | ||
expect(findUserById.mock.calls[0]).toEqual(['id']); | ||
expect(user).toEqual('user'); | ||
expect(ret).not.toBeTruthy(); | ||
case 7: | ||
case 'end': | ||
return _context31.stop(); | ||
} | ||
case 7: | ||
case 'end': | ||
return _context30.stop(); | ||
} | ||
}, _callee31, undefined); | ||
}))); | ||
} | ||
}, _callee30, undefined); | ||
}))); | ||
}); | ||
it('return user', _asyncToGenerator(regeneratorRuntime.mark(function _callee32() { | ||
var user, _Accounts$createToken10, accessToken, foundUser; | ||
describe('addEmail', function () { | ||
it('call this.db.addEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee31() { | ||
var addEmail; | ||
return regeneratorRuntime.wrap(function _callee31$(_context31) { | ||
while (1) { | ||
switch (_context31.prev = _context31.next) { | ||
case 0: | ||
addEmail = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
return regeneratorRuntime.wrap(function _callee32$(_context32) { | ||
while (1) { | ||
switch (_context32.prev = _context32.next) { | ||
case 0: | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
Accounts.config({}, { addEmail: addEmail }); | ||
_context31.next = 4; | ||
return Accounts.addEmail('id', 'email', true); | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
} | ||
}); | ||
_Accounts$createToken10 = Accounts.createTokens('456'), accessToken = _Accounts$createToken10.accessToken; | ||
_context32.next = 5; | ||
return Accounts.resumeSession(accessToken); | ||
case 4: | ||
expect(addEmail.mock.calls[0]).toEqual(['id', 'email', true]); | ||
case 5: | ||
foundUser = _context32.sent; | ||
case 5: | ||
case 'end': | ||
return _context31.stop(); | ||
} | ||
} | ||
}, _callee31, undefined); | ||
}))); | ||
}); | ||
expect(foundUser).toEqual(user); | ||
describe('removeEmail', function () { | ||
it('call this.db.removeEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee32() { | ||
var removeEmail; | ||
return regeneratorRuntime.wrap(function _callee32$(_context32) { | ||
while (1) { | ||
switch (_context32.prev = _context32.next) { | ||
case 0: | ||
removeEmail = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
case 7: | ||
case 'end': | ||
return _context32.stop(); | ||
} | ||
Accounts.config({}, { removeEmail: removeEmail }); | ||
_context32.next = 4; | ||
return Accounts.removeEmail('id', 'email'); | ||
case 4: | ||
expect(removeEmail.mock.calls[0]).toEqual(['id', 'email']); | ||
case 5: | ||
case 'end': | ||
return _context32.stop(); | ||
} | ||
}, _callee32, undefined); | ||
}))); | ||
}); | ||
} | ||
}, _callee32, undefined); | ||
}))); | ||
}); | ||
it('return user with custom validation method', _asyncToGenerator(regeneratorRuntime.mark(function _callee33() { | ||
var resumeSessionValidator, user, _Accounts$createToken11, accessToken; | ||
describe('resumeSession', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee33() { | ||
var _Accounts$createToken10, accessToken, message; | ||
@@ -1202,5 +1241,44 @@ return regeneratorRuntime.wrap(function _callee33$(_context33) { | ||
case 0: | ||
resumeSessionValidator = jest.fn(function () { | ||
return Promise.resolve({}); | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
userId: '123' | ||
}); | ||
}, | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context33.prev = 1; | ||
_Accounts$createToken10 = Accounts.createTokens('456'), accessToken = _Accounts$createToken10.accessToken; | ||
_context33.next = 5; | ||
return Accounts.resumeSession(accessToken); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context33.prev = 8; | ||
_context33.t0 = _context33['catch'](1); | ||
message = _context33.t0.message; | ||
expect(message).toEqual('User not found'); | ||
case 12: | ||
case 'end': | ||
return _context33.stop(); | ||
} | ||
} | ||
}, _callee33, undefined, [[1, 8]]); | ||
}))); | ||
it('return false if session is not valid', _asyncToGenerator(regeneratorRuntime.mark(function _callee34() { | ||
var user, _Accounts$createToken11, accessToken, ret; | ||
return regeneratorRuntime.wrap(function _callee34$(_context34) { | ||
while (1) { | ||
switch (_context34.prev = _context34.next) { | ||
case 0: | ||
user = { | ||
@@ -1211,7 +1289,7 @@ userId: '123', | ||
Accounts.config({ resumeSessionValidator: resumeSessionValidator }, { | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
return Promise.resolve({ | ||
sessionId: '456', | ||
valid: true, | ||
valid: false, | ||
userId: '123' | ||
@@ -1224,29 +1302,26 @@ }); | ||
}); | ||
_Accounts$createToken11 = Accounts.createTokens('456'), accessToken = _Accounts$createToken11.accessToken; | ||
_context33.next = 6; | ||
_context34.next = 5; | ||
return Accounts.resumeSession(accessToken); | ||
case 6: | ||
case 5: | ||
ret = _context34.sent; | ||
expect(resumeSessionValidator.mock.calls.length).toBe(1); | ||
expect(ret).not.toBeTruthy(); | ||
case 7: | ||
case 'end': | ||
return _context33.stop(); | ||
return _context34.stop(); | ||
} | ||
} | ||
}, _callee33, undefined); | ||
}, _callee34, undefined); | ||
}))); | ||
it('throw when custom validation method rejects', _asyncToGenerator(regeneratorRuntime.mark(function _callee34() { | ||
var resumeSessionValidator, user, _Accounts$createToken12, accessToken; | ||
it('return user', _asyncToGenerator(regeneratorRuntime.mark(function _callee35() { | ||
var user, _Accounts$createToken12, accessToken, foundUser; | ||
return regeneratorRuntime.wrap(function _callee34$(_context34) { | ||
return regeneratorRuntime.wrap(function _callee35$(_context35) { | ||
while (1) { | ||
switch (_context34.prev = _context34.next) { | ||
switch (_context35.prev = _context35.next) { | ||
case 0: | ||
resumeSessionValidator = jest.fn(function () { | ||
return Promise.reject('Custom session error'); | ||
}); | ||
user = { | ||
@@ -1257,3 +1332,3 @@ userId: '123', | ||
Accounts.config({ resumeSessionValidator: resumeSessionValidator }, { | ||
Accounts.config({}, { | ||
findSessionById: function findSessionById() { | ||
@@ -1270,433 +1345,426 @@ return Promise.resolve({ | ||
}); | ||
_Accounts$createToken12 = Accounts.createTokens('456'), accessToken = _Accounts$createToken12.accessToken; | ||
_context34.prev = 4; | ||
_context34.next = 7; | ||
_context35.next = 5; | ||
return Accounts.resumeSession(accessToken); | ||
case 7: | ||
throw new Error(); | ||
case 5: | ||
foundUser = _context35.sent; | ||
case 10: | ||
_context34.prev = 10; | ||
_context34.t0 = _context34['catch'](4); | ||
expect(foundUser).toEqual(user); | ||
expect(resumeSessionValidator.mock.calls.length).toBe(1); | ||
expect(_context34.t0.message).toEqual('Custom session error'); | ||
case 14: | ||
case 7: | ||
case 'end': | ||
return _context34.stop(); | ||
return _context35.stop(); | ||
} | ||
} | ||
}, _callee34, undefined, [[4, 10]]); | ||
}, _callee35, undefined); | ||
}))); | ||
}); | ||
describe('setProfile', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee35() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee35$(_context35) { | ||
while (1) { | ||
switch (_context35.prev = _context35.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context35.prev = 1; | ||
_context35.next = 4; | ||
return Accounts.setProfile(); | ||
describe('setProfile', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee36() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee36$(_context36) { | ||
while (1) { | ||
switch (_context36.prev = _context36.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context36.prev = 1; | ||
_context36.next = 4; | ||
return Accounts.setProfile(); | ||
case 4: | ||
throw new Error(); | ||
case 4: | ||
throw new Error(); | ||
case 7: | ||
_context35.prev = 7; | ||
_context35.t0 = _context35['catch'](1); | ||
message = _context35.t0.message; | ||
case 7: | ||
_context36.prev = 7; | ||
_context36.t0 = _context36['catch'](1); | ||
message = _context36.t0.message; | ||
expect(message).toEqual('User not found'); | ||
expect(message).toEqual('User not found'); | ||
case 11: | ||
case 'end': | ||
return _context35.stop(); | ||
} | ||
case 11: | ||
case 'end': | ||
return _context36.stop(); | ||
} | ||
}, _callee35, undefined, [[1, 7]]); | ||
}))); | ||
} | ||
}, _callee36, undefined, [[1, 7]]); | ||
}))); | ||
it('calls set profile on db interface', _asyncToGenerator(regeneratorRuntime.mark(function _callee36() { | ||
var user, profile, setProfile; | ||
return regeneratorRuntime.wrap(function _callee36$(_context36) { | ||
while (1) { | ||
switch (_context36.prev = _context36.next) { | ||
case 0: | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
profile = { | ||
bio: 'bio' | ||
}; | ||
setProfile = jest.fn(); | ||
it('calls set profile on db interface', _asyncToGenerator(regeneratorRuntime.mark(function _callee37() { | ||
var user, profile, setProfile; | ||
return regeneratorRuntime.wrap(function _callee37$(_context37) { | ||
while (1) { | ||
switch (_context37.prev = _context37.next) { | ||
case 0: | ||
user = { | ||
userId: '123', | ||
username: 'username' | ||
}; | ||
profile = { | ||
bio: 'bio' | ||
}; | ||
setProfile = jest.fn(); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
setProfile: setProfile | ||
}); | ||
_context36.next = 6; | ||
return Accounts.setProfile('123', profile); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
setProfile: setProfile | ||
}); | ||
_context37.next = 6; | ||
return Accounts.setProfile('123', profile); | ||
case 6: | ||
expect(setProfile.mock.calls.length).toEqual(1); | ||
expect(setProfile.mock.calls[0][0]).toEqual('123'); | ||
expect(setProfile.mock.calls[0][1]).toEqual(profile); | ||
case 6: | ||
expect(setProfile.mock.calls.length).toEqual(1); | ||
expect(setProfile.mock.calls[0][0]).toEqual('123'); | ||
expect(setProfile.mock.calls[0][1]).toEqual(profile); | ||
case 9: | ||
case 'end': | ||
return _context36.stop(); | ||
} | ||
case 9: | ||
case 'end': | ||
return _context37.stop(); | ||
} | ||
}, _callee36, undefined); | ||
}))); | ||
} | ||
}, _callee37, undefined); | ||
}))); | ||
it('merges profile and calls set profile on db interface', _asyncToGenerator(regeneratorRuntime.mark(function _callee37() { | ||
var user, profile, mergedProfile, setProfile, res; | ||
return regeneratorRuntime.wrap(function _callee37$(_context37) { | ||
while (1) { | ||
switch (_context37.prev = _context37.next) { | ||
case 0: | ||
user = { | ||
userId: '123', | ||
username: 'username', | ||
profile: { | ||
title: 'title' | ||
} | ||
}; | ||
profile = { | ||
bio: 'bio' | ||
}; | ||
mergedProfile = { | ||
title: 'title', | ||
bio: 'bio' | ||
}; | ||
setProfile = jest.fn(function () { | ||
return mergedProfile; | ||
}); | ||
it('merges profile and calls set profile on db interface', _asyncToGenerator(regeneratorRuntime.mark(function _callee38() { | ||
var user, profile, mergedProfile, setProfile, res; | ||
return regeneratorRuntime.wrap(function _callee38$(_context38) { | ||
while (1) { | ||
switch (_context38.prev = _context38.next) { | ||
case 0: | ||
user = { | ||
userId: '123', | ||
username: 'username', | ||
profile: { | ||
title: 'title' | ||
} | ||
}; | ||
profile = { | ||
bio: 'bio' | ||
}; | ||
mergedProfile = { | ||
title: 'title', | ||
bio: 'bio' | ||
}; | ||
setProfile = jest.fn(function () { | ||
return mergedProfile; | ||
}); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
setProfile: setProfile | ||
}); | ||
_context37.next = 7; | ||
return Accounts.updateProfile('123', profile); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
setProfile: setProfile | ||
}); | ||
_context38.next = 7; | ||
return Accounts.updateProfile('123', profile); | ||
case 7: | ||
res = _context37.sent; | ||
case 7: | ||
res = _context38.sent; | ||
expect(setProfile.mock.calls.length).toEqual(1); | ||
expect(setProfile.mock.calls[0][0]).toEqual('123'); | ||
expect(setProfile.mock.calls[0][1]).toEqual(mergedProfile); | ||
expect(res).toEqual(mergedProfile); | ||
expect(setProfile.mock.calls.length).toEqual(1); | ||
expect(setProfile.mock.calls[0][0]).toEqual('123'); | ||
expect(setProfile.mock.calls[0][1]).toEqual(mergedProfile); | ||
expect(res).toEqual(mergedProfile); | ||
case 12: | ||
case 'end': | ||
return _context37.stop(); | ||
} | ||
case 12: | ||
case 'end': | ||
return _context38.stop(); | ||
} | ||
}, _callee37, undefined); | ||
}))); | ||
}); | ||
} | ||
}, _callee38, undefined); | ||
}))); | ||
}); | ||
describe('sendVerificationEmail', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee38() { | ||
return regeneratorRuntime.wrap(function _callee38$(_context38) { | ||
while (1) { | ||
switch (_context38.prev = _context38.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context38.prev = 1; | ||
_context38.next = 4; | ||
return Accounts.sendVerificationEmail(); | ||
describe('sendVerificationEmail', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee39() { | ||
return regeneratorRuntime.wrap(function _callee39$(_context39) { | ||
while (1) { | ||
switch (_context39.prev = _context39.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context39.prev = 1; | ||
_context39.next = 4; | ||
return Accounts.sendVerificationEmail(); | ||
case 4: | ||
throw new Error(); | ||
case 4: | ||
throw new Error(); | ||
case 7: | ||
_context38.prev = 7; | ||
_context38.t0 = _context38['catch'](1); | ||
case 7: | ||
_context39.prev = 7; | ||
_context39.t0 = _context39['catch'](1); | ||
expect(_context38.t0.message).toEqual('User not found'); | ||
expect(_context39.t0.message).toEqual('User not found'); | ||
case 10: | ||
case 'end': | ||
return _context38.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context39.stop(); | ||
} | ||
}, _callee38, undefined, [[1, 7]]); | ||
}))); | ||
} | ||
}, _callee39, undefined, [[1, 7]]); | ||
}))); | ||
it('throws when bad email address passed', _asyncToGenerator(regeneratorRuntime.mark(function _callee39() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee39$(_context39) { | ||
while (1) { | ||
switch (_context39.prev = _context39.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
it('throws when bad email address passed', _asyncToGenerator(regeneratorRuntime.mark(function _callee40() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee40$(_context40) { | ||
while (1) { | ||
switch (_context40.prev = _context40.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
} | ||
}); | ||
_context39.prev = 2; | ||
_context39.next = 5; | ||
return Accounts.sendVerificationEmail('userId', 'toto'); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
} | ||
}); | ||
_context40.prev = 2; | ||
_context40.next = 5; | ||
return Accounts.sendVerificationEmail('userId', 'toto'); | ||
case 5: | ||
throw new Error(); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context39.prev = 8; | ||
_context39.t0 = _context39['catch'](2); | ||
case 8: | ||
_context40.prev = 8; | ||
_context40.t0 = _context40['catch'](2); | ||
expect(_context39.t0.message).toEqual('No such email address for user'); | ||
expect(_context40.t0.message).toEqual('No such email address for user'); | ||
case 11: | ||
case 'end': | ||
return _context39.stop(); | ||
} | ||
case 11: | ||
case 'end': | ||
return _context40.stop(); | ||
} | ||
}, _callee39, undefined, [[2, 8]]); | ||
}))); | ||
} | ||
}, _callee40, undefined, [[2, 8]]); | ||
}))); | ||
it('should send to first unverified email', _asyncToGenerator(regeneratorRuntime.mark(function _callee40() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee40$(_context40) { | ||
while (1) { | ||
switch (_context40.prev = _context40.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
it('should send to first unverified email', _asyncToGenerator(regeneratorRuntime.mark(function _callee41() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee41$(_context41) { | ||
while (1) { | ||
switch (_context41.prev = _context41.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
addEmailVerificationToken: function addEmailVerificationToken() { | ||
return Promise.resolve('token'); | ||
} | ||
}); | ||
Accounts.email = { sendMail: jest.fn() }; | ||
_context40.next = 5; | ||
return Accounts.sendVerificationEmail('userId'); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
addEmailVerificationToken: function addEmailVerificationToken() { | ||
return Promise.resolve('token'); | ||
} | ||
}); | ||
Accounts.email = { sendMail: jest.fn() }; | ||
_context41.next = 5; | ||
return Accounts.sendVerificationEmail('userId'); | ||
case 5: | ||
expect(Accounts.email.sendMail.mock.calls.length).toEqual(1); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].from).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].to).toEqual('email'); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].subject).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].text).toBeTruthy(); | ||
case 5: | ||
expect(Accounts.email.sendMail.mock.calls.length).toEqual(1); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].from).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].to).toEqual('email'); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].subject).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].text).toBeTruthy(); | ||
case 10: | ||
case 'end': | ||
return _context40.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context41.stop(); | ||
} | ||
}, _callee40, undefined); | ||
}))); | ||
} | ||
}, _callee41, undefined); | ||
}))); | ||
it('should send email', _asyncToGenerator(regeneratorRuntime.mark(function _callee41() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee41$(_context41) { | ||
while (1) { | ||
switch (_context41.prev = _context41.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
it('should send email', _asyncToGenerator(regeneratorRuntime.mark(function _callee42() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee42$(_context42) { | ||
while (1) { | ||
switch (_context42.prev = _context42.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
addEmailVerificationToken: function addEmailVerificationToken() { | ||
return Promise.resolve('token'); | ||
} | ||
}); | ||
Accounts.email = { sendMail: jest.fn() }; | ||
_context41.next = 5; | ||
return Accounts.sendVerificationEmail('userId', 'email'); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
addEmailVerificationToken: function addEmailVerificationToken() { | ||
return Promise.resolve('token'); | ||
} | ||
}); | ||
Accounts.email = { sendMail: jest.fn() }; | ||
_context42.next = 5; | ||
return Accounts.sendVerificationEmail('userId', 'email'); | ||
case 5: | ||
expect(Accounts.email.sendMail.mock.calls.length).toEqual(1); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].from).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].to).toEqual('email'); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].subject).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].text).toBeTruthy(); | ||
case 5: | ||
expect(Accounts.email.sendMail.mock.calls.length).toEqual(1); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].from).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].to).toEqual('email'); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].subject).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].text).toBeTruthy(); | ||
case 10: | ||
case 'end': | ||
return _context41.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context42.stop(); | ||
} | ||
}, _callee41, undefined); | ||
}))); | ||
}); | ||
} | ||
}, _callee42, undefined); | ||
}))); | ||
}); | ||
describe('sendResetPasswordEmail', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee42() { | ||
return regeneratorRuntime.wrap(function _callee42$(_context42) { | ||
while (1) { | ||
switch (_context42.prev = _context42.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context42.prev = 1; | ||
_context42.next = 4; | ||
return Accounts.sendResetPasswordEmail(); | ||
describe('sendResetPasswordEmail', function () { | ||
it('throws error if user is not found', _asyncToGenerator(regeneratorRuntime.mark(function _callee43() { | ||
return regeneratorRuntime.wrap(function _callee43$(_context43) { | ||
while (1) { | ||
switch (_context43.prev = _context43.next) { | ||
case 0: | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(null); | ||
} | ||
}); | ||
_context43.prev = 1; | ||
_context43.next = 4; | ||
return Accounts.sendResetPasswordEmail(); | ||
case 4: | ||
throw new Error(); | ||
case 4: | ||
throw new Error(); | ||
case 7: | ||
_context42.prev = 7; | ||
_context42.t0 = _context42['catch'](1); | ||
case 7: | ||
_context43.prev = 7; | ||
_context43.t0 = _context43['catch'](1); | ||
expect(_context42.t0.message).toEqual('User not found'); | ||
expect(_context43.t0.message).toEqual('User not found'); | ||
case 10: | ||
case 'end': | ||
return _context42.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context43.stop(); | ||
} | ||
}, _callee42, undefined, [[1, 7]]); | ||
}))); | ||
} | ||
}, _callee43, undefined, [[1, 7]]); | ||
}))); | ||
it('throws when bad email address passed', _asyncToGenerator(regeneratorRuntime.mark(function _callee43() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee43$(_context43) { | ||
while (1) { | ||
switch (_context43.prev = _context43.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
it('throws when bad email address passed', _asyncToGenerator(regeneratorRuntime.mark(function _callee44() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee44$(_context44) { | ||
while (1) { | ||
switch (_context44.prev = _context44.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
} | ||
}); | ||
_context43.prev = 2; | ||
_context43.next = 5; | ||
return Accounts.sendResetPasswordEmail('userId', 'toto'); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
} | ||
}); | ||
_context44.prev = 2; | ||
_context44.next = 5; | ||
return Accounts.sendResetPasswordEmail('userId', 'toto'); | ||
case 5: | ||
throw new Error(); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context43.prev = 8; | ||
_context43.t0 = _context43['catch'](2); | ||
case 8: | ||
_context44.prev = 8; | ||
_context44.t0 = _context44['catch'](2); | ||
expect(_context43.t0.message).toEqual('No such email address for user'); | ||
expect(_context44.t0.message).toEqual('No such email address for user'); | ||
case 11: | ||
case 'end': | ||
return _context43.stop(); | ||
} | ||
case 11: | ||
case 'end': | ||
return _context44.stop(); | ||
} | ||
}, _callee43, undefined, [[2, 8]]); | ||
}))); | ||
} | ||
}, _callee44, undefined, [[2, 8]]); | ||
}))); | ||
it('should send to first user email', _asyncToGenerator(regeneratorRuntime.mark(function _callee44() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee44$(_context44) { | ||
while (1) { | ||
switch (_context44.prev = _context44.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
it('should send to first user email', _asyncToGenerator(regeneratorRuntime.mark(function _callee45() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee45$(_context45) { | ||
while (1) { | ||
switch (_context45.prev = _context45.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
addResetPasswordToken: function addResetPasswordToken() { | ||
return Promise.resolve('token'); | ||
} | ||
}); | ||
Accounts.email = { sendMail: jest.fn() }; | ||
_context44.next = 5; | ||
return Accounts.sendResetPasswordEmail('userId'); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
addResetPasswordToken: function addResetPasswordToken() { | ||
return Promise.resolve('token'); | ||
} | ||
}); | ||
Accounts.email = { sendMail: jest.fn() }; | ||
_context45.next = 5; | ||
return Accounts.sendResetPasswordEmail('userId'); | ||
case 5: | ||
expect(Accounts.email.sendMail.mock.calls.length).toEqual(1); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].from).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].to).toEqual('email'); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].subject).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].text).toBeTruthy(); | ||
case 5: | ||
expect(Accounts.email.sendMail.mock.calls.length).toEqual(1); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].from).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].to).toEqual('email'); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].subject).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].text).toBeTruthy(); | ||
case 10: | ||
case 'end': | ||
return _context44.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context45.stop(); | ||
} | ||
}, _callee44, undefined); | ||
}))); | ||
} | ||
}, _callee45, undefined); | ||
}))); | ||
it('should send email', _asyncToGenerator(regeneratorRuntime.mark(function _callee45() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee45$(_context45) { | ||
while (1) { | ||
switch (_context45.prev = _context45.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
it('should send email', _asyncToGenerator(regeneratorRuntime.mark(function _callee46() { | ||
var user; | ||
return regeneratorRuntime.wrap(function _callee46$(_context46) { | ||
while (1) { | ||
switch (_context46.prev = _context46.next) { | ||
case 0: | ||
user = { | ||
emails: [{ address: 'email' }] | ||
}; | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
addResetPasswordToken: function addResetPasswordToken() { | ||
return Promise.resolve('token'); | ||
} | ||
}); | ||
Accounts.email = { sendMail: jest.fn() }; | ||
_context45.next = 5; | ||
return Accounts.sendResetPasswordEmail('userId', 'email'); | ||
Accounts.config({}, { | ||
findUserById: function findUserById() { | ||
return Promise.resolve(user); | ||
}, | ||
addResetPasswordToken: function addResetPasswordToken() { | ||
return Promise.resolve('token'); | ||
} | ||
}); | ||
Accounts.email = { sendMail: jest.fn() }; | ||
_context46.next = 5; | ||
return Accounts.sendResetPasswordEmail('userId', 'email'); | ||
case 5: | ||
expect(Accounts.email.sendMail.mock.calls.length).toEqual(1); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].from).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].to).toEqual('email'); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].subject).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].text).toBeTruthy(); | ||
case 5: | ||
expect(Accounts.email.sendMail.mock.calls.length).toEqual(1); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].from).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].to).toEqual('email'); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].subject).toBeTruthy(); | ||
expect(Accounts.email.sendMail.mock.calls[0][0].text).toBeTruthy(); | ||
case 10: | ||
case 'end': | ||
return _context45.stop(); | ||
} | ||
case 10: | ||
case 'end': | ||
return _context46.stop(); | ||
} | ||
}, _callee45, undefined); | ||
}))); | ||
}); | ||
} | ||
}, _callee46, undefined); | ||
}))); | ||
}); | ||
}); |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.verifyPassword = exports.hashPassword = undefined; | ||
exports.verifyPassword = exports.hashPassword = exports.bcryptPassword = undefined; | ||
@@ -13,2 +13,6 @@ var _bcryptjs = require('bcryptjs'); | ||
var _crypto = require('crypto'); | ||
var _crypto2 = _interopRequireDefault(_crypto); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -18,3 +22,3 @@ | ||
var hashPassword = function () { | ||
var bcryptPassword = function () { | ||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(password) { | ||
@@ -46,3 +50,3 @@ var salt, hash; | ||
return function hashPassword(_x) { | ||
return function bcryptPassword(_x) { | ||
return _ref.apply(this, arguments); | ||
@@ -52,5 +56,8 @@ }; | ||
exports.hashPassword = hashPassword; | ||
var hashPassword = function hashPassword(password, algorithm) { | ||
var hash = _crypto2.default.createHash(algorithm); | ||
hash.update(password); | ||
return hash.digest('hex'); | ||
}; | ||
var verifyPassword = function () { | ||
@@ -77,2 +84,4 @@ var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(password, hash) { | ||
exports.bcryptPassword = bcryptPassword; | ||
exports.hashPassword = hashPassword; | ||
exports.verifyPassword = verifyPassword; |
@@ -7,4 +7,4 @@ 'use strict'; | ||
describe('hashPassword', function () { | ||
it('hashes password', _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
describe('bcryptPassword', function () { | ||
it('hashes password using bcrypt', _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
var hash; | ||
@@ -16,3 +16,3 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
_context.next = 2; | ||
return (0, _encryption.hashPassword)('password'); | ||
return (0, _encryption.bcryptPassword)('password'); | ||
@@ -33,5 +33,5 @@ case 2: | ||
describe('verifyPassword', function () { | ||
it('true if password matches', _asyncToGenerator(regeneratorRuntime.mark(function _callee2() { | ||
var password, hash; | ||
describe('hashPassword', function () { | ||
it('hashes password', _asyncToGenerator(regeneratorRuntime.mark(function _callee2() { | ||
var hash; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
@@ -41,53 +41,77 @@ while (1) { | ||
case 0: | ||
_context2.next = 2; | ||
return (0, _encryption.hashPassword)('password', 'sha256'); | ||
case 2: | ||
hash = _context2.sent; | ||
expect(hash).toBe('5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8'); | ||
case 4: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, undefined); | ||
}))); | ||
}); | ||
describe('verifyPassword', function () { | ||
it('true if password matches', _asyncToGenerator(regeneratorRuntime.mark(function _callee3() { | ||
var password, hash; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
password = 'password'; | ||
_context2.next = 3; | ||
return (0, _encryption.hashPassword)(password); | ||
_context3.next = 3; | ||
return (0, _encryption.bcryptPassword)(password); | ||
case 3: | ||
hash = _context2.sent; | ||
_context2.t0 = expect; | ||
_context2.next = 7; | ||
hash = _context3.sent; | ||
_context3.t0 = expect; | ||
_context3.next = 7; | ||
return (0, _encryption.verifyPassword)(password, hash); | ||
case 7: | ||
_context2.t1 = _context2.sent; | ||
(0, _context2.t0)(_context2.t1).toBe(true); | ||
_context3.t1 = _context3.sent; | ||
(0, _context3.t0)(_context3.t1).toBe(true); | ||
case 9: | ||
case 'end': | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2, undefined); | ||
}, _callee3, undefined); | ||
}))); | ||
it('false if password does not match', function () { | ||
it('true if password matches', _asyncToGenerator(regeneratorRuntime.mark(function _callee3() { | ||
it('true if password matches', _asyncToGenerator(regeneratorRuntime.mark(function _callee4() { | ||
var password, wrongPassword, hash; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
password = 'password'; | ||
wrongPassword = 'wrongPassword'; | ||
_context3.next = 4; | ||
return (0, _encryption.hashPassword)(password); | ||
_context4.next = 4; | ||
return (0, _encryption.bcryptPassword)(password); | ||
case 4: | ||
hash = _context3.sent; | ||
_context3.t0 = expect; | ||
_context3.next = 8; | ||
hash = _context4.sent; | ||
_context4.t0 = expect; | ||
_context4.next = 8; | ||
return (0, _encryption.verifyPassword)(wrongPassword, hash); | ||
case 8: | ||
_context3.t1 = _context3.sent; | ||
(0, _context3.t0)(_context3.t1).toBe(false); | ||
_context4.t1 = _context4.sent; | ||
(0, _context4.t0)(_context4.t1).toBe(false); | ||
case 10: | ||
case 'end': | ||
return _context3.stop(); | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee3, undefined); | ||
}, _callee4, undefined); | ||
}))); | ||
}); | ||
}); |
@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
root["@accounts/server"] = factory(root["babel-runtime/regenerator"], root["babel-runtime/helpers/asyncToGenerator"], root["babel-runtime/helpers/extends"], root["babel-runtime/helpers/classCallCheck"], root["babel-runtime/helpers/createClass"], root["lodash"], root["jsonwebtoken"], root["@accounts/common"], root["bcryptjs"], root["crypto"], root["babel-runtime/core-js/promise"], root["emailjs"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__, __WEBPACK_EXTERNAL_MODULE_5__, __WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_7__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_14__, __WEBPACK_EXTERNAL_MODULE_16__, __WEBPACK_EXTERNAL_MODULE_17__) { | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__, __WEBPACK_EXTERNAL_MODULE_5__, __WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_7__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_13__, __WEBPACK_EXTERNAL_MODULE_16__, __WEBPACK_EXTERNAL_MODULE_17__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
@@ -132,3 +132,3 @@ /******/ // The module cache | ||
var _tokens = __webpack_require__(13); | ||
var _tokens = __webpack_require__(14); | ||
@@ -166,6 +166,6 @@ var _email = __webpack_require__(15); | ||
this.db = db; | ||
if (options.sendMail) { | ||
this.email = { sendMail: options.sendMail }; | ||
if (this._options.sendMail) { | ||
this.email = { sendMail: this._options.sendMail }; | ||
} else { | ||
this.email = new _email2.default(_config3.default.email); | ||
this.email = new _email2.default(this._options.email); | ||
} | ||
@@ -323,3 +323,3 @@ this.emailTemplates = _emailTemplates2.default; | ||
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(user, password) { | ||
var _ref4, username, email, id, foundUser, hash, isPasswordValid; | ||
var _ref4, username, email, id, foundUser, hash, hashAlgorithm, pass, isPasswordValid; | ||
@@ -395,10 +395,12 @@ return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
case 25: | ||
_context3.next = 27; | ||
return (0, _encryption.verifyPassword)(password, hash); | ||
hashAlgorithm = this._options.passwordHashAlgorithm; | ||
pass = hashAlgorithm ? (0, _encryption.hashPassword)(password, hashAlgorithm) : password; | ||
_context3.next = 29; | ||
return (0, _encryption.verifyPassword)(pass, hash); | ||
case 27: | ||
case 29: | ||
isPasswordValid = _context3.sent; | ||
if (isPasswordValid) { | ||
_context3.next = 30; | ||
_context3.next = 32; | ||
break; | ||
@@ -409,6 +411,6 @@ } | ||
case 30: | ||
case 32: | ||
return _context3.abrupt('return', foundUser); | ||
case 31: | ||
case 33: | ||
case 'end': | ||
@@ -642,4 +644,6 @@ return _context3.stop(); | ||
var _options = this._options, | ||
tokenSecret = _options.tokenSecret, | ||
tokenConfigs = _options.tokenConfigs; | ||
_options$tokenSecret = _options.tokenSecret, | ||
tokenSecret = _options$tokenSecret === undefined ? _config3.default.tokenSecret : _options$tokenSecret, | ||
_options$tokenConfigs = _options.tokenConfigs, | ||
tokenConfigs = _options$tokenConfigs === undefined ? _config3.default.tokenConfigs : _options$tokenConfigs; | ||
@@ -651,7 +655,7 @@ var accessToken = (0, _tokens.generateAccessToken)({ | ||
secret: tokenSecret, | ||
config: tokenConfigs.accessToken | ||
config: tokenConfigs.accessToken || {} | ||
}); | ||
var refreshToken = (0, _tokens.generateRefreshToken)({ | ||
secret: tokenSecret, | ||
config: tokenConfigs.refreshToken | ||
config: tokenConfigs.refreshToken || {} | ||
}); | ||
@@ -1203,3 +1207,3 @@ return { accessToken: accessToken, refreshToken: refreshToken }; | ||
var _ref14 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee13(userId, address) { | ||
var user, email, emails, token, verifyEmailUrl; | ||
var user, email, emails, token, siteUrl, verifyEmailUrl; | ||
return _regenerator2.default.wrap(function _callee13$(_context13) { | ||
@@ -1249,4 +1253,5 @@ while (1) { | ||
case 12: | ||
verifyEmailUrl = this._options.siteUrl + '/verify-email/' + token; | ||
_context13.next = 15; | ||
siteUrl = this._options.siteUrl || _config3.default.siteUrl; | ||
verifyEmailUrl = siteUrl + '/verify-email/' + token; | ||
_context13.next = 16; | ||
return this.email.sendMail({ | ||
@@ -1259,3 +1264,3 @@ from: this.emailTemplates.verifyEmail.from ? this.emailTemplates.verifyEmail.from : this.emailTemplates.from, | ||
case 15: | ||
case 16: | ||
case 'end': | ||
@@ -1288,3 +1293,3 @@ return _context13.stop(); | ||
var _ref15 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee14(userId, address) { | ||
var user, token, resetPasswordUrl; | ||
var user, token, siteUrl, resetPasswordUrl; | ||
return _regenerator2.default.wrap(function _callee14$(_context14) { | ||
@@ -1314,4 +1319,5 @@ while (1) { | ||
case 9: | ||
resetPasswordUrl = this._options.siteUrl + '/reset-password/' + token; | ||
_context14.next = 12; | ||
siteUrl = this._options.siteUrl || _config3.default.siteUrl; | ||
resetPasswordUrl = siteUrl + '/reset-password/' + token; | ||
_context14.next = 13; | ||
return this.email.sendMail({ | ||
@@ -1324,3 +1330,3 @@ from: this.emailTemplates.resetPassword.from ? this.emailTemplates.resetPassword.from : this.emailTemplates.from, | ||
case 12: | ||
case 13: | ||
case 'end': | ||
@@ -1353,3 +1359,3 @@ return _context14.stop(); | ||
var _ref16 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee15(userId, address) { | ||
var user, token, enrollAccountUrl; | ||
var user, token, siteUrl, enrollAccountUrl; | ||
return _regenerator2.default.wrap(function _callee15$(_context15) { | ||
@@ -1379,4 +1385,5 @@ while (1) { | ||
case 9: | ||
enrollAccountUrl = this._options.siteUrl + '/enroll-account/' + token; | ||
_context15.next = 12; | ||
siteUrl = this._options.siteUrl || _config3.default.siteUrl; | ||
enrollAccountUrl = siteUrl + '/enroll-account/' + token; | ||
_context15.next = 13; | ||
return this.email.sendMail({ | ||
@@ -1389,3 +1396,3 @@ from: this.emailTemplates.enrollAccount.from ? this.emailTemplates.enrollAccount.from : this.emailTemplates.from, | ||
case 12: | ||
case 13: | ||
case 'end': | ||
@@ -1513,3 +1520,3 @@ return _context15.stop(); | ||
}); | ||
exports.verifyPassword = exports.hashPassword = undefined; | ||
exports.verifyPassword = exports.hashPassword = exports.bcryptPassword = undefined; | ||
@@ -1528,5 +1535,9 @@ var _regenerator = __webpack_require__(2); | ||
var _crypto = __webpack_require__(13); | ||
var _crypto2 = _interopRequireDefault(_crypto); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var hashPassword = function () { | ||
var bcryptPassword = function () { | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(password) { | ||
@@ -1558,3 +1569,3 @@ var salt, hash; | ||
return function hashPassword(_x) { | ||
return function bcryptPassword(_x) { | ||
return _ref.apply(this, arguments); | ||
@@ -1564,5 +1575,8 @@ }; | ||
exports.hashPassword = hashPassword; | ||
var hashPassword = function hashPassword(password, algorithm) { | ||
var hash = _crypto2.default.createHash(algorithm); | ||
hash.update(password); | ||
return hash.digest('hex'); | ||
}; | ||
var verifyPassword = function () { | ||
@@ -1589,2 +1603,4 @@ var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(password, hash) { | ||
exports.bcryptPassword = bcryptPassword; | ||
exports.hashPassword = hashPassword; | ||
exports.verifyPassword = verifyPassword; | ||
@@ -1600,2 +1616,8 @@ | ||
/* 13 */ | ||
/***/ function(module, exports) { | ||
module.exports = require("crypto"); | ||
/***/ }, | ||
/* 14 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1614,3 +1636,3 @@ | ||
var _crypto = __webpack_require__(14); | ||
var _crypto = __webpack_require__(13); | ||
@@ -1645,8 +1667,2 @@ var _crypto2 = _interopRequireDefault(_crypto); | ||
/***/ }, | ||
/* 14 */ | ||
/***/ function(module, exports) { | ||
module.exports = require("crypto"); | ||
/***/ }, | ||
/* 15 */ | ||
@@ -1653,0 +1669,0 @@ /***/ function(module, exports, __webpack_require__) { |
{ | ||
"name": "@accounts/server", | ||
"version": "0.0.9", | ||
"version": "0.0.10-alpha.b575b352", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -21,3 +21,5 @@ "main": "lib/index.js", | ||
"flow:check": "flow check", | ||
"flow:prepublish": "for i in `ls ./src/*.js`; do cp $i `echo $i | sed \"s/src/lib-es6/g\" | sed \"s/js/js\\.flow/g\"`; done", | ||
"flow:prepublish": "npm run flow:cplib && npm run flow:cplibes6", | ||
"flow:cplib": "for i in `ls ./src/*.js`; do cp $i `echo $i | sed \"s/src/lib/g\" | sed \"s/js/js\\.flow/g\"`; done", | ||
"flow:cplibes6": "for i in `ls ./src/*.js`; do cp $i `echo $i | sed \"s/src/lib-es6/g\" | sed \"s/js/js\\.flow/g\"`; done", | ||
"coverage": "npm run testonly -- --coverage", | ||
@@ -50,3 +52,3 @@ "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||
"dependencies": { | ||
"@accounts/common": "^0.0.9", | ||
"@accounts/common": "^0.0.10-alpha.b575b352", | ||
"babel-polyfill": "^6.23.0", | ||
@@ -53,0 +55,0 @@ "bcryptjs": "^2.4.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
571361
51
8355
0
+ Added@accounts/common@0.0.10(transitive)
- Removed@accounts/common@0.0.9(transitive)