This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccessRule_test.go
147 lines (119 loc) · 2.53 KB
/
accessRule_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package goftd
import (
"testing"
)
var (
n1 *NetworkObject
g1 *NetworkObjectGroup
ftd *FTD
)
func setupTestAccessRuleObjects(t *testing.T) error {
var err error
ftd, err = initTest()
if err != nil {
t.Errorf("error: %s\n", err)
return err
}
tearDownTestAccessRuleObjects(t)
n1 = new(NetworkObject)
n1.Name = "testObj001"
n1.SubType = "HOST"
n1.Value = "1.1.1.1"
err = ftd.CreateNetworkObject(n1, DuplicateActionReplace)
if err != nil {
t.Errorf("error: %s\n", err)
return err
}
g1 = new(NetworkObjectGroup)
g1.Name = "testObjGroup001"
g1.Objects = append(g1.Objects, n1.Reference())
err = ftd.CreateNetworkObjectGroup(g1, DuplicateActionReplace)
if err != nil {
t.Errorf("error: %s\n", err)
return err
}
return nil
}
func tearDownTestAccessRuleObjects(t *testing.T) error {
var err error
if g1 != nil {
err = ftd.DeleteNetworkObjectGroup(g1)
if err != nil {
t.Errorf("error: %s\n", err)
return err
}
}
if n1 != nil {
err = ftd.DeleteNetworkObject(n1)
if err != nil {
t.Errorf("error: %s\n", err)
return err
}
}
return nil
}
func TestGetAccessRules(t *testing.T) {
ftd, err := initTest()
if err != nil {
t.Errorf("error: %s\n", err)
return
}
_, err = ftd.GetAccessRules("default", 0)
if err != nil {
t.Errorf("error: %s\n", err)
return
}
}
func TestCreateAccessRules(t *testing.T) {
var err error
ftd, err := initTest()
if err != nil {
t.Errorf("error: %s\n", err)
return
}
a := new(AccessRule)
a.Name = "testPolicy001"
a.RuleAction = RuleActionPermit
a.EventLogAction = LogActionNone
err = ftd.CreateAccessRule(a, "default")
if err != nil {
t.Errorf("error: %s\n", err)
return
}
if a.ID == "" {
t.Errorf("ID was not set\n")
}
err = ftd.DeleteAccessRule(a)
if err != nil {
t.Errorf("error: %s\n", err)
return
}
}
func TestCombinedCreateAccessRules(t *testing.T) {
var err error
err = setupTestAccessRuleObjects(t)
if err != nil {
t.Errorf("error: %s\n", err)
return
}
a := new(AccessRule)
a.Name = "testPolicy001"
a.RuleAction = RuleActionPermit
a.EventLogAction = LogActionNone
a.DestinationNetworks = append(a.DestinationNetworks, n1.Reference())
a.DestinationNetworks = append(a.DestinationNetworks, g1.Reference())
err = ftd.CreateAccessRule(a, "default")
if err != nil {
t.Errorf("error: %s\n", err)
tearDownTestAccessRuleObjects(t)
return
}
//spew.Dump(a)
err = ftd.DeleteAccessRule(a)
if err != nil {
t.Errorf("error: %s\n", err)
tearDownTestAccessRuleObjects(t)
return
}
tearDownTestAccessRuleObjects(t)
}