(t *testing.T)
| 61 | } |
| 62 | |
| 63 | func TestSession_MCPAuthRequestSendsHostToken(t *testing.T) { |
| 64 | stdinR, stdinW := io.Pipe() |
| 65 | stdoutR, stdoutW := io.Pipe() |
| 66 | defer stdinR.Close() |
| 67 | defer stdinW.Close() |
| 68 | defer stdoutR.Close() |
| 69 | defer stdoutW.Close() |
| 70 | |
| 71 | client := jsonrpc2.NewClient(stdinW, stdoutR) |
| 72 | client.Start() |
| 73 | defer client.Stop() |
| 74 | |
| 75 | paramsCh := make(chan map[string]any, 1) |
| 76 | errCh := make(chan error, 1) |
| 77 | |
| 78 | go func() { |
| 79 | frame, err := readTestJSONRPCFrame(stdinR) |
| 80 | if err != nil { |
| 81 | errCh <- err |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | var request struct { |
| 86 | ID json.RawMessage `json:"id"` |
| 87 | Method string `json:"method"` |
| 88 | Params map[string]any `json:"params"` |
| 89 | } |
| 90 | if err := json.Unmarshal(frame, &request); err != nil { |
| 91 | errCh <- err |
| 92 | return |
| 93 | } |
| 94 | if request.Method != "session.mcp.oauth.handlePendingRequest" { |
| 95 | errCh <- fmt.Errorf("expected session.mcp.oauth.handlePendingRequest, got %s", request.Method) |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | paramsCh <- request.Params |
| 100 | |
| 101 | response := map[string]any{ |
| 102 | "jsonrpc": "2.0", |
| 103 | "id": json.RawMessage(request.ID), |
| 104 | "result": map[string]any{"success": true}, |
| 105 | } |
| 106 | data, err := json.Marshal(response) |
| 107 | if err != nil { |
| 108 | errCh <- err |
| 109 | return |
| 110 | } |
| 111 | if _, err := fmt.Fprintf(stdoutW, "Content-Length: %d\r\n\r\n%s", len(data), data); err != nil { |
| 112 | errCh <- err |
| 113 | } |
| 114 | }() |
| 115 | |
| 116 | session := &Session{ |
| 117 | SessionID: "session-1", |
| 118 | client: client, |
| 119 | RPC: rpc.NewSessionRPC(client, "session-1"), |
| 120 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…