(t *testing.T)
| 196 | } |
| 197 | |
| 198 | func TestOpenAI_CreateInterceptor(t *testing.T) { |
| 199 | t.Parallel() |
| 200 | |
| 201 | tests := []struct { |
| 202 | name string |
| 203 | route string |
| 204 | requestBody string |
| 205 | responseBody string |
| 206 | setHeaders map[string]string |
| 207 | wantAuthorization string |
| 208 | wantCredentialKind intercept.CredentialKind |
| 209 | wantCredentialHint string |
| 210 | }{ |
| 211 | { |
| 212 | name: "ChatCompletions_BYOK", |
| 213 | route: routeChatCompletions, |
| 214 | requestBody: `{"model": "gpt-4", "messages": [{"role": "user", "content": "hello"}], "stream": false}`, |
| 215 | responseBody: chatCompletionResponse, |
| 216 | setHeaders: map[string]string{"Authorization": "Bearer user-token"}, |
| 217 | wantAuthorization: "Bearer user-token", |
| 218 | wantCredentialKind: intercept.CredentialKindBYOK, |
| 219 | wantCredentialHint: "us...en", |
| 220 | }, |
| 221 | { |
| 222 | name: "ChatCompletions_Centralized", |
| 223 | route: routeChatCompletions, |
| 224 | requestBody: `{"model": "gpt-4", "messages": [{"role": "user", "content": "hello"}], "stream": false}`, |
| 225 | responseBody: chatCompletionResponse, |
| 226 | setHeaders: map[string]string{}, |
| 227 | wantAuthorization: "Bearer centralized-key", |
| 228 | wantCredentialKind: intercept.CredentialKindCentralized, |
| 229 | wantCredentialHint: "ce...ey", |
| 230 | }, |
| 231 | { |
| 232 | name: "Responses_BYOK", |
| 233 | route: routeResponses, |
| 234 | requestBody: `{"model": "gpt-5", "input": "hello", "stream": false}`, |
| 235 | responseBody: responsesAPIResponse, |
| 236 | setHeaders: map[string]string{"Authorization": "Bearer user-token"}, |
| 237 | wantAuthorization: "Bearer user-token", |
| 238 | wantCredentialKind: intercept.CredentialKindBYOK, |
| 239 | wantCredentialHint: "us...en", |
| 240 | }, |
| 241 | { |
| 242 | name: "Responses_Centralized", |
| 243 | route: routeResponses, |
| 244 | requestBody: `{"model": "gpt-5", "input": "hello", "stream": false}`, |
| 245 | responseBody: responsesAPIResponse, |
| 246 | setHeaders: map[string]string{}, |
| 247 | wantAuthorization: "Bearer centralized-key", |
| 248 | wantCredentialKind: intercept.CredentialKindCentralized, |
| 249 | wantCredentialHint: "ce...ey", |
| 250 | }, |
| 251 | // X-Api-Key should not appear in production since clients use Authorization, |
| 252 | // but ensure it is stripped if it does arrive. |
| 253 | { |
| 254 | name: "ChatCompletions_BYOK_XApiKeyStripped", |
| 255 | route: routeChatCompletions, |
nothing calls this directly
no test coverage detected