Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1739611 add automated tests for okta, oauth and keypair #976

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/workflows/parameters_aws_auth_tests.json.gpg
Binary file not shown.
Binary file not shown.
Binary file added .github/workflows/rsa_keys/rsa_key.p8.gpg
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ wss-*-agent.config
wss-unified-agent.jar
whitesource/
.nyc_output
rsa_*.p8
4 changes: 4 additions & 0 deletions ci/container/test_authentication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ set -o pipefail
AUTH_PARAMETER_FILE=./.github/workflows/parameters_aws_auth_tests.json
eval $(jq -r '.authtestparams | to_entries | map("export \(.key)=\(.value|tostring)")|.[]' $AUTH_PARAMETER_FILE)

export SNOWFLAKE_AUTH_TEST_PRIVATE_KEY_PATH=./.github/workflows/rsa_keys/rsa_key.p8
export SNOWFLAKE_AUTH_TEST_ENCRYPTED_PRIVATE_KEY_PATH=./.github/workflows/rsa_keys/rsa_encrypted_key.p8
export SNOWFLAKE_AUTH_TEST_INVALID_PRIVATE_KEY_PATH=./.github/workflows/rsa_keys/rsa_key_invalid.p8

npm run test:authentication
5 changes: 4 additions & 1 deletion ci/test_authentication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export WORKSPACE=${WORKSPACE:-/tmp}

gpg --quiet --batch --yes --decrypt --passphrase="$PARAMETERS_SECRET" --output $THIS_DIR/../.github/workflows/parameters_aws_auth_tests.json "$THIS_DIR/../.github/workflows/parameters_aws_auth_tests.json.gpg"
gpg --quiet --batch --yes --decrypt --passphrase="$PARAMETERS_SECRET" --output $THIS_DIR/../.github/workflows/rsa_keys/rsa_encrypted_key.p8 "$THIS_DIR/../.github/workflows/rsa_keys/rsa_encrypted_key.p8.gpg"
gpg --quiet --batch --yes --decrypt --passphrase="$PARAMETERS_SECRET" --output $THIS_DIR/../.github/workflows/rsa_keys/rsa_key.p8 "$THIS_DIR/../.github/workflows/rsa_keys/rsa_key.p8.gpg"
gpg --quiet --batch --yes --decrypt --passphrase="$PARAMETERS_SECRET" --output $THIS_DIR/../.github/workflows/rsa_keys/rsa_key_invalid.p8 "$THIS_DIR/../.github/workflows/rsa_keys/rsa_key_invalid.p8.gpg"

docker run \
-v $(cd $THIS_DIR/.. && pwd):/mnt/host \
-v $WORKSPACE:/mnt/workspace \
--rm \
nexus.int.snowflakecomputing.com:8086/docker/snowdrivers-test-external-browser:2 \
nexus.int.snowflakecomputing.com:8086/docker/snowdrivers-test-external-browser:3 \
"/mnt/host/ci/container/test_authentication.sh"
69 changes: 69 additions & 0 deletions test/authentication/authTestsBaseClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const assert = require('assert');
const testUtil = require('../integration/testUtil');
const snowflake = require('../../lib/snowflake');

class AuthTest {
constructor() {
this.connection = null;
this.error = null;
this.callbackCompleted = false;
}

connectAsyncCallback() {
return (err) => {
this.error = err;
this.callbackCompleted = true;
};
}

async waitForCallbackCompletion() {
const timeout = Date.now() + 5000;
while (Date.now() < timeout) {
await new Promise(resolve => setTimeout(resolve, 100));
if (this.callbackCompleted) {
return;
}
}
throw new Error('Connection callback did not complete');
}

async createConnection(connectionOption) {
this.connection = snowflake.createConnection(connectionOption);
}

async connectAsync() {
await this.connection.connectAsync(this.connectAsyncCallback());
await this.waitForCallbackCompletion();
}

async verifyConnectionIsUp() {
assert.ok(await this.connection.isValidAsync(), 'Connection is not valid');
await testUtil.executeCmdAsync(this.connection, 'Select 1');
}

async verifyConnectionIsNotUp(message = 'Unable to perform operation because a connection was never established.') {
assert.ok(!(this.connection.isUp()), 'Connection should not be up');
try {
await testUtil.executeCmdAsync(this.connection, 'Select 1');
assert.fail('Expected error was not thrown');
} catch (error) {
assert.strictEqual(error.message, message);
}
}

async destroyConnection() {
if (this.connection !== undefined && this.connection !== null && this.connection.isUp()) {
await testUtil.destroyConnectionAsync(this.connection);
}
}

verifyNoErrorWasThrown() {
assert.equal(this.error, null);
}

verifyErrorWasThrown(message) {
assert.strictEqual(this.error?.message, message);
}
}

module.exports = AuthTest;
93 changes: 79 additions & 14 deletions test/authentication/connectionParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,93 @@ const snowflakeAuthTestHost = process.env.SNOWFLAKE_AUTH_TEST_HOST;
const snowflakeAuthTestPort = process.env.SNOWFLAKE_AUTH_TEST_PORT;
const snowflakeAuthTestAccount = process.env.SNOWFLAKE_AUTH_TEST_ACCOUNT;
const snowflakeAuthTestRole = process.env.SNOWFLAKE_AUTH_TEST_ROLE;
const snowflakeTestBrowserUser = process.env.SNOWFLAKE_AUTH_TEST_BROWSER_USER;
const snowflakeAuthTestBrowserUser = process.env.SNOWFLAKE_AUTH_TEST_BROWSER_USER;
const snowflakeAuthTestOktaAuth = process.env.SNOWFLAKE_AUTH_TEST_OKTA_AUTH;
const snowflakeAuthTestOktaUser = process.env.SNOWFLAKE_AUTH_TEST_OKTA_USER;
const snowflakeAuthTestOktaPass = process.env.SNOWFLAKE_AUTH_TEST_OKTA_PASS;
const snowflakeAuthTestOauthUrl = process.env.SNOWFLAKE_AUTH_TEST_OAUTH_URL;
const snowflakeAuthTestOauthClientId = process.env.SNOWFLAKE_AUTH_TEST_OAUTH_CLIENT_ID;
const snowflakeAuthTestOauthClientSecret = process.env.SNOWFLAKE_AUTH_TEST_OAUTH_CLIENT_SECRET;
const snowflakeAuthTestDatabase = process.env.SNOWFLAKE_AUTH_TEST_DATABASE;
const snowflakeAuthTestWarehouse = process.env.SNOWFLAKE_AUTH_TEST_WAREHOUSE;
const snowflakeAuthTestSchema = process.env.SNOWFLAKE_AUTH_TEST_SCHEMA;
const snowflakeAuthTestPrivateKeyPath = process.env.SNOWFLAKE_AUTH_TEST_PRIVATE_KEY_PATH;
const snowflakeAuthTestInvalidPrivateKeyPath = process.env.SNOWFLAKE_AUTH_TEST_INVALID_PRIVATE_KEY_PATH;
const snowflakeAuthTestPrivateKeyPassword = process.env.SNOWFLAKE_AUTH_TEST_PRIVATE_KEY_PASSWORD;
const snowflakeAuthTestEncryptedPrivateKeyPath = process.env.SNOWFLAKE_AUTH_TEST_ENCRYPTED_PRIVATE_KEY_PATH;

const accessUrlAuthTests = snowflakeAuthTestProtocol + '://' + snowflakeAuthTestHost + ':' +
snowflakeAuthTestPort;
snowflakeAuthTestPort;

const baseParameters =
{
accessUrl: accessUrlAuthTests,
account: snowflakeAuthTestAccount,
role: snowflakeAuthTestRole,
host: snowflakeAuthTestHost,
warehouse: snowflakeAuthTestWarehouse,
database: snowflakeAuthTestDatabase,
schema: snowflakeAuthTestSchema,
};

const externalBrowser =
{
accessUrl: accessUrlAuthTests,
username: snowflakeTestBrowserUser,
account: snowflakeAuthTestAccount,
role: snowflakeAuthTestRole,
host: snowflakeAuthTestHost,
warehouse: snowflakeAuthTestWarehouse,
database: snowflakeAuthTestDatabase,
schema: snowflakeAuthTestSchema,
authenticator: 'EXTERNALBROWSER'
};
{
...baseParameters,
username: snowflakeAuthTestBrowserUser,
authenticator: 'EXTERNALBROWSER'
};

const okta =
{
...baseParameters,
username: snowflakeAuthTestOktaUser,
password: snowflakeAuthTestOktaPass,
authenticator: snowflakeAuthTestOktaAuth
};

const oauth =
{
...baseParameters,
username: snowflakeAuthTestOktaUser,
authenticator: 'OAUTH'
};

const keypairPrivateKey =
{
...baseParameters,
username: snowflakeAuthTestOktaUser,
authenticator: 'SNOWFLAKE_JWT'
};

const keypairPrivateKeyPath =
{
...baseParameters,
username: snowflakeAuthTestOktaUser,
privateKeyPath: snowflakeAuthTestPrivateKeyPath,
authenticator: 'SNOWFLAKE_JWT'
};

const keypairEncryptedPrivateKeyPath =
{
...baseParameters,
username: snowflakeAuthTestOktaUser,
privateKeyPass: snowflakeAuthTestPrivateKeyPassword,
privateKeyPath: snowflakeAuthTestEncryptedPrivateKeyPath,
authenticator: 'SNOWFLAKE_JWT'
};

exports.externalBrowser = externalBrowser;
exports.snowflakeTestBrowserUser = snowflakeTestBrowserUser;
exports.okta = okta;
exports.oauth = oauth;
exports.keypairPrivateKey = keypairPrivateKey;
exports.keypairPrivateKeyPath = keypairPrivateKeyPath;
exports.keypairEncryptedPrivateKeyPath = keypairEncryptedPrivateKeyPath;
exports.snowflakeTestBrowserUser = snowflakeAuthTestBrowserUser;
exports.snowflakeAuthTestOktaUser = snowflakeAuthTestOktaUser;
exports.snowflakeAuthTestOktaPass = snowflakeAuthTestOktaPass;
exports.snowflakeAuthTestRole = snowflakeAuthTestRole;
exports.snowflakeAuthTestOauthClientId = snowflakeAuthTestOauthClientId;
exports.snowflakeAuthTestOauthClientSecret = snowflakeAuthTestOauthClientSecret;
exports.snowflakeAuthTestOauthUrl = snowflakeAuthTestOauthUrl;
exports.snowflakeAuthTestPrivateKeyPath = snowflakeAuthTestPrivateKeyPath;
exports.snowflakeAuthTestInvalidPrivateKeyPath = snowflakeAuthTestInvalidPrivateKeyPath;
Loading
Loading