From 95e6144e44b750018784ce01a3d63d7950b1f5e5 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Wed, 31 Mar 2021 15:02:17 -0400 Subject: [PATCH 1/2] test: Fix flaky origin test in desktop --- ui/desktop/tests/acceptance/origin-test.js | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/ui/desktop/tests/acceptance/origin-test.js b/ui/desktop/tests/acceptance/origin-test.js index 4d7469c45..0def4c585 100644 --- a/ui/desktop/tests/acceptance/origin-test.js +++ b/ui/desktop/tests/acceptance/origin-test.js @@ -157,15 +157,28 @@ module('Acceptance | origin', function (hooks) { }); test('can set origin', async function (assert) { - assert.expect(2); + assert.expect(3); assert.notOk(mockIPC.origin); await visit(urls.origin); await a11yAudit(); await fillIn('[name="host"]', window.location.origin); await click('[type="submit"]'); + assert.equal(currentURL(), urls.authenticate.methods.global); assert.equal(mockIPC.origin, window.location.origin); }); + test('can reset origin before authentication', async function (assert) { + assert.expect(4); + assert.notOk(mockIPC.origin); + await visit(urls.origin); + await fillIn('[name="host"]', window.location.origin); + await click('[type="submit"]'); + assert.equal(currentURL(), urls.authenticate.methods.global); + assert.equal(mockIPC.origin, window.location.origin); + await click('.change-origin a'); + assert.equal(currentURL(), urls.origin); + }); + test('captures error on origin update', async function (assert) { assert.expect(2); assert.notOk(mockIPC.origin); @@ -177,18 +190,6 @@ module('Acceptance | origin', function (hooks) { assert.ok(find('.rose-notification.is-error')); }); - test('can reset origin before authentication', async function (assert) { - assert.expect(4); - assert.notOk(mockIPC.origin); - await visit(urls.origin); - await fillIn('[name="host"]', window.location.origin); - await click('[type="submit"]'); - assert.equal(mockIPC.origin, window.location.origin); - assert.equal(currentURL(), urls.authenticate.methods.global); - await click('.change-origin a'); - assert.equal(currentURL(), urls.origin); - }); - test('origin set automatically in dev mode', async function (assert) { assert.expect(1); config.autoOrigin = true; From 838567c2d24125d7c6eab2c69207b7f116ff9de9 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 31 Mar 2021 18:00:42 -0400 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20clean=20up=20ori?= =?UTF-8?q?gin=20error=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/desktop/electron-app/src/index.js | 14 ++++++++----- ui/desktop/tests/acceptance/origin-test.js | 24 +++++----------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/ui/desktop/electron-app/src/index.js b/ui/desktop/electron-app/src/index.js index 4ed11956a..9dff06506 100644 --- a/ui/desktop/electron-app/src/index.js +++ b/ui/desktop/electron-app/src/index.js @@ -57,7 +57,8 @@ app.on('ready', async () => { // Register custom protocol // This file protocol is the exclusive protocol for this application. All // other protocols are disabled. - ses.protocol.registerFileProtocol(emberAppProtocol, (request, callback) => { /* eng-disable PROTOCOL_HANDLER_JS_CHECK */ + ses.protocol.registerFileProtocol(emberAppProtocol, (request, callback) => { + /* eng-disable PROTOCOL_HANDLER_JS_CHECK */ const isDir = request.url.endsWith('/'); const absolutePath = request.url.substr(emberAppURL.length); const normalizedPath = isDir @@ -71,7 +72,8 @@ app.on('ready', async () => { // Disallow all permissions requests, // per Electronegativity PERMISSION_REQUEST_HANDLER_GLOBAL_CHECK - ses.setPermissionRequestHandler((webContents, permission, callback) => { /* eng-disable PERMISSION_REQUEST_HANDLER_JS_CHECK */ + ses.setPermissionRequestHandler((webContents, permission, callback) => { + /* eng-disable PERMISSION_REQUEST_HANDLER_JS_CHECK */ return callback(false); }); @@ -119,7 +121,7 @@ app.on('ready', async () => { allowRunningInsecureContent: false, // The preload script establishes the message-based IPC pathway without // exposing new modules to the renderer. - preload: preloadPath, /* eng-disable PRELOAD_JS_CHECK */ + preload: preloadPath /* eng-disable PRELOAD_JS_CHECK */, disableBlinkFeatures: 'Auxclick', }, }); @@ -151,10 +153,12 @@ app.on('ready', async () => { // Prevent navigation outside of serve://boundary per // Electronegativity LIMIT_NAVIGATION_GLOBAL_CHECK - mainWindow.webContents.on('will-navigate', (event, url) => { /* eng-disable LIMIT_NAVIGATION_JS_CHECK */ + mainWindow.webContents.on('will-navigate', (event, url) => { + /* eng-disable LIMIT_NAVIGATION_JS_CHECK */ if (!url.startsWith('serve://boundary')) event.preventDefault(); }); - mainWindow.webContents.on('new-window', (event, url) => { /* eng-disable LIMIT_NAVIGATION_JS_CHECK */ + mainWindow.webContents.on('new-window', (event, url) => { + /* eng-disable LIMIT_NAVIGATION_JS_CHECK */ if (!url.startsWith('serve://boundary')) event.preventDefault(); }); diff --git a/ui/desktop/tests/acceptance/origin-test.js b/ui/desktop/tests/acceptance/origin-test.js index 0def4c585..68642c831 100644 --- a/ui/desktop/tests/acceptance/origin-test.js +++ b/ui/desktop/tests/acceptance/origin-test.js @@ -9,7 +9,6 @@ import { //getRootElement //setupOnerror, } from '@ember/test-helpers'; -import { run, later } from '@ember/runloop'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; //import { Response } from 'miragejs'; @@ -160,7 +159,6 @@ module('Acceptance | origin', function (hooks) { assert.expect(3); assert.notOk(mockIPC.origin); await visit(urls.origin); - await a11yAudit(); await fillIn('[name="host"]', window.location.origin); await click('[type="submit"]'); assert.equal(currentURL(), urls.authenticate.methods.global); @@ -184,7 +182,6 @@ module('Acceptance | origin', function (hooks) { assert.notOk(mockIPC.origin); sinon.stub(this.owner.lookup('service:origin'), 'setOrigin').throws(); await visit(urls.origin); - await a11yAudit(); await fillIn('[name="host"]', window.location.origin); await click('[type="submit"]'); assert.ok(find('.rose-notification.is-error')); @@ -205,26 +202,15 @@ module('Acceptance | origin', function (hooks) { test('can reset origin on error', async function (assert) { assert.expect(4); + this.server.get('/targets', () => new Response(500)); await visit(urls.origin); - await a11yAudit(); await fillIn('[name="host"]', window.location.origin); await click('[type="submit"]'); - await fillIn('[name="identification"]', 'test'); - await fillIn('[name="password"]', 'test'); - this.server.get('/targets', () => new Response(500)); - await later(async () => { - run.cancelTimers(); - assert.ok(currentSession().isAuthenticated); - assert.equal( - find('main section button').textContent.trim(), - 'Disconnect' - ); - }, 750); await click('[type="submit"]'); - later(async () => { - assert.notOk(currentSession().isAuthenticated); - assert.equal(currentURL(), urls.authenticate.methods.global); - }, 750); + assert.ok(currentSession().isAuthenticated); + assert.equal(find('main section button').textContent.trim(), 'Disconnect'); await click('main section button'); + assert.notOk(currentSession().isAuthenticated); + assert.equal(currentURL(), urls.authenticate.methods.global); }); });