Skip to content

Commit 859243b

Browse files
committed
[service] redact previous passwords from local auth documents
1 parent 8302731 commit 859243b

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

service/src/models/authentication.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const LocalSchema = new Schema(
5858
function DbLocalAuthenticationToObject(authIn, authOut, options) {
5959
authOut = DbAuthenticationToObject(authIn, authOut, options)
6060
delete authOut.password;
61+
delete authOut.previousPasswords;
6162
return authOut;
6263
}
6364

service/test/models/authenticationTest.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ describe("authentication model", function () {
3636

3737
describe('toObject', function() {
3838

39-
it('redacts password', function() {
39+
it('redacts passwords', function() {
4040

4141
const authentication = new Authentication.Local({
4242
type: 'local',
43-
password: 'password',
43+
password: 'password now',
44+
previousPasswords: [ 'password before' ],
4445
authenticationConfigurationId: mongoose.Types.ObjectId()
4546
});
4647
const authObj = authentication.toObject();
4748

48-
expect(authObj.password).to.be.undefined
49+
expect(authObj).to.not.have.property('password')
50+
expect(authObj).to.not.have.property('previousPasswords')
4951
})
5052
})
5153
})

service/test/user/userReadTest.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ describe("user read tests", function() {
258258
displayName: 'Test 1',
259259
authenticationId: new Authentication.Local({
260260
_id: mongoose.Types.ObjectId(),
261-
password: 'hide me 1'
261+
password: 'hide me 1',
262+
previousPasswords: []
262263
})
263264
}),
264265
new UserModel({
@@ -267,7 +268,8 @@ describe("user read tests", function() {
267268
displayName: 'Test 2',
268269
authenticationId: new Authentication.Local({
269270
_id: mongoose.Types.ObjectId(),
270-
password: 'hide me 2'
271+
password: 'hide me 2',
272+
previousPasswords: [ 'prev 1', 'prev 2' ]
271273
})
272274
})
273275
];
@@ -286,8 +288,10 @@ describe("user read tests", function() {
286288
expect(Array.isArray(res.body)).to.be.true;
287289
expect(res.body[0].authentication.id).to.equal(userDocs[0].authenticationId._id.toHexString());
288290
expect(res.body[0].authentication).to.not.have.property('password');
291+
expect(res.body[0].authentication).to.not.have.property('previousPasswords');
289292
expect(res.body[1].authentication.id).to.equal(userDocs[1].authenticationId._id.toHexString());
290293
expect(res.body[1].authentication).to.not.have.property('password');
294+
expect(res.body[1].authentication).to.not.have.property('previousPasswords');
291295
})
292296

293297
it('redacts local auth password when paging all users', async function() {
@@ -299,7 +303,8 @@ describe("user read tests", function() {
299303
displayName: 'Test 1',
300304
authenticationId: new Authentication.Local({
301305
_id: mongoose.Types.ObjectId(),
302-
password: 'hide me 1'
306+
password: 'hide me 1',
307+
previousPasswords: [ 'hide this too' ]
303308
})
304309
}),
305310
new UserModel({
@@ -308,7 +313,8 @@ describe("user read tests", function() {
308313
displayName: 'Test 2',
309314
authenticationId: new Authentication.Local({
310315
_id: mongoose.Types.ObjectId(),
311-
password: 'hide me 2'
316+
password: 'hide me 2',
317+
previousPasswords: [ 'hide prev 1', 'hide prev 2' ]
312318
})
313319
})
314320
];
@@ -335,6 +341,7 @@ describe("user read tests", function() {
335341
expect(Array.isArray(res.body.items)).to.be.true;
336342
expect(res.body.items[0].authentication.id).to.equal(userDocs[0].authenticationId._id.toHexString());
337343
expect(res.body.items[0].authentication).to.not.have.property('password');
344+
expect(res.body.items[0].authentication).to.not.have.property('previousPasswords');
338345
})
339346

340347

0 commit comments

Comments
 (0)