Skip to content

Commit

Permalink
SNOW-1883649 wiremock integration and mappings for oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmotacki committed Jan 22, 2025
1 parent e4b0340 commit c9d54c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@
"test:ci:coverage": "nyc npm run test:ci",
"test:ci:withSystemTests": "mocha -timeout 180000 --recursive --full-trace 'test/{unit,integration}/**/*.js' system_test/*.js",
"test:ci:withSystemTests:coverage": "nyc npm run test:ci:withSystemTests",
"test:manual": "mocha -timeout 180000 --full-trace --full-trace test/integration/testManualConnection.js",
"serve-wiremock": "wiremock --enable-browser-proxying --proxy-pass-through false --port 8081 ",
"wiremock": "npm run serve-wiremock"
"test:manual": "mocha -timeout 180000 --full-trace --full-trace test/integration/testManualConnection.js"
},
"author": {
"name": "Snowflake Computing, Inc.",
Expand Down
36 changes: 17 additions & 19 deletions test/authentication/testOauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,26 @@ async function waitForWiremockStarted(wireMock) {
}

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 () {
const wireMock = await runWireMockAsync();
try {
assert.doesNotReject(async () => await wireMock.mappings.getAllMappings());
} finally {
await wireMock.global.shutdown();
}
assert.doesNotReject(async () => await wireMock.mappings.getAllMappings());
});
it('Add mappings', async function () {
const wireMock = await runWireMockAsync();
try {
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:8081/test/authorize.html');
assert.strictEqual(response.status, 200);
} finally {
await wireMock.global.shutdown();
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);
});
});

Expand Down Expand Up @@ -148,7 +146,7 @@ describe('Oauth PAT authentication', function () {

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 };
const connectionOption = { ...connParameters.oauthPATOnWiremock, password: 'MOCK_TOKEN', port: port };
authTest.createConnection(connectionOption);
await authTest.connectAsync();
authTest.verifyNoErrorWasThrown();
Expand Down

0 comments on commit c9d54c7

Please sign in to comment.