forked from rdmcgregor/conf2yaml
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_data.py
213 lines (200 loc) · 4.45 KB
/
test_data.py
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
#
# Define the file input and expected output for each test case
#
test_firewall_1 = {
"input": """package firewall
config rule
option name 'Allow-MLD'
option src 'wan'
option proto 'icmp'
option src_ip 'fe80::/10'
option family 'ipv6'
option target 'ACCEPT'\n""",
"output": """---
firewall:
rule:
- name: Allow-MLD
src: wan
proto: icmp
src_ip: fe80::/10
family: ipv6
target: ACCEPT\n"""
}
test_firewall_2 = {
"input": """package firewall
config rule
option name 'Allow-MLD'
option src 'wan'
option proto 'icmp'
option src_ip 'fe80::/10'
option family 'ipv6'
option target 'ACCEPT'
config rule
option name 'DROP-MLsadsdsaD'
option src 'lan'
option proto 'tcp'
option src_ip 'fe80::/10'
option family 'ipv4'
option target 'DROP'\n
\n""",
"output": """---
firewall:
rule:
- name: Allow-MLD
src: wan
proto: icmp
src_ip: fe80::/10
family: ipv6
target: ACCEPT
- name: DROP-MLsadsdsaD
src: lan
proto: tcp
src_ip: fe80::/10
family: ipv4
target: DROP\n"""
}
test_firewall_1_with_list = {
"input": """package firewall
config rule
option name 'Allow-MLD'
option src 'wan'
option proto 'icmp'
option src_ip 'fe80::/10'
list icmp_type '130/0'
list icmp_type '131/0'
list icmp_type '132/0'
list icmp_type '143/0'
option family 'ipv6'
option target 'ACCEPT'\n""",
"output": """---
firewall:
rule:
- name: Allow-MLD
src: wan
proto: icmp
src_ip: fe80::/10
icmp_type:
- 130/0
- 131/0
- 132/0
- 143/0
family: ipv6
target: ACCEPT\n"""
}
test_firewall_3_with_comment = {
"input": """package firewall
config rule
option name 'Allow-MLD' #some Comment
option target 'ACCEPT'\n""",
"output": """---
firewall:
rule:
# some Comment
- name: Allow-MLD
target: ACCEPT\n"""
}
test_firewall_4_network_named = {
"input": """package network
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'lan'
option ifname 'eth1.1'
option type 'bridge'
option proto 'static'
option ipaddr '192.168.15.1'
option netmask '255.255.255.0'
option ip6assign '32'\n""",
"output": """---
network:
interface:
- interface: loopback
ifname: lo
proto: static
ipaddr: 127.0.0.1
netmask: 255.0.0.0
- interface: lan
ifname: eth1.1
type: bridge
proto: static
ipaddr: 192.168.15.1
netmask: 255.255.255.0
ip6assign: '32'\n"""
}
test_beardropper = {
"input":
"""package bearDropper
config bearDropper
option defaultMode 'entire'
list firewallHookChain 'input_wan_rule:1'
list firewallHookChain 'forwarding_wan_rule:1'
list firewallHookChain 'input_lan_rule:1'
list firewallHookChain 'forwarding_lan_rule:1'
option firewallTarget 'DROP'
list logRegex '/has invalid shell, rejected$/d'
option attemptCount '5'
option banLength '100w'""",
"output":
"""---
bearDropper:
bearDropper:
- defaultMode: entire
firewallHookChain:
- input_wan_rule:1
- forwarding_wan_rule:1
- input_lan_rule:1
- forwarding_lan_rule:1
firewallTarget: DROP
logRegex:
- /has invalid shell, rejected$/d
attemptCount: '5'
banLength: 100w\n"""
}
test_interface_switchport_access_vlan = {
"input": """interface GigabitEthernet1/0/1
switchport access vlan 4""",
"output": """---
interfaces:
- name: GigabitEthernet1/0/1
switchport:
access_vlan: '4'\n"""
}
test_interface_switchport_mode = {
"input": """interface GigabitEthernet1/0/1
switchport mode access""",
"output": """---
interfaces:
- name: GigabitEthernet1/0/1
switchport:
mode: access\n"""
}
test_interface_switchport_port_security = {
"input": """interface GigabitEthernet1/0/1
switchport port-security""",
"output": """---
interfaces:
- name: GigabitEthernet1/0/1
switchport:
port_security: true\n"""
}
test_interface_power_inline_police = {
"input": """interface GigabitEthernet1/0/1
power inline police""",
"output": """---
interfaces:
- name: GigabitEthernet1/0/1
power_inline_police: true\n"""
}
test_interface_spanning_tree = {
"input": """interface GigabitEthernet1/0/1
spanning-tree portfast
spanning-tree guard root""",
"output": """---
interfaces:
- name: GigabitEthernet1/0/1
spanning_tree:
guard_root: true
portfast: true\n"""
}