[ARVADOS] updated: 452dace2a30db53753d98baa21905b32aac4b78d

git at public.curoverse.com git at public.curoverse.com
Tue Mar 24 16:21:13 EDT 2015


Summary of changes:
 services/arv-git-httpd/auth_handler.go |  2 +-
 services/arv-git-httpd/basic_go13.go   | 28 ++++++++++++++++++++++++++++
 services/arv-git-httpd/basic_go14.go   | 11 +++++++++++
 services/arv-git-httpd/basic_test.go   | 30 ++++++++++++++++++++++++++++++
 services/arv-git-httpd/server_test.go  | 24 ++++++++++++------------
 5 files changed, 82 insertions(+), 13 deletions(-)
 create mode 100644 services/arv-git-httpd/basic_go13.go
 create mode 100644 services/arv-git-httpd/basic_go14.go
 create mode 100644 services/arv-git-httpd/basic_test.go

       via  452dace2a30db53753d98baa21905b32aac4b78d (commit)
       via  d1ad9601654a26643b73f871ac58b47ee04e6479 (commit)
       via  1f3874e876617406da51ed61aded11eb7166bc49 (commit)
      from  f2d1eec06a7f44fcd2ded1939d6a2fcfad50840a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 452dace2a30db53753d98baa21905b32aac4b78d
Merge: d1ad960 f2d1eec
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Mar 24 16:22:46 2015 -0400

    5416: Merge remote-tracking branch 'origin/5416-arv-git-httpd' into 5416-arv-git-httpd


commit d1ad9601654a26643b73f871ac58b47ee04e6479
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Mar 24 16:20:06 2015 -0400

    5416: gofmt formatting changes.

diff --git a/services/arv-git-httpd/server_test.go b/services/arv-git-httpd/server_test.go
index 9d2c190..3971d17 100644
--- a/services/arv-git-httpd/server_test.go
+++ b/services/arv-git-httpd/server_test.go
@@ -8,8 +8,8 @@ import (
 	"strings"
 	"testing"
 
-	check "gopkg.in/check.v1"
 	"git.curoverse.com/arvados.git/sdk/go/arvadostest"
+	check "gopkg.in/check.v1"
 )
 
 var _ = check.Suite(&IntegrationSuite{})
@@ -81,19 +81,19 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
 	c.Assert(err, check.Equals, nil)
 	s.tmpWorkdir, err = ioutil.TempDir("", "arv-git-httpd")
 	c.Assert(err, check.Equals, nil)
-	_, err = exec.Command("git", "init", s.tmpRepoRoot + "/foo").Output()
+	_, err = exec.Command("git", "init", s.tmpRepoRoot+"/foo").Output()
 	c.Assert(err, check.Equals, nil)
-	_, err = exec.Command("sh", "-c", "cd " + s.tmpRepoRoot + "/foo && echo test >test && git add test && git commit -am 'foo: test'").CombinedOutput()
+	_, err = exec.Command("sh", "-c", "cd "+s.tmpRepoRoot+"/foo && echo test >test && git add test && git commit -am 'foo: test'").CombinedOutput()
 	c.Assert(err, check.Equals, nil)
 	_, err = exec.Command("git", "init", s.tmpWorkdir).Output()
 	c.Assert(err, check.Equals, nil)
-	_, err = exec.Command("sh", "-c", "cd " + s.tmpWorkdir + " && echo work >work && git add work && git commit -am 'workdir: test'").CombinedOutput()
+	_, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && echo work >work && git add work && git commit -am 'workdir: test'").CombinedOutput()
 	c.Assert(err, check.Equals, nil)
 
 	theConfig = &config{
-		Addr: ":",
+		Addr:       ":",
 		GitCommand: "/usr/bin/git",
-		Root: s.tmpRepoRoot,
+		Root:       s.tmpRepoRoot,
 	}
 	err = s.testServer.Start()
 	c.Assert(err, check.Equals, nil)
@@ -103,13 +103,13 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
 	os.Setenv("ARVADOS_API_TOKEN", "")
 
 	_, err = exec.Command("git", "config",
-		"--file", s.tmpWorkdir + "/.git/config",
-		"credential.http://" + s.testServer.Addr + "/.helper",
+		"--file", s.tmpWorkdir+"/.git/config",
+		"credential.http://"+s.testServer.Addr+"/.helper",
 		"!foo(){ echo password=$ARVADOS_API_TOKEN; };foo").Output()
 	c.Assert(err, check.Equals, nil)
 	_, err = exec.Command("git", "config",
-		"--file", s.tmpWorkdir + "/.git/config",
-		"credential.http://" + s.testServer.Addr + "/.username",
+		"--file", s.tmpWorkdir+"/.git/config",
+		"credential.http://"+s.testServer.Addr+"/.username",
 		"none").Output()
 	c.Assert(err, check.Equals, nil)
 }
@@ -154,9 +154,9 @@ func (s *IntegrationSuite) runGit(c *check.C, gitCmd, repo string, args ...strin
 
 // Make a bare arvados repo at {tmpRepoRoot}/arvados.git
 func (s *IntegrationSuite) makeArvadosRepo(c *check.C) {
-	_, err := exec.Command("git", "init", "--bare", s.tmpRepoRoot + "/arvados.git").Output()
+	_, err := exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/arvados.git").Output()
 	c.Assert(err, check.Equals, nil)
-	_, err = exec.Command("git", "--git-dir", s.tmpRepoRoot + "/arvados.git", "fetch", "../../.git", "master:master").Output()
+	_, err = exec.Command("git", "--git-dir", s.tmpRepoRoot+"/arvados.git", "fetch", "../../.git", "master:master").Output()
 	c.Assert(err, check.Equals, nil)
 }
 

commit 1f3874e876617406da51ed61aded11eb7166bc49
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Mar 24 16:19:50 2015 -0400

    5416: Add BasicAuth compatibility shim for go1.3.

diff --git a/services/arv-git-httpd/auth_handler.go b/services/arv-git-httpd/auth_handler.go
index 3d29993..f91ed3f 100644
--- a/services/arv-git-httpd/auth_handler.go
+++ b/services/arv-git-httpd/auth_handler.go
@@ -57,7 +57,7 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 
 	// HTTP request username is logged, but unused. Password is an
 	// Arvados API token.
-	username, password, ok := r.BasicAuth()
+	username, password, ok := BasicAuth(r)
 	if !ok || username == "" || password == "" {
 		statusCode, statusText = http.StatusUnauthorized, "no credentials provided"
 		w.Header().Add("WWW-Authenticate", "basic")
diff --git a/services/arv-git-httpd/basic_go13.go b/services/arv-git-httpd/basic_go13.go
new file mode 100644
index 0000000..2839b16
--- /dev/null
+++ b/services/arv-git-httpd/basic_go13.go
@@ -0,0 +1,28 @@
+// +build !go1.4
+
+package main
+
+import (
+	"encoding/base64"
+	"net/http"
+	"strings"
+)
+
+func BasicAuth(r *http.Request) (username, password string, ok bool) {
+	toks := strings.SplitN(r.Header.Get("Authorization"), " ", 2)
+	if len(toks) != 2 || toks[0] != "Basic" {
+		return "", "", false
+	}
+
+	decoded, err := base64.StdEncoding.DecodeString(toks[1])
+	if err != nil {
+		return "", "", false
+	}
+
+	userAndPass := strings.SplitN(string(decoded), ":", 2)
+	if len(userAndPass) != 2 {
+		return "", "", false
+	}
+
+	return userAndPass[0], userAndPass[1], true
+}
diff --git a/services/arv-git-httpd/basic_go14.go b/services/arv-git-httpd/basic_go14.go
new file mode 100644
index 0000000..6a0079a
--- /dev/null
+++ b/services/arv-git-httpd/basic_go14.go
@@ -0,0 +1,11 @@
+// +build go1.4
+
+package main
+
+import (
+	"net/http"
+)
+
+func BasicAuth(r *http.Request) (username, password string, ok bool) {
+	return r.BasicAuth()
+}
diff --git a/services/arv-git-httpd/basic_test.go b/services/arv-git-httpd/basic_test.go
new file mode 100644
index 0000000..6bc88cb
--- /dev/null
+++ b/services/arv-git-httpd/basic_test.go
@@ -0,0 +1,30 @@
+package main
+
+import (
+	"net/http"
+	"testing"
+)
+
+type basicAuthTestCase struct {
+	hdr  string
+	user string
+	pass string
+	ok   bool
+}
+
+func TestBasicAuth(t *testing.T) {
+	tests := []basicAuthTestCase{
+		basicAuthTestCase{"Basic Zm9vOmJhcg==", "foo", "bar", true},
+		basicAuthTestCase{"Bogus Zm9vOmJhcg==", "", "", false},
+		basicAuthTestCase{"Zm9vOmJhcg==", "", "", false},
+		basicAuthTestCase{"Basic", "", "", false},
+		basicAuthTestCase{"", "", "", false},
+	}
+	for _, test := range tests {
+		if u, p, ok := BasicAuth(&http.Request{Header: map[string][]string{
+			"Authorization": []string{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)
+		}
+	}
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list