MCPcopy
hub / github.com/zalando/skipper / TestRequestWithBasicAuth

Function TestRequestWithBasicAuth

etcd/etcd_test.go:625–667  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

623}
624
625func TestRequestWithBasicAuth(t *testing.T) {
626 var authHeader string
627 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
628 authHeader = r.Header.Get("Authorization")
629 w.Header().Set("X-Etcd-Index", "42")
630 w.Write([]byte(`{"node": {"key": "foo"}}`))
631 }))
632 defer s.Close()
633
634 c, err := New(Options{[]string{s.URL}, "/skippertest", 0, false, "", "user", "password"})
635 if err != nil {
636 t.Fatal(err)
637 }
638
639 if err := c.Delete("foo"); err != nil {
640 t.Fatal(err)
641 }
642
643 k, v, found := strings.Cut(authHeader, " ")
644 if !found || k == "" || v == "" {
645 t.Error("invalid auth header sent")
646 t.Log(authHeader)
647 return
648 }
649
650 if k != "Basic" {
651 t.Error("invalid auth header sent")
652 t.Log(authHeader)
653 return
654 }
655
656 decodedArr, err := base64.StdEncoding.DecodeString(v)
657 if err != nil {
658 t.Error(err)
659 t.Log("header sent:", authHeader)
660 return
661 }
662
663 decoded := string(decodedArr)
664 if decoded != "user:password" {
665 t.Fatal("invalid token not set")
666 }
667}

Callers

nothing calls this directly

Calls 9

LogMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
DeleteMethod · 0.65
ErrorMethod · 0.65
HeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…