2411: Add copyright notices to everything.
[arvados.git] / sdk / go / auth / basic_auth_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package auth
6
7 import (
8         "net/http"
9         "testing"
10 )
11
12 type basicAuthTestCase struct {
13         hdr  string
14         user string
15         pass string
16         ok   bool
17 }
18
19 func TestBasicAuth(t *testing.T) {
20         tests := []basicAuthTestCase{
21                 {"Basic Zm9vOmJhcg==", "foo", "bar", true},
22                 {"Bogus Zm9vOmJhcg==", "", "", false},
23                 {"Zm9vOmJhcg==", "", "", false},
24                 {"Basic", "", "", false},
25                 {"", "", "", false},
26         }
27         for _, test := range tests {
28                 if u, p, ok := BasicAuth(&http.Request{Header: map[string][]string{
29                         "Authorization": {test.hdr},
30                 }}); u != test.user || p != test.pass || ok != test.ok {
31                         t.Error("got:", u, p, ok, "expected:", test.user, test.pass, test.ok, "from:", test.hdr)
32                 }
33         }
34 }