(t *testing.T)
| 141 | } |
| 142 | |
| 143 | func TestSessionPrompterPromptActions(t *testing.T) { |
| 144 | t.Parallel() |
| 145 | |
| 146 | tests := []struct { |
| 147 | name string |
| 148 | action string |
| 149 | wantDecline bool |
| 150 | }{ |
| 151 | {name: "accept", action: "accept", wantDecline: false}, |
| 152 | {name: "decline", action: "decline", wantDecline: true}, |
| 153 | {name: "cancel", action: "cancel", wantDecline: true}, |
| 154 | } |
| 155 | |
| 156 | caps := &mcp.ClientCapabilities{Elicitation: &mcp.ElicitationCapabilities{ |
| 157 | URL: &mcp.URLElicitationCapabilities{}, |
| 158 | Form: &mcp.FormElicitationCapabilities{}, |
| 159 | }} |
| 160 | |
| 161 | for _, tc := range tests { |
| 162 | // URL and form modes share the accept/decline mapping; cover both. |
| 163 | for _, mode := range []string{"url", "form"} { |
| 164 | t.Run(tc.name+"/"+mode, func(t *testing.T) { |
| 165 | t.Parallel() |
| 166 | |
| 167 | handler := func(_ context.Context, _ *mcp.ElicitRequest) (*mcp.ElicitResult, error) { |
| 168 | return &mcp.ElicitResult{Action: tc.action}, nil |
| 169 | } |
| 170 | |
| 171 | got := runProbe(t, caps, handler, func(ctx context.Context, p *sessionPrompter) string { |
| 172 | var err error |
| 173 | if mode == "url" { |
| 174 | err = p.PromptURL(ctx, oauth.Prompt{Message: "msg", URL: "https://example.com/auth"}) |
| 175 | } else { |
| 176 | err = p.PromptForm(ctx, oauth.Prompt{Message: "msg"}) |
| 177 | } |
| 178 | if err == nil { |
| 179 | return "ok" |
| 180 | } |
| 181 | if err == oauth.ErrPromptDeclined { |
| 182 | return "declined" |
| 183 | } |
| 184 | return "error: " + err.Error() |
| 185 | }) |
| 186 | |
| 187 | if tc.wantDecline { |
| 188 | assert.Equal(t, "declined", got) |
| 189 | } else { |
| 190 | assert.Equal(t, "ok", got) |
| 191 | } |
| 192 | }) |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // TestSessionPrompterTransportError verifies that a prompt which fails to be |
| 198 | // delivered (the client errors instead of returning an action) is reported as |
nothing calls this directly
no test coverage detected