Skip to content

Commit

Permalink
SNOW-1883649 Added manual integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmotacki committed Jan 30, 2025
1 parent 2dc1d95 commit e7c980c
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ci/_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ fi
export DRIVER_NAME=nodejs

# Build images
BUILD_IMAGE_VERSION=1
BUILD_IMAGE_VERSION=2

# Test Images
TEST_IMAGE_VERSION=1
TEST_IMAGE_VERSION=2

declare -A BUILD_IMAGE_NAMES=(
[$DRIVER_NAME-chainguard-node18]=$DOCKER_REGISTRY_NAME/client-$DRIVER_NAME-chainguard-node18-build:$BUILD_IMAGE_VERSION
Expand Down
2 changes: 1 addition & 1 deletion ci/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM $IMAGE

USER root

RUN apk update && apk add python3 jq aws-cli gosu
RUN apk update && apk add python3 python3-dev py3-pip jq aws-cli gosu openjdk-17
RUN pip install -U snowflake-connector-python

# workspace
Expand Down
4 changes: 3 additions & 1 deletion ci/image/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ set -o pipefail
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $THIS_DIR/../_init.sh

echo 'INIT SH DONE'

for name in "${!BUILD_IMAGE_NAMES[@]}"; do
docker build \
docker --debug build \
--platform=linux/amd64 \
--file $THIS_DIR/Dockerfile \
--label snowflake \
Expand Down
2 changes: 2 additions & 0 deletions ci/test_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ echo [INFO] Schema: %SNOWFLAKE_TEST_SCHEMA%
echo [INFO] Warehouse: %SNOWFLAKE_TEST_WAREHOUSE%
echo [INFO] Role: %SNOWFLAKE_TEST_ROLE%

echo [INFO] JAVA_HOME %JAVA_HOME%

echo [INFO] Creating schema %SNOWFLAKE_TEST_SCHEMA%
pushd %GITHUB_WORKSPACE%\ci\container
python create_schema.py
Expand Down
199 changes: 199 additions & 0 deletions test/integration/authentication_mock/testOauthAuthorizationCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
const assert = require('assert');
const fs = require('fs');
const net = require('net');
const connParameters = require('../../authentication/connectionParameters');
const axios = require('axios');
const AuthTest = require('../../authentication/authTestsBaseClass');
const WireMockRestClient = require('wiremock-rest-client').WireMockRestClient;
const { exec } = require('child_process');
const Os = require("os");

Check failure on line 9 in test/integration/authentication_mock/testOauthAuthorizationCode.js

View workflow job for this annotation

GitHub Actions / Run lint

Strings must use singlequote



async function runWireMockAsync(port) {
let timeoutHandle;
const waitingWireMockPromise = new Promise(async (resolve, reject) => {

Check failure on line 15 in test/integration/authentication_mock/testOauthAuthorizationCode.js

View workflow job for this annotation

GitHub Actions / Run lint

Promise executor functions should not be async
try {
exec(`npx wiremock --enable-browser-proxying --proxy-pass-through false --port ${port} `, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);

Check failure on line 22 in test/integration/authentication_mock/testOauthAuthorizationCode.js

View workflow job for this annotation

GitHub Actions / Run lint

Unexpected console statement
console.error(`stderr: ${stderr}`);
});
const wireMock = new WireMockRestClient(`http://localhost:${port}`);
const readyWireMock = await waitForWiremockStarted(wireMock);
resolve(readyWireMock);
} catch (err) {
reject(err);
}
});


const timeout = new Promise((resolve, reject) =>
timeoutHandle = setTimeout(
() => reject('Wiremock unavailable after 26000 ms.'),
26000));
return Promise.race([waitingWireMockPromise, timeout])
.then(result => {
clearTimeout(timeoutHandle);
return result;
});
}

async function waitForWiremockStarted(wireMock) {
return fetch(wireMock.baseUri)
.then(async (resp) => {
if (resp.ok) {
return Promise.resolve(wireMock);
} else {
await new Promise(resolve => setTimeout(resolve, 1000));
console.log(`Retry connection to WireMock after wrong response status: ${resp.status}`);

Check failure on line 52 in test/integration/authentication_mock/testOauthAuthorizationCode.js

View workflow job for this annotation

GitHub Actions / Run lint

Unexpected console statement
return await waitForWiremockStarted(wireMock);
}
})
.catch(async (err) => {
await new Promise(resolve => setTimeout(resolve, 1000));
console.log(`Retry connection to WireMock after error: ${err}`);

Check failure on line 58 in test/integration/authentication_mock/testOauthAuthorizationCode.js

View workflow job for this annotation

GitHub Actions / Run lint

Unexpected console statement
return await waitForWiremockStarted(wireMock);
});
}

if (Os.platform() === 'linux') {
describe('Wiremock test', function () {
let port, wireMock;
before(async () => {
port = await getPortFree();
wireMock = await runWireMockAsync(port);
});
after(async () => {
await wireMock.global.shutdown();
});
it('Run Wiremock instance, wait, verify connection and shutdown', async function () {
assert.doesNotReject(async () => await wireMock.mappings.getAllMappings());
});
it('Add mappings', async function () {
const requests = JSON.parse(fs.readFileSync('wiremock/mappings/test.json', 'utf8'));
for (const mapping of requests.mappings) {
await wireMock.mappings.createMapping(mapping);
}
const mappings = await wireMock.mappings.getAllMappings();
assert.strictEqual(mappings.mappings.length, 2);
const response = await axios.get(`http://localhost:${port}/test/authorize.html`);
assert.strictEqual(response.status, 200);
});
});

describe.only('Oauth PAT authentication', function () {
let port;
let authTest;
let wireMock;
before(async () => {
port = await getPortFree();
wireMock = await runWireMockAsync(port);
});
beforeEach(async () => {
authTest = new AuthTest();
});
afterEach(async () => {
wireMock.scenarios.resetAllScenarios();
});
after(async () => {
await wireMock.global.shutdown();
});


it('Successful flow scenario PAT as token', async function () {
await addWireMockMappingsFromFile('wiremock/mappings/pat/successful_flow.json');
const connectionOption = {...connParameters.oauthPATOnWiremock, token: 'MOCK_TOKEN', port: port};
authTest.createConnection(connectionOption);
await authTest.connectAsync();
authTest.verifyNoErrorWasThrown();
});

it('Successful flow scenario PAT as password', async function () {
await addWireMockMappingsFromFile('wiremock/mappings/pat/successful_flow.json');
const connectionOption = {...connParameters.oauthPATOnWiremock, password: 'MOCK_TOKEN', port: port};
authTest.createConnection(connectionOption);
await authTest.connectAsync();
authTest.verifyNoErrorWasThrown();
});

it('Invalid token', async function () {
await addWireMockMappingsFromFile('wiremock/mappings/pat/invalid_pat_token.json');
const connectionOption = {...connParameters.oauthPATOnWiremock, token: 'INVALID_TOKEN', port: port};
authTest.createConnection(connectionOption);
await authTest.connectAsync();
authTest.verifyErrorWasThrown('Programmatic access token is invalid.');
});

async function addWireMockMappingsFromFile(filePath) {
const requests = JSON.parse(fs.readFileSync(filePath, 'utf8'));
for (const mapping of requests.mappings) {
await wireMock.mappings.createMapping(mapping);
}
}
});

// describe('Oauth PAT authentication', function () {
// let port;
// let authTest;
// let wireMock;
// before(async () => {
// port = await getPortFree();
// wireMock = await runWireMockAsync(port);
// });
// beforeEach(async () => {
// authTest = new AuthTest();
// });
// afterEach(async () => {
// wireMock.scenarios.resetAllScenarios();
// });
// after(async () => {
// await wireMock.global.shutdown();
// });
//
//
// it('Successful flow scenario PAT as token', async function () {
// await addWireMockMappingsFromFile('wiremock/mappings/pat/successful_flow.json');
// const connectionOption = {...connParameters.oauthPATOnWiremock, token: 'MOCK_TOKEN', port: port};
// authTest.createConnection(connectionOption);
// await authTest.connectAsync();
// authTest.verifyNoErrorWasThrown();
// });
//
// it('Successful flow scenario PAT as password', async function () {
// await addWireMockMappingsFromFile('wiremock/mappings/pat/successful_flow.json');
// const connectionOption = {...connParameters.oauthPATOnWiremock, password: 'MOCK_TOKEN', port: port};
// authTest.createConnection(connectionOption);
// await authTest.connectAsync();
// authTest.verifyNoErrorWasThrown();
// });
//
// it('Invalid token', async function () {
// await addWireMockMappingsFromFile('wiremock/mappings/pat/invalid_pat_token.json');
// const connectionOption = {...connParameters.oauthPATOnWiremock, token: 'INVALID_TOKEN', port: port};
// authTest.createConnection(connectionOption);
// await authTest.connectAsync();
// authTest.verifyErrorWasThrown('Programmatic access token is invalid.');
// });
//
// async function addWireMockMappingsFromFile(filePath) {
// const requests = JSON.parse(fs.readFileSync(filePath, 'utf8'));
// for (const mapping of requests.mappings) {
// await wireMock.mappings.createMapping(mapping);
// }
// }
// });

async function getPortFree() {
return new Promise(res => {
const srv = net.createServer();
srv.listen(0, () => {
const port = srv.address().port;
srv.close((err) => res(port));
});
});
}
}

0 comments on commit e7c980c

Please sign in to comment.