mirror of
https://github.com/vector-im/element-call.git
synced 2026-09-10 21:55:19 +00:00
Add tests for openid errors
This commit is contained in:
@@ -11,11 +11,12 @@ import {
|
|||||||
describe,
|
describe,
|
||||||
expect,
|
expect,
|
||||||
it,
|
it,
|
||||||
MockedObject,
|
type MockedObject,
|
||||||
vi,
|
vi,
|
||||||
} from "vitest";
|
} from "vitest";
|
||||||
import { type CallMembership } from "matrix-js-sdk/lib/matrixrtc";
|
import { type CallMembership } from "matrix-js-sdk/lib/matrixrtc";
|
||||||
import { BehaviorSubject } from "rxjs";
|
import { BehaviorSubject, lastValueFrom } from "rxjs";
|
||||||
|
import fetchMock from "fetch-mock";
|
||||||
|
|
||||||
import { mockConfig, flushPromises } from "../../../utils/test";
|
import { mockConfig, flushPromises } from "../../../utils/test";
|
||||||
import { createLocalTransport$ } from "./LocalTransport";
|
import { createLocalTransport$ } from "./LocalTransport";
|
||||||
@@ -27,7 +28,6 @@ import {
|
|||||||
} from "../../../utils/errors";
|
} from "../../../utils/errors";
|
||||||
import * as openIDSFU from "../../../livekit/openIDSFU";
|
import * as openIDSFU from "../../../livekit/openIDSFU";
|
||||||
import { customLivekitUrl } from "../../../settings/settings";
|
import { customLivekitUrl } from "../../../settings/settings";
|
||||||
import fetchMock from "fetch-mock";
|
|
||||||
|
|
||||||
describe("LocalTransport", () => {
|
describe("LocalTransport", () => {
|
||||||
let scope: ObservableScope;
|
let scope: ObservableScope;
|
||||||
@@ -188,6 +188,20 @@ describe("LocalTransport", () => {
|
|||||||
type: "livekit",
|
type: "livekit",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it("fails fast if the openID request fails for backend config", async () => {
|
||||||
|
localTransportOpts.client._unstable_getRTCTransports.mockResolvedValue([
|
||||||
|
{ type: "livekit", livekit_service_url: "https://lk.example.org" },
|
||||||
|
]);
|
||||||
|
openIdResolver.reject(
|
||||||
|
new FailToGetOpenIdToken(new Error("Test driven error")),
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
await lastValueFrom(createLocalTransport$(localTransportOpts));
|
||||||
|
throw Error("Expected test to throw");
|
||||||
|
} catch (ex) {
|
||||||
|
expect(ex).toBeInstanceOf(FailToGetOpenIdToken);
|
||||||
|
}
|
||||||
|
});
|
||||||
it("supports getting transport via well-known", async () => {
|
it("supports getting transport via well-known", async () => {
|
||||||
localTransportOpts.client.getDomain.mockReturnValue("example.org");
|
localTransportOpts.client.getDomain.mockReturnValue("example.org");
|
||||||
fetchMock.getOnce("https://example.org/.well-known/matrix/client", {
|
fetchMock.getOnce("https://example.org/.well-known/matrix/client", {
|
||||||
@@ -206,8 +220,23 @@ describe("LocalTransport", () => {
|
|||||||
});
|
});
|
||||||
expect(fetchMock.done()).toEqual(true);
|
expect(fetchMock.done()).toEqual(true);
|
||||||
});
|
});
|
||||||
|
it("fails fast if the openId request fails for the well-known config", async () => {
|
||||||
|
localTransportOpts.client.getDomain.mockReturnValue("example.org");
|
||||||
|
fetchMock.getOnce("https://example.org/.well-known/matrix/client", {
|
||||||
|
"org.matrix.msc4143.rtc_foci": [
|
||||||
|
{ type: "livekit", livekit_service_url: "https://lk.example.org" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
openIdResolver.reject(
|
||||||
|
new FailToGetOpenIdToken(new Error("Test driven error")),
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
await lastValueFrom(createLocalTransport$(localTransportOpts));
|
||||||
|
throw Error("Expected test to throw");
|
||||||
|
} catch (ex) {
|
||||||
|
expect(ex).toBeInstanceOf(FailToGetOpenIdToken);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws if no options are available", async () => {
|
it("throws if no options are available", async () => {
|
||||||
const localTransport$ = createLocalTransport$({
|
const localTransport$ = createLocalTransport$({
|
||||||
scope,
|
scope,
|
||||||
@@ -230,3 +259,4 @@ describe("LocalTransport", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user