-
Notifications
You must be signed in to change notification settings - Fork 2
/
system_certificate_test.go
74 lines (58 loc) · 2.2 KB
/
system_certificate_test.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
63
64
65
66
67
68
69
70
71
72
73
74
package gofortiadc
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestSystemCertficate(t *testing.T) {
client, err := NewClientHelper()
require.NoError(t, err, "NewClientHelper")
// Create local certificate
cert, key, err := generateCertificate()
require.NoError(t, err, "generateCertificate")
err = client.SystemCreateLocalCertificate("gofortiadc", "", cert, key)
require.NoError(t, err, "SystemCreateLocalCertificate")
defer func() {
// Delete local certificate
err = client.SystemDeleteLocalCertificate("gofortiadc")
require.NoError(t, err, "SystemDeleteLocalCertificate")
}()
// Get local certificate
certRes, err := client.SystemGetLocalCertificate("gofortiadc")
require.NoError(t, err, "SystemGetLocalCertificate")
require.Equal(t, "/O=Gofortiadc Test", certRes.Subject)
// Create local certificate group
group := SystemLocalCertificateGroup{
Mkey: "goforti_group",
}
err = client.SystemCreateLocalCertificateGroup(group)
require.NoError(t, err, "SystemCreateLocalCertificateGroup")
defer func() {
// Delete local certificate group
err = client.SystemDeleteLocalCertificateGroup("goforti_group")
require.NoError(t, err, "SystemDeleteLocalCertificateGroup")
}()
// Get local certificate group
_, err = client.SystemGetLocalCertificateGroup(group.Mkey)
require.NoError(t, err, "SystemGetLocalCertificateGroup")
// Create local certificate group member
member := SystemLocalCertificateGroupMember{
Default: "disable",
LocalCert: "gofortiadc",
}
err = client.SystemCreateLocalCertificateGroupMember("goforti_group", member)
require.NoError(t, err, "SystemCreateLocalCertificateGroupMember")
defer func() {
// Delete local certificate group member
err = client.SystemDeleteLocalCertificateGroupMember("goforti_group", "1")
require.NoError(t, err, "SystemDeleteLocalCertificateGroupMember")
}()
// Update local certificate group member
member = SystemLocalCertificateGroupMember{
Default: "enable",
IntermediateCag: "Letsencrypt",
LocalCert: "gofortiadc",
Mkey: "1",
}
err = client.SystemUpdateLocalCertificateGroupMember("goforti_group", "1", member)
require.NoError(t, err, "SystemUpdateLocalCertificateGroupMember")
}