Skip to content

Commit 8f36779

Browse files
committed
refactor: add option for disabling ssl (for icp)
1 parent 06cdb2e commit 8f36779

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/base_service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ export interface UserOptions {
4343
iam_access_token?: string;
4444
iam_apikey?: string;
4545
iam_url?: string;
46+
allow_unauthorized?: boolean;
4647
}
4748

4849
export interface BaseServiceOptions extends UserOptions {
4950
headers: HeaderOptions;
5051
url: string;
5152
jar?: request.CookieJar;
5253
qs: any;
54+
rejectUnauthorized?: boolean;
5355
}
5456

5557
export interface Credentials {
@@ -149,6 +151,9 @@ export class BaseService {
149151
} else {
150152
this.tokenManager = null;
151153
}
154+
// rejectUnauthorized should only be false if allow_unauthorized is true
155+
// used to disable ssl checking for icp
156+
this._options.rejectUnauthorized = !options.allow_unauthorized;
152157
}
153158

154159
/**

test/unit/test.base_service.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,30 @@ describe('BaseService', function() {
264264
assert.equal(instance.tokenManager, null);
265265
assert(authHeader.startsWith('Basic'));
266266
});
267+
268+
it('should set rejectUnauthorized to `false` if allow_unauthorized is `true`', function() {
269+
const instance = new TestService({
270+
username: 'apikey',
271+
password: 'icp-1234',
272+
allow_unauthorized: true,
273+
});
274+
assert.equal(instance._options.rejectUnauthorized, false);
275+
});
276+
277+
it('should set rejectUnauthorized to `true` if allow_unauthorized is `false`', function() {
278+
const instance = new TestService({
279+
username: 'apikey',
280+
password: 'icp-1234',
281+
allow_unauthorized: false,
282+
});
283+
assert(instance._options.rejectUnauthorized);
284+
});
285+
286+
it('should set rejectUnauthorized to `true` if allow_unauthorized is not set', function() {
287+
const instance = new TestService({
288+
username: 'apikey',
289+
password: 'icp-1234',
290+
});
291+
assert(instance._options.rejectUnauthorized);
292+
});
267293
});

0 commit comments

Comments
 (0)