forked from unioslo/mreg-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsuite
301 lines (279 loc) · 10.3 KB
/
testsuite
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
##### Tests: Zone
# - zone creation
# - zone info
# - zone list
# - set/update ns, soa, ttl
zone create example.org [email protected] ns1.example.org # should require force because ns1 is unknown
zone create example.org [email protected] ns1.example.org -force
zone info example.org
zone list -forward
zone set_ns example.org ns2.example.org # requires force because ns2 is unknown
zone set_ns example.org ns2.example.org -force
zone set_soa example.org -email [email protected] -serialno 12345 -refresh 360 -retry 1800 -expire 2400 -soa-ttl 1800
zone set_default_ttl example.org 60 # should fail, must be >= 300
zone set_default_ttl example.org 300
##### Tests: Network
# - list used/unused IPv4 addresses
# - pick next unused address
# - set number of reserved addresses
network create -network 10.0.2.0/28 -desc "TinyNet"
network list_used_addresses 10.0.2.0/28
network list_unused_addresses 10.0.2.0/28
network set_reserved 10.0.2.0/28 8
host add tinyhost -ip 10.0.2.0/28 -contact [email protected]
network list_used_addresses 10.0.2.0/28
network list_unused_addresses 10.0.2.0/28
host remove tinyhost
network remove 10.0.2.0/28 -force
# ipv6
network create -network 2001:db8::/64 -desc "Lorem ipsum dolor sit amet"
network list_used_addresses 2001:db8::/64
network list_unused_addresses 2001:db8::/64
network set_reserved 2001:db8::/64 50
host add tinyhost -ip 2001:db8::/64 -contact [email protected]
host remove tinyhost
network remove 2001:db8::/64 -f
##### Tests: Network
# - frozen network
# - excluded ip ranges
# - network info
network create -network 10.0.1.0/24 -desc "Frozzzen" # frozen network
network set_frozen 10.0.1.0/24
host add somehost -ip 10.0.1.0/24 -contact [email protected] # should require force, because net's frozen
network add_excluded_range 10.0.1.0/24 10.0.1.20 10.0.1.30
host add somehost -ip 10.0.1.20 -contact [email protected] -force # should fail because ip is in excluded range
host add somehost -ip 10.0.1.0/24 -contact [email protected] -force
network list_used_addresses 10.0.1.0/24
network set_description 10.0.1.0/24 "Frozen but has one host"
network info 10.0.1.0/24
host remove somehost
network unset_frozen 10.0.1.0/24
host add otherhost -ip 10.0.1.20 -contact [email protected] # fails because reserved range
network remove_excluded_range 10.0.1.0/24 10.0.1.20 10.0.1.30
host add otherhost -ip 10.0.1.20 -contact [email protected] # should not need force now that net is unfrozen
host remove otherhost
network remove 10.0.1.0/24 -f
# IPv6
network create -network 2001:db8::/64 -desc "Lorem ipsum dolor sit amet"
network set_frozen 2001:db8::/64
host add somehost -ip 2001:db8::/64 -contact [email protected] # should require force
network add_excluded_range 2001:db8::/64 2001:db8::20 2001:db8::30
host add somehost -ip 2001:db8::20 -contact [email protected] -force # should fail
host add somehost -ip 2001:db8::/64 -contact [email protected] -force
network set_description 2001:db8::/64 "Frozen but has one host"
network info 2001:db8::/64
host remove somehost
network remove 2001:db8::/64 -f
# TODO: # - setting network category, location, vlan
#network set_category 10.0.1.0/24 Comedy_Drama
#network set_location 10.0.1.0/24 Oslo_Norway
#network set_vlan 10.0.1.0/24 1234
##### Tests: Hostgroups
# - create, delete groups
# - add/remove hosts to/from groups
# - add groups to other groups
# - add/remove owners
group create mygroup "This describes the group"
host add testhost1
host add testhost2
group host_add mygroup testhost1
group host_add mygroup testhost2
group owner_add mygroup myself
group host_remove mygroup testhost2
group info mygroup
group create yourgroup "meh"
group group_add mygroup yourgroup
group info mygroup
group group_remove mygroup yourgroup
group owner_add mygroup anotherowner
group owner_remove mygroup myself
group delete mygroup # fails because the group contains testhost1, must force
group delete mygroup -force
group delete yourgroup
host remove testhost1
host remove testhost2
##### Tests: Delegations
# - create, delete, list
# - set delegation comment
zone delegation_create example.org wut.example.org ns2.example.org -force
zone delegation_comment_set example.org wut.example.org "This is a comment"
zone delegation_list example.org
host add testhost.wut.example.org # should fail: host is in delegation, should require force
host add testhost.wut.example.org -force # should work
host remove testhost.wut.example.org
zone delegation_comment_remove example.org wut.example.org
zone delegation_delete example.org wut.example.org
##### Tests: Policy
# - create/delete atoms
# - create/delete roles
# - add/remove hosts from policies
# - rename
# - set description
policy atom_create apple "Here's the description"
policy atom_create -created 2018-07-07 orange "Round and orange"
policy list_atoms *
policy role_create fruit "5 a day"
policy list_roles *
policy add_atom fruit apple
policy add_atom fruit orange
policy info orange
policy info fruit
policy list_members fruit
policy atom_delete apple # Should fail because 'apple' is used in role 'fruit'
policy remove_atom fruit apple
policy atom_delete apple
policy set_description orange "Juicy"
policy rename orange tangerine
host add foo
policy host_add tangerine foo # should fail, tangerine is an atom, not a role
policy host_add fruit foo
policy list_hosts fruit
policy host_list foo
policy host_remove fruit foo
policy remove_atom fruit banana # should fail
policy remove_atom fruit tangerine
policy role_delete vegetables # fails, that role doesn't exist
policy role_delete fruit
policy atom_delete tangerine
host remove foo
##### Tests: Network permissions
# - add/remove permissions for network ranges
permission network_add 10.0.0.0/24 somegroup "[abc]+.uio.no"
permission network_list
permission network_remove 10.0.0.0/24 othergroup "[abc]*.uio.no" # fails, no match
permission network_remove 10.0.0.0/24 somegroup "[abc]+.uio.no"
##### Tests: DHCP
# - associate / disassociate ip with mac address
network create -network 10.0.0.0/24 -desc foo
host add foo
host a_add foo 10.0.0.5
dhcp assoc 1.2.3.4 aa:bb:cc:dd:ee:ff # doesn't work, because ip addr doesn't exist
dhcp assoc 10.0.0.5 aa:bb:cc:dd:ee:ff
dhcp disassoc 1.2.3.4 # ip addr dosnt exst
dhcp disassoc 10.0.0.5
dhcp assoc meh 11:22:33:44:55:66 # host not found
dhcp assoc foo aa:bb:cc:dd:ee:ff
dhcp disassoc foo
dhcp disassoc meh # host not found
host remove foo
network remove 10.0.0.0/24 -f
##### Tests: host
# - all the host sub-commands
network create -network 10.0.0.0/24 -desc "lorem ipsum"
network create -network 2001:db8::/64 -desc "dolor sit amet"
host add foo -ip 10.0.0.10 -contact [email protected] -comment "meh" -macaddress 11:22:33:aa:bb:cc
host info foo
host find -name *oo*
host find -contact hi*
host find -comment meh
host find -name f* -contact h* -comment m*
host rename foo bar
host set_comment bar 'This is the comment'
host set_contact bar "I'm the contact" # fails because invalid email address
host set_contact bar [email protected]
# IPv4 management
host a_add bar 10.0.0.12 # must force
host a_add bar 10.0.0.12 -f
host a_add bar 10.0.0.13 -macaddress 11:22:33:44:55:66 -force
host a_change -old 10.0.0.12 -new 10.0.0.14 bar
host a_change -old 10.0.0.13 -new 10.0.0.15 bar # has mac addr, should keep it assigned to the new ip
host a_remove bar 10.0.0.13
host add baz
host a_move -ip 10.0.0.10 -fromhost bar -tohost baz
host a_show baz
# IPv6 management
host aaaa_add bar 2001:db8::/64 # must force
host aaaa_add bar 2001:db8::11 -f
host aaaa_add bar 2001:db8::12 -macaddress 11:22:33:44:55:67 -f
host aaaa_show bar
host aaaa_change -old 2001:db8::11 -new 2001:db8::13 bar
host aaaa_change -old 2001:db8::12 -new 2001:db8::14 bar # has mac addr, should keep it assigned to the new ip
host aaaa_remove bar 2001:db8::13
host aaaa_move -ip 2001:db8::14 -fromhost bar -tohost baz
host a_show baz
# CNAME
host cname_add bar fubar
host cname_show bar
host cname_remove bar fubar
# HINFO
host hinfo_add baz x86 Win
host hinfo_show baz
host hinfo_remove baz
# LOC
host loc_add baz "52 22 23.000 N 4 53 32.000 E -2.00m 0.00m 10000m 10m"
host loc_show baz
host loc_remove baz
# MX
host mx_add baz 10 mail.example.org
host mx_show baz
host mx_remove baz 10 mail.example.org
# NAPTR
host naptr_add -name baz -preference 16384 -order 3 -flag u -service "SIP" -regex "[abc]+" -replacement "wonk"
host naptr_show baz
host naptr_remove -name baz -preference 16384 -order 3 -flag u -service "sip" -regex "[abc]+" -replacement "wonk"
# PTR
host ptr_add 10.0.0.20 baz.example.org
host ptr_show 10.0.0.20
host add clover
host ptr_change -ip 10.0.0.20 -old baz -new clover
host ptr_remove 10.0.0.20 clover
network
# SRV
host srv_add -name "whatever" -priority 1 -weight 1 -port 80 -host baz # doesn't work
host srv_add -name "_sip._tcp.example.org" -priority 10 -weight 5 -port 3456 -host baz.example.org
host srv_show "_sip._tcp.example.org"
host srv_remove -name "_sip._tcp.example.org" -priority 10 -weight 5 -port 3456 -host baz.example.org
# SSHFP
host sshfp_add bar 1 1 12345678abcde
host sshfp_show bar
host sshfp_remove -fingerprint 394875985 bar # not found
host sshfp_remove bar
# ttl
host ttl_set bar 3600
host ttl_show bar
host ttl_remove bar
# TXT
host txt_add bar "Lorem ipsum dolor sit amet"
host txt_show bar
host txt_remove bar "Whatever" # no match
host txt_remove bar "Lorem ipsum dolor sit amet"
# wildcard
host add *.example.org -force
host remove *.example.org
# cleanup
host remove bar -f
host remove baz -f
host remove clover
network remove 10.0.0.0/24 -f
network remove 2001:db8::/64 -f
##### Tests: Label admin
# - create, delete, list
# - rename, change description
# - add/remove labels to roles
# - add/remove labels to permissions
label add postit 'This is a label'
label list
label info postit
label rename postit mylabel -desc 'This is the new description'
label remove mylabel
# Roles
label add postit 'A label again'
policy role_create myrole 'This is the description'
policy label_add postit myrole
policy list_roles *
policy info myrole
label info postit
policy label_remove postit myrole
policy role_delete myrole
# Permissions
permission network_add 192.168.0.0/16 mygroup .*
permission label_add 192.168.0.0/16 mygroup .* postit
permission network_list
label info postit
permission label_remove 192.168.0.0/16 mygroup .* postit
permission network_list
permission network_remove 192.168.0.0/16 mygroup .*
label remove postit
##### Tests: Zone
# - Zone removal
zone delete example.org