Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 49ac32a

Browse files
authored
Merge pull request #445 from cloudant/new-test-server
Update test server config
2 parents 155a230 + 07524de commit 49ac32a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Jenkinsfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def getEnvForSuite(suiteName) {
2424
switch(suiteName) {
2525
case 'test':
2626
envVars.add("NOCK_OFF=true")
27+
envVars.add("SERVER_URL=${env.SDKS_TEST_SERVER_URL}")
28+
envVars.add("cloudant_iam_token_server=${env.SDKS_TEST_IAM_SERVER}")
2729
break
2830
default:
2931
error("Unknown test suite environment ${suiteName}")
@@ -40,7 +42,7 @@ def setupNodeAndTest(version, testSuite='test') {
4042
unstash name: 'built'
4143

4244
// Run tests using creds
43-
withCredentials([usernamePassword(credentialsId: 'clientlibs-test', usernameVariable: 'cloudant_username', passwordVariable: 'cloudant_password'), string(credentialsId: 'clientlibs-test-iam', variable: 'cloudant_iam_api_key')]) {
45+
withCredentials([usernamePassword(credentialsId: 'testServerLegacy', usernameVariable: 'cloudant_username', passwordVariable: 'cloudant_password'), string(credentialsId: 'testServerIamApiKey', variable: 'cloudant_iam_api_key')]) {
4446
withEnv(getEnvForSuite("${testSuite}")) {
4547
try {
4648
// Actions:

test/plugins/iamauth.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const IAM_API_KEY = process.env.cloudant_iam_api_key || 'CqbrIYzdO3btWV-5t4teJLY
2727
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2828
const SERVER_NO_PROTOCOL = SERVER.replace(/^https?:\/\//, '');
2929
const SERVER_WITH_CREDS = `https://${ME}:${PASSWORD}@${SERVER_NO_PROTOCOL}`;
30-
const TOKEN_SERVER = 'https://iam.cloud.ibm.com';
30+
const TOKEN_SERVER = process.env.cloudant_iam_token_server || 'https://iam.cloud.ibm.com';
31+
const TOKEN_SERVER_URL = `${TOKEN_SERVER}/identity/token`;
3132
const DBNAME = `/nodejs-cloudant-${uuidv4()}`;
3233

3334
// mocks
@@ -134,7 +135,7 @@ describe('#db IAMAuth Plugin', function() {
134135
.get(DBNAME)
135136
.reply(200, {doc_count: 0});
136137

137-
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: { iamauth: { autoRenew: false, iamApiKey: IAM_API_KEY } } });
138+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: { iamauth: { autoRenew: false, iamApiKey: IAM_API_KEY, iamTokenUrl: TOKEN_SERVER_URL } } });
138139
var req = { url: SERVER + DBNAME, method: 'GET' };
139140
cloudantClient.request(req, function(err, resp, data) {
140141
assert.equal(err, null);
@@ -217,7 +218,7 @@ describe('#db IAMAuth Plugin', function() {
217218
var end1 = false;
218219
var end2 = false;
219220

220-
var cloudantClient = new Client({ creds: { outUrl: SERVER }, plugins: { iamauth: { autoRenew: false, iamApiKey: IAM_API_KEY } } });
221+
var cloudantClient = new Client({ creds: { outUrl: SERVER }, plugins: { iamauth: { autoRenew: false, iamApiKey: IAM_API_KEY, iamTokenUrl: TOKEN_SERVER_URL } } });
221222
var req = { url: SERVER + DBNAME, method: 'GET' };
222223
cloudantClient.request(req, function(err, resp, data) {
223224
assert.equal(err, null);
@@ -510,12 +511,18 @@ describe('#db IAMAuth Plugin', function() {
510511
var cloudant = new Cloudant({
511512
vcapServices: {
512513
cloudantNoSQLDB: [
513-
{ credentials: { apikey: IAM_API_KEY, host: `${ME}.cloudant.com` } }
514+
{ credentials: { apikey: IAM_API_KEY, host: SERVER_NO_PROTOCOL } }
514515
]
515516
},
516517
plugins: 'promises'
517518
});
518519

520+
// Retrospectively modify the IAM token server URL to whatever is configured for the tests
521+
// since the VCAP blob always expects the production IAM token server
522+
const iamPlugin = cloudant.cc._plugins[cloudant.cc._pluginIds.indexOf('iamauth')];
523+
iamPlugin._tokenManager._iamTokenUrl = TOKEN_SERVER_URL;
524+
iamPlugin._cfg._iamTokenUrl = TOKEN_SERVER_URL;
525+
519526
cloudant.use(DBNAME.substring(1)).info().then((data) => {
520527
assert.equal(data.doc_count, 0);
521528
iamMocks.done();

0 commit comments

Comments
 (0)