Skip to content

Commit

Permalink
Fix auth after Electron upgrade (#5243)
Browse files Browse the repository at this point in the history
* Fix auth after Electron upgrade

shell.openExternal should've been converted to a Promise w/ Electron 5.

* add comment
  • Loading branch information
flotwig authored and brian-mann committed Sep 30, 2019
1 parent 21cdf6f commit 053b6bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 12 additions & 7 deletions packages/server/lib/gui/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,17 @@ const _launchServer = (baseLoginUrl, sendMessage) => {
res.redirect(`${baseLoginUrl}?status=${status}`)
}

if (_.get(req.query, 'status') === 'error') {
authCallback(new Error('There was an error authenticating to the Cypress dashboard.'))
redirectToStatus('error')
/**
* Cypress Dashboard can redirect to us with an error; or, if Electron's shell.openExternal
* is bugging out, `authCallback` can be undefined and reaching this point makes no sense.
* @see https://github.com/cypress-io/cypress/pull/5243
*/
if (_.get(req.query, 'status') === 'error' || !authCallback) {
if (authCallback) {
authCallback(new Error('There was an error authenticating to the Cypress dashboard.'))
}

return redirectToStatus('error')
}

const { state, name, email, access_token } = req.query
Expand Down Expand Up @@ -190,10 +198,7 @@ const _launchNativeAuth = Promise.method((loginUrl, sendMessage) => {

openExternalAttempted = true

// wrap openExternal here in case `electron.shell` is not available (during tests)
return Promise.fromCallback((cb) => {
shell.openExternal(loginUrl, {}, cb)
})
return shell.openExternal(loginUrl)
.catch((err) => {
debug('Error launching native auth: %o', { err })
warnCouldNotLaunch()
Expand Down
8 changes: 4 additions & 4 deletions packages/server/test/unit/gui/auth_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,21 @@ describe('lib/gui/auth', function () {
})

it('returns a promise that is fulfilled when openExternal succeeds', function () {
sinon.stub(electron.shell, 'openExternal').callsArg(2)
sinon.stub(electron.shell, 'openExternal').resolves()

return auth._launchNativeAuth(REDIRECT_URL)
.then(() => {
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func)
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL)
})
})

it('is still fulfilled when openExternal fails, but sendWarning is called', function () {
sinon.stub(electron.shell, 'openExternal').callsArgWith(2, new Error)
sinon.stub(electron.shell, 'openExternal').rejects()
const sendWarning = sinon.stub()

return auth._launchNativeAuth(REDIRECT_URL, sendWarning)
.then(() => {
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func)
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL)
expect(sendWarning).to.be.calledWithMatch('warning', 'AUTH_COULD_NOT_LAUNCH_BROWSER', REDIRECT_URL)
})
})
Expand Down

6 comments on commit 053b6bd

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 053b6bd Sep 30, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/linux-x64/circle-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-158387/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-158400/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 053b6bd Sep 30, 2019

Choose a reason for hiding this comment

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

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

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/darwin-x64/circle-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-158411/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-158412/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 053b6bd Sep 30, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-27773182/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-27773182/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 053b6bd Sep 30, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-27773182/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-27773182/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 053b6bd Sep 30, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-27776851/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-27776851/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 053b6bd Sep 30, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-27776851/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-053b6bd993f8016171f1f7b8148840d2c0d37716-27776851/cypress.zip

Please sign in to comment.