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

Update test server config #445

Merged
merged 2 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions test/plugins/iamauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down