5824: Merge branch 'master' into 5824-go-sdk
[arvados.git] / sdk / go / auth / basic_auth_test.go
1 package auth
2
3 import (
4         "net/http"
5         "testing"
6 )
7
8 type basicAuthTestCase struct {
9         hdr  string
10         user string
11         pass string
12         ok   bool
13 }
14
15 func TestBasicAuth(t *testing.T) {
16         tests := []basicAuthTestCase{
17                 {"Basic Zm9vOmJhcg==", "foo", "bar", true},
18                 {"Bogus Zm9vOmJhcg==", "", "", false},
19                 {"Zm9vOmJhcg==", "", "", false},
20                 {"Basic", "", "", false},
21                 {"", "", "", false},
22         }
23         for _, test := range tests {
24                 if u, p, ok := BasicAuth(&http.Request{Header: map[string][]string{
25                         "Authorization": {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)
28                 }
29         }
30 }