Skip to content

Commit

Permalink
refactor: remove project token, unused since 0.19.0 (#17039)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser authored Jun 23, 2021
1 parent 4c864e3 commit 2bfe264
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 355 deletions.
6 changes: 3 additions & 3 deletions packages/desktop-gui/src/runs/runs-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class RunsList extends Component {
componentDidMount () {
this._pingApiServer()
this._handlePolling()
this._getKey()
this._getRecordKeys()
}

componentDidUpdate () {
this._getKey()
this._getRecordKeys()
this._handlePolling()
}

Expand Down Expand Up @@ -106,7 +106,7 @@ class RunsList extends Component {
runsApi.stopPollingRuns()
}

_getKey () {
_getRecordKeys () {
if (this._needsKey()) {
projectsApi.getRecordKeys().then((keys = []) => {
if (keys.length) {
Expand Down
24 changes: 0 additions & 24 deletions packages/server/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
22 changes: 0 additions & 22 deletions packages/server/lib/cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 0 additions & 28 deletions packages/server/lib/project-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,34 +1025,6 @@ export class ProjectBase<TServer extends ServerE2E | ServerCt> 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) {
Expand Down
4 changes: 1 addition & 3 deletions packages/server/lib/util/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion packages/server/lib/util/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
140 changes: 0 additions & 140 deletions packages/server/test/integration/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
68 changes: 0 additions & 68 deletions packages/server/test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Loading

3 comments on commit 2bfe264

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 2bfe264 Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.6.0/circle-develop-2bfe26481be1895bc880094ab62c866db126fef5/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 2bfe264 Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.6.0/appveyor-develop-2bfe26481be1895bc880094ab62c866db126fef5/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 2bfe264 Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.6.0/appveyor-develop-2bfe26481be1895bc880094ab62c866db126fef5/cypress.tgz

Please sign in to comment.