8 type basicAuthTestCase struct {
15 func TestBasicAuth(t *testing.T) {
16 tests := []basicAuthTestCase{
17 basicAuthTestCase{"Basic Zm9vOmJhcg==", "foo", "bar", true},
18 basicAuthTestCase{"Bogus Zm9vOmJhcg==", "", "", false},
19 basicAuthTestCase{"Zm9vOmJhcg==", "", "", false},
20 basicAuthTestCase{"Basic", "", "", false},
21 basicAuthTestCase{"", "", "", false},
23 for _, test := range tests {
24 if u, p, ok := BasicAuth(&http.Request{Header: map[string][]string{
25 "Authorization": []string{test.hdr},
26 }}); u != test.user || p != test.pass || ok != test.ok {
27 t.Error("got:", u, p, ok, "expected:", test.user, test.pass, test.ok, "from:", test.hdr)