(t *testing.T)
| 169 | } |
| 170 | |
| 171 | func TestBasic_Authorised_should_fail_without_htpasswd_file(t *testing.T) { |
| 172 | filename, err := createBasicAuthFile("foo:bar", t) |
| 173 | if err != nil { |
| 174 | t.Error(err) |
| 175 | } |
| 176 | |
| 177 | a, err := newBasicAuth(config.BasicAuth{ |
| 178 | File: filename, |
| 179 | Refresh: time.Second, |
| 180 | }) |
| 181 | if err != nil { |
| 182 | t.Error(err) |
| 183 | } |
| 184 | |
| 185 | creds := []byte("foo:bar") |
| 186 | r := &http.Request{ |
| 187 | Header: http.Header{ |
| 188 | "Authorization": []string{fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString(creds))}, |
| 189 | }, |
| 190 | } |
| 191 | |
| 192 | w := &responseWriter{} |
| 193 | |
| 194 | t.Run("should authorize against supplied htpasswd file", func(t *testing.T) { |
| 195 | if got, want := a.Authorized(r, w), true; !reflect.DeepEqual(got, want) { |
| 196 | t.Errorf("got %v want %v", got, want) |
| 197 | } |
| 198 | }) |
| 199 | |
| 200 | if err := os.Remove(filename); err != nil { |
| 201 | t.Fatalf("removing htpasswd file: %s", err) |
| 202 | } |
| 203 | |
| 204 | time.Sleep(2 * time.Second) // ensure htpasswd file refresh happened |
| 205 | |
| 206 | t.Run("should not authorize after removing htpasswd file", func(t *testing.T) { |
| 207 | if got, want := a.Authorized(r, w), false; !reflect.DeepEqual(got, want) { |
| 208 | t.Errorf("got %v want %v", got, want) |
| 209 | } |
| 210 | }) |
| 211 | } |
| 212 | |
| 213 | func TestBasic_Authorized_should_set_www_realm_header(t *testing.T) { |
| 214 | basicAuth, err := createBasicAuth("foo", "bar", t) |
nothing calls this directly
no test coverage detected