Signed-off-by: Lorenzo Fontana <fontanalorenzo@me.com>
This commit is contained in:
Lorenzo Fontana 2015-04-20 22:06:17 +02:00
Родитель b5584ec24a
Коммит 92849fdcce
3 изменённых файлов: 7 добавлений и 41 удалений

Просмотреть файл

@ -98,9 +98,9 @@ RUN cd /usr/local/go/src \
./make.bash --no-clean 2>&1; \
done
# We still support compiling with older Go, so need to grab older "gofmt"
ENV GOFMT_VERSION 1.3.3
RUN curl -sSL https://storage.googleapis.com/golang/go${GOFMT_VERSION}.$(go env GOOS)-$(go env GOARCH).tar.gz | tar -C /go/bin -xz --strip-components=2 go/bin/gofmt
# This has been commented out and kept as reference because we don't support compiling with older Go anymore.
# ENV GOFMT_VERSION 1.3.3
# RUN curl -sSL https://storage.googleapis.com/golang/go${GOFMT_VERSION}.$(go env GOOS)-$(go env GOARCH).tar.gz | tar -C /go/bin -xz --strip-components=2 go/bin/gofmt
# Update this sha when we upgrade to go 1.5.0
ENV GO_TOOLS_COMMIT 069d2f3bcb68257b627205f0486d6cc69a231ff9

Просмотреть файл

@ -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")
}

Просмотреть файл

@ -45,7 +45,7 @@ need to package Docker your way, without denaturing it in the process.
To build Docker, you will need the following:
* A recent version of Git and Mercurial
* Go version 1.3 or later
* Go version 1.4 or later
* A clean checkout of the source added to a valid [Go
workspace](https://golang.org/doc/code.html#Workspaces) under the path
*src/github.com/docker/docker* (unless you plan to use `AUTO_GOPATH`,