Skip to content

Commit

Permalink
added a test for managed identity credetnial with and without client …
Browse files Browse the repository at this point in the history
…id in Cloudshell env
  • Loading branch information
KarishmaGhiya committed Feb 8, 2022
1 parent 9930997 commit af247a4
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { createResponse, IdentityTestContextInterface } from "../../httpRequestsCommon";
import { IdentityTestContext } from "../../httpRequests";
import { AzureAuthorityHosts, DefaultAuthorityHost, DefaultTenantId } from "../../../src/constants";
import { setLogLevel } from "@azure/logger";

describe("ManagedIdentityCredential", function () {
let testContext: IdentityTestContextInterface;
Expand Down Expand Up @@ -360,18 +361,36 @@ describe("ManagedIdentityCredential", function () {
it("sends an authorization request correctly in an Cloud Shell environment", async () => {
// Trigger Cloud Shell behavior by setting environment variables
process.env.MSI_ENDPOINT = "https://endpoint";

const authDetails = await testContext.sendCredentialRequests({
scopes: ["https://service/.default"],
credential: new ManagedIdentityCredential("client"),
credential: new ManagedIdentityCredential(),
secureResponses: [createResponse(200, { access_token: "token" })],
});

console.dir(authDetails);
const authRequest = authDetails.requests[0];
assert.equal(authRequest.method, "POST");
assert.equal(authDetails.result!.token, "token");
});

it("authorization request fails with client id passed in an Cloud Shell environment", async () => {
// Trigger Cloud Shell behavior by setting environment variables
process.env.MSI_ENDPOINT = "https://endpoint";
setLogLevel("warning");
const authDetails = await testContext.sendCredentialRequests({
scopes: ["https://service/.default"],
credential: new ManagedIdentityCredential("client"),
secureResponses: [createResponse(200, { access_token: "token" })],
});
console.dir(authDetails);
assert.equal(authDetails.result, null);
assert.equal(authDetails.error?.name, "CredentialUnavailableError");
assert.equal(
authDetails.error?.message,
"ManagedIdentityCredential: Authentication failed. Message No responses left."
);
assert.equal(authDetails.requests.length, 0);
});

it("sends an authorization request correctly in an Azure Arc environment", async function (this: Mocha.Context) {
// Trigger Azure Arc behavior by setting environment variables

Expand Down

0 comments on commit af247a4

Please sign in to comment.