Skip to content

Commit a5cc105

Browse files
committedJan 4, 2020
chore: switch to prettier and prettify
1 parent e37894e commit a5cc105

12 files changed

+562
-326
lines changed
 

‎.eslintrc

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
2-
"extends": "eslint:recommended",
2+
"extends": [
3+
"eslint:recommended",
4+
"prettier"
5+
],
6+
"plugins": [
7+
"prettier"
8+
],
39
"parserOptions": {
4-
"ecmaVersion": 2017,
5-
"sourceType": "module"
10+
"ecmaVersion": 2018
611
},
712
"env": {
813
"es6": true,
@@ -12,10 +17,6 @@
1217
"rules": {
1318
"no-var": "error",
1419
"prefer-const": "error",
15-
"quotes": [
16-
"error",
17-
"single",
18-
{ "avoidEscape": true }
19-
]
20+
"prettier/prettier": "error"
2021
}
2122
}

‎.jsbeautifyrc

-4
This file was deleted.

‎.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 2,
4+
"printWidth": 140
5+
}

‎index.js

+51-54
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ module.exports = function(schema, options) {
1313
options.encoding = options.encoding || 'hex';
1414
options.digestAlgorithm = options.digestAlgorithm || 'sha256'; // To get a list of supported hashes use crypto.getHashes()
1515

16-
options.passwordValidator = options.passwordValidator || function(password, cb) { cb(null); };
17-
options.passwordValidatorAsync = options.passwordValidatorAsync || function(password) {
18-
return new Promise((resolve, reject) => {
19-
options.passwordValidator(password, (err) => err?reject(err):resolve());
20-
});
21-
};
16+
options.passwordValidator =
17+
options.passwordValidator ||
18+
function(password, cb) {
19+
cb(null);
20+
};
21+
options.passwordValidatorAsync =
22+
options.passwordValidatorAsync ||
23+
function(password) {
24+
return new Promise((resolve, reject) => {
25+
options.passwordValidator(password, err => (err ? reject(err) : resolve()));
26+
});
27+
};
2228

2329
// Populate field names with defaults if not set
2430
options.usernameField = options.usernameField || 'username';
@@ -49,13 +55,19 @@ module.exports = function(schema, options) {
4955
options.maxAttempts = options.maxAttempts || Infinity;
5056
}
5157

52-
options.findByUsername = options.findByUsername || function(model, queryParameters) { return model.findOne(queryParameters); }
58+
options.findByUsername =
59+
options.findByUsername ||
60+
function(model, queryParameters) {
61+
return model.findOne(queryParameters);
62+
};
5363

5464
options.errorMessages = options.errorMessages || {};
5565
options.errorMessages.MissingPasswordError = options.errorMessages.MissingPasswordError || 'No password was given';
5666
options.errorMessages.AttemptTooSoonError = options.errorMessages.AttemptTooSoonError || 'Account is currently locked. Try again later';
57-
options.errorMessages.TooManyAttemptsError = options.errorMessages.TooManyAttemptsError || 'Account locked due to too many failed login attempts';
58-
options.errorMessages.NoSaltValueStoredError = options.errorMessages.NoSaltValueStoredError || 'Authentication not possible. No salt value stored';
67+
options.errorMessages.TooManyAttemptsError =
68+
options.errorMessages.TooManyAttemptsError || 'Account locked due to too many failed login attempts';
69+
options.errorMessages.NoSaltValueStoredError =
70+
options.errorMessages.NoSaltValueStoredError || 'Authentication not possible. No salt value stored';
5971
options.errorMessages.IncorrectPasswordError = options.errorMessages.IncorrectPasswordError || 'Password or username is incorrect';
6072
options.errorMessages.IncorrectUsernameError = options.errorMessages.IncorrectUsernameError || 'Password or username is incorrect';
6173
options.errorMessages.MissingUsernameError = options.errorMessages.MissingUsernameError || 'No username was given';
@@ -109,9 +121,7 @@ module.exports = function(schema, options) {
109121
return promise;
110122
}
111123

112-
promise
113-
.then(result => cb(null, result))
114-
.catch(err => cb(err));
124+
promise.then(result => cb(null, result)).catch(err => cb(err));
115125
};
116126

117127
schema.methods.changePassword = function(oldPassword, newPassword, cb) {
@@ -135,75 +145,64 @@ module.exports = function(schema, options) {
135145
return promise;
136146
}
137147

138-
promise
139-
.then(result => cb(null, result))
140-
.catch(err => cb(err));
148+
promise.then(result => cb(null, result)).catch(err => cb(err));
141149
};
142150

143151
schema.methods.authenticate = function(password, cb) {
144-
const promise = Promise.resolve()
145-
.then(() => {
146-
if (this.get(options.saltField)) {
147-
return authenticate(this, password, options);
148-
}
152+
const promise = Promise.resolve().then(() => {
153+
if (this.get(options.saltField)) {
154+
return authenticate(this, password, options);
155+
}
149156

150-
return this.constructor.findByUsername(this.get(options.usernameField), true)
151-
.then(user => {
152-
if (user) {
153-
return authenticate(user, password, options);
154-
}
157+
return this.constructor.findByUsername(this.get(options.usernameField), true).then(user => {
158+
if (user) {
159+
return authenticate(user, password, options);
160+
}
155161

156-
return { user: false, error: new errors.IncorrectUsernameError(options.errorMessages.IncorrectUsernameError) };
157-
});
162+
return { user: false, error: new errors.IncorrectUsernameError(options.errorMessages.IncorrectUsernameError) };
158163
});
164+
});
159165

160166
if (!cb) {
161167
return promise;
162168
}
163169

164-
promise
165-
.then(({ user, error }) => cb(null, user, error))
166-
.catch(err => cb(err));
170+
promise.then(({ user, error }) => cb(null, user, error)).catch(err => cb(err));
167171
};
168172

169173
if (options.limitAttempts) {
170174
schema.methods.resetAttempts = function(cb) {
171-
const promise = Promise.resolve()
172-
.then(() => {
173-
this.set(options.attemptsField, 0);
174-
return this.save();
175-
});
175+
const promise = Promise.resolve().then(() => {
176+
this.set(options.attemptsField, 0);
177+
return this.save();
178+
});
176179

177180
if (!cb) {
178181
return promise;
179182
}
180183

181-
promise
182-
.then(result => cb(null, result))
183-
.catch(err => cb(err));
184+
promise.then(result => cb(null, result)).catch(err => cb(err));
184185
};
185186
}
186187

187188
// Passport Local Interface
188189
schema.statics.authenticate = function() {
189190
return (username, password, cb) => {
190191
const promise = Promise.resolve()
191-
.then(() => this.findByUsername(username, true))
192-
.then((user) => {
193-
if (user) {
194-
return user.authenticate(password);
195-
}
192+
.then(() => this.findByUsername(username, true))
193+
.then(user => {
194+
if (user) {
195+
return user.authenticate(password);
196+
}
196197

197-
return { user: false, error: new errors.IncorrectUsernameError(options.errorMessages.IncorrectUsernameError) };
198-
});
198+
return { user: false, error: new errors.IncorrectUsernameError(options.errorMessages.IncorrectUsernameError) };
199+
});
199200

200201
if (!cb) {
201202
return promise;
202203
}
203204

204-
promise
205-
.then(({ user, error }) => cb(null, user, error))
206-
.catch(err => cb(err));
205+
promise.then(({ user, error }) => cb(null, user, error)).catch(err => cb(err));
207206
};
208207
};
209208

@@ -233,7 +232,7 @@ module.exports = function(schema, options) {
233232
}
234233
})
235234
.then(() => this.findByUsername(user.get(options.usernameField)))
236-
.then((existingUser) => {
235+
.then(existingUser => {
237236
if (existingUser) {
238237
throw new errors.UserExistsError(options.errorMessages.UserExistsError);
239238
}
@@ -245,9 +244,7 @@ module.exports = function(schema, options) {
245244
return promise;
246245
}
247246

248-
promise
249-
.then(result => cb(null, result))
250-
.catch(err => cb(err));
247+
promise.then(result => cb(null, result)).catch(err => cb(err));
251248
};
252249

253250
schema.statics.findByUsername = function(username, opts, cb) {
@@ -306,11 +303,11 @@ module.exports = function(schema, options) {
306303
};
307304

308305
function pbkdf2Promisified(password, salt, options) {
309-
return new Promise((resolve, reject) => pbkdf2(password, salt, options, (err, hashRaw) => err ? reject(err) : resolve(hashRaw)));
306+
return new Promise((resolve, reject) => pbkdf2(password, salt, options, (err, hashRaw) => (err ? reject(err) : resolve(hashRaw))));
310307
}
311308

312309
function randomBytes(saltlen) {
313-
return new Promise((resolve, reject) => crypto.randomBytes(saltlen, (err, saltBuffer) => err ? reject(err) : resolve(saltBuffer)));
310+
return new Promise((resolve, reject) => crypto.randomBytes(saltlen, (err, saltBuffer) => (err ? reject(err) : resolve(saltBuffer))));
314311
}
315312

316313
module.exports.errors = errors;

‎lib/authenticate.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ module.exports = function(user, password, options, cb) {
1010
}
1111

1212
return new Promise((resolve, reject) => {
13-
authenticate(user, password, options, (err, user, error) => err?reject(err):resolve({ user, error }));
13+
authenticate(user, password, options, (err, user, error) => (err ? reject(err) : resolve({ user, error })));
1414
});
15-
}
15+
};
1616

1717
function authenticate(user, password, options, cb) {
1818
if (options.limitAttempts) {
1919
const attemptsInterval = Math.pow(options.interval, Math.log(user.get(options.attemptsField) + 1));
20-
const calculatedInterval = (attemptsInterval < options.maxInterval) ? attemptsInterval : options.maxInterval;
20+
const calculatedInterval = attemptsInterval < options.maxInterval ? attemptsInterval : options.maxInterval;
2121

2222
if (Date.now() - user.get(options.lastLoginField) < calculatedInterval) {
2323
user.set(options.lastLoginField, Date.now());
@@ -76,4 +76,4 @@ function authenticate(user, password, options, cb) {
7676
}
7777
}
7878
});
79-
}
79+
}

‎lib/errors.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ const generaterr = require('generaterr');
33
const AuthenticationError = generaterr('AuthenticationError');
44

55
module.exports = {
6-
AuthenticationError : AuthenticationError,
7-
IncorrectUsernameError : generaterr('IncorrectUsernameError', null, { inherits : AuthenticationError }),
8-
IncorrectPasswordError : generaterr('IncorrectPasswordError', null,{ inherits : AuthenticationError }),
9-
MissingUsernameError : generaterr('MissingUsernameError', null,{ inherits : AuthenticationError }),
10-
MissingPasswordError : generaterr('MissingPasswordError', null,{ inherits : AuthenticationError }),
11-
UserExistsError : generaterr('UserExistsError', null,{ inherits : AuthenticationError }),
12-
NoSaltValueStoredError : generaterr('NoSaltValueStoredError', null,{ inherits : AuthenticationError }),
13-
AttemptTooSoonError : generaterr('AttemptTooSoonError', null,{ inherits : AuthenticationError }),
14-
TooManyAttemptsError : generaterr('TooManyAttemptsError', null,{ inherits : AuthenticationError })
15-
};
6+
AuthenticationError: AuthenticationError,
7+
IncorrectUsernameError: generaterr('IncorrectUsernameError', null, { inherits: AuthenticationError }),
8+
IncorrectPasswordError: generaterr('IncorrectPasswordError', null, { inherits: AuthenticationError }),
9+
MissingUsernameError: generaterr('MissingUsernameError', null, { inherits: AuthenticationError }),
10+
MissingPasswordError: generaterr('MissingPasswordError', null, { inherits: AuthenticationError }),
11+
UserExistsError: generaterr('UserExistsError', null, { inherits: AuthenticationError }),
12+
NoSaltValueStoredError: generaterr('NoSaltValueStoredError', null, { inherits: AuthenticationError }),
13+
AttemptTooSoonError: generaterr('AttemptTooSoonError', null, { inherits: AuthenticationError }),
14+
TooManyAttemptsError: generaterr('TooManyAttemptsError', null, { inherits: AuthenticationError })
15+
};

‎lib/pbkdf2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ module.exports = function pbkdf2(password, salt, options, callback) {
99
} else {
1010
crypto.pbkdf2(password, salt, options.iterations, options.keylen, callback);
1111
}
12-
};
12+
};

‎package-lock.json

+48-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030
"debug": "^4.1.1",
3131
"drop-mongodb-collections": "^1.2.5",
3232
"eslint": "^6.8.0",
33+
"eslint-config-prettier": "^6.9.0",
34+
"eslint-plugin-prettier": "^3.1.2",
3335
"mocha": "^6.2.2",
3436
"mocha-lcov-reporter": "^1.3.0",
3537
"mongoose": "^5.8.4",
3638
"nyc": "^15.0.0",
39+
"prettier": "^1.19.1",
3740
"standard-version": "^7.0.1"
3841
},
3942
"scripts": {

‎test/alternative-query-field.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ describe('alternative query field', function() {
1717
this.timeout(10000); // Ten seconds - mongo db access needed
1818

1919
beforeEach(dropMongodbCollections(connectionString));
20-
beforeEach(() => mongoose.connect(connectionString, { bufferCommands: false, autoIndex: false, useNewUrlParser: true, useUnifiedTopology: true }));
20+
beforeEach(() =>
21+
mongoose.connect(connectionString, { bufferCommands: false, autoIndex: false, useNewUrlParser: true, useUnifiedTopology: true })
22+
);
2123
afterEach(() => mongoose.disconnect());
2224

2325
it('should find an existing user by alternative query field', function(done) {
2426
const UserSchema = new Schema({
2527
email: String
2628
});
27-
UserSchema.plugin(passportLocalMongoose, {iterations: 1, usernameQueryFields: ['email']}); // 1 iteration - safes time in tests
29+
UserSchema.plugin(passportLocalMongoose, { iterations: 1, usernameQueryFields: ['email'] }); // 1 iteration - safes time in tests
2830
const User = mongoose.model('FindAlternativeQueryField', UserSchema);
2931

3032
const email = 'hugo@test.org';
31-
const user = new User({username: 'hugo', email: email});
33+
const user = new User({ username: 'hugo', email: email });
3234
user.save(function(err) {
3335
expect(err).to.not.exist;
3436

@@ -46,11 +48,11 @@ describe('alternative query field', function() {
4648
const UserSchema = new Schema({
4749
email: String
4850
});
49-
UserSchema.plugin(passportLocalMongoose, {iterations: 1, usernameQueryFields: ['email']}); // 1 iteration - safes time in tests
51+
UserSchema.plugin(passportLocalMongoose, { iterations: 1, usernameQueryFields: ['email'] }); // 1 iteration - safes time in tests
5052
const User = mongoose.model('AuthenticateAlternativeQueryField', UserSchema);
5153

5254
const email = 'hugo@test.org';
53-
const user = new User({username: 'hugo', email: email});
55+
const user = new User({ username: 'hugo', email: email });
5456
User.register(user, 'password', function(err) {
5557
expect(err).to.not.exist;
5658

@@ -68,11 +70,11 @@ describe('alternative query field', function() {
6870
const UserSchema = new Schema({
6971
email: String
7072
});
71-
UserSchema.plugin(passportLocalMongoose, {iterations: 1, usernameQueryFields: ['email']}); // 1 iteration - safes time in tests
73+
UserSchema.plugin(passportLocalMongoose, { iterations: 1, usernameQueryFields: ['email'] }); // 1 iteration - safes time in tests
7274
const User = mongoose.model('AuthenticateDefaultField', UserSchema);
7375

7476
const email = 'hugo@test.org';
75-
const user = new User({username: 'hugo', email: email});
77+
const user = new User({ username: 'hugo', email: email });
7678
User.register(user, 'password', function(err) {
7779
expect(err).to.not.exist;
7880

@@ -91,16 +93,20 @@ describe('alternative query field', function() {
9193
email: String
9294
});
9395

94-
UserSchema.plugin(passportLocalMongoose, {iterations: 1, usernameQueryFields: []}); // 1 iteration - safes time in tests
96+
UserSchema.plugin(passportLocalMongoose, { iterations: 1, usernameQueryFields: [] }); // 1 iteration - safes time in tests
9597
const User = mongoose.model('NotAuthenticateUnconfiguredAlternativeQueryField', UserSchema);
9698

9799
const email = 'hugo@test.org';
98-
const user = new User({username: 'hugo', email: email});
100+
const user = new User({ username: 'hugo', email: email });
99101
User.register(user, 'password', function(err) {
100-
if (err) { return done(err); }
102+
if (err) {
103+
return done(err);
104+
}
101105

102106
User.authenticate()('hugo@test.org', 'password', function(err, user, error) {
103-
if (err) { return done(err); }
107+
if (err) {
108+
return done(err);
109+
}
104110

105111
expect(err).to.not.exist;
106112
expect(user).to.be.false;

‎test/issues.js

+55-39
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ describe('issues', function() {
1717
this.timeout(10000); // Ten seconds - mongodb access needed
1818

1919
beforeEach(dropMongodbCollections(connectionString));
20-
beforeEach(() => mongoose.connect(connectionString, { bufferCommands: false, autoIndex: false, useNewUrlParser: true, useUnifiedTopology: true }));
20+
beforeEach(() =>
21+
mongoose.connect(connectionString, { bufferCommands: false, autoIndex: false, useNewUrlParser: true, useUnifiedTopology: true })
22+
);
2123
afterEach(() => mongoose.disconnect());
2224

2325
it('should support nested fields - Issue #9', function(done) {
@@ -30,10 +32,10 @@ describe('issues', function() {
3032
}
3133
});
3234

33-
UserSchema.plugin(passportLocalMongoose, {usernameField: 'account.email'});
35+
UserSchema.plugin(passportLocalMongoose, { usernameField: 'account.email' });
3436
const User = mongoose.model('ShouldSupportNestedFields_Issue_9', UserSchema);
3537

36-
User.register({account: {email: 'nestedemail'}}, 'password', function(err, user) {
38+
User.register({ account: { email: 'nestedemail' } }, 'password', function(err, user) {
3739
expect(err).to.not.exist;
3840
expect(user).to.exist;
3941

@@ -54,7 +56,7 @@ describe('issues', function() {
5456
UserSchema.plugin(passportLocalMongoose);
5557
const User = mongoose.model('ShouldNotThrowIfPasswordOrSaltAreNotStored_Issue_27', UserSchema);
5658

57-
User.create({username: 'hugo', name: 'Hugo Wiener', age: 143}, function(err, user) {
59+
User.create({ username: 'hugo', name: 'Hugo Wiener', age: 143 }, function(err, user) {
5860
expect(err).to.not.exist;
5961
expect(user).to.exist;
6062

@@ -76,10 +78,10 @@ describe('issues', function() {
7678
age: Number
7779
});
7880

79-
UserSchema.plugin(passportLocalMongoose, {selectFields: 'name'});
81+
UserSchema.plugin(passportLocalMongoose, { selectFields: 'name' });
8082
const User = mongoose.model('ShouldNotThrowIfPasswordAndSaltAreNotSelected_Issue_27', UserSchema);
8183

82-
User.register(new User({username: 'hugo'}), 'password', function(err, user) {
84+
User.register(new User({ username: 'hugo' }), 'password', function(err, user) {
8385
expect(err).to.not.exist;
8486
expect(user).to.exist;
8587

@@ -95,24 +97,24 @@ describe('issues', function() {
9597
});
9698

9799
it('should populate fields in findByUsername if option is given - Issue #20', function(done) {
98-
const LoginSchema = new Schema({date: Date, success: Boolean});
99-
const UserSchema = new Schema({logins: [{type: Schema.Types.ObjectId, ref: 'Login'}]});
100+
const LoginSchema = new Schema({ date: Date, success: Boolean });
101+
const UserSchema = new Schema({ logins: [{ type: Schema.Types.ObjectId, ref: 'Login' }] });
100102

101-
UserSchema.plugin(passportLocalMongoose, {populateFields: 'logins'});
103+
UserSchema.plugin(passportLocalMongoose, { populateFields: 'logins' });
102104
const User = mongoose.model('ShouldPopulateFields_Issue_20', UserSchema);
103105
const Login = mongoose.model('Login', LoginSchema);
104106

105107
const loginDate = new Date();
106108
const loginSuccess = true;
107109

108-
Login.create({date: loginDate, success: loginSuccess}, function(err, login) {
110+
Login.create({ date: loginDate, success: loginSuccess }, function(err, login) {
109111
expect(err).to.not.exist;
110112
expect(login).to.exist;
111113

112114
const logins = [];
113115
logins.push(login._id);
114116

115-
User.register(new User({username: 'hugo', logins: logins}), 'password', function(err, user) {
117+
User.register(new User({ username: 'hugo', logins: logins }), 'password', function(err, user) {
116118
expect(err).to.not.exist;
117119
expect(user).to.exist;
118120

@@ -144,7 +146,7 @@ describe('issues', function() {
144146

145147
const User = mongoose.model('ShouldSupportPasswordValidation_Issue_57', UserSchema);
146148

147-
User.register({username: 'nicolascage'}, 'password', function(err) {
149+
User.register({ username: 'nicolascage' }, 'password', function(err) {
148150
expect(err.message).to.equal('No password is valid');
149151
done();
150152
});
@@ -163,9 +165,9 @@ describe('issues', function() {
163165

164166
const User = mongoose.model('ShouldSupportPasswordValidation_With_Promises_Issue_57', UserSchema);
165167

166-
return User.register({username: 'nicolascage'}, 'password')
168+
return User.register({ username: 'nicolascage' }, 'password')
167169
.then(() => {
168-
throw new Error('Expected password validator to throw!')
170+
throw new Error('Expected password validator to throw!');
169171
})
170172
.catch(err => {
171173
expect(err.message).to.equal('No password is valid');
@@ -178,10 +180,10 @@ describe('issues', function() {
178180
UserSchema.plugin(passportLocalMongoose, {});
179181
const User = mongoose.model('ShouldNotExposeHashAndSaltFields_Issue_72', UserSchema);
180182

181-
User.register({username: 'nicolascage'}, 'password', function(err, user) {
183+
User.register({ username: 'nicolascage' }, 'password', function(err, user) {
182184
expect(err).to.not.exist;
183185
expect(user).to.exist;
184-
User.findOne({username: 'nicolascage'}, function(err, user) {
186+
User.findOne({ username: 'nicolascage' }, function(err, user) {
185187
expect(err).to.not.exist;
186188
expect(user).to.exist;
187189
expect(user.username).to.equal('nicolascage');
@@ -198,15 +200,15 @@ describe('issues', function() {
198200
const userName = 'user_' + Math.random();
199201
const User = mongoose.model('ShouldAuthenticateWithSaltAndHashNotExposed_Issue_96', UserSchema);
200202
beforeEach(function(done) {
201-
User.register({username: userName}, 'password', function(err, user) {
203+
User.register({ username: userName }, 'password', function(err, user) {
202204
expect(err).to.not.exist;
203205
expect(user).to.exist;
204206
done();
205207
});
206208
});
207209

208210
it('instance.authenticate( password, callback )', function(done) {
209-
User.findOne({username: userName}, function(err, user) {
211+
User.findOne({ username: userName }, function(err, user) {
210212
expect(err).to.not.exist;
211213
expect(user).to.exist;
212214
expect(user.username).to.equal(userName);
@@ -233,24 +235,28 @@ describe('issues', function() {
233235
it('should authenticate a user created in a 3.x version - issue #115', function(done) {
234236
const UserSchema = new Schema();
235237
// Backward compatible digest is used: sha1 because pre node.js 0.12 this was the only supported digest algorithm!
236-
UserSchema.plugin(passportLocalMongoose, {usernameLowerCase: true, digestAlgorithm: 'sha1' });
238+
UserSchema.plugin(passportLocalMongoose, { usernameLowerCase: true, digestAlgorithm: 'sha1' });
237239
const User = mongoose.model('AuthenticateBackwardCompatible', UserSchema);
238240

239241
// 3.0 generated hash and salt of 'username', 'password'
240-
User.create({
241-
'salt' : 'fd4bb06e65cd4d582efde28427ffdeb8839c64169d72cfe131bd971f70dc08f8',
242-
'hash' : '2ce573e406497fcbc2c1e91532cdbcf198ecbe2692cd5b3dffc303c51e6ccf56ae6a1ed9bac17f6f185d2d289ed713f7bd2a7a6246a4974495a35ff95bba234e00757d8a78fb28836a984c3e67465a019ead84d684896712c50f670663134685225b6832ec5a0a99922eabe6ba03abc1e79bc6a29ca2fe23456034eff2987277331f9e32713b3293ab355882feebe9c37ecdcd1a22dcebd6e5799adeb6a4dc32e56398d21ece6eda07b84944c3918de6bda69ab7998be461f98ff1559a07fd5d3100d732da443110b3ac7d27d16098c4e1eab7489f6d2a5849981a5c9f5dadb86d8dbbb9b60ce67304e21221e77d1a2700cab460450702c16b99db2e3b67454765fe9e4054c87a9e436fb17db1774b9d22a129c1b120dad0925b58390b8a02241e7e06acbe87dbe7f0e91b5d000cd93fc7cc8f316f45b901b8eb58ea6853c8e7ead245a9329239ed4f3797bc12a151ffedd8e8d2533547a1aec7231a460ca128ebfb1bd6b6f988455505c21d2dbfe01ee4b321a3d20a5bf6e2a356b6f4dbb8ddb4cff7dc9779b9747881af4d08e2fbcf452746e07275ed350fad0d4e6e8fcbedb0575c1413be5a913ca6ef4fcf17d1021b93fe2b3b410cf612791f967521ae558459673156e431be5203ca944e80652559eaf3faa90250df3d24526d5f9fc3409e508a3e2175daaf492fd6efd748e4418834b631f84fe266ac32f4927c3a426b',
243-
'username' : 'username'
244-
}, function(err) {
245-
expect(err).to.not.exist;
246-
247-
User.authenticate()('username', 'password', function(err, authenticated) {
242+
User.create(
243+
{
244+
salt: 'fd4bb06e65cd4d582efde28427ffdeb8839c64169d72cfe131bd971f70dc08f8',
245+
hash:
246+
'2ce573e406497fcbc2c1e91532cdbcf198ecbe2692cd5b3dffc303c51e6ccf56ae6a1ed9bac17f6f185d2d289ed713f7bd2a7a6246a4974495a35ff95bba234e00757d8a78fb28836a984c3e67465a019ead84d684896712c50f670663134685225b6832ec5a0a99922eabe6ba03abc1e79bc6a29ca2fe23456034eff2987277331f9e32713b3293ab355882feebe9c37ecdcd1a22dcebd6e5799adeb6a4dc32e56398d21ece6eda07b84944c3918de6bda69ab7998be461f98ff1559a07fd5d3100d732da443110b3ac7d27d16098c4e1eab7489f6d2a5849981a5c9f5dadb86d8dbbb9b60ce67304e21221e77d1a2700cab460450702c16b99db2e3b67454765fe9e4054c87a9e436fb17db1774b9d22a129c1b120dad0925b58390b8a02241e7e06acbe87dbe7f0e91b5d000cd93fc7cc8f316f45b901b8eb58ea6853c8e7ead245a9329239ed4f3797bc12a151ffedd8e8d2533547a1aec7231a460ca128ebfb1bd6b6f988455505c21d2dbfe01ee4b321a3d20a5bf6e2a356b6f4dbb8ddb4cff7dc9779b9747881af4d08e2fbcf452746e07275ed350fad0d4e6e8fcbedb0575c1413be5a913ca6ef4fcf17d1021b93fe2b3b410cf612791f967521ae558459673156e431be5203ca944e80652559eaf3faa90250df3d24526d5f9fc3409e508a3e2175daaf492fd6efd748e4418834b631f84fe266ac32f4927c3a426b',
247+
username: 'username'
248+
},
249+
function(err) {
248250
expect(err).to.not.exist;
249-
expect(authenticated).to.exist;
250251

251-
done();
252-
});
253-
});
252+
User.authenticate()('username', 'password', function(err, authenticated) {
253+
expect(err).to.not.exist;
254+
expect(authenticated).to.exist;
255+
256+
done();
257+
});
258+
}
259+
);
254260
});
255261
});
256262

@@ -272,12 +278,16 @@ describe('issues', function() {
272278

273279
const User = mongoose.model('ShouldSupportAdditionalQueryRestrictions', UserSchema);
274280

275-
User.register({username:'username', active: false}, 'password', function(err) {
276-
if (err) { return done(err); }
281+
User.register({ username: 'username', active: false }, 'password', function(err) {
282+
if (err) {
283+
return done(err);
284+
}
277285

278286
const authenticate = User.authenticate();
279287
authenticate('username', 'password', function(err, result) {
280-
if (err) { return done(err); }
288+
if (err) {
289+
return done(err);
290+
}
281291

282292
// Expect that non active users must not authenticate successfully!
283293
expect(result).to.be.false;
@@ -304,15 +314,21 @@ describe('issues', function() {
304314

305315
const User = mongoose.model('ShouldAllowRegisteredNonActiveUsernamesInRegister', UserSchema);
306316

307-
User.register({username:'username', active: false }, 'password', function(err) {
308-
if (err) { return done(err); }
317+
User.register({ username: 'username', active: false }, 'password', function(err) {
318+
if (err) {
319+
return done(err);
320+
}
309321

310-
User.register({username:'username', active: true}, 'password', function(err) {
311-
if (err) { return done(err); }
322+
User.register({ username: 'username', active: true }, 'password', function(err) {
323+
if (err) {
324+
return done(err);
325+
}
312326

313327
const authenticate = User.authenticate();
314328
authenticate('username', 'password', function(err, user) {
315-
if (err) { return done(err); }
329+
if (err) {
330+
return done(err);
331+
}
316332

317333
// Expect that active users can authenticate!
318334
expect(user).to.exist;

‎test/passport-local-mongoose.js

+359-194
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.