github.com/argoproj/argo-cd/v2@v2.10.5/test/e2e/fixture/certs/certs.go (about) 1 package certs 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/argoproj/argo-cd/v2/test/e2e/fixture" 8 "github.com/argoproj/argo-cd/v2/util/errors" 9 ) 10 11 // Add a custom CA certificate to the test and also create the certificate file 12 // on the file system, so argocd-server and argocd-repo-server can use it. 13 func AddCustomCACert() { 14 caCertPath, err := filepath.Abs("../fixture/certs/argocd-test-ca.crt") 15 errors.CheckError(err) 16 // We need to setup TLS certs according to whether we are running tests 17 // against a local workload (repositories available as localhost) and 18 // against remote workloads (repositories available as argocd-e2e-server) 19 if fixture.IsLocal() { 20 args := []string{"cert", "add-tls", "localhost", "--from", caCertPath} 21 errors.FailOnErr(fixture.RunCli(args...)) 22 args = []string{"cert", "add-tls", "127.0.0.1", "--from", caCertPath} 23 errors.FailOnErr(fixture.RunCli(args...)) 24 certData, err := os.ReadFile(caCertPath) 25 errors.CheckError(err) 26 err = os.WriteFile(fixture.TmpDir+"/app/config/tls/localhost", certData, 0644) 27 errors.CheckError(err) 28 err = os.WriteFile(fixture.TmpDir+"/app/config/tls/127.0.0.1", certData, 0644) 29 errors.CheckError(err) 30 } else { 31 args := []string{"cert", "add-tls", "argocd-e2e-server", "--from", caCertPath} 32 errors.FailOnErr(fixture.RunCli(args...)) 33 fixture.RestartAPIServer() 34 fixture.RestartRepoServer() 35 } 36 37 } 38 39 // AddCustomSSHKnownHostsKeys adds SSH known hosts data to the Argo CD server 40 // being tested against. The env ARGOCD_E2E_SSH_KNOWN_HOSTS lets you specify 41 // an optional path to the known hosts file, instead of using the default one. 42 func AddCustomSSHKnownHostsKeys() { 43 source := os.Getenv("ARGOCD_E2E_SSH_KNOWN_HOSTS") 44 if source == "" { 45 source = "../fixture/testrepos/ssh_known_hosts" 46 } 47 knownHostsPath, err := filepath.Abs(source) 48 errors.CheckError(err) 49 args := []string{"cert", "add-ssh", "--upsert", "--batch", "--from", knownHostsPath} 50 errors.FailOnErr(fixture.RunCli(args...)) 51 52 if fixture.IsLocal() { 53 knownHostsData, err := os.ReadFile(knownHostsPath) 54 errors.CheckError(err) 55 err = os.WriteFile(fixture.TmpDir+"/app/config/ssh/ssh_known_hosts", knownHostsData, 0644) 56 errors.CheckError(err) 57 } else { 58 fixture.RestartAPIServer() 59 fixture.RestartRepoServer() 60 } 61 }