Skip to content

Commit

Permalink
move cleaning browser processes to browser docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-akolodziejczyk committed Nov 27, 2024
1 parent c5b3f4a commit 2de8c6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ci/test_authentication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ docker run \
-v $(cd $THIS_DIR/.. && pwd):/mnt/host \
-v $WORKSPACE:/mnt/workspace \
--rm \
nexus.int.snowflakecomputing.com:8086/docker/snowdrivers-test-external-browser:1 \
nexus.int.snowflakecomputing.com:8086/docker/snowdrivers-test-external-browser:2 \
"/mnt/host/ci/container/test_authentication.sh"
22 changes: 8 additions & 14 deletions test/authentication/testExternalBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ const snowflake = require('../../lib/snowflake');
const assert = require('assert');
const testUtil = require('../integration/testUtil');
const connParameters = require('./connectionParameters');
const { exec, spawn } = require('child_process');
const { spawn } = require('child_process');
const Util = require('../../lib/util');
const JsonCredentialManager = require('../../lib/authentication/secure_storage/json_credential_manager');

describe('External browser authentication tests', function () {
const cleanBrowserProcessesPath = '/externalbrowser/cleanBrowserProcesses.js';
const provideBrowserCredentialsPath = '/externalbrowser/provideBrowserCredentials.js';
const login = connParameters.snowflakeTestBrowserUser;
const password = connParameters.snowflakeAuthTestOktaPass;
Expand Down Expand Up @@ -72,12 +73,6 @@ describe('External browser authentication tests', function () {

before(async () => {
await defaultCredentialManager.remove(key);
await cleanBrowserProcesses();
});

afterEach(async () => {
await cleanBrowserProcesses();
await destroyConnection(connection);
});

it('obtains the id token from the server and saves it on the local storage', async function () {
Expand Down Expand Up @@ -124,12 +119,11 @@ describe('External browser authentication tests', function () {
function verifyNoErrorWasThrown() {
assert.equal(error, null);
}
});

async function cleanBrowserProcesses() {
exec('pkill -f chromium');
exec('pkill -f xdg-open');
}
async function cleanBrowserProcesses() {
await execWithTimeout('node', [cleanBrowserProcessesPath], 15000);
}
});

async function verifyConnectionIsUp(connection) {
assert.ok(await connection.isValidAsync(), 'Connection is not valid');
Expand Down Expand Up @@ -173,15 +167,15 @@ function execWithTimeout(command, args, timeout = 5000) {

child.on('close', (code) => {
if (code !== 0) {
reject(new Error(`Provide browser credentials process exited with code: ${code}, error: ${stderr}`));
reject(new Error(`Process exited with code: ${code}, error: ${stderr}`));
} else {
resolve({ stdout, stderr });
}
});

setTimeout(() => {
child.kill();
reject(new Error('Provide browser credentials process timed out'));
reject(new Error('Process timed out'));
}, timeout);
});
}

0 comments on commit 2de8c6e

Please sign in to comment.