From a63f8d8dad52b15884cfa2be87bcdb966b1304d5 Mon Sep 17 00:00:00 2001 From: Andras Laczi Date: Thu, 7 Sep 2023 09:45:05 +0200 Subject: [PATCH] fix: ManagementTokenProviders should also respect the keepAlive config option --- src/management/ManagementTokenProvider.js | 2 ++ test/management/management-token-provider.tests.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/management/ManagementTokenProvider.js b/src/management/ManagementTokenProvider.js index 78a2fe757..348f65c6b 100644 --- a/src/management/ManagementTokenProvider.js +++ b/src/management/ManagementTokenProvider.js @@ -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') { @@ -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); diff --git a/test/management/management-token-provider.tests.js b/test/management/management-token-provider.tests.js index a6b1b0958..e26163f77 100644 --- a/test/management/management-token-provider.tests.js +++ b/test/management/management-token-provider.tests.js @@ -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';