Commit 16330853 authored by Adam Reese's avatar Adam Reese Committed by GitHub

Merge pull request #1710 from bacongobbler/chart-repo-authentication

test(cmd): add unit test for chart backed by basic auth
parents 97db9145 d9346e2f
......@@ -20,6 +20,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"testing"
......@@ -35,6 +36,7 @@ func TestResolveChartRef(t *testing.T) {
}{
{name: "full URL", ref: "http://example.com/foo-1.2.3.tgz", expect: "http://example.com/foo-1.2.3.tgz"},
{name: "full URL, HTTPS", ref: "https://example.com/foo-1.2.3.tgz", expect: "https://example.com/foo-1.2.3.tgz"},
{name: "full URL, with authentication", ref: "http://username:password@example.com/foo-1.2.3.tgz", expect: "http://username:password@example.com/foo-1.2.3.tgz"},
{name: "full URL, HTTPS, irrelevant version", ref: "https://example.com/foo-1.2.3.tgz", version: "0.1.0", expect: "https://example.com/foo-1.2.3.tgz"},
{name: "reference, testing repo", ref: "testing/alpine", expect: "http://example.com/alpine-1.2.3.tgz"},
{name: "reference, version, testing repo", ref: "testing/alpine", version: "0.2.0", expect: "http://example.com/alpine-0.2.0.tgz"},
......@@ -90,6 +92,27 @@ func TestDownload(t *testing.T) {
if got.String() != expect {
t.Errorf("Expected %q, got %q", expect, got.String())
}
// test with server backed by basic auth
basicAuthSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
if !ok || username != "username" && password != "password" {
t.Errorf("Expected request to use basic auth and for username == 'username' and password == 'password', got '%v', '%s', '%s'", ok, username, password)
}
fmt.Fprint(w, expect)
}))
defer basicAuthSrv.Close()
u, _ := url.ParseRequestURI(basicAuthSrv.URL)
u.User = url.UserPassword("username", "password")
got, err = download(u.String())
if err != nil {
t.Fatal(err)
}
if got.String() != expect {
t.Errorf("Expected %q, got %q", expect, got.String())
}
}
func TestIsTar(t *testing.T) {
......
......@@ -268,6 +268,15 @@ $ helm repo list
fantastic-charts https://fantastic-charts.storage.googleapis.com
```
If the charts are backed by HTTP basic authentication, you can also supply the
username and password here:
```console
$ helm repo add fantastic-charts https://username:password@fantastic-charts.storage.googleapis.com
$ helm repo list
fantastic-charts https://username:password@fantastic-charts.storage.googleapis.com
```
**Note:** A repository will not be added if it does not contain a valid
`index.yaml`.
......
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