diff --git a/pkg/repo/inmem_repo_service.go b/pkg/repo/inmem_repo_service.go index 7e048e373..3865f8947 100644 --- a/pkg/repo/inmem_repo_service.go +++ b/pkg/repo/inmem_repo_service.go @@ -17,6 +17,7 @@ limitations under the License. package repo import ( + "errors" "fmt" "strings" "sync" @@ -62,6 +63,11 @@ func (rs *inmemRepoService) CreateRepo(repository IRepo) error { URL := repository.GetURL() name := repository.GetName() + valid := GCSRepoURLMatcher.MatchString(URL) + if !valid { + return errors.New(URL + " is an invalid Repo URL") + } + for u, r := range rs.repositories { if u == URL { return fmt.Errorf("Repository with URL %s already exists", URL) diff --git a/pkg/repo/inmem_repo_service_test.go b/pkg/repo/inmem_repo_service_test.go index 4c214188b..119c8535f 100644 --- a/pkg/repo/inmem_repo_service_test.go +++ b/pkg/repo/inmem_repo_service_test.go @@ -85,6 +85,19 @@ func TestCreateRepoWithDuplicateURL(t *testing.T) { } } +func TestCreateRepoWithInvalidURL(t *testing.T) { + rs := NewInmemRepoService() + invalidURL := "fake://sfds" + r, err := newRepo(invalidURL, "", TestName, GCSRepoFormat, GCSRepoType) + if err != nil { + t.Fatalf("cannot create test repo: %v", err) + } + + if err = rs.CreateRepo(r); err == nil { + t.Fatalf("created repo with invalid URL: %s", invalidURL) + } +} + func TestGetRepoWithInvalidURL(t *testing.T) { invalidURL := "https://not.a.valid/url" rs := NewInmemRepoService() @@ -96,7 +109,7 @@ func TestGetRepoWithInvalidURL(t *testing.T) { func TestGetRepoURLByName(t *testing.T) { rs := NewInmemRepoService() - testURL := "gcs://helm-test-charts" + testURL := "gs://helm-test-charts" r, err := newRepo(testURL, "", TestName, GCSRepoFormat, GCSRepoType) err = rs.CreateRepo(r) if err != nil {