Skip to content

Commit

Permalink
Case insensitive match.
Browse files Browse the repository at this point in the history
  • Loading branch information
bstopp committed May 16, 2024
1 parent 725b972 commit 79db428
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ export async function isAuthorized(env, org, user) {
}, []);

if (!admins) return true;
return admins.some((admin) => admin === user.email);
return admins.some((admin) => admin.toLowerCase() === user.email.toLowerCase());
}
5 changes: 5 additions & 0 deletions test/utils/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ describe('Dark Alley auth', () => {
assert.strictEqual(authed, true);
});

it('authorized if org and user match - case insensitive', async () => {
const authed = await isAuthorized(env, 'geometrixx', { email: '[email protected]' });
assert.strictEqual(authed, true);
});

it('not authorized no user match', async () => {
const authed = await isAuthorized(env, 'geometrixx', { email: '[email protected]' });
assert.strictEqual(authed, false);
Expand Down
8 changes: 4 additions & 4 deletions test/utils/mocks/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const DA_CONFIG = {
"limit": 1,
"offset": 0,
"data": [
{
"key": "admin.role.all",
"value": "[email protected]"
}
{
"key": "admin.role.all",
"value": "[email protected]"
}
],
":type": "sheet"
}
Expand Down

0 comments on commit 79db428

Please sign in to comment.