From 2bfe26481be1895bc880094ab62c866db126fef5 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Wed, 23 Jun 2021 11:22:59 -0400 Subject: [PATCH] refactor: remove project token, unused since 0.19.0 (#17039) --- packages/desktop-gui/src/runs/runs-list.jsx | 6 +- packages/server/lib/api.js | 24 --- packages/server/lib/cypress.js | 22 --- packages/server/lib/project-base.ts | 28 ---- packages/server/lib/util/args.js | 4 +- packages/server/lib/util/routes.js | 1 - .../server/test/integration/cypress_spec.js | 140 ------------------ packages/server/test/unit/api_spec.js | 68 --------- packages/server/test/unit/args_spec.js | 4 - packages/server/test/unit/project_spec.js | 58 -------- packages/server/test/unit/routes_util_spec.js | 4 - 11 files changed, 4 insertions(+), 355 deletions(-) diff --git a/packages/desktop-gui/src/runs/runs-list.jsx b/packages/desktop-gui/src/runs/runs-list.jsx index e800073cf733..13bb56636ae3 100644 --- a/packages/desktop-gui/src/runs/runs-list.jsx +++ b/packages/desktop-gui/src/runs/runs-list.jsx @@ -41,11 +41,11 @@ class RunsList extends Component { componentDidMount () { this._pingApiServer() this._handlePolling() - this._getKey() + this._getRecordKeys() } componentDidUpdate () { - this._getKey() + this._getRecordKeys() this._handlePolling() } @@ -106,7 +106,7 @@ class RunsList extends Component { runsApi.stopPollingRuns() } - _getKey () { + _getRecordKeys () { if (this._needsKey()) { projectsApi.getRecordKeys().then((keys = []) => { if (keys.length) { diff --git a/packages/server/lib/api.js b/packages/server/lib/api.js index 22bd1906ed5b..17b06940bc0c 100644 --- a/packages/server/lib/api.js +++ b/packages/server/lib/api.js @@ -458,30 +458,6 @@ module.exports = { .catch(tagError) }, - _projectToken (method, projectId, authToken) { - return rp({ - method, - url: apiRoutes.projectToken(projectId), - json: true, - auth: { - bearer: authToken, - }, - headers: { - 'x-route-version': '2', - }, - }) - .get('apiToken') - .catch(tagError) - }, - - getProjectToken (projectId, authToken) { - return this._projectToken('get', projectId, authToken) - }, - - updateProjectToken (projectId, authToken) { - return this._projectToken('put', projectId, authToken) - }, - getReleaseNotes (version) { return rp.get({ url: onRoutes.releaseNotes(version), diff --git a/packages/server/lib/cypress.js b/packages/server/lib/cypress.js index 088a07745d54..6859d28e716c 100644 --- a/packages/server/lib/cypress.js +++ b/packages/server/lib/cypress.js @@ -175,10 +175,6 @@ module.exports = { mode = 'logs' } else if (options.clearLogs) { mode = 'clearLogs' - } else if (options.getKey) { - mode = 'getKey' - } else if (options.generateKey) { - mode = 'generateKey' } else if (!(options.exitWithCode == null)) { mode = 'exitWithCode' } else if (options.runProject) { @@ -242,24 +238,6 @@ module.exports = { .then(exit0) .catch(exitErr) - case 'getKey': - // print the key + exit - return require('./project-base').ProjectBase - .getSecretKeyByPath(options.projectRoot) - .then((key) => { - return console.log(key) // eslint-disable-line no-console - }).then(exit0) - .catch(exitErr) - - case 'generateKey': - // generate + print the key + exit - return require('./project-base').ProjectBase - .generateSecretKeyByPath(options.projectRoot) - .then((key) => { - return console.log(key) // eslint-disable-line no-console - }).then(exit0) - .catch(exitErr) - case 'exitWithCode': return require('./modes/exit')(options) .then(exit) diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index f3ab56fd47d1..bfd21b68aabc 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -1025,34 +1025,6 @@ export class ProjectBase extends EE { return new ProjectBase(path).getConfig() } - static getSecretKeyByPath (path) { - // get project id - return ProjectBase.id(path) - .then((id) => { - return user.ensureAuthToken() - .then((authToken) => { - return api.getProjectToken(id, authToken) - .catch(() => { - errors.throw('CANNOT_FETCH_PROJECT_TOKEN') - }) - }) - }) - } - - static generateSecretKeyByPath (path) { - // get project id - return ProjectBase.id(path) - .then((id) => { - return user.ensureAuthToken() - .then((authToken) => { - return api.updateProjectToken(id, authToken) - .catch(() => { - errors.throw('CANNOT_CREATE_PROJECT_TOKEN') - }) - }) - }) - } - // Given a path to the project, finds all specs // returns list of specs with respect to the project root static findSpecs (projectRoot, specPattern) { diff --git a/packages/server/lib/util/args.js b/packages/server/lib/util/args.js index cec2f76ee8d8..6fae8c8b96bc 100644 --- a/packages/server/lib/util/args.js +++ b/packages/server/lib/util/args.js @@ -13,7 +13,7 @@ const nestedObjectsInCurlyBracesRe = /\{(.+?)\}/g const nestedArraysInSquareBracketsRe = /\[(.+?)\]/g const everythingAfterFirstEqualRe = /=(.*)/ -const allowList = 'appPath apiKey browser ci ciBuildId clearLogs config configFile cwd env execPath exit exitWithCode generateKey getKey group headed inspectBrk key logs mode outputPath parallel ping port project proxySource quiet record reporter reporterOptions returnPkg runMode runProject smokeTest spec tag updating version testingType'.split(' ') +const allowList = 'appPath apiKey browser ci ciBuildId clearLogs config configFile cwd env execPath exit exitWithCode group headed inspectBrk key logs mode outputPath parallel ping port project proxySource quiet record reporter reporterOptions returnPkg runMode runProject smokeTest spec tag updating version testingType'.split(' ') // returns true if the given string has double quote character " // only at the last position. const hasStrayEndQuote = (s) => { @@ -177,8 +177,6 @@ module.exports = { 'exec-path': 'execPath', 'exit-with-code': 'exitWithCode', 'inspect-brk': 'inspectBrk', - 'get-key': 'getKey', - 'new-key': 'generateKey', 'output-path': 'outputPath', 'proxy-source': 'proxySource', 'reporter-options': 'reporterOptions', diff --git a/packages/server/lib/util/routes.js b/packages/server/lib/util/routes.js index 0281c565e56e..4085a250203a 100644 --- a/packages/server/lib/util/routes.js +++ b/packages/server/lib/util/routes.js @@ -56,7 +56,6 @@ const apiRoutes = makeRoutes(apiUrl, { orgs: 'organizations', projects: 'projects', project: 'projects/:id', - projectToken: 'projects/:id/token', projectRuns: 'projects/:id/runs', projectRecordKeys: 'projects/:id/keys', exceptions: 'exceptions', diff --git a/packages/server/test/integration/cypress_spec.js b/packages/server/test/integration/cypress_spec.js index 00d63dd49bc3..82e8ffe2648b 100644 --- a/packages/server/test/integration/cypress_spec.js +++ b/packages/server/test/integration/cypress_spec.js @@ -281,146 +281,6 @@ describe('lib/cypress', () => { }) }) - context('--get-key', () => { - it('writes out key and exits on success', function () { - return Promise.all([ - user.set({ name: 'brian', authToken: 'auth-token-123' }), - - ProjectBase.id(this.todosPath) - .then((id) => { - this.projectId = id - }), - ]) - .then(() => { - sinon.stub(api, 'getProjectToken') - .withArgs(this.projectId, 'auth-token-123') - .resolves('new-key-123') - - return cypress.start(['--get-key', `--project=${this.todosPath}`]) - }).then(() => { - expect(console.log).to.be.calledWith('new-key-123') - this.expectExitWith(0) - }) - }) - - it('logs error and exits when user isn\'t logged in', function () { - return user.set({}) - .then(() => { - return cypress.start(['--get-key', `--project=${this.todosPath}`]) - }).then(() => { - this.expectExitWithErr('NOT_LOGGED_IN') - }) - }) - - it('logs error and exits when project does not have an id', function () { - return user.set({ authToken: 'auth-token-123' }) - .then(() => { - return cypress.start(['--get-key', `--project=${this.pristinePath}`]) - }).then(() => { - this.expectExitWithErr('NO_PROJECT_ID', this.pristinePath) - }) - }) - - it('logs error and exits when project could not be found at the path', function () { - return user.set({ authToken: 'auth-token-123' }) - .then(() => { - return cypress.start(['--get-key', '--project=path/to/no/project']) - }).then(() => { - this.expectExitWithErr('NO_PROJECT_FOUND_AT_PROJECT_ROOT', 'path/to/no/project') - }) - }) - - it('logs error and exits when project token cannot be fetched', function () { - return Promise.all([ - user.set({ authToken: 'auth-token-123' }), - - ProjectBase.id(this.todosPath) - .then((id) => { - this.projectId = id - }), - ]) - .then(() => { - sinon.stub(api, 'getProjectToken') - .withArgs(this.projectId, 'auth-token-123') - .rejects(new Error()) - - return cypress.start(['--get-key', `--project=${this.todosPath}`]) - }).then(() => { - this.expectExitWithErr('CANNOT_FETCH_PROJECT_TOKEN') - }) - }) - }) - - context('--new-key', () => { - it('writes out key and exits on success', function () { - return Promise.all([ - user.set({ name: 'brian', authToken: 'auth-token-123' }), - - ProjectBase.id(this.todosPath) - .then((id) => { - this.projectId = id - }), - ]) - .then(() => { - sinon.stub(api, 'updateProjectToken') - .withArgs(this.projectId, 'auth-token-123') - .resolves('new-key-123') - - return cypress.start(['--new-key', `--project=${this.todosPath}`]) - }).then(() => { - expect(console.log).to.be.calledWith('new-key-123') - this.expectExitWith(0) - }) - }) - - it('logs error and exits when user isn\'t logged in', function () { - return user.set({}) - .then(() => { - return cypress.start(['--new-key', `--project=${this.todosPath}`]) - }).then(() => { - this.expectExitWithErr('NOT_LOGGED_IN') - }) - }) - - it('logs error and exits when project does not have an id', function () { - return user.set({ authToken: 'auth-token-123' }) - .then(() => { - return cypress.start(['--new-key', `--project=${this.pristinePath}`]) - }).then(() => { - this.expectExitWithErr('NO_PROJECT_ID', this.pristinePath) - }) - }) - - it('logs error and exits when project could not be found at the path', function () { - return user.set({ authToken: 'auth-token-123' }) - .then(() => { - return cypress.start(['--new-key', '--project=path/to/no/project']) - }).then(() => { - this.expectExitWithErr('NO_PROJECT_FOUND_AT_PROJECT_ROOT', 'path/to/no/project') - }) - }) - - it('logs error and exits when project token cannot be fetched', function () { - return Promise.all([ - user.set({ authToken: 'auth-token-123' }), - - ProjectBase.id(this.todosPath) - .then((id) => { - this.projectId = id - }), - ]) - .then(() => { - sinon.stub(api, 'updateProjectToken') - .withArgs(this.projectId, 'auth-token-123') - .rejects(new Error()) - - return cypress.start(['--new-key', `--project=${this.todosPath}`]) - }).then(() => { - this.expectExitWithErr('CANNOT_CREATE_PROJECT_TOKEN') - }) - }) - }) - context('--run-project', () => { beforeEach(() => { sinon.stub(electron.app, 'on').withArgs('ready').yieldsAsync() diff --git a/packages/server/test/unit/api_spec.js b/packages/server/test/unit/api_spec.js index 15b50e023d29..96e6d33a1694 100644 --- a/packages/server/test/unit/api_spec.js +++ b/packages/server/test/unit/api_spec.js @@ -1128,74 +1128,6 @@ describe('lib/api', () => { }) }) - context('.getProjectToken', () => { - it('GETs /projects/:id/token', () => { - nock(API_BASEURL) - .matchHeader('x-os-name', 'linux') - .matchHeader('x-cypress-version', pkg.version) - .matchHeader('authorization', 'Bearer auth-token-123') - .matchHeader('accept-encoding', /gzip/) - .get('/projects/project-123/token') - .reply(200, { - apiToken: 'token-123', - }) - - return api.getProjectToken('project-123', 'auth-token-123') - .then((resp) => { - expect(resp).to.eq('token-123') - }) - }) - - it('tags errors', () => { - nock(API_BASEURL) - .matchHeader('authorization', 'Bearer auth-token-123') - .matchHeader('accept-encoding', /gzip/) - .get('/projects/project-123/token') - .reply(500, {}) - - return api.getProjectToken('project-123', 'auth-token-123') - .then(() => { - throw new Error('should have thrown here') - }).catch((err) => { - expect(err.isApiError).to.be.true - }) - }) - }) - - context('.updateProjectToken', () => { - it('PUTs /projects/:id/token', () => { - nock(API_BASEURL) - .matchHeader('x-os-name', 'linux') - .matchHeader('x-cypress-version', pkg.version) - .matchHeader('authorization', 'Bearer auth-token-123') - .matchHeader('accept-encoding', /gzip/) - .put('/projects/project-123/token') - .reply(200, { - apiToken: 'token-123', - }) - - return api.updateProjectToken('project-123', 'auth-token-123') - .then((resp) => { - expect(resp).to.eq('token-123') - }) - }) - - it('tags errors', () => { - nock(API_BASEURL) - .matchHeader('authorization', 'Bearer auth-token-123') - .matchHeader('accept-encoding', /gzip/) - .put('/projects/project-id-123/token') - .reply(500, {}) - - return api.updateProjectToken('project-123', 'auth-token-123') - .then(() => { - throw new Error('should have thrown here') - }).catch((err) => { - expect(err.isApiError).to.be.true - }) - }) - }) - context('.createCrashReport', () => { beforeEach(function () { this.setup = (body, authToken, delay = 0) => { diff --git a/packages/server/test/unit/args_spec.js b/packages/server/test/unit/args_spec.js index 2554a023e2bc..74fee4211971 100644 --- a/packages/server/test/unit/args_spec.js +++ b/packages/server/test/unit/args_spec.js @@ -404,7 +404,6 @@ describe('lib/util/args', () => { } this.obj = this.setup( - '--get-key', '--env=foo=bar,baz=quux,bar=foo=quz', '--config', `requestTimeout=1234,blockHosts=${s(this.blockHosts)},hosts=${s(this.hosts)}`, @@ -425,7 +424,6 @@ describe('lib/util/args', () => { cwd, _: [], config: this.config, - getKey: true, invokedFromCli: false, spec: this.specs, testingType: 'e2e', @@ -448,7 +446,6 @@ describe('lib/util/args', () => { expect(args).to.deep.eq([ `--config=${mergedConfig}`, `--cwd=${cwd}`, - '--getKey=true', `--spec=${JSON.stringify(this.specs)}`, '--testingType=e2e', ]) @@ -456,7 +453,6 @@ describe('lib/util/args', () => { expect(argsUtil.toObject(args)).to.deep.eq({ cwd, _: [], - getKey: true, invokedFromCli: true, config: this.config, spec: this.specs, diff --git a/packages/server/test/unit/project_spec.js b/packages/server/test/unit/project_spec.js index fbb601cb7633..a7e1938ac222 100644 --- a/packages/server/test/unit/project_spec.js +++ b/packages/server/test/unit/project_spec.js @@ -1363,62 +1363,4 @@ This option will not have an effect in Some-other-name. Tests that rely on web s }) }) }) - - context('.getSecretKeyByPath', () => { - beforeEach(() => { - sinon.stub(user, 'ensureAuthToken').resolves('auth-token-123') - }) - - it('calls api.getProjectToken with id + session', function () { - sinon.stub(api, 'getProjectToken') - .withArgs(this.projectId, 'auth-token-123') - .resolves('key-123') - - return ProjectE2E.getSecretKeyByPath(this.todosPath).then((key) => { - expect(key).to.eq('key-123') - }) - }) - - it('throws CANNOT_FETCH_PROJECT_TOKEN on error', function () { - sinon.stub(api, 'getProjectToken') - .withArgs(this.projectId, 'auth-token-123') - .rejects(new Error()) - - return ProjectE2E.getSecretKeyByPath(this.todosPath) - .then(() => { - throw new Error('should have caught error but did not') - }).catch((err) => { - expect(err.type).to.eq('CANNOT_FETCH_PROJECT_TOKEN') - }) - }) - }) - - context('.generateSecretKeyByPath', () => { - beforeEach(() => { - sinon.stub(user, 'ensureAuthToken').resolves('auth-token-123') - }) - - it('calls api.updateProjectToken with id + session', function () { - sinon.stub(api, 'updateProjectToken') - .withArgs(this.projectId, 'auth-token-123') - .resolves('new-key-123') - - return ProjectE2E.generateSecretKeyByPath(this.todosPath).then((key) => { - expect(key).to.eq('new-key-123') - }) - }) - - it('throws CANNOT_CREATE_PROJECT_TOKEN on error', function () { - sinon.stub(api, 'updateProjectToken') - .withArgs(this.projectId, 'auth-token-123') - .rejects(new Error()) - - return ProjectE2E.generateSecretKeyByPath(this.todosPath) - .then(() => { - throw new Error('should have caught error but did not') - }).catch((err) => { - expect(err.type).to.eq('CANNOT_CREATE_PROJECT_TOKEN') - }) - }) - }) }) diff --git a/packages/server/test/unit/routes_util_spec.js b/packages/server/test/unit/routes_util_spec.js index bf55a23b8787..bcf0e0c78346 100644 --- a/packages/server/test/unit/routes_util_spec.js +++ b/packages/server/test/unit/routes_util_spec.js @@ -44,10 +44,6 @@ describe('lib/util/routes', () => { expect(apiRoutes.projectRuns('123-foo')).to.eq('http://localhost:1234/projects/123-foo/runs') }) - it('projectToken', () => { - expect(apiRoutes.projectToken('123-foo')).to.eq('http://localhost:1234/projects/123-foo/token') - }) - it('exceptions', () => { expect(apiRoutes.exceptions()).to.eq('http://localhost:1234/exceptions') })