@@ -335,4 +335,86 @@ describe('BaseService', function() {
335335 } ) ;
336336 expect ( instance . _options . rejectUnauthorized ) . toBe ( true ) ;
337337 } ) ;
338+
339+ describe ( 'check credentials for common problems' , function ( ) {
340+ function assertConstructorThrows ( params ) {
341+ expect ( ( ) => {
342+ new TestService ( params ) ;
343+ } ) . toThrowError (
344+ 'Revise these credentials - they should not start or end with curly brackets or quotes.'
345+ ) ;
346+ }
347+
348+ it ( 'should throw when username starts with {' , function ( ) {
349+ assertConstructorThrows ( {
350+ username : '{batman}' ,
351+ password : 'goodpass' ,
352+ } ) ;
353+ } ) ;
354+
355+ it ( 'should throw when username starts with "' , function ( ) {
356+ assertConstructorThrows ( {
357+ username : '"<batman">' ,
358+ password : 'goodpass' ,
359+ } ) ;
360+ } ) ;
361+
362+ it ( 'should throw when password starts with {' , function ( ) {
363+ assertConstructorThrows ( {
364+ username : 'batman' ,
365+ password : '{badpass}' ,
366+ } ) ;
367+ } ) ;
368+
369+ it ( 'should throw when password starts with "' , function ( ) {
370+ assertConstructorThrows ( {
371+ username : 'batman' ,
372+ password : '"badpass"' ,
373+ } ) ;
374+ } ) ;
375+
376+ it ( 'should throw when iam_apikey starts with {' , function ( ) {
377+ assertConstructorThrows ( {
378+ iam_apikey : '{abc123}' ,
379+ } ) ;
380+ } ) ;
381+
382+ it ( 'should throw when iam_apikey starts with "' , function ( ) {
383+ assertConstructorThrows ( {
384+ iam_apikey : '"<abc123' ,
385+ } ) ;
386+ } ) ;
387+
388+ it ( 'should throw when url starts with {' , function ( ) {
389+ assertConstructorThrows ( {
390+ username : 'batman' ,
391+ password : 'goodpass' ,
392+ url : '{watson-url}/some-api/v1/endpoint' ,
393+ } ) ;
394+ } ) ;
395+
396+ it ( 'should throw when url ends with }' , function ( ) {
397+ assertConstructorThrows ( {
398+ username : 'batman' ,
399+ password : 'goodpass' ,
400+ url : 'watson-url.com/some-api/v1/endpoint}' ,
401+ } ) ;
402+ } ) ;
403+
404+ it ( 'should throw when url starts with "' , function ( ) {
405+ assertConstructorThrows ( {
406+ username : 'batman' ,
407+ password : 'goodpass' ,
408+ url : '"watson-url.com/some-api/v1/endpoint' ,
409+ } ) ;
410+ } ) ;
411+
412+ it ( 'should throw when mutiple creds are bad' , function ( ) {
413+ assertConstructorThrows ( {
414+ username : '{batman}' ,
415+ password : '"<badpass>"' ,
416+ url : '{watson-url}/some-api/v1/endpoint' ,
417+ } ) ;
418+ } ) ;
419+ } ) ;
338420} ) ;
0 commit comments