@@ -27,7 +27,8 @@ const IAM_API_KEY = process.env.cloudant_iam_api_key || 'CqbrIYzdO3btWV-5t4teJLY
2727const SERVER = process . env . SERVER_URL || `https://${ ME } .cloudant.com` ;
2828const SERVER_NO_PROTOCOL = SERVER . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ;
2929const 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` ;
3132const 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