// Load base64-encoded token from "Authorization: Basic ..."
// header (typically used by git via credential helper)
- if _, password, ok := BasicAuth(r); ok {
+ if _, password, ok := r.BasicAuth(); ok {
a.Tokens = append(a.Tokens, password)
}
+++ /dev/null
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: Apache-2.0
-
-// +build !go1.4
-
-package auth
-
-import (
- "encoding/base64"
- "net/http"
- "strings"
-)
-
-func BasicAuth(r *http.Request) (username, password string, ok bool) {
- tokens := strings.SplitN(r.Header.Get("Authorization"), " ", 2)
- if len(tokens) != 2 || tokens[0] != "Basic" {
- return "", "", false
- }
-
- decoded, err := base64.StdEncoding.DecodeString(tokens[1])
- if err != nil {
- return "", "", false
- }
-
- userAndPass := strings.SplitN(string(decoded), ":", 2)
- if len(userAndPass) != 2 {
- return "", "", false
- }
-
- return userAndPass[0], userAndPass[1], true
-}
+++ /dev/null
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: Apache-2.0
-
-// +build go1.4
-
-package auth
-
-import (
- "net/http"
-)
-
-func BasicAuth(r *http.Request) (username, password string, ok bool) {
- return r.BasicAuth()
-}
+++ /dev/null
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: Apache-2.0
-
-package auth
-
-import (
- "net/http"
- "testing"
-)
-
-type basicAuthTestCase struct {
- hdr string
- user string
- pass string
- ok bool
-}
-
-func TestBasicAuth(t *testing.T) {
- tests := []basicAuthTestCase{
- {"Basic Zm9vOmJhcg==", "foo", "bar", true},
- {"Bogus Zm9vOmJhcg==", "", "", false},
- {"Zm9vOmJhcg==", "", "", false},
- {"Basic", "", "", false},
- {"", "", "", false},
- }
- for _, test := range tests {
- if u, p, ok := BasicAuth(&http.Request{Header: map[string][]string{
- "Authorization": {test.hdr},
- }}); u != test.user || p != test.pass || ok != test.ok {
- t.Error("got:", u, p, ok, "expected:", test.user, test.pass, test.ok, "from:", test.hdr)
- }
- }
-}