MCPcopy Index your code
hub / github.com/coder/coder / TestServeHTTP_StripCoderToken

Function TestServeHTTP_StripCoderToken

coderd/aibridged/aibridged_test.go:407–508  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

405}
406
407func TestServeHTTP_StripCoderToken(t *testing.T) {
408 t.Parallel()
409
410 cases := []struct {
411 name string
412 reqHeaders map[string]string
413 expectPresent map[string]string // header → expected value
414 expectAbsent []string // headers that must be gone
415 }{
416 {
417 // Centralized: the client sets Authorization and X-Api-Key,
418 // but does not include HeaderCoderToken.
419 // All auth headers are stripped.
420 name: "centralized",
421 reqHeaders: map[string]string{
422 "Authorization": "Bearer coder-token",
423 "X-Api-Key": "sk-ant-api03-user-key",
424 },
425 expectAbsent: []string{
426 "Authorization",
427 "X-Api-Key",
428 agplaibridge.HeaderCoderToken,
429 },
430 },
431 {
432 // BYOK with access token: Coder token in BYOK header,
433 // user's access token in Authorization. Only the
434 // BYOK header is stripped.
435 name: "byok bearer token",
436 reqHeaders: map[string]string{
437 agplaibridge.HeaderCoderToken: "coder-token",
438 "Authorization": "Bearer sk-ant-oat01-user-oauth-token",
439 },
440 expectPresent: map[string]string{
441 "Authorization": "Bearer sk-ant-oat01-user-oauth-token",
442 },
443 expectAbsent: []string{
444 agplaibridge.HeaderCoderToken,
445 },
446 },
447 {
448 // BYOK with personal API key: Coder token in BYOK header,
449 // user's API key in X-Api-Key. Only the BYOK header is
450 // stripped.
451 name: "byok api key",
452 reqHeaders: map[string]string{
453 agplaibridge.HeaderCoderToken: "coder-token",
454 "X-Api-Key": "sk-ant-api03-user-key",
455 },
456 expectPresent: map[string]string{
457 "X-Api-Key": "sk-ant-api03-user-key",
458 },
459 expectAbsent: []string{
460 agplaibridge.HeaderCoderToken,
461 },
462 },
463 }
464

Callers

nothing calls this directly

Calls 14

ContextFunction · 0.92
newTestServerFunction · 0.70
RunMethod · 0.65
DRPCConnMethod · 0.65
IsAuthorizedMethod · 0.65
AcquireMethod · 0.65
CleanupMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected