Skip to content

Commit

Permalink
fix: ManagementTokenProvider should also respect the keepAlive config…
Browse files Browse the repository at this point in the history
… option (#927)
  • Loading branch information
alaczi committed Sep 11, 2023
1 parent d10c97a commit 2fc510d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/management/ManagementTokenProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ManagementTokenProvider {
* @param {number} [options.cacheTTLInSeconds] By default the `expires_in` value will be used to determine the cached time of the token, this can be overridden.
* @param {object} [options.headers] Additional headers that will be added to the outgoing requests.
* @param {string} [options.proxy] Add the `superagent-proxy` dependency and specify a proxy url eg 'https://myproxy.com:1234'
* @param {boolean} [options.keepAlive] Keep the http connections alive.
*/
constructor(options) {
if (!options || typeof options !== 'object') {
Expand Down Expand Up @@ -76,6 +77,7 @@ class ManagementTokenProvider {
clientInfo: this.options.clientInfo,
headers: this.options.headers,
proxy: this.options.proxy,
keepAlive: this.options.keepAlive,
};
this.authenticationClient = new AuthenticationClient(authenticationClientOptions);

Expand Down
14 changes: 14 additions & 0 deletions test/management/management-token-provider.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ describe('ManagementTokenProvider', () => {
expect(provider.options.headers).to.be.equal(options.headers);
});

it('should send keepAlive true value to authentication client when passed into options', () => {
const options = Object.assign({}, defaultOptions);
options.keepAlive = true;
const provider = new ManagementTokenProvider(options);
expect(provider.authenticationClient.oauth.oauth.options.keepAlive).to.be.true;
});

it('should send keepAlive false value to authentication client when passed into options', () => {
const options = Object.assign({}, defaultOptions);
options.keepAlive = false;
const provider = new ManagementTokenProvider(options);
expect(provider.authenticationClient.oauth.oauth.options.keepAlive).to.be.false;
});

it('should handle network errors correctly', async () => {
const options = Object.assign({}, defaultOptions);
options.domain = 'domain';
Expand Down

0 comments on commit 2fc510d

Please sign in to comment.