pull/13495/head
George Jenkins 10 months ago
parent e3ce2b188b
commit e81d56a247

@ -29,7 +29,10 @@ import (
) )
func TestDependencyBuildCmd(t *testing.T) { func TestDependencyBuildCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"),
)
defer srv.Stop() defer srv.Stop()
rootDir := srv.Root() rootDir := srv.Root()

@ -32,7 +32,10 @@ import (
) )
func TestDependencyUpdateCmd(t *testing.T) { func TestDependencyUpdateCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"),
)
defer srv.Stop() defer srv.Stop()
t.Logf("Listening on directory %s", srv.Root()) t.Logf("Listening on directory %s", srv.Root())
@ -148,7 +151,10 @@ func TestDependencyUpdateCmd_DoNotDeleteOldChartsOnError(t *testing.T) {
defer resetEnv()() defer resetEnv()()
ensure.HelmHome(t) ensure.HelmHome(t)
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"),
)
defer srv.Stop() defer srv.Stop()
t.Logf("Listening on directory %s", srv.Root()) t.Logf("Listening on directory %s", srv.Root())
@ -242,7 +248,10 @@ func TestDependencyUpdateCmd_WithRepoThatWasNotAdded(t *testing.T) {
} }
func setupMockRepoServer(t *testing.T) *repotest.Server { func setupMockRepoServer(t *testing.T) *repotest.Server {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"),
)
t.Logf("Listening on directory %s", srv.Root()) t.Logf("Listening on directory %s", srv.Root())

@ -27,7 +27,11 @@ import (
) )
func TestInstall(t *testing.T) { func TestInstall(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"), repotest.WithBasicAuth()) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
repotest.WithMiddleware(repotest.BasicAuthMiddleware(t)),
)
defer srv.Stop() defer srv.Stop()
srv2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { srv2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

@ -28,7 +28,10 @@ import (
) )
func TestPullCmd(t *testing.T) { func TestPullCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
)
defer srv.Stop() defer srv.Stop()
ociSrv, err := repotest.NewOCIServer(t, srv.Root()) ociSrv, err := repotest.NewOCIServer(t, srv.Root())
@ -249,7 +252,11 @@ func TestPullCmd(t *testing.T) {
} }
func TestPullWithCredentialsCmd(t *testing.T) { func TestPullWithCredentialsCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"), repotest.WithBasicAuth()) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
repotest.WithMiddleware(repotest.BasicAuthMiddleware(t)),
)
defer srv.Stop() defer srv.Stop()
srv2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { srv2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

@ -34,11 +34,17 @@ import (
) )
func TestRepoAddCmd(t *testing.T) { func TestRepoAddCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer srv.Stop() defer srv.Stop()
// A second test server is setup to verify URL changing // A second test server is setup to verify URL changing
srv2 := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) srv2 := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer srv2.Stop() defer srv2.Stop()
tmpdir := filepath.Join(t.TempDir(), "path-component.yaml/data") tmpdir := filepath.Join(t.TempDir(), "path-component.yaml/data")
@ -74,7 +80,10 @@ func TestRepoAddCmd(t *testing.T) {
} }
func TestRepoAdd(t *testing.T) { func TestRepoAdd(t *testing.T) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop() defer ts.Stop()
rootDir := t.TempDir() rootDir := t.TempDir()
@ -125,7 +134,10 @@ func TestRepoAdd(t *testing.T) {
} }
func TestRepoAddCheckLegalName(t *testing.T) { func TestRepoAddCheckLegalName(t *testing.T) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop() defer ts.Stop()
defer resetEnv()() defer resetEnv()()
@ -179,7 +191,10 @@ func TestRepoAddConcurrentHiddenFile(t *testing.T) {
} }
func repoAddConcurrent(t *testing.T, testName, repoFile string) { func repoAddConcurrent(t *testing.T, testName, repoFile string) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop() defer ts.Stop()
var wg sync.WaitGroup var wg sync.WaitGroup
@ -227,7 +242,11 @@ func TestRepoAddFileCompletion(t *testing.T) {
} }
func TestRepoAddWithPasswordFromStdin(t *testing.T) { func TestRepoAddWithPasswordFromStdin(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"), repotest.WithBasicAuth()) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
repotest.WithMiddleware(repotest.BasicAuthMiddleware(t)),
)
defer srv.Stop() defer srv.Stop()
defer resetEnv()() defer resetEnv()()

@ -30,7 +30,10 @@ import (
) )
func TestRepoRemove(t *testing.T) { func TestRepoRemove(t *testing.T) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop() defer ts.Stop()
rootDir := t.TempDir() rootDir := t.TempDir()
@ -159,7 +162,11 @@ func testCacheFiles(t *testing.T, cacheIndexFile string, cacheChartsFile string,
} }
func TestRepoRemoveCompletion(t *testing.T) { func TestRepoRemoveCompletion(t *testing.T) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop() defer ts.Stop()
rootDir := t.TempDir() rootDir := t.TempDir()

@ -106,7 +106,11 @@ func TestUpdateCustomCacheCmd(t *testing.T) {
cachePath := filepath.Join(rootDir, "updcustomcache") cachePath := filepath.Join(rootDir, "updcustomcache")
os.Mkdir(cachePath, os.ModePerm) os.Mkdir(cachePath, os.ModePerm)
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop() defer ts.Stop()
o := &repoUpdateOptions{ o := &repoUpdateOptions{
@ -127,7 +131,9 @@ func TestUpdateCharts(t *testing.T) {
defer resetEnv()() defer resetEnv()()
ensure.HelmHome(t) ensure.HelmHome(t)
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) ts := repotest.NewTempServer(t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop() defer ts.Stop()
r, err := repo.NewChartRepository(&repo.Entry{ r, err := repo.NewChartRepository(&repo.Entry{
@ -159,7 +165,10 @@ func TestUpdateChartsFail(t *testing.T) {
defer resetEnv()() defer resetEnv()()
ensure.HelmHome(t) ensure.HelmHome(t)
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop() defer ts.Stop()
var invalidURL = ts.URL() + "55" var invalidURL = ts.URL() + "55"
@ -189,7 +198,10 @@ func TestUpdateChartsFailWithError(t *testing.T) {
defer resetEnv()() defer resetEnv()()
ensure.HelmHome(t) ensure.HelmHome(t)
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*")) ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop() defer ts.Stop()
var invalidURL = ts.URL() + "55" var invalidURL = ts.URL() + "55"

@ -26,7 +26,10 @@ import (
) )
func TestShowPreReleaseChart(t *testing.T) { func TestShowPreReleaseChart(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
)
defer srv.Stop() defer srv.Stop()
if err := srv.LinkIndices(); err != nil { if err := srv.LinkIndices(); err != nil {

@ -171,7 +171,11 @@ func TestIsTar(t *testing.T) {
} }
func TestDownloadTo(t *testing.T) { func TestDownloadTo(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*"), repotest.WithBasicAuth()) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
repotest.WithMiddleware(repotest.BasicAuthMiddleware(t)),
)
defer srv.Stop() defer srv.Stop()
if err := srv.CreateIndex(); err != nil { if err := srv.CreateIndex(); err != nil {
t.Fatal(err) t.Fatal(err)
@ -218,7 +222,11 @@ func TestDownloadTo(t *testing.T) {
func TestDownloadTo_TLS(t *testing.T) { func TestDownloadTo_TLS(t *testing.T) {
// Set up mock server w/ tls enabled // Set up mock server w/ tls enabled
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*"), repotest.WithTLS()) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
repotest.WithTLS(),
)
defer srv.Stop() defer srv.Stop()
if err := srv.CreateIndex(); err != nil { if err := srv.CreateIndex(); err != nil {
t.Fatal(err) t.Fatal(err)
@ -269,7 +277,10 @@ func TestDownloadTo_VerifyLater(t *testing.T) {
dest := t.TempDir() dest := t.TempDir()
// Set up a fake repo // Set up a fake repo
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
)
defer srv.Stop() defer srv.Stop()
if err := srv.LinkIndices(); err != nil { if err := srv.LinkIndices(); err != nil {
t.Fatal(err) t.Fatal(err)

@ -292,7 +292,10 @@ version: 0.1.0`
func TestUpdateBeforeBuild(t *testing.T) { func TestUpdateBeforeBuild(t *testing.T) {
// Set up a fake repo // Set up a fake repo
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
)
defer srv.Stop() defer srv.Stop()
if err := srv.LinkIndices(); err != nil { if err := srv.LinkIndices(); err != nil {
t.Fatal(err) t.Fatal(err)
@ -358,7 +361,10 @@ func TestUpdateBeforeBuild(t *testing.T) {
// to be fetched. // to be fetched.
func TestUpdateWithNoRepo(t *testing.T) { func TestUpdateWithNoRepo(t *testing.T) {
// Set up a fake repo // Set up a fake repo
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
)
defer srv.Stop() defer srv.Stop()
if err := srv.LinkIndices(); err != nil { if err := srv.LinkIndices(); err != nil {
t.Fatal(err) t.Fatal(err)
@ -427,7 +433,10 @@ func TestUpdateWithNoRepo(t *testing.T) {
// If each of these main fields (name, version, repository) is not supplied by dep param, default value will be used. // If each of these main fields (name, version, repository) is not supplied by dep param, default value will be used.
func checkBuildWithOptionalFields(t *testing.T, chartName string, dep chart.Dependency) { func checkBuildWithOptionalFields(t *testing.T, chartName string, dep chart.Dependency) {
// Set up a fake repo // Set up a fake repo
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*")) srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
)
defer srv.Stop() defer srv.Stop()
if err := srv.LinkIndices(); err != nil { if err := srv.LinkIndices(); err != nil {
t.Fatal(err) t.Fatal(err)

@ -33,14 +33,23 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
"helm.sh/helm/v3/internal/tlsutil"
"helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/chartutil"
ociRegistry "helm.sh/helm/v3/pkg/registry" ociRegistry "helm.sh/helm/v3/pkg/registry"
"helm.sh/helm/v3/pkg/repo" "helm.sh/helm/v3/pkg/repo"
"helm.sh/helm/v3/testdata"
) )
func BasicAuthMiddleware(t *testing.T) http.HandlerFunc {
return http.HandlerFunc(func(_ 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)
}
})
}
type ServerOption func(*testing.T, *Server) type ServerOption func(*testing.T, *Server)
func WithTLS() ServerOption { func WithTLS() ServerOption {
@ -49,14 +58,9 @@ func WithTLS() ServerOption {
} }
} }
func WithBasicAuth() ServerOption { func WithMiddleware(middleware http.HandlerFunc) ServerOption {
return func(t *testing.T, server *Server) { return func(_ *testing.T, server *Server) {
server.middleware = http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { server.middleware = middleware
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)
}
})
} }
} }
@ -369,10 +373,14 @@ func (s *Server) Start() {
if s.useTLS { if s.useTLS {
insecure := false insecure := false
tlsConf, err := testdata.ReadTLSConfig(insecure) cd := "../../testdata"
ca, pub, priv := filepath.Join(cd, "rootca.crt"), filepath.Join(cd, "crt.pem"), filepath.Join(cd, "key.pem")
tlsConf, err := tlsutil.NewClientTLS(pub, priv, ca, insecure)
if err != nil { if err != nil {
panic(err) panic(err)
} }
tlsConf.ServerName = "helm.sh" tlsConf.ServerName = "helm.sh"
s.srv.TLS = tlsConf s.srv.TLS = tlsConf
s.srv.StartTLS() s.srv.StartTLS()

@ -100,7 +100,10 @@ func TestServer(t *testing.T) {
func TestNewTempServer(t *testing.T) { func TestNewTempServer(t *testing.T) {
ensure.HelmHome(t) ensure.HelmHome(t)
srv := NewTempServer(t, WithChartSourceGlob("testdata/examplechart-0.1.0.tgz")) srv := NewTempServer(
t,
WithChartSourceGlob("testdata/examplechart-0.1.0.tgz"),
)
defer srv.Stop() defer srv.Stop()
if srv.srv.URL == "" { if srv.srv.URL == "" {
@ -137,7 +140,11 @@ func TestNewTempServer(t *testing.T) {
func TestNewTempServer_TLS(t *testing.T) { func TestNewTempServer_TLS(t *testing.T) {
ensure.HelmHome(t) ensure.HelmHome(t)
srv := NewTempServer(t, WithChartSourceGlob("testdata/examplechart-0.1.0.tgz"), WithTLS()) srv := NewTempServer(
t,
WithChartSourceGlob("testdata/examplechart-0.1.0.tgz"),
WithTLS(),
)
defer srv.Stop() defer srv.Stop()
if !strings.HasPrefix(srv.URL(), "https://") { if !strings.HasPrefix(srv.URL(), "https://") {

Loading…
Cancel
Save