github.com/argoproj/argo-cd@v1.8.7/test/e2e/repo_creds_test.go (about)

     1  package e2e
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/argoproj/argo-cd/test/e2e/fixture"
     8  	. "github.com/argoproj/argo-cd/test/e2e/fixture/app"
     9  	. "github.com/argoproj/argo-cd/util/errors"
    10  )
    11  
    12  // make sure you cannot create an app from a private repo without set-up
    13  func TestCannotAddAppFromPrivateRepoWithoutCfg(t *testing.T) {
    14  	Given(t).
    15  		RepoURLType(fixture.RepoURLTypeHTTPS).
    16  		Path(fixture.GuestbookPath).
    17  		When().
    18  		IgnoreErrors().
    19  		Create().
    20  		Then().
    21  		Expect(Error("", "repository not accessible"))
    22  }
    23  
    24  // make sure you cannot create an app from a private repo without set-up
    25  func TestCannotAddAppFromClientCertRepoWithoutCfg(t *testing.T) {
    26  	Given(t).
    27  		RepoURLType(fixture.RepoURLTypeHTTPSClientCert).
    28  		Path(fixture.GuestbookPath).
    29  		When().
    30  		IgnoreErrors().
    31  		Create().
    32  		Then().
    33  		Expect(Error("", "repository not accessible"))
    34  }
    35  
    36  // make sure you can create an app from a private repo, if the repo is set-up in the CM
    37  func TestCanAddAppFromPrivateRepoWithRepoCfg(t *testing.T) {
    38  	Given(t).
    39  		RepoURLType(fixture.RepoURLTypeHTTPS).
    40  		Path("https-kustomize-base").
    41  		And(func() {
    42  			// I use CLI, but you could also modify the settings, we get a free test of the CLI here
    43  			FailOnErr(fixture.RunCli("repo", "add", fixture.RepoURL(fixture.RepoURLTypeHTTPS), "--username", fixture.GitUsername, "--password", fixture.GitPassword, "--insecure-skip-server-verification"))
    44  		}).
    45  		When().
    46  		Create().
    47  		Then().
    48  		Expect(Success(""))
    49  }
    50  
    51  // make sure you can create an app from a private repo, if the creds are set-up in the CM
    52  func TestCanAddAppFromInsecurePrivateRepoWithCredCfg(t *testing.T) {
    53  	Given(t).
    54  		CustomCACertAdded().
    55  		RepoURLType(fixture.RepoURLTypeHTTPS).
    56  		Path("https-kustomize-base").
    57  		And(func() {
    58  			secretName := fixture.CreateSecret(fixture.GitUsername, fixture.GitPassword)
    59  			FailOnErr(fixture.Run("", "kubectl", "patch", "cm", "argocd-cm",
    60  				"-n", fixture.ArgoCDNamespace,
    61  				"-p", fmt.Sprintf(
    62  					`{"data": {"repository.credentials": "- passwordSecret:\n    key: password\n    name: %s\n  url: %s\n  insecure: true\n  usernameSecret:\n    key: username\n    name: %s\n"}}`,
    63  					secretName,
    64  					fixture.RepoURL(fixture.RepoURLTypeHTTPS),
    65  					secretName,
    66  				)))
    67  		}).
    68  		When().
    69  		Create().
    70  		Then().
    71  		Expect(Success(""))
    72  }
    73  
    74  // make sure we can create an app from a private repo, in a secure manner using
    75  // a custom CA certificate bundle
    76  func TestCanAddAppFromPrivateRepoWithCredCfg(t *testing.T) {
    77  	Given(t).
    78  		CustomCACertAdded().
    79  		HTTPSCredentialsUserPassAdded().
    80  		HTTPSRepoURLAdded(false).
    81  		RepoURLType(fixture.RepoURLTypeHTTPS).
    82  		Path("https-kustomize-base").
    83  		And(func() {
    84  			secretName := fixture.CreateSecret(fixture.GitUsername, fixture.GitPassword)
    85  			FailOnErr(fixture.Run("", "kubectl", "patch", "cm", "argocd-cm",
    86  				"-n", fixture.ArgoCDNamespace,
    87  				"-p", fmt.Sprintf(
    88  					`{"data": {"repository.credentials": "- passwordSecret:\n    key: password\n    name: %s\n  url: %s\n  usernameSecret:\n    key: username\n    name: %s\n"}}`,
    89  					secretName,
    90  					fixture.RepoURL(fixture.RepoURLTypeHTTPS),
    91  					secretName,
    92  				)))
    93  		}).
    94  		When().
    95  		Create().
    96  		Then().
    97  		Expect(Success(""))
    98  }
    99  
   100  // make sure we can create an app from a private repo, in a secure manner using
   101  // a custom CA certificate bundle
   102  func TestCanAddAppFromClientCertRepoWithCredCfg(t *testing.T) {
   103  	Given(t).
   104  		CustomCACertAdded().
   105  		HTTPSRepoURLWithClientCertAdded().
   106  		RepoURLType(fixture.RepoURLTypeHTTPSClientCert).
   107  		Path("https-kustomize-base").
   108  		And(func() {
   109  			secretName := fixture.CreateSecret(fixture.GitUsername, fixture.GitPassword)
   110  			FailOnErr(fixture.Run("", "kubectl", "patch", "cm", "argocd-cm",
   111  				"-n", fixture.ArgoCDNamespace,
   112  				"-p", fmt.Sprintf(
   113  					`{"data": {"repository.credentials": "- passwordSecret:\n    key: password\n    name: %s\n  url: %s\n  usernameSecret:\n    key: username\n    name: %s\n"}}`,
   114  					secretName,
   115  					fixture.RepoURL(fixture.RepoURLTypeHTTPS),
   116  					secretName,
   117  				)))
   118  		}).
   119  		When().
   120  		Create().
   121  		Then().
   122  		Expect(Success(""))
   123  }