MCPcopy
hub / github.com/perkeep/perkeep / TestEmptyPasswords

Function TestEmptyPasswords

pkg/auth/auth_test.go:100–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

98}
99
100func TestEmptyPasswords(t *testing.T) {
101 tests := []struct {
102 config string
103 providedPassword string
104
105 allowed bool
106 }{
107 {config: "foo:", providedPassword: "", allowed: true},
108 {config: "foo:", providedPassword: "bar", allowed: false},
109 {config: "foo:bar", providedPassword: "", allowed: false},
110 {config: "foo:bar", providedPassword: "bar", allowed: true},
111 {config: "foo:bar:vivify=", providedPassword: "", allowed: true},
112 {config: "foo:bar:vivify=", providedPassword: "notbar", allowed: false},
113 {config: "foo:bar:vivify=otherbar", providedPassword: "", allowed: false},
114 {config: "foo:bar:vivify=otherbar", providedPassword: "notbar", allowed: false},
115 {config: "foo:bar:vivify=otherbar", providedPassword: "bar", allowed: true},
116 {config: "foo:bar:vivify=otherbar", providedPassword: "otherbar", allowed: true},
117 }
118
119 for _, test := range tests {
120 req, err := http.NewRequest("GET", "/", nil)
121 if err != nil {
122 t.Fatal(err)
123 }
124 (&UserPass{Username: "foo", Password: test.providedPassword}).AddAuthHeader(req)
125
126 auth, err := newUserPassAuth(test.config)
127 if err != nil {
128 t.Errorf("newUserPassAuth(%q) = error %v; want nil", test.config, err)
129 continue
130 }
131 SetMode(auth)
132
133 if Allowed(req, OpVivify) != test.allowed {
134 t.Errorf("Allowed(req, OpVivify) = %#v; want %#v (config: %q, providedPassword: %q)",
135 Allowed(req, OpVivify), test.allowed, test.config, test.providedPassword)
136 }
137 }
138}

Callers

nothing calls this directly

Calls 6

newUserPassAuthFunction · 0.85
SetModeFunction · 0.85
AllowedFunction · 0.85
NewRequestMethod · 0.80
FatalMethod · 0.80
AddAuthHeaderMethod · 0.65

Tested by

no test coverage detected