MCPcopy Create free account
hub / github.com/prometheus/common / TestMissingBearerAuthFile

Function TestMissingBearerAuthFile

config/http_config_test.go:665–697  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

663}
664
665func TestMissingBearerAuthFile(t *testing.T) {
666 cfg := HTTPClientConfig{
667 BearerTokenFile: MissingBearerTokenFile,
668 TLSConfig: TLSConfig{
669 CAFile: TLSCAChainPath,
670 CertFile: ClientCertificatePath,
671 KeyFile: ClientKeyNoPassPath,
672 ServerName: "",
673 InsecureSkipVerify: false,
674 },
675 }
676 handler := func(w http.ResponseWriter, r *http.Request) {
677 bearer := r.Header.Get("Authorization")
678 if bearer != ExpectedBearer {
679 fmt.Fprintf(w, "The expected Bearer Authorization (%s) differs from the obtained Bearer Authorization (%s)",
680 ExpectedBearer, bearer)
681 } else {
682 fmt.Fprint(w, ExpectedMessage)
683 }
684 }
685
686 testServer, err := newTestServer(handler)
687 require.NoError(t, err)
688 defer testServer.Close()
689
690 client, err := NewClientFromConfig(cfg, "test")
691 require.NoError(t, err)
692
693 _, err = client.Get(testServer.URL)
694 require.Errorf(t, err, "No error is returned here")
695
696 require.ErrorContainsf(t, err, "unable to read authorization credentials: unable to read file missing/bearer.token: open missing/bearer.token: no such file or directory", "wrong error message being returned")
697}
698
699func TestBearerAuthRoundTripper(t *testing.T) {
700 const (

Callers

nothing calls this directly

Calls 4

newTestServerFunction · 0.85
NewClientFromConfigFunction · 0.85
GetMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…