Skip to content

Commit 994ad01

Browse files
[Identity] Fixed bug on 2.0.3 (#20444)
* [Identity] Fixed bug on 2.0.3 2.0.3 contains a regression: Passing a client Id besides the options argument on the `ManagedIdentityCredential` would discard the options argument. We have fixed it and we have added tests. * Update sdk/identity/identity/CHANGELOG.md Co-authored-by: Will Temple <[email protected]> * one more test, to reflect the feedback from Will Co-authored-by: Will Temple <[email protected]>
1 parent 579c48e commit 994ad01

3 files changed

Lines changed: 59 additions & 7 deletions

File tree

sdk/identity/identity/CHANGELOG.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
# Release History
22

3-
## 2.0.4 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
3+
## 2.0.4 (2022-02-18)
84

95
### Bugs Fixed
106

11-
### Other Changes
7+
- Fixed a regression in version 2.0.3 in which providing an options bag, but _not_ a client ID, to the `ManagedIdentityCredential` constructor would discard the `options` parameter.
128

139
## 2.0.3 (2022-02-16)
1410

sdk/identity/identity/src/credentials/managedIdentityCredential/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class ManagedIdentityCredential implements TokenCredential {
6262
_options = options;
6363
} else {
6464
// options only constructor
65-
_options = options;
65+
_options = clientIdOrOptions;
6666
}
6767
this.identityClient = new IdentityClient(_options);
6868
this.isAvailableIdentityClient = new IdentityClient({

sdk/identity/identity/test/internal/node/managedIdentityCredential.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,62 @@ describe("ManagedIdentityCredential", function () {
299299
);
300300
});
301301

302+
it("IMDS MSI accepts a custom set of retries, even when client Id is passed through the first parameter", async function () {
303+
const { error } = await testContext.sendCredentialRequests({
304+
scopes: ["scopes"],
305+
credential: new ManagedIdentityCredential("errclient", {
306+
retryOptions: {
307+
maxRetries: 4,
308+
},
309+
}),
310+
insecureResponses: [
311+
// Any response on the ping request is fine, since it means that the endpoint is indeed there.
312+
createResponse(503, {}, { "Retry-After": "2" }),
313+
// After the ping, we try to get a token from the IMDS endpoint.
314+
createResponse(503, {}, { "Retry-After": "2" }),
315+
createResponse(503, {}, { "Retry-After": "2" }),
316+
createResponse(503, {}, { "Retry-After": "2" }),
317+
createResponse(503, {}, { "Retry-After": "2" }),
318+
// This is the extra one
319+
createResponse(503, {}, { "Retry-After": "2" }),
320+
],
321+
});
322+
323+
assert.ok(error?.message);
324+
assert.equal(
325+
error?.message.split("\n")[0],
326+
"ManagedIdentityCredential authentication failed. Status code: 503"
327+
);
328+
});
329+
330+
it("IMDS MSI accepts a custom set of retries, even when client Id is not passed through the first parameter", async function () {
331+
const { error } = await testContext.sendCredentialRequests({
332+
scopes: ["scopes"],
333+
credential: new ManagedIdentityCredential({
334+
retryOptions: {
335+
maxRetries: 4,
336+
},
337+
}),
338+
insecureResponses: [
339+
// Any response on the ping request is fine, since it means that the endpoint is indeed there.
340+
createResponse(503, {}, { "Retry-After": "2" }),
341+
// After the ping, we try to get a token from the IMDS endpoint.
342+
createResponse(503, {}, { "Retry-After": "2" }),
343+
createResponse(503, {}, { "Retry-After": "2" }),
344+
createResponse(503, {}, { "Retry-After": "2" }),
345+
createResponse(503, {}, { "Retry-After": "2" }),
346+
// This is the extra one
347+
createResponse(503, {}, { "Retry-After": "2" }),
348+
],
349+
});
350+
351+
assert.ok(error?.message);
352+
assert.equal(
353+
error?.message.split("\n")[0],
354+
"ManagedIdentityCredential authentication failed. Status code: 503"
355+
);
356+
});
357+
302358
it("IMDS MSI skips verification if the AZURE_POD_IDENTITY_AUTHORITY_HOST environment variable is available", async function () {
303359
process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST = "token URL";
304360

0 commit comments

Comments
 (0)