-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathconnection_token.test.ts
More file actions
51 lines (42 loc) · 2.01 KB
/
connection_token.test.ts
File metadata and controls
51 lines (42 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { afterAll, describe, expect, it } from "vitest";
import { CopilotClient, RuntimeConnection } from "../../src/index.js";
import { createSdkTestContext } from "./harness/sdkTestContext.js";
describe("Connection token", async () => {
const ctx = await createSdkTestContext({
copilotClientOptions: {
connection: RuntimeConnection.forTcp({ connectionToken: "right-token" }),
},
});
const goodClient = ctx.copilotClient;
await goodClient.start();
const port = (goodClient as unknown as { runtimePort: number }).runtimePort;
const wrongClient = new CopilotClient({
connection: RuntimeConnection.forUri(`localhost:${port}`, { connectionToken: "wrong" }),
});
const noTokenClient = new CopilotClient({
connection: RuntimeConnection.forUri(`localhost:${port}`),
});
afterAll(async () => {
await wrongClient.forceStop();
await noTokenClient.forceStop();
});
it("connects with the matching token", async () => {
await expect(goodClient.ping("hi")).resolves.toMatchObject({ message: "pong: hi" });
});
it("rejects a wrong token", async () => {
await expect(wrongClient.start()).rejects.toThrow(/AUTHENTICATION_FAILED/);
});
it("rejects a missing token when one is required", async () => {
await expect(noTokenClient.start()).rejects.toThrow(/AUTHENTICATION_FAILED/);
});
});
describe("Connection token (auto-generated)", async () => {
const { copilotClient } = await createSdkTestContext({ useStdio: false });
it("the SDK-auto-generated UUID round-trips through the spawned CLI", async () => {
await copilotClient.start();
await expect(copilotClient.ping("hi")).resolves.toMatchObject({ message: "pong: hi" });
});
});