Skip to content

Tidy up Authorization error tests #24404

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

Merged
merged 1 commit into from
Apr 18, 2025
Merged
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
65 changes: 31 additions & 34 deletions packages/drivers/odsp-driver/src/test/odspError.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import {
IAuthorizationError,
IGenericNetworkError,
} from "@fluidframework/driver-definitions/internal";
import {
type AuthorizationError,
NonRetryableError,
} from "@fluidframework/driver-utils/internal";
import { NonRetryableError } from "@fluidframework/driver-utils/internal";
import {
createOdspNetworkError,
throwOdspNetworkError,
Expand Down Expand Up @@ -272,19 +269,21 @@ describe("Odsp Error", () => {
throwOdspNetworkError(errorMessage, 401, testResponseWithInsufficientClaims);
}

it("Authorization error with insufficient claims first-class properties", async () => {
try {
throwAuthorizationErrorWithInsufficientClaims("TestMessage");
} catch (error: unknown) {
assert(isIAuthorizationError(error), "error should be a IAuthorizationError");
assert(error.message.includes("TestMessage"), "message should contain original message");
assert.equal((error as AuthorizationError).canRetry, false, "canRetry should be false");
assert.equal(
(error as AuthorizationError).claims,
'{"access_token":{"nbf":{"essential":true, "value":"1597959090"}}}',
"claims should be extracted from response",
);
}
it("Authorization error with insufficient claims first-class properties", () => {
assert.throws(
() => throwAuthorizationErrorWithInsufficientClaims("TestMessage"),
(error) => {
assert(isIAuthorizationError(error), "error should be a IAuthorizationError");
assert.match(error.message, /TestMessage/, "message should contain original message");
assert.equal(error.canRetry, false, "canRetry should be false");
assert.equal(
error.claims,
'{"access_token":{"nbf":{"essential":true, "value":"1597959090"}}}',
"claims should be extracted from response",
);
return true;
},
);
});

it("Authorization error with insufficient claims results in retry with claims passed in options", async () => {
Expand Down Expand Up @@ -322,23 +321,21 @@ describe("Odsp Error", () => {
throwOdspNetworkError(errorMessage, 401, testResponseWithRealm);
}

it("Authorization error with realm first-class properties", async () => {
try {
throwAuthorizationErrorWithRealm("TestMessage");
} catch (error: unknown) {
assert(isIAuthorizationError(error), "error should be a IAuthorizationError");
assert(error.message.includes("TestMessage"), "message should contain original message");
assert.strictEqual(
(error as AuthorizationError).canRetry,
false,
"canRetry should be false",
);
assert.strictEqual(
(error as AuthorizationError).tenantId,
"6c482541-f706-4168-9e58-8e35a9992f58",
"realm should be extracted from response",
);
}
it("Authorization error with realm first-class properties", () => {
assert.throws(
() => throwAuthorizationErrorWithRealm("TestMessage"),
(error) => {
assert(isIAuthorizationError(error), "error should be a IAuthorizationError");
assert.match(error.message, /TestMessage/, "message should contain original message");
assert.equal(error.canRetry, false, "canRetry should be false");
assert.equal(
error.tenantId,
"6c482541-f706-4168-9e58-8e35a9992f58",
"realm should be extracted from response",
);
return true;
},
);
});

it("Authorization error with realm results in retry and realm passed as tenant id", async () => {
Expand Down
Loading