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

Function TestBasicAuthNoUsername

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

Source from the content-addressed store, hash-verified

906}
907
908func TestBasicAuthNoUsername(t *testing.T) {
909 cfg, _, err := LoadHTTPConfigFile("testdata/http.conf.basic-auth.no-username.yaml")
910 if err != nil {
911 t.Fatalf("Error loading HTTP client config: %v", err)
912 }
913 client, err := NewClientFromConfig(*cfg, "test")
914 if err != nil {
915 t.Fatalf("Error creating HTTP Client: %v", err)
916 }
917
918 rt, ok := client.Transport.(*basicAuthRoundTripper)
919 if !ok {
920 t.Fatalf("Error casting to basic auth transport, %v", client.Transport)
921 }
922
923 if rt.username != "" {
924 t.Errorf("Got unexpected username: %s", rt.username)
925 }
926 if string(rt.password) != "secret" {
927 t.Errorf("Unexpected HTTP client password: %s", string(rt.password))
928 }
929 if string(rt.passwordFile) != "" {
930 t.Errorf("Expected empty HTTP client passwordFile: %s", rt.passwordFile)
931 }
932}
933
934func TestBasicAuthPasswordFile(t *testing.T) {
935 cfg, _, err := LoadHTTPConfigFile("testdata/http.conf.basic-auth.good.yaml")

Callers

nothing calls this directly

Calls 2

LoadHTTPConfigFileFunction · 0.85
NewClientFromConfigFunction · 0.85

Tested by

no test coverage detected