Skip to content

Commit

Permalink
fix: update permitted GitHub token characters
Browse files Browse the repository at this point in the history
Our commit linter is flagging the GitHub blog URL for being longer than
100 characters so here it is as a tinyurl.

Refs: https://tinyurl.com/2p9cz8m3
Fixes: #617
  • Loading branch information
Trott committed Apr 7, 2022
1 parent 64a977c commit dc3d3ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function check(username, token) {
if (typeof token !== 'string') {
errorExit(`token must be a string, received ${typeof token}`);
}
if (!/^[0-9a-f]+$/.test(token)) {
errorExit(`token must be lowercase hexadecimal, received ${token}`);
if (!/^[A-Za-z0-9_]+$/.test(token)) {
errorExit(`token is misformatted: ${token}`);
}
}

Expand Down
20 changes: 18 additions & 2 deletions test/unit/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,25 @@ describe('auth', async function() {
it('does not accept an invalid token format', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: '0123456789ABCDEF' } },
{ HOME: { username: 'nyancat', token: '@fhqwhgads' } },
[],
'token must be lowercase hexadecimal, received 0123456789ABCDEF\n'
'token is misformatted: @fhqwhgads\n'
);
});

it('permits capital letters in token format', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: '0123456789ABCDEF' } },
['{"github":"bnlhbmNhdDowMTIzNDU2Nzg5QUJDREVG"}']
);
});

it('permits underscores in token format', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: 'ghp_0123456789ABCDEF' } },
['{"github":"bnlhbmNhdDpnaHBfMDEyMzQ1Njc4OUFCQ0RFRg=="}']
);
});
});
Expand Down

0 comments on commit dc3d3ef

Please sign in to comment.