Skip to content

Commit

Permalink
Add property for configurable security reviewers
Browse files Browse the repository at this point in the history
  • Loading branch information
ebickle committed Oct 15, 2024
1 parent 3d617c7 commit 3abd7ef
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
9 changes: 6 additions & 3 deletions common/authorization.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export function isSecurityReviewer(username) {
// TODO: Externalize to configuration
const securityReviewers = ['octocat', 'monalisa'];
return securityReviewers.includes(username);
if (!process.env.SECURITY_REVIEWERS) {
throw new Error('SECURITY_REVIEWERS environment variable is not set');
}

const securityReviewers = process.env.SECURITY_REVIEWERS.split(',').map(r => r.trim().toLowerCase());
return securityReviewers.includes(username.toLowerCase());
}
33 changes: 33 additions & 0 deletions test/common/authorization.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from 'node:assert/strict';
import { describe, test, beforeEach, afterEach } from 'node:test';
import { isSecurityReviewer } from '../../common/authorization.js';

describe('isSecurityReviewer', () => {
let envBackup;

beforeEach(() => {
envBackup = process.env.SECURITY_REVIEWERS;
});

afterEach(() => {
process.env.SECURITY_REVIEWERS = envBackup;
});

test('throws error when SECURITY_REVIEWERS is not set', () => {
delete process.env.SECURITY_REVIEWERS;
assert.throws(() => isSecurityReviewer('user1'), {
message: 'SECURITY_REVIEWERS environment variable is not set'
});
});

test('returns true for a security reviewer', () => {
process.env.SECURITY_REVIEWERS = ' USER1, user2, user3 ';
assert.equal(isSecurityReviewer('user1'), true);
assert.equal(isSecurityReviewer('USER2'), true);
});

test('returns false for a non-security reviewer', () => {
process.env.SECURITY_REVIEWERS = ' USER1, user2, user3 ';
assert.equal(isSecurityReviewer('user4'), false);
});
});

0 comments on commit 3abd7ef

Please sign in to comment.