Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Validate UUID tokens #239

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const validator = require('validator')
* @returns boolean
*/
function validateToken(token) {
return validator.isAlphanumeric(token)
return validator.isAlphanumeric(token) || validator.isUUID(token)
}

function validateURL(url) {
Expand Down
6 changes: 5 additions & 1 deletion test/helpers/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ const realEnv = { ...process.env }

describe('Input Validators', () => {
describe('Tokens', () => {
it('Returns true with a valid token', () => {
it('Returns true with a valid alphanumeric token', () => {
expect(validate.validateToken('1bc123')).toBe(true)
})
it('Returns true with a valid UUID token', () => {
// Use a randomly generated UUIDv4
expect(validate.validateToken('5becd1a9-efa8-4bd8-8f94-e9f8613820c3')).toBe(true)
})
it('Returns false with an invalid token', () => {
expect(validate.validateToken('1bc1 23')).toBe(false)
})
Expand Down
31 changes: 22 additions & 9 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const { version } = require('../package.json')
const nock = require('nock')
const fs = require('fs')

// Backup the env
const realEnv = { ...process.env }

describe('Uploader Core', () => {
const env = process.env

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

it('Can upload without token', async () => {
jest.spyOn(process, 'exit').mockImplementation(() => {})
const log = jest.spyOn(console, 'log').mockImplementation(() => {})
await app.main({
name: 'customname',
url: 'https://codecov.io',
dryRun: true,
env: 'SOMETHING,ANOTHER',
describe('Token', () => {
beforeEach(() => {
delete process.env.CODECOV_TOKEN
})

afterEach(() => {
process.env = realEnv
})

it('Can upload without token', async () => {
jest.spyOn(process, 'exit').mockImplementation(() => {})
const log = jest.spyOn(console, 'log').mockImplementation(() => {})
await app.main({
name: 'customname',
url: 'https://codecov.io',
dryRun: true,
env: 'SOMETHING,ANOTHER',
})
expect(log).toHaveBeenCalledWith(expect.stringMatching('-> No token specified or token is empty'))
})
expect(log).toHaveBeenCalledWith(expect.stringMatching('-> No token specified or token is empty'))
})

describe('Flags', () => {
Expand Down