Skip to content

Commit e6899e5

Browse files
committed
Merge branch 'master' into v4.0.0-branch
2 parents e5e5302 + ab4c1cb commit e6899e5

6 files changed

Lines changed: 122 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [3.15.1](https://github.com/watson-developer-cloud/node-sdk/compare/v3.15.0...v3.15.1) (2019-01-07)
2+
3+
4+
### Bug Fixes
5+
6+
* add `disabled` property to CreateDialogNode ([41cd8dc](https://github.com/watson-developer-cloud/node-sdk/commit/41cd8dc))
7+
* add `user_defined` property to MessageOutput model ([ea28bf3](https://github.com/watson-developer-cloud/node-sdk/commit/ea28bf3))
8+
19
# [3.15.0](https://github.com/watson-developer-cloud/node-sdk/compare/v3.14.0...v3.15.0) (2018-12-07)
210

311

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,8 @@ function (err, token) {
281281
```
282282

283283
### Assistant v2
284-
> Watson Assistant v2 API is released in beta. For details, see the ["Introducing Watson Assistant"](https://www.ibm.com/blogs/watson/2018/03/the-future-of-watson-conversation-watson-assistant/) blog post.
285284

286-
Use the [Assistant][assistant] service to determine the intent of a message.
285+
Use the [Assistant][conversation] service to determine the intent of a message.
287286

288287
Note: You must first create a workspace via IBM Cloud. See [the documentation](https://console.bluemix.net/docs/services/conversation/index.html#about) for details.
289288

lib/base_service.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ function usesBasicForIam(obj: any): boolean {
8686
return obj.username === 'apikey' && !obj.password.startsWith('icp-');
8787
}
8888

89+
// returns true if the string has a curly bracket or quote as the first or last character
90+
// these are common user-issues that we should handle before they get a network error
91+
function badCharAtAnEnd(value: string): boolean {
92+
return value.startsWith('{') || value.startsWith('"') || value.endsWith('}') || value.endsWith('"');
93+
}
94+
95+
// checks credentials for common user mistakes of copying {, }, or " characters from the documentation
96+
function checkCredentials(obj: any) {
97+
let errorMessage = '';
98+
const credsToCheck = ['url', 'username', 'password', 'iam_apikey'];
99+
credsToCheck.forEach(cred => {
100+
if (obj[cred] && badCharAtAnEnd(obj[cred])) {
101+
errorMessage += `The ${cred} shouldn't start or end with curly brackets or quotes. Be sure to remove any {, }, or "`;
102+
}
103+
});
104+
105+
if (errorMessage.length) {
106+
errorMessage += 'Revise these credentials - they should not start or end with curly brackets or quotes.';
107+
return errorMessage;
108+
} else {
109+
return null;
110+
}
111+
}
112+
89113
export class BaseService {
90114
static URL: string;
91115
name: string;
@@ -293,6 +317,11 @@ export class BaseService {
293317
}
294318
}
295319
}
320+
// check credentials for common user errors
321+
const credentialProblems = checkCredentials(_options);
322+
if (credentialProblems) {
323+
throw new Error(credentialProblems);
324+
}
296325
return _options;
297326
}
298327
/**

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "watson-developer-cloud",
3-
"version": "3.15.0",
3+
"version": "3.15.1",
44
"description": "Client library to use the IBM Watson Services and AlchemyAPI",
55
"main": "./index",
66
"repository": {

test/unit/baseService.test.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)