Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ManagementTokenProvider should also respect the keepAlive config option #927

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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