-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathtest_device_profile_xpaths.py
More file actions
251 lines (218 loc) · 6.3 KB
/
test_device_profile_xpaths.py
File metadata and controls
251 lines (218 loc) · 6.3 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import xml.etree.ElementTree as ET
import pytest
try:
from unittest import mock
except ImportError:
import mock
from panos.device import SnmpServerProfile
from panos.device import SnmpV2cServer
from panos.device import SnmpV3Server
from panos.device import EmailServerProfile
from panos.device import EmailServer
from panos.device import LdapServerProfile
from panos.device import LdapServer
from panos.device import SyslogServerProfile
from panos.device import SyslogServer
from panos.device import HttpServerProfile
from panos.device import HttpServer
from panos.device import HttpConfigHeader
from panos.device import HttpConfigParam
from panos.device import HttpSystemHeader
from panos.device import HttpSystemParam
from panos.device import HttpThreatHeader
from panos.device import HttpThreatParam
from panos.device import HttpTrafficHeader
from panos.device import HttpTrafficParam
from panos.device import HttpHipMatchHeader
from panos.device import HttpHipMatchParam
from panos.device import HttpUrlHeader
from panos.device import HttpUrlParam
from panos.device import HttpDataHeader
from panos.device import HttpDataParam
from panos.device import HttpWildfireHeader
from panos.device import HttpWildfireParam
from panos.device import HttpTunnelHeader
from panos.device import HttpTunnelParam
from panos.device import HttpUserIdHeader
from panos.device import HttpUserIdParam
from panos.device import HttpGtpHeader
from panos.device import HttpGtpParam
from panos.device import HttpAuthHeader
from panos.device import HttpAuthParam
from panos.device import HttpSctpHeader
from panos.device import HttpSctpParam
from panos.device import HttpIpTagHeader
from panos.device import HttpIpTagParam
from panos.firewall import Firewall
from panos.device import Vsys
from panos.panorama import Panorama
from panos.panorama import Template
OBJECTS = {
SnmpServerProfile: [None, SnmpV2cServer, SnmpV3Server],
EmailServerProfile: [
None,
EmailServer,
],
LdapServerProfile: [
None,
LdapServer,
],
SyslogServerProfile: [
None,
SyslogServer,
],
HttpServerProfile: [
None,
HttpServer,
HttpConfigHeader,
HttpConfigParam,
HttpSystemHeader,
HttpSystemParam,
HttpThreatHeader,
HttpThreatParam,
HttpTrafficHeader,
HttpTrafficParam,
HttpHipMatchHeader,
HttpHipMatchParam,
HttpUrlHeader,
HttpUrlParam,
HttpDataHeader,
HttpDataParam,
HttpWildfireHeader,
HttpWildfireParam,
HttpTunnelHeader,
HttpTunnelParam,
HttpUserIdHeader,
HttpUserIdParam,
HttpGtpHeader,
HttpGtpParam,
HttpAuthHeader,
HttpAuthParam,
HttpSctpHeader,
HttpSctpParam,
HttpIpTagHeader,
HttpIpTagParam,
],
}
"""
@pytest.fixture(
scope="function",
params=[x for x in DEVICES],
ids=[x.__class__.__name__ for x in DEVICES],
)
def pdev(request):
request.param.removeall()
return request.param
"""
@pytest.fixture(
scope="function",
params=[(x, y) for x, v in OBJECTS.items() for y in v],
ids=[
"{0}{1}".format(x.__class__.__name__, y.__class__.__name__ if y else "None")
for x, v in OBJECTS.items()
for y in v
],
)
def combination(request):
return request.param
def test_firewall_shared_xpath(combination):
expected = [
"/config/shared",
]
fw = Firewall("127.0.0.1", "admin", "admin", "secret")
fw._version_info = (9999, 0, 0)
fw.vsys = "shared"
parent_cls, child_cls = combination
o = parent_cls("one")
expected.append(o.xpath())
if child_cls is not None:
o2 = child_cls("two")
expected.append(o2.xpath())
o.add(o2)
o = o2
fw.add(o.parent)
else:
fw.add(o)
assert "".join(expected) == o.xpath()
def test_firewall_vsys_xpath(combination):
expected = [
"/config/devices/entry[@name='localhost.localdomain']",
"/vsys/entry[@name='vsys1']",
]
fw = Firewall("127.0.0.1", "admin", "admin", "secret")
fw._version_info = (9999, 0, 0)
parent_cls, child_cls = combination
o = parent_cls("one")
expected.append(o.xpath())
if child_cls is not None:
o2 = child_cls("two")
expected.append(o2.xpath())
o.add(o2)
o = o2
fw.add(o.parent)
else:
fw.add(o)
assert "".join(expected) == o.xpath()
def test_firewall_vsys_object_xpath(combination):
expected = [
"/config/devices/entry[@name='localhost.localdomain']",
"/vsys/entry[@name='vsys2']",
]
fw = Firewall("127.0.0.1", "admin", "admin", "secret")
fw._version_info = (9999, 0, 0)
vsys = Vsys("vsys2")
fw.add(vsys)
parent_cls, child_cls = combination
o = parent_cls("one")
expected.append(o.xpath())
if child_cls is not None:
o2 = child_cls("two")
expected.append(o2.xpath())
o.add(o2)
o = o2
vsys.add(o.parent)
else:
vsys.add(o)
assert "".join(expected) == o.xpath()
def test_panorama_template_object_xpath(combination):
expected = [
"/config/devices/entry[@name='localhost.localdomain']",
]
pano = Panorama("127.0.0.1", "admin", "admin", "secret")
pano._version_info = (9999, 0, 0)
tmpl = Template("myTemplate")
expected.append(tmpl.xpath())
pano.add(tmpl)
expected.append("/config/shared")
vsys = Vsys("shared")
tmpl.add(vsys)
parent_cls, child_cls = combination
o = parent_cls("one")
expected.append(o.xpath())
if child_cls is not None:
o2 = child_cls("two")
expected.append(o2.xpath())
o.add(o2)
o = o2
vsys.add(o.parent)
else:
vsys.add(o)
assert "".join(expected) == o.xpath()
def test_panorama_local_object_xpath(combination):
expected = [
"/config/panorama",
]
pano = Panorama("127.0.0.1", "admin", "admin", "secret")
pano._version_info = (9999, 0, 0)
parent_cls, child_cls = combination
o = parent_cls("one")
expected.append(o.xpath())
if child_cls is not None:
o2 = child_cls("two")
expected.append(o2.xpath())
o.add(o2)
o = o2
pano.add(o.parent)
else:
pano.add(o)
assert "".join(expected) == o.xpath()