From 45065c7b99ff24adda7832dd43993fbe84f99c24 Mon Sep 17 00:00:00 2001 From: Rich Ellis Date: Wed, 12 May 2021 15:22:05 +0100 Subject: [PATCH 1/2] Make IAM token server configurable in tests --- test/plugins/iamauth.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/plugins/iamauth.js b/test/plugins/iamauth.js index 13cc08bd..ac8057fb 100644 --- a/test/plugins/iamauth.js +++ b/test/plugins/iamauth.js @@ -27,7 +27,8 @@ const IAM_API_KEY = process.env.cloudant_iam_api_key || 'CqbrIYzdO3btWV-5t4teJLY const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`; const SERVER_NO_PROTOCOL = SERVER.replace(/^https?:\/\//, ''); const SERVER_WITH_CREDS = `https://${ME}:${PASSWORD}@${SERVER_NO_PROTOCOL}`; -const TOKEN_SERVER = 'https://iam.cloud.ibm.com'; +const TOKEN_SERVER = process.env.cloudant_iam_token_server || 'https://iam.cloud.ibm.com'; +const TOKEN_SERVER_URL = `${TOKEN_SERVER}/identity/token`; const DBNAME = `/nodejs-cloudant-${uuidv4()}`; // mocks @@ -134,7 +135,7 @@ describe('#db IAMAuth Plugin', function() { .get(DBNAME) .reply(200, {doc_count: 0}); - var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: { iamauth: { autoRenew: false, iamApiKey: IAM_API_KEY } } }); + var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: { iamauth: { autoRenew: false, iamApiKey: IAM_API_KEY, iamTokenUrl: TOKEN_SERVER_URL } } }); var req = { url: SERVER + DBNAME, method: 'GET' }; cloudantClient.request(req, function(err, resp, data) { assert.equal(err, null); @@ -217,7 +218,7 @@ describe('#db IAMAuth Plugin', function() { var end1 = false; var end2 = false; - var cloudantClient = new Client({ creds: { outUrl: SERVER }, plugins: { iamauth: { autoRenew: false, iamApiKey: IAM_API_KEY } } }); + var cloudantClient = new Client({ creds: { outUrl: SERVER }, plugins: { iamauth: { autoRenew: false, iamApiKey: IAM_API_KEY, iamTokenUrl: TOKEN_SERVER_URL } } }); var req = { url: SERVER + DBNAME, method: 'GET' }; cloudantClient.request(req, function(err, resp, data) { assert.equal(err, null); @@ -510,12 +511,18 @@ describe('#db IAMAuth Plugin', function() { var cloudant = new Cloudant({ vcapServices: { cloudantNoSQLDB: [ - { credentials: { apikey: IAM_API_KEY, host: `${ME}.cloudant.com` } } + { credentials: { apikey: IAM_API_KEY, host: SERVER_NO_PROTOCOL } } ] }, plugins: 'promises' }); + // Retrospectively modify the IAM token server URL to whatever is configured for the tests + // since the VCAP blob always expects the production IAM token server + const iamPlugin = cloudant.cc._plugins[cloudant.cc._pluginIds.indexOf('iamauth')]; + iamPlugin._tokenManager._iamTokenUrl = TOKEN_SERVER_URL; + iamPlugin._cfg._iamTokenUrl = TOKEN_SERVER_URL; + cloudant.use(DBNAME.substring(1)).info().then((data) => { assert.equal(data.doc_count, 0); iamMocks.done(); From 07524de06235f3e30e64ae637e2f9ae5a563cf09 Mon Sep 17 00:00:00 2001 From: Rich Ellis Date: Wed, 12 May 2021 15:22:23 +0100 Subject: [PATCH 2/2] Add new test server env vars --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 667f4343..e65b21cf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,6 +24,8 @@ def getEnvForSuite(suiteName) { switch(suiteName) { case 'test': envVars.add("NOCK_OFF=true") + envVars.add("SERVER_URL=${env.SDKS_TEST_SERVER_URL}") + envVars.add("cloudant_iam_token_server=${env.SDKS_TEST_IAM_SERVER}") break default: error("Unknown test suite environment ${suiteName}") @@ -40,7 +42,7 @@ def setupNodeAndTest(version, testSuite='test') { unstash name: 'built' // Run tests using creds - withCredentials([usernamePassword(credentialsId: 'clientlibs-test', usernameVariable: 'cloudant_username', passwordVariable: 'cloudant_password'), string(credentialsId: 'clientlibs-test-iam', variable: 'cloudant_iam_api_key')]) { + withCredentials([usernamePassword(credentialsId: 'testServerLegacy', usernameVariable: 'cloudant_username', passwordVariable: 'cloudant_password'), string(credentialsId: 'testServerIamApiKey', variable: 'cloudant_iam_api_key')]) { withEnv(getEnvForSuite("${testSuite}")) { try { // Actions: