MCPcopy
hub / github.com/TecharoHQ/anubis / TestBasePrefix

Function TestBasePrefix

lib/anubis_test.go:471–636  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

469}
470
471func TestBasePrefix(t *testing.T) {
472 h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
473 fmt.Fprintln(w, "OK")
474 })
475
476 testCases := []struct {
477 name string
478 basePrefix string
479 path string
480 expected string
481 }{
482 {
483 name: "no prefix",
484 basePrefix: "",
485 path: "/.within.website/x/cmd/anubis/api/make-challenge",
486 expected: "/.within.website/x/cmd/anubis/api/make-challenge",
487 },
488 {
489 name: "with prefix",
490 basePrefix: "/myapp",
491 path: "/myapp/.within.website/x/cmd/anubis/api/make-challenge",
492 expected: "/myapp/.within.website/x/cmd/anubis/api/make-challenge",
493 },
494 {
495 name: "with prefix and trailing slash",
496 basePrefix: "/myapp/",
497 path: "/myapp/.within.website/x/cmd/anubis/api/make-challenge",
498 expected: "/myapp/.within.website/x/cmd/anubis/api/make-challenge",
499 },
500 }
501
502 for _, tc := range testCases {
503 t.Run(tc.name, func(t *testing.T) {
504 // Reset the global BasePrefix before each test
505 anubis.BasePrefix = ""
506
507 pol := loadPolicies(t, "", 4)
508
509 srv := spawnAnubis(t, Options{
510 Next: h,
511 Policy: pol,
512 BasePrefix: tc.basePrefix,
513 })
514
515 ts := httptest.NewServer(internal.RemoteXRealIP(true, "tcp", srv))
516 defer ts.Close()
517
518 cli := httpClient(t)
519
520 req, err := http.NewRequest(http.MethodPost, ts.URL+tc.path, nil)
521 if err != nil {
522 t.Fatal(err)
523 }
524
525 q := req.URL.Query()
526 redir := tc.basePrefix
527 if tc.basePrefix == "" {
528 redir = "/"

Callers

nothing calls this directly

Calls 9

RemoteXRealIPFunction · 0.92
SHA256sumFunction · 0.92
loadPoliciesFunction · 0.85
httpClientFunction · 0.85
CookiesMethod · 0.80
spawnAnubisFunction · 0.70
SetMethod · 0.65
CloseMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected