forked from adamlaska/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcert_test.go
More file actions
81 lines (70 loc) · 1.69 KB
/
cert_test.go
File metadata and controls
81 lines (70 loc) · 1.69 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cert
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestGenerateCACertificate(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "machine-test-")
if err != nil {
t.Fatal(err)
}
// cleanup
defer os.RemoveAll(tmpDir)
caCertPath := filepath.Join(tmpDir, "ca.pem")
caKeyPath := filepath.Join(tmpDir, "key.pem")
testOrg := "test-org"
bits := 2048
if err := GenerateCACertificate(caCertPath, caKeyPath, testOrg, bits); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(caCertPath); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(caKeyPath); err != nil {
t.Fatal(err)
}
}
func TestGenerateCert(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "machine-test-")
if err != nil {
t.Fatal(err)
}
// cleanup
defer os.RemoveAll(tmpDir)
caCertPath := filepath.Join(tmpDir, "ca.pem")
caKeyPath := filepath.Join(tmpDir, "key.pem")
certPath := filepath.Join(tmpDir, "cert.pem")
keyPath := filepath.Join(tmpDir, "cert-key.pem")
testOrg := "test-org"
bits := 2048
if err := GenerateCACertificate(caCertPath, caKeyPath, testOrg, bits); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(caCertPath); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(caKeyPath); err != nil {
t.Fatal(err)
}
opts := &Options{
Hosts: []string{},
CertFile: certPath,
CAKeyFile: caKeyPath,
CAFile: caCertPath,
KeyFile: keyPath,
Org: testOrg,
Bits: bits,
SwarmMaster: false,
}
if err := GenerateCert(opts); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(certPath); err != nil {
t.Fatalf("certificate not created at %s", certPath)
}
if _, err := os.Stat(keyPath); err != nil {
t.Fatalf("key not created at %s", keyPath)
}
}