github.com/argoproj/argo-cd/v2@v2.10.5/test/e2e/repo_management_test.go (about) 1 package e2e 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 9 repositorypkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository" 10 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" 11 "github.com/argoproj/argo-cd/v2/test/e2e/fixture" 12 "github.com/argoproj/argo-cd/v2/test/e2e/fixture/app" 13 "github.com/argoproj/argo-cd/v2/test/e2e/fixture/repos" 14 . "github.com/argoproj/argo-cd/v2/util/errors" 15 argoio "github.com/argoproj/argo-cd/v2/util/io" 16 "github.com/argoproj/argo-cd/v2/util/settings" 17 ) 18 19 func TestAddRemovePublicRepo(t *testing.T) { 20 app.Given(t).And(func() { 21 repoUrl := fixture.RepoURL(fixture.RepoURLTypeFile) 22 _, err := fixture.RunCli("repo", "add", repoUrl) 23 assert.NoError(t, err) 24 25 conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() 26 assert.NoError(t, err) 27 defer argoio.Close(conn) 28 29 repo, err := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{}) 30 31 assert.Nil(t, err) 32 exists := false 33 for i := range repo.Items { 34 if repo.Items[i].Repo == repoUrl { 35 exists = true 36 break 37 } 38 } 39 assert.True(t, exists) 40 41 _, err = fixture.RunCli("repo", "rm", repoUrl) 42 assert.NoError(t, err) 43 44 repo, err = repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{}) 45 assert.NoError(t, err) 46 exists = false 47 for i := range repo.Items { 48 if repo.Items[i].Repo == repoUrl { 49 exists = true 50 break 51 } 52 } 53 assert.False(t, exists) 54 }) 55 } 56 57 func TestGetRepoWithInheritedCreds(t *testing.T) { 58 app.Given(t).And(func() { 59 // create repo credentials 60 FailOnErr(fixture.RunCli("repocreds", "add", fixture.RepoURL(fixture.RepoURLTypeHTTPSOrg), "--github-app-id", fixture.GithubAppID, "--github-app-installation-id", fixture.GithubAppInstallationID, "--github-app-private-key-path", repos.CertKeyPath)) 61 62 repoUrl := fixture.RepoURL(fixture.RepoURLTypeHTTPS) 63 64 // Hack: First we need to create repo with valid credentials 65 FailOnErr(fixture.RunCli("repo", "add", repoUrl, "--username", fixture.GitUsername, "--password", fixture.GitPassword, "--insecure-skip-server-verification")) 66 67 // Then, we remove username/password so that the repo inherits the credentials from our repocreds 68 conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() 69 assert.NoError(t, err) 70 defer argoio.Close(conn) 71 72 _, err = repoClient.UpdateRepository(context.Background(), &repositorypkg.RepoUpdateRequest{ 73 Repo: &v1alpha1.Repository{ 74 Repo: repoUrl, 75 }, 76 }) 77 assert.NoError(t, err) 78 79 // CLI output should indicate that repo has inherited credentials 80 out, err := fixture.RunCli("repo", "get", repoUrl) 81 assert.NoError(t, err) 82 assert.Contains(t, out, "inherited") 83 84 _, err = fixture.RunCli("repo", "rm", repoUrl) 85 assert.NoError(t, err) 86 }) 87 } 88 89 func TestUpsertExistingRepo(t *testing.T) { 90 app.Given(t).And(func() { 91 fixture.SetRepos(settings.RepositoryCredentials{URL: fixture.RepoURL(fixture.RepoURLTypeFile)}) 92 repoUrl := fixture.RepoURL(fixture.RepoURLTypeFile) 93 _, err := fixture.RunCli("repo", "add", repoUrl) 94 assert.NoError(t, err) 95 96 _, err = fixture.RunCli("repo", "add", repoUrl, "--username", fixture.GitUsername, "--password", fixture.GitPassword) 97 assert.Error(t, err) 98 99 _, err = fixture.RunCli("repo", "add", repoUrl, "--upsert", "--username", fixture.GitUsername, "--password", fixture.GitPassword) 100 assert.NoError(t, err) 101 }) 102 } 103 104 func TestAddRemoveHelmRepo(t *testing.T) { 105 app.Given(t).CustomCACertAdded().And(func() { 106 _, err := fixture.RunCli("repo", "add", fixture.RepoURL(fixture.RepoURLTypeHelm), 107 "--name", "testrepo", 108 "--type", "helm", 109 "--username", fixture.GitUsername, 110 "--password", fixture.GitPassword, 111 "--tls-client-cert-path", repos.CertPath, 112 "--tls-client-cert-key-path", repos.CertKeyPath) 113 assert.NoError(t, err) 114 115 conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() 116 assert.NoError(t, err) 117 defer argoio.Close(conn) 118 119 repo, err := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{}) 120 121 assert.NoError(t, err) 122 exists := false 123 for i := range repo.Items { 124 if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) { 125 exists = true 126 break 127 } 128 } 129 assert.True(t, exists) 130 131 _, err = fixture.RunCli("repo", "rm", fixture.RepoURL(fixture.RepoURLTypeHelm)) 132 assert.NoError(t, err) 133 134 repo, err = repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{}) 135 assert.NoError(t, err) 136 exists = false 137 for i := range repo.Items { 138 if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) { 139 exists = true 140 break 141 } 142 } 143 assert.False(t, exists) 144 }) 145 146 } 147 148 func TestAddHelmRepoInsecureSkipVerify(t *testing.T) { 149 app.Given(t).And(func() { 150 _, err := fixture.RunCli("repo", "add", fixture.RepoURL(fixture.RepoURLTypeHelm), 151 "--name", "testrepo", 152 "--type", "helm", 153 "--username", fixture.GitUsername, 154 "--password", fixture.GitPassword, 155 "--insecure-skip-server-verification", 156 "--tls-client-cert-path", repos.CertPath, 157 "--tls-client-cert-key-path", repos.CertKeyPath) 158 159 if !assert.NoError(t, err) { 160 return 161 } 162 163 conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() 164 if !assert.NoError(t, err) { 165 return 166 } 167 168 defer argoio.Close(conn) 169 170 repo, err := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{}) 171 172 if !assert.NoError(t, err) { 173 return 174 } 175 176 exists := false 177 for i := range repo.Items { 178 if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) { 179 exists = true 180 break 181 } 182 } 183 assert.True(t, exists) 184 }) 185 186 }