From f4a7450f747ab5e45b15871ebfdedcf89ba2e7ea Mon Sep 17 00:00:00 2001 From: Lorenzo Fontana Date: Mon, 20 Apr 2015 22:06:17 +0200 Subject: [PATCH] Removed go1.3.3 support Signed-off-by: Lorenzo Fontana --- requestdecorator/requestdecorator_test.go | 40 ++--------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/requestdecorator/requestdecorator_test.go b/requestdecorator/requestdecorator_test.go index f1f9ef7..ed61135 100644 --- a/requestdecorator/requestdecorator_test.go +++ b/requestdecorator/requestdecorator_test.go @@ -1,45 +1,11 @@ package requestdecorator import ( - "encoding/base64" "net/http" "strings" "testing" ) -// The following 2 functions are here for 1.3.3 support -// After we drop 1.3.3 support we can use the functions supported -// in go v1.4.0 + -// BasicAuth returns the username and password provided in the request's -// Authorization header, if the request uses HTTP Basic Authentication. -// See RFC 2617, Section 2. -func basicAuth(r *http.Request) (username, password string, ok bool) { - auth := r.Header.Get("Authorization") - if auth == "" { - return - } - return parseBasicAuth(auth) -} - -// parseBasicAuth parses an HTTP Basic Authentication string. -// "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" returns ("Aladdin", "open sesame", true). -func parseBasicAuth(auth string) (username, password string, ok bool) { - const prefix = "Basic " - if !strings.HasPrefix(auth, prefix) { - return - } - c, err := base64.StdEncoding.DecodeString(auth[len(prefix):]) - if err != nil { - return - } - cs := string(c) - s := strings.IndexByte(cs, ':') - if s < 0 { - return - } - return cs[:s], cs[s+1:], true -} - func TestUAVersionInfo(t *testing.T) { uavi := NewUAVersionInfo("foo", "bar") if !uavi.isValid() { @@ -147,7 +113,7 @@ func TestAuthDecorator(t *testing.T) { t.Fatal(err) } - username, password, ok := basicAuth(reqDecorated) + username, password, ok := reqDecorated.BasicAuth() if !ok { t.Fatalf("Cannot retrieve basic auth info from request") } @@ -189,7 +155,7 @@ func TestRequestFactory(t *testing.T) { t.Fatal(err) } - username, password, ok := basicAuth(req) + username, password, ok := req.BasicAuth() if !ok { t.Fatalf("Cannot retrieve basic auth info from request") } @@ -220,7 +186,7 @@ func TestRequestFactoryNewRequestWithDecorators(t *testing.T) { t.Fatal(err) } - username, password, ok := basicAuth(req) + username, password, ok := req.BasicAuth() if !ok { t.Fatalf("Cannot retrieve basic auth info from request") }