Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
834eb57
Improve test coverage to ~100% for @azure/core-client
Apr 16, 2026
3f2b5c5
Remove 'coverage' from test describe block names
Apr 17, 2026
44659d5
Remove 'edge cases' from describe block names
Apr 17, 2026
bee00b8
Extract repeated test constants into shared variables
Apr 17, 2026
33febd2
Fix TypeScript compilation errors caught by CI
Apr 17, 2026
b75d1e4
Format utils.spec.ts
Apr 17, 2026
2790ffc
Fix browser test: guard Buffer usage in base64.spec.ts (core-client)
Apr 17, 2026
498dc0a
Move Node-only base64 test to node/ folder (core-client)
Apr 17, 2026
8cdfca4
Fix test substance issues in core-client
Apr 17, 2026
21973ec
fix: remove line numbers from core-client test names
Apr 18, 2026
ae7ae2f
fix: use assert.isTrue instead of assert.equal(x, true) in serializer…
Apr 18, 2026
a7a91f0
fix: strengthen assertions in core-client tests
Apr 18, 2026
f83d579
fix: replace bare assert() with specific assertions in core-client tests
Apr 18, 2026
b489137
fix: remove line number from deserializationPolicy test name
Apr 18, 2026
91d429a
fix: resolve CI failures in core-client tests
Apr 19, 2026
feee24a
refactor: replace mutable request capture with vi.fn() in serviceClie…
Apr 19, 2026
d15ca39
refactor: remove unused request capture in assertServiceClientResponse
Apr 19, 2026
0898576
refactor: replace capturedRequest mutable capture with vi.fn() in ser…
Apr 19, 2026
2682405
fix: format serviceClient.ts test utility
Apr 19, 2026
ccd8fe1
refactor: modernize error assertions in core-client tests
Apr 19, 2026
cd07353
refactor: second pass modernization in core-client tests
Apr 19, 2026
69b77d7
refactor: second pass modernization in core-rest-pipeline tests
Apr 19, 2026
f5d92cd
fix: remove foreign package files from core-client branch
Apr 19, 2026
f61edef
refactor: modernize test patterns in core-client
Apr 20, 2026
9274809
Eliminate unnecessary type casts in core-client tests
Apr 20, 2026
bf534bc
Eliminate unnecessary type casts in core-client-rest tests
Apr 20, 2026
c453317
Strengthen weak isDefined assertions in core-client-rest tests
Apr 20, 2026
3239a5a
Strengthen weak isDefined assertions in core-client tests
Apr 20, 2026
d53a64e
fix: restore foreign core-client-rest files to main version
Apr 20, 2026
8da2c5b
fix: align test name with actual assertion (null, not undefined)
Apr 20, 2026
6cd6495
rename duplicate test name in serializationPolicy.spec.ts for clarity
Apr 20, 2026
f1e86f0
fix: align 9 test titles with actual assertions in core-client tests
Apr 21, 2026
a9271a2
Strengthen weak assertions in serialization and deserialization tests
Apr 21, 2026
bf8e099
Replace isAbove(x.length, 0) with isNotEmpty for consistency
Apr 21, 2026
4cea7c4
Address Jeremy review feedback on core-client tests
Apr 22, 2026
c717594
Strengthen XML body assertions with exact value verification
Apr 22, 2026
c75b036
Convert .catch(e => e) to expect().rejects.toMatchObject()
Apr 22, 2026
fef0a56
Fix TS2454: initialize request as undefined
Apr 22, 2026
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
10 changes: 10 additions & 0 deletions sdk/core/core-client-rest/test/internal/clientHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ describe("clientHelpers", () => {
);
});

it("should not treat a non-string key property as a KeyCredential", () => {
const pipeline = createDefaultPipeline(mockBaseUrl, { key: 123 } as any);
const policies = pipeline.getOrderedPolicies();

assert.isUndefined(
policies.find((p) => p.name === keyCredentialAuthenticationPolicyName),
"pipeline should not have keyCredentialAuthenticationPolicyName for non-string key",
);
});

it("should create a default pipeline with TokenCredential", () => {
const mockCredential: TokenCredential = {
getToken: async () => ({ expiresOnTimestamp: 0, token: "mockToken" }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import {
} from "../../src/authorizeRequestOnClaimChallenge.js";
import { encodeString } from "../../src/base64.js";

const defaultRequest = () => createPipelineRequest({ url: "https://example.com" });

describe("authorizeRequestOnClaimChallenge", function () {
it(`should try to get the access token if the response has a valid claims parameter on the WWW-Authenticate header`, async function () {
const request = createPipelineRequest({ url: "https://example.com" });
const request = defaultRequest();
const getAccessTokenParameters: {
scopes: string | string[];
getTokenOptions: GetTokenOptions;
Expand Down Expand Up @@ -55,13 +57,13 @@ describe("authorizeRequestOnClaimChallenge", function () {
scopes: ["https://endpoint/.default"],
getTokenOptions: {
claims: '{"access_token":{"nbf":{"essential":true, "value":"1603742800"}}}',
} as GetTokenOptions,
} satisfies GetTokenOptions,
},
]);
});

it(`should try to get the access token with the parametrized scopes if the response has no scope property on the WWW-authenticate header`, async function () {
const request = createPipelineRequest({ url: "https://example.com" });
const request = defaultRequest();
const getAccessTokenParameters: {
scopes: string | string[];
getTokenOptions: GetTokenOptions;
Expand Down Expand Up @@ -97,7 +99,7 @@ describe("authorizeRequestOnClaimChallenge", function () {
scopes: ["https://parametrized-endpoint/.default"],
getTokenOptions: {
claims: '{"access_token":{"nbf":{"essential":true, "value":"1603742800"}}}',
} as GetTokenOptions,
} satisfies GetTokenOptions,
},
]);
});
Expand All @@ -106,7 +108,7 @@ describe("authorizeRequestOnClaimChallenge", function () {
// In Python, padding has to be added at the end if the size of the base64 string is not a multiple of 4.
// In JavaScript, the padding is added automatically.

const request = createPipelineRequest({ url: "https://example.com" });
const request = defaultRequest();
const getAccessTokenParameters: {
scopes: string | string[];
getTokenOptions: GetTokenOptions;
Expand Down Expand Up @@ -143,13 +145,13 @@ describe("authorizeRequestOnClaimChallenge", function () {
scopes: ["https://parametrized-endpoint/.default"],
getTokenOptions: {
claims: '{"access_token":{"nbf":{"essential":true, "value":"1603742800"}}}',
} as GetTokenOptions,
} satisfies GetTokenOptions,
},
]);
});

it(`should return false if getAccessToken is called and if it doesn't return an access token`, async function () {
const request = createPipelineRequest({ url: "https://example.com" });
const request = defaultRequest();
const getAccessTokenParameters: {
scopes: string | string[];
getTokenOptions: GetTokenOptions;
Expand Down Expand Up @@ -182,13 +184,13 @@ describe("authorizeRequestOnClaimChallenge", function () {
scopes: ["https://parametrized-endpoint/.default"],
getTokenOptions: {
claims: '{"access_token":{"nbf":{"essential":true, "value":"1603742800"}}}',
} as GetTokenOptions,
} satisfies GetTokenOptions,
},
]);
});

it(`should return false if the response has an invalid claims parameter on the WWW-Authenticate header`, async function () {
const request = createPipelineRequest({ url: "https://example.com" });
const request = defaultRequest();
const getAccessTokenParameters: {
scopes: string | string[];
getTokenOptions: GetTokenOptions;
Expand Down Expand Up @@ -216,7 +218,7 @@ describe("authorizeRequestOnClaimChallenge", function () {
});

it(`should return false if the response has no WWW-Authenticate header`, async function () {
const request = createPipelineRequest({ url: "https://example.com" });
const request = defaultRequest();
const getAccessTokenParameters: {
scopes: string | string[];
getTokenOptions: GetTokenOptions;
Expand Down Expand Up @@ -283,7 +285,7 @@ describe("authorizeRequestOnClaimChallenge", function () {
}),
};

const pipelineRequest = createPipelineRequest({ url: "https://example.com" });
const pipelineRequest = defaultRequest();
const responses: PipelineResponse[] = [
{
headers: createHttpHeaders({
Expand Down Expand Up @@ -353,7 +355,7 @@ describe("authorizeRequestOnClaimChallenge", function () {
});

it(`a custom logger should log a reasonable message if no challenge is received`, async function () {
const request = createPipelineRequest({ url: "https://example.com" });
const request = defaultRequest();
const getAccessTokenParameters: {
scopes: string | string[];
getTokenOptions: GetTokenOptions;
Expand Down Expand Up @@ -391,7 +393,7 @@ describe("authorizeRequestOnClaimChallenge", function () {
});

it(`a custom logger should log a reasonable message if a bad challenge is received`, async function () {
const request = createPipelineRequest({ url: "https://example.com" });
const request = defaultRequest();
const getAccessTokenParameters: {
scopes: string | string[];
getTokenOptions: GetTokenOptions;
Expand Down Expand Up @@ -436,3 +438,62 @@ describe("authorizeRequestOnClaimChallenge", function () {
);
});
});

describe("authorizeRequestOnClaimChallenge", () => {
it("should handle malformed WWW-Authenticate header (no claims)", async () => {
const request = defaultRequest();
const result = await authorizeRequestOnClaimChallenge({
async getAccessToken() {
return { token: "token", expiresOnTimestamp: Date.now() + 3600000 };
},
scopes: [],
response: {
headers: createHttpHeaders({
"WWW-Authenticate": 'Bearer realm="test"',
}),
request,
status: 401,
},
request,
});
assert.isFalse(result);
});

it("should handle missing WWW-Authenticate header", async () => {
const request = defaultRequest();
const result = await authorizeRequestOnClaimChallenge({
async getAccessToken() {
return { token: "token", expiresOnTimestamp: Date.now() + 3600000 };
},
scopes: [],
response: {
headers: createHttpHeaders(),
request,
status: 401,
},
request,
});
assert.isFalse(result);
});
});

describe("authorizeRequestOnClaimChallenge", () => {
it("should handle completely unparseable WWW-Authenticate value", async () => {
Comment thread
deyaaeldeen marked this conversation as resolved.
const request = defaultRequest();
const result = await authorizeRequestOnClaimChallenge({
async getAccessToken() {
return { token: "token", expiresOnTimestamp: Date.now() + 3600000 };
},
scopes: [],
response: {
headers: createHttpHeaders({
"WWW-Authenticate": "NotBearer gibberish",
}),
request,
status: 401,
},
request,
});
assert.isFalse(result);
});
});
13 changes: 13 additions & 0 deletions sdk/core/core-client/test/internal/base64.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { describe, it, assert } from "vitest";
import { encodeByteArray } from "../../src/base64.js";

describe("base64", () => {
it("should handle Uint8Array input in encodeByteArray", () => {
const arr = new Uint8Array([72, 101, 108, 108, 111]);
const result = encodeByteArray(arr);
assert.strictEqual(result, "SGVsbG8=");
});
});
Loading