mirror of
https://github.com/cypress-io/cypress.git
synced 2026-03-01 04:19:15 -06:00
* electron@7.x * node12.8.1-chrome78-ff70 * Revert "node12.8.1-chrome78-ff70" for now This reverts commitdb2d521994. * update sendCommand to log on all sendcommands * promisification in 6.x * Revert "Revert "node12.8.1-chrome78-ff70" for now" This reverts commit57fe764098. * fix sendcommand * fix cdp in electron * fix desktop-gui test * skip tests that will be fixed by #4973 * bump MAX_ALLOWED_FILE_SIZE :/ * update electron browser spec * make new dialog code null-proof * add failing e2e test for issue 5475 * bump electron packager * add e2e snapshot * update deprecated electron getters/setters https://github.com/electron/electron/blob/7-1-x/docs/api/modernization/property-updates.md * build and test on Mac * move macbuildfilters to top * 7.1.3 * electron@7.1.4 Co-authored-by: Brian Mann <brian.mann86@gmail.com> Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
114 lines
3.6 KiB
JavaScript
114 lines
3.6 KiB
JavaScript
require('../../spec_helper')
|
|
const root = global.root
|
|
|
|
const auth = require(`${root}../lib/gui/auth`)
|
|
const electron = require('electron')
|
|
const machineId = require(`${root}../lib/util/machine_id`)
|
|
const os = require('os')
|
|
const pkg = require('@packages/root')
|
|
const random = require(`${root}../lib/util/random`)
|
|
|
|
const BASE_URL = 'https://foo.invalid/login.html'
|
|
const RANDOM_STRING = 'a'.repeat(32)
|
|
const PORT = 9001
|
|
const REDIRECT_URL = `http://127.0.0.1:${PORT}/redirect-to-auth`
|
|
const FULL_LOGIN_URL = `https://foo.invalid/login.html?port=${PORT}&state=${RANDOM_STRING}&machineId=abc123&cypressVersion=${pkg.version}&platform=linux`
|
|
|
|
describe('lib/gui/auth', function () {
|
|
beforeEach(() => {
|
|
sinon.stub(os, 'platform').returns('linux')
|
|
sinon.stub(machineId, 'machineId').resolves('abc123')
|
|
})
|
|
|
|
afterEach(function () {
|
|
auth._stopServer()
|
|
})
|
|
|
|
context('._getOriginFromUrl', function () {
|
|
it('given an https URL, returns the origin', function () {
|
|
const origin = auth._getOriginFromUrl(FULL_LOGIN_URL)
|
|
|
|
expect(origin).to.eq('https://foo.invalid')
|
|
})
|
|
|
|
it('given an http URL, returns the origin', function () {
|
|
const origin = auth._getOriginFromUrl('http://foo.invalid/login.html?abc=123&foo=bar')
|
|
|
|
expect(origin).to.eq('http://foo.invalid')
|
|
})
|
|
})
|
|
|
|
context('._buildFullLoginUrl', function () {
|
|
beforeEach(function () {
|
|
sinon.stub(random, 'id').returns(RANDOM_STRING)
|
|
this.server = {
|
|
address: sinon.stub().returns({
|
|
port: PORT,
|
|
}),
|
|
}
|
|
})
|
|
|
|
it('uses random and server.port to form a URL along with environment info', function () {
|
|
return auth._buildFullLoginUrl(BASE_URL, this.server)
|
|
.then((url) => {
|
|
expect(url).to.eq(FULL_LOGIN_URL)
|
|
expect(random.id).to.be.calledWith(32)
|
|
expect(this.server.address).to.be.calledOnce
|
|
})
|
|
})
|
|
|
|
it('does not regenerate the state code', function () {
|
|
return auth._buildFullLoginUrl(BASE_URL, this.server)
|
|
.then(() => {
|
|
return auth._buildFullLoginUrl(BASE_URL, this.server)
|
|
})
|
|
.then(() => {
|
|
expect(random.id).to.be.calledOnce
|
|
})
|
|
})
|
|
})
|
|
|
|
context('._launchNativeAuth', function () {
|
|
it('is catchable if `shell` does not exist', function () {
|
|
return auth._launchNativeAuth(REDIRECT_URL)
|
|
.then(() => {
|
|
throw new Error('This should not succeed')
|
|
})
|
|
.catchReturn(TypeError)
|
|
})
|
|
|
|
context('with `shell` available', function () {
|
|
beforeEach(function () {
|
|
this.oldOpenExternal = electron.shell.openExternal
|
|
electron.shell.openExternal = () => {}
|
|
})
|
|
|
|
afterEach(function () {
|
|
electron.shell.openExternal = this.oldOpenExternal
|
|
})
|
|
|
|
it('returns a promise that is fulfilled when openExternal succeeds', function () {
|
|
sinon.stub(electron.shell, 'openExternal').resolves()
|
|
const sendWarning = sinon.stub()
|
|
|
|
return auth._launchNativeAuth(REDIRECT_URL, sendWarning)
|
|
.then(() => {
|
|
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL)
|
|
expect(sendWarning).to.not.be.called
|
|
})
|
|
})
|
|
|
|
it('is still fulfilled when openExternal fails, but sendWarning is called', function () {
|
|
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)
|
|
expect(sendWarning).to.be.calledWithMatch('warning', 'AUTH_COULD_NOT_LAUNCH_BROWSER', REDIRECT_URL)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|