Commit 2f1b3ddd authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Alain Takoudjou

fixup! NXD blob/auth: Teach it to handle HTTP Basic Auth too

Adjust the test because download-archive format has been changed (see
fixup to first patch in nxd series), while `git fetch` expects the old
way.
parent 9435ce7c
......@@ -872,6 +872,7 @@ func TestPrivateBlobDownload(t *testing.T) {
// access is ok if token is provided either via query or via header
ts := testhelper.TestServerWithHandler(nil, func(w http.ResponseWriter, r *http.Request) {
log.Println("UPSTREAM", r.Method, r.URL)
gitfetch := (strings.HasSuffix(r.URL.Path, "/info/refs") && r.URL.RawQuery == "service=git-upload-pack")
token_ok1 := r.URL.Query().Get("aaa_token") == "TOKEN-4AAA"
token_ok2 := r.Header.Get("BBB-TOKEN") == "TOKEN-4BBB"
cookie, _ := r.Cookie("_gitlab_session")
......@@ -879,9 +880,7 @@ func TestPrivateBlobDownload(t *testing.T) {
username, password, user_ok4 := r.BasicAuth()
if user_ok4 {
// user:password only accepted for `git fetch` requests
user_ok4 = (strings.HasSuffix(r.URL.Path, "/info/refs") &&
r.URL.RawQuery == "service=git-upload-pack" &&
username == "user-ddd" && password == "password-eee")
user_ok4 = (gitfetch && username == "user-ddd" && password == "password-eee")
}
if !(token_ok1 || token_ok2 || cookie_ok3 || user_ok4) {
w.WriteHeader(403)
......@@ -889,6 +888,18 @@ func TestPrivateBlobDownload(t *testing.T) {
return
}
// `git fetch` expects json in body, not senddata-compatible headers
if gitfetch {
data, err := json.Marshal(gitOkBody(t))
if err != nil {
t.Fatal(err)
}
w.WriteHeader(200)
w.Write(data)
return
}
// for authorized .../repository/archive.zip reply the same way archiveOKServer does.
aok := archiveOKServer(t, "")
defer aok.Close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment