-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c097139
commit 4c44ce4
Showing
12 changed files
with
255 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const Util = require('../util'); | ||
/** | ||
* Creates an oauth PAT authenticator. | ||
* | ||
* @param {String} token | ||
* @param {String} password | ||
* | ||
* @returns {Object} | ||
* @constructor | ||
*/ | ||
function AuthOauthPAT(token, password) { | ||
/** | ||
* Update JSON body with token. | ||
* | ||
* @param {JSON} body | ||
* | ||
* @returns {null} | ||
*/ | ||
this.updateBody = function (body) { | ||
if (Util.exists(token)) { | ||
body['data']['TOKEN'] = token; | ||
} else if (Util.exists(password)) { | ||
body['data']['TOKEN'] = password; | ||
} | ||
}; | ||
|
||
this.authenticate = async function () {}; | ||
} | ||
module.exports = AuthOauthPAT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const net = require('net'); | ||
const connParameters = require('../../authentication/connectionParameters'); | ||
const AuthTest = require('../../authentication/authTestsBaseClass'); | ||
const { runWireMockAsync, addWireMockMappingsFromFile, } = require('../../wiremockRunner'); | ||
const os = require('os'); | ||
const { getFreePort } = require('../../../lib/util'); | ||
|
||
if (os.platform !== 'win32') { | ||
describe('Oauth PAT authentication', function () { | ||
let port; | ||
let authTest; | ||
let wireMock; | ||
before(async () => { | ||
port = await getFreePort(); | ||
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, '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, '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, '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.'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"scenarioName": "Invalid PAT authentication flow", | ||
"requiredScenarioState": "Started", | ||
"newScenarioState": "Authenticated", | ||
"request": { | ||
"urlPathPattern": "/session/v1/login-request.*", | ||
"method": "POST", | ||
"headers": { | ||
"accept": { | ||
"equalTo": "application/json" | ||
} | ||
}, | ||
"bodyPatterns": [ | ||
{ | ||
"equalToJson": { | ||
"data": { | ||
"ACCOUNT_NAME": "MOCK_ACCOUNT_NAME", | ||
"TOKEN": "INVALID_TOKEN", | ||
"LOGIN_NAME": "MOCK_USERNAME", | ||
"AUTHENTICATOR": "PROGRAMMATIC_ACCESS_TOKEN" | ||
} | ||
}, | ||
"ignoreExtraElements": true | ||
} | ||
] | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"jsonBody": { | ||
"data": { | ||
"nextAction": "RETRY_LOGIN", | ||
"authnMethod": "PAT", | ||
"signInOptions": {} | ||
}, | ||
"code": "394400", | ||
"message": "Programmatic access token is invalid.", | ||
"success": false, | ||
"headers": null | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"scenarioName": "Successful PAT authentication flow", | ||
"requiredScenarioState": "Started", | ||
"newScenarioState": "Authenticated", | ||
"request": { | ||
"urlPathPattern": "/session/v1/login-request.*", | ||
"method": "POST", | ||
"headers": { | ||
"accept": { | ||
"equalTo": "application/json" | ||
} | ||
}, | ||
"bodyPatterns": [ | ||
{ | ||
"equalToJson": { | ||
"data": { | ||
"ACCOUNT_NAME": "MOCK_ACCOUNT_NAME", | ||
"TOKEN": "MOCK_TOKEN", | ||
"LOGIN_NAME": "MOCK_USERNAME", | ||
"AUTHENTICATOR": "PROGRAMMATIC_ACCESS_TOKEN" | ||
} | ||
}, | ||
"ignoreExtraElements": true | ||
} | ||
] | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"jsonBody": { | ||
"data": { | ||
"masterToken": "master token", | ||
"token": "session token", | ||
"validityInSeconds": 3600, | ||
"masterValidityInSeconds": 14400, | ||
"displayUserName": "OAUTH_TEST_AUTH_CODE", | ||
"serverVersion": "8.48.0 b2024121104444034239f05", | ||
"firstLogin": false, | ||
"remMeToken": null, | ||
"remMeValidityInSeconds": 0, | ||
"healthCheckInterval": 45, | ||
"newClientForUpgrade": "3.12.3", | ||
"sessionId": 1172562260498, | ||
"parameters": [ | ||
{ | ||
"name": "CLIENT_PREFETCH_THREADS", | ||
"value": 4 | ||
} | ||
], | ||
"sessionInfo": { | ||
"databaseName": "TEST_DHEYMAN", | ||
"schemaName": "TEST_JDBC", | ||
"warehouseName": "TEST_XSMALL", | ||
"roleName": "ANALYST" | ||
}, | ||
"idToken": null, | ||
"idTokenValidityInSeconds": 0, | ||
"responseData": null, | ||
"mfaToken": null, | ||
"mfaTokenValidityInSeconds": 0 | ||
}, | ||
"code": null, | ||
"message": null, | ||
"success": true | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|