Skip to content

Commit 300eb11

Browse files
authored
Merge pull request #239 from codecov/fix-uuid-token
fix: Validate UUID tokens
2 parents b3d01c0 + 1756b26 commit 300eb11

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/helpers/validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const validator = require('validator')
66
* @returns boolean
77
*/
88
function validateToken(token) {
9-
return validator.isAlphanumeric(token)
9+
return validator.isAlphanumeric(token) || validator.isUUID(token)
1010
}
1111

1212
function validateURL(url) {

test/helpers/validate.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ const realEnv = { ...process.env }
55

66
describe('Input Validators', () => {
77
describe('Tokens', () => {
8-
it('Returns true with a valid token', () => {
8+
it('Returns true with a valid alphanumeric token', () => {
99
expect(validate.validateToken('1bc123')).toBe(true)
1010
})
11+
it('Returns true with a valid UUID token', () => {
12+
// Use a randomly generated UUIDv4
13+
expect(validate.validateToken('5becd1a9-efa8-4bd8-8f94-e9f8613820c3')).toBe(true)
14+
})
1115
it('Returns false with an invalid token', () => {
1216
expect(validate.validateToken('1bc1 23')).toBe(false)
1317
})

test/index.test.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const { version } = require('../package.json')
44
const nock = require('nock')
55
const fs = require('fs')
66

7+
// Backup the env
8+
const realEnv = { ...process.env }
9+
710
describe('Uploader Core', () => {
811
const env = process.env
912

@@ -68,16 +71,26 @@ describe('Uploader Core', () => {
6871
expect(log).toHaveBeenCalledWith(expect.stringMatching(/<<<<<< ENV/))
6972
})
7073

71-
it('Can upload without token', async () => {
72-
jest.spyOn(process, 'exit').mockImplementation(() => {})
73-
const log = jest.spyOn(console, 'log').mockImplementation(() => {})
74-
await app.main({
75-
name: 'customname',
76-
url: 'https://codecov.io',
77-
dryRun: true,
78-
env: 'SOMETHING,ANOTHER',
74+
describe('Token', () => {
75+
beforeEach(() => {
76+
delete process.env.CODECOV_TOKEN
77+
})
78+
79+
afterEach(() => {
80+
process.env = realEnv
81+
})
82+
83+
it('Can upload without token', async () => {
84+
jest.spyOn(process, 'exit').mockImplementation(() => {})
85+
const log = jest.spyOn(console, 'log').mockImplementation(() => {})
86+
await app.main({
87+
name: 'customname',
88+
url: 'https://codecov.io',
89+
dryRun: true,
90+
env: 'SOMETHING,ANOTHER',
91+
})
92+
expect(log).toHaveBeenCalledWith(expect.stringMatching('-> No token specified or token is empty'))
7993
})
80-
expect(log).toHaveBeenCalledWith(expect.stringMatching('-> No token specified or token is empty'))
8194
})
8295

8396
describe('Flags', () => {

0 commit comments

Comments
 (0)