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

     1  package certs
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/argoproj/argo-cd/test/e2e/fixture"
     9  	"github.com/argoproj/argo-cd/util/errors"
    10  )
    11  
    12  // Add a custom CA certificate to the test and also create the certificate file
    13  // on the file system, so argocd-server and argocd-repo-server can use it.
    14  func AddCustomCACert() {
    15  	caCertPath, err := filepath.Abs("../fixture/certs/argocd-test-ca.crt")
    16  	errors.CheckError(err)
    17  	args := []string{"cert", "add-tls", "localhost", "--from", caCertPath}
    18  	errors.FailOnErr(fixture.RunCli(args...))
    19  	args = []string{"cert", "add-tls", "127.0.0.1", "--from", caCertPath}
    20  	errors.FailOnErr(fixture.RunCli(args...))
    21  
    22  	certData, err := ioutil.ReadFile(caCertPath)
    23  	errors.CheckError(err)
    24  	err = ioutil.WriteFile(fixture.TmpDir+"/app/config/tls/localhost", certData, 0644)
    25  	errors.CheckError(err)
    26  	err = ioutil.WriteFile(fixture.TmpDir+"/app/config/tls/127.0.0.1", certData, 0644)
    27  	errors.CheckError(err)
    28  }
    29  
    30  func AddCustomSSHKnownHostsKeys() {
    31  	source := os.Getenv("ARGOCD_E2E_SSH_KNOWN_HOSTS")
    32  	if source == "" {
    33  		source = "../fixture/testrepos/ssh_known_hosts"
    34  	}
    35  	knownHostsPath, err := filepath.Abs(source)
    36  	errors.CheckError(err)
    37  	args := []string{"cert", "add-ssh", "--batch", "--from", knownHostsPath}
    38  	errors.FailOnErr(fixture.RunCli(args...))
    39  
    40  	knownHostsData, err := ioutil.ReadFile(knownHostsPath)
    41  	errors.CheckError(err)
    42  	err = ioutil.WriteFile(fixture.TmpDir+"/app/config/ssh/ssh_known_hosts", knownHostsData, 0644)
    43  	errors.CheckError(err)
    44  }