From 504e43dd4dbfbc667dd0cf83466f07567cb48fee Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 20 Jul 2021 21:07:53 +0000 Subject: [PATCH 1/2] chore(deps): update google/cloud-sdk docker tag to v349 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a35fcceb7..6c7a40787 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -392,7 +392,7 @@ jobs: - release_tag release: docker: - - image: google/cloud-sdk:348.0.0-slim + - image: google/cloud-sdk:349.0.0-slim steps: - attach_workspace: # Must be absolute path or relative path from working_directory From 1756b26ba8edce9cce90831234353ce188d87b73 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Thu, 22 Jul 2021 10:22:55 -0700 Subject: [PATCH 2/2] fix: Validate UUID tokens --- src/helpers/validate.js | 2 +- test/helpers/validate.test.js | 6 +++++- test/index.test.js | 31 ++++++++++++++++++++++--------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/helpers/validate.js b/src/helpers/validate.js index 1796d9e99..a1d6665a1 100644 --- a/src/helpers/validate.js +++ b/src/helpers/validate.js @@ -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) { diff --git a/test/helpers/validate.test.js b/test/helpers/validate.test.js index 1842ab394..6329fe77d 100644 --- a/test/helpers/validate.test.js +++ b/test/helpers/validate.test.js @@ -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) }) diff --git a/test/index.test.js b/test/index.test.js index a3d899f16..fdcd0881d 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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 @@ -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', () => {