-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1265 from EcrituresNumeriques/fix/1264
Supprime le champ `user.admin`
- Loading branch information
Showing
20 changed files
with
271 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
exports.up = async function (db) { | ||
const mongo = await db._run('getDbInstance', true) | ||
try { | ||
await mongo.collection('users').updateMany({}, { $unset: { admin: '' } }) | ||
} finally { | ||
await mongo.close() | ||
} | ||
} | ||
|
||
exports.down = async function (db) { | ||
const mongo = await db._run('getDbInstance', true) | ||
try { | ||
await mongo.collection('users').updateMany({}, { $set: { admin: false } }) | ||
} finally { | ||
await mongo.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,20 @@ const UserModel = require('../models/user.js') | |
|
||
const user = '63977de2f83aa77c5f92cb1c' | ||
const sameUserObject = new UserModel({ _id: user }) | ||
const sameUserToken = { _id: user, email: '[email protected]', admin: false, session: true, authType: 'oidc' } | ||
const sameUserToken = { | ||
_id: user, | ||
email: '[email protected]', | ||
session: true, | ||
authType: 'oidc', | ||
} | ||
|
||
const differentUserObject = new UserModel({ _id: '00000de2f83aa77c5f92dc2f'}) | ||
const differentUserObject = new UserModel({ _id: '00000de2f83aa77c5f92dc2f' }) | ||
|
||
const adminToken = { admin: true, roles: ['read'], readonly: true } | ||
|
||
|
||
describe('isUser', () => { | ||
test('without token, no args.user', () => { | ||
expect(() => isUser({ }, { token: {} })).toThrow(/Unauthorized/) | ||
expect(() => isUser({}, { token: {} })).toThrow(/Unauthorized/) | ||
}) | ||
|
||
test('without token, explicit args.user', () => { | ||
|
@@ -28,14 +32,23 @@ describe('isUser', () => { | |
}) | ||
|
||
test('with token, implicit user is token user', () => { | ||
expect(isUser({}, { token: sameUserToken, user: sameUserObject })).toEqual({ userId: sameUserToken._id }) | ||
expect(isUser({}, { token: sameUserToken, user: sameUserObject })).toEqual({ | ||
userId: sameUserToken._id, | ||
}) | ||
}) | ||
|
||
test('with token, explicit user is same as user token', () => { | ||
expect(isUser({ user }, { token: sameUserToken, user: sameUserObject })).toEqual({ userId: user }) | ||
expect( | ||
isUser({ user }, { token: sameUserToken, user: sameUserObject }) | ||
).toEqual({ userId: user }) | ||
}) | ||
|
||
test('with token, explicit user is different than user token', () => { | ||
expect(() => isUser({ user: differentUserObject.id }, { token: sameUserToken, user: sameUserObject })).toThrow(/Forbidden/) | ||
expect(() => | ||
isUser( | ||
{ user: differentUserObject.id }, | ||
{ token: sameUserToken, user: sameUserObject } | ||
) | ||
).toThrow(/Forbidden/) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.