@@ -335,4 +335,76 @@ 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 ( 'Revise these credentials - they should not start with a { or "' ) ;
344+ }
345+
346+ it ( 'should throw when username starts with {' , function ( ) {
347+ assertConstructorThrows ( {
348+ username : '{batman}' ,
349+ password : 'goodpass' ,
350+ } ) ;
351+ } ) ;
352+
353+ it ( 'should throw when username starts with "' , function ( ) {
354+ assertConstructorThrows ( {
355+ username : '"<batman">' ,
356+ password : 'goodpass' ,
357+ } ) ;
358+ } ) ;
359+
360+ it ( 'should throw when password starts with {' , function ( ) {
361+ assertConstructorThrows ( {
362+ username : 'batman' ,
363+ password : '{badpass}' ,
364+ } ) ;
365+ } ) ;
366+
367+ it ( 'should throw when password starts with "' , function ( ) {
368+ assertConstructorThrows ( {
369+ username : 'batman' ,
370+ password : '"badpass"' ,
371+ } ) ;
372+ } ) ;
373+
374+ it ( 'should throw when iam_apikey starts with {' , function ( ) {
375+ assertConstructorThrows ( {
376+ iam_apikey : '{abc123}' ,
377+ } ) ;
378+ } ) ;
379+
380+ it ( 'should throw when iam_apikey starts with "' , function ( ) {
381+ assertConstructorThrows ( {
382+ iam_apikey : '"<abc123' ,
383+ } ) ;
384+ } ) ;
385+
386+ it ( 'should throw when url starts with {' , function ( ) {
387+ assertConstructorThrows ( {
388+ username : 'batman' ,
389+ password : 'goodpass' ,
390+ url : '{watson-url}/some-api/v1/endpoint' ,
391+ } ) ;
392+ } ) ;
393+
394+ it ( 'should throw when url starts with "' , function ( ) {
395+ assertConstructorThrows ( {
396+ username : 'batman' ,
397+ password : 'goodpass' ,
398+ url : '"watson-url.com/some-api/v1/endpoint' ,
399+ } ) ;
400+ } ) ;
401+
402+ it ( 'should throw when mutiple creds are bad' , function ( ) {
403+ assertConstructorThrows ( {
404+ username : '{batman}' ,
405+ password : '"<badpass>"' ,
406+ url : '{watson-url}/some-api/v1/endpoint' ,
407+ } ) ;
408+ } ) ;
409+ } ) ;
338410} ) ;
0 commit comments