Merge pull request #512 from hashicorp/fix-flaky-origin-test

test: Fix flaky origin test in desktop
This commit is contained in:
Susmitha Girumala authored and GitHub committed 2021-04-01 09:29:16 -04:00
commit a50a0735bb
2 files changed
+27 -36

No files matched your search

+9 -5
View File
@@ -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();
});
+18 -31
View File
@@ -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';
@@ -157,38 +156,37 @@ 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('captures error on origin update', async function (assert) {
assert.expect(2);
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'));
});
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);
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);
sinon.stub(this.owner.lookup('service:origin'), 'setOrigin').throws();
await visit(urls.origin);
await fillIn('[name="host"]', window.location.origin);
await click('[type="submit"]');
assert.ok(find('.rose-notification.is-error'));
});
test('origin set automatically in dev mode', async function (assert) {
assert.expect(1);
config.autoOrigin = true;
@@ -204,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);
});
});