MCPcopy Create free account
hub / github.com/github/copilot-sdk / TestPerSessionAuthE2E

Function TestPerSessionAuthE2E

go/internal/e2e/per_session_auth_e2e_test.go:11–143  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestPerSessionAuthE2E(t *testing.T) {
12 ctx := testharness.NewTestContext(t)
13
14 // Create client with COPILOT_DEBUG_GITHUB_API_URL redirected to the proxy
15 // so per-session auth token resolution (fetchCopilotUser) is intercepted.
16 client := ctx.NewClient(func(opts *copilot.ClientOptions) {
17 opts.Env = append(opts.Env, "COPILOT_DEBUG_GITHUB_API_URL="+ctx.ProxyURL)
18 })
19 t.Cleanup(func() { client.ForceStop() })
20 // Register per-token user configs on the proxy
21 if err := ctx.SetCopilotUserByToken("token-alice", map[string]interface{}{
22 "login": "alice",
23 "copilot_plan": "individual_pro",
24 "endpoints": map[string]interface{}{"api": ctx.ProxyURL, "telemetry": "https://localhost:1/telemetry"},
25 "analytics_tracking_id": "alice-tracking-id",
26 }); err != nil {
27 t.Fatalf("Failed to set copilot user for alice: %v", err)
28 }
29
30 if err := ctx.SetCopilotUserByToken("token-bob", map[string]interface{}{
31 "login": "bob",
32 "copilot_plan": "business",
33 "endpoints": map[string]interface{}{"api": ctx.ProxyURL, "telemetry": "https://localhost:1/telemetry"},
34 "analytics_tracking_id": "bob-tracking-id",
35 }); err != nil {
36 t.Fatalf("Failed to set copilot user for bob: %v", err)
37 }
38
39 t.Run("should authenticate with per-session token", func(t *testing.T) {
40 ctx.ConfigureForTest(t)
41
42 session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
43 OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
44 GitHubToken: "token-alice",
45 })
46 if err != nil {
47 t.Fatalf("Failed to create session: %v", err)
48 }
49
50 authStatus, err := session.RPC.GitHubAuth.GetStatus(t.Context())
51 if err != nil {
52 t.Fatalf("Failed to get auth status: %v", err)
53 }
54
55 if !authStatus.IsAuthenticated {
56 t.Errorf("Expected session to be authenticated")
57 }
58 if authStatus.Login == nil || *authStatus.Login != "alice" {
59 t.Errorf("Expected login to be 'alice', got %v", authStatus.Login)
60 }
61 })
62
63 t.Run("should isolate auth between sessions", func(t *testing.T) {
64 ctx.ConfigureForTest(t)
65
66 sessionA, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
67 OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
68 GitHubToken: "token-alice",

Callers

nothing calls this directly

Calls 8

NewClientMethod · 0.95
ForceStopMethod · 0.95
SetCopilotUserByTokenMethod · 0.95
ConfigureForTestMethod · 0.95
CreateSessionMethod · 0.95
EnvMethod · 0.95
withoutAuthEnvFunction · 0.70
GetStatusMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…