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