From c4c2f71d6cb5ca3f3b7ad8a10d05013609b753b6 Mon Sep 17 00:00:00 2001 From: Brian Maher Date: Tue, 25 Jul 2017 10:39:24 -0700 Subject: [PATCH 1/3] Github usernames should be case-insensitive One of our admin users give me their github username, but the API returned their user-name with some capitol letters which made them appear as though they were not administrators. --- src/authorizers/github.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/authorizers/github.js b/src/authorizers/github.js index e2201e0..e18c80f 100644 --- a/src/authorizers/github.js +++ b/src/authorizers/github.js @@ -112,7 +112,8 @@ export default async ({ methodArn, authorizationToken }, context, callback) => { } if (process.env.admins) { - isAdmin = process.env.admins.split(',').indexOf(user.login) > -1; + let login = user.login.toLowerCase(); + isAdmin = process.env.admins.toLowerCase().split(',').indexOf(login) > -1; } const policy = generatePolicy({ From fc74a3741a3630f87d52d001e2c0894517386f9e Mon Sep 17 00:00:00 2001 From: Brian Maher Date: Tue, 25 Jul 2017 10:49:59 -0700 Subject: [PATCH 2/3] Use const instead of let per linting... --- src/authorizers/github.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/authorizers/github.js b/src/authorizers/github.js index e18c80f..adf8126 100644 --- a/src/authorizers/github.js +++ b/src/authorizers/github.js @@ -112,7 +112,7 @@ export default async ({ methodArn, authorizationToken }, context, callback) => { } if (process.env.admins) { - let login = user.login.toLowerCase(); + const login = user.login.toLowerCase(); isAdmin = process.env.admins.toLowerCase().split(',').indexOf(login) > -1; } From 06302930c4949c781e8b5372429498fc93dbae3a Mon Sep 17 00:00:00 2001 From: Brian Maher Date: Tue, 25 Jul 2017 10:52:58 -0700 Subject: [PATCH 3/3] Test that github username is case-insensitive --- test/authorizers/github.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/authorizers/github.test.js b/test/authorizers/github.test.js index 6259c58..c456876 100644 --- a/test/authorizers/github.test.js +++ b/test/authorizers/github.test.js @@ -414,7 +414,7 @@ describe('GitHub Authorizer', () => { authStub = stub(); checkAuthStub = stub().returns({ user: { - login: 'foo-user', + login: 'Foo-User', avatar_url: 'https://example.com', }, created_at: '2001-01-01T00:00:00Z', @@ -479,7 +479,7 @@ describe('GitHub Authorizer', () => { ], }, context: { - username: 'foo-user', + username: 'Foo-User', avatar: 'https://example.com', createdAt: '2001-01-01T00:00:00Z', updatedAt: '2001-02-01T00:00:00Z',