forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.bats
388 lines (333 loc) · 9.09 KB
/
checks.bats
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!/usr/bin/env bats
if [ "${PATH#*/usr/local/hestia/bin*}" = "$PATH" ]; then
. /etc/profile.d/hestia.sh
fi
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
load 'test_helper/bats-file/load'
function random() {
head /dev/urandom | tr -dc 0-9 | head -c$1
}
function setup() {
# echo "# Setup_file" > &3
if [ $BATS_TEST_NUMBER = 1 ]; then
echo 'user=test-5285' > /tmp/hestia-test-env.sh
echo 'user2=test-5286' >> /tmp/hestia-test-env.sh
echo 'userbk=testbk-5285' >> /tmp/hestia-test-env.sh
echo 'userpass1=test-5285' >> /tmp/hestia-test-env.sh
echo 'userpass2=t3st-p4ssw0rd' >> /tmp/hestia-test-env.sh
echo 'HESTIA=/usr/local/hestia' >> /tmp/hestia-test-env.sh
echo 'domain=test-5285.hestiacp.com' >> /tmp/hestia-test-env.sh
echo 'domainuk=test-5285.hestiacp.com.uk' >> /tmp/hestia-test-env.sh
echo 'rootdomain=testhestiacp.com' >> /tmp/hestia-test-env.sh
echo 'subdomain=cdn.testhestiacp.com' >> /tmp/hestia-test-env.sh
echo 'database=test-5285_database' >> /tmp/hestia-test-env.sh
echo 'dbuser=test-5285_dbuser' >> /tmp/hestia-test-env.sh
fi
source /tmp/hestia-test-env.sh
source $HESTIA/func/main.sh
source $HESTIA/conf/hestia.conf
source $HESTIA/func/ip.sh
}
@test "is_hash_format_valid accesskey:secret valid" {
run is_hash_format_valid 'bxDaKPyAfLPRgSkoqlkI:Pc8czGPRECp3GxTNMr3LF6zWc8cjfPrNHy_-=A' "hash"
assert_success
}
@test "is_access_key_id_format_valid valid" {
run is_access_key_id_format_valid 'M0ocDoIKbsoXSqtk1mgc' "key"
assert_success
}
@test "is_access_key_id_format_valid short" {
run is_access_key_id_format_valid 'M0ocDoIKbsoXSqtk1mg' "key"
assert_failure $E_INVALID
}
@test "is_access_key_id_format_valid long" {
run is_access_key_id_format_valid 'M0ocDoIKbsoXSqtk1mgca' "key"
assert_failure $E_INVALID
}
@test "is_access_key_id_format_valid non alpha" {
run is_access_key_id_format_valid 'M0ocDoIKbsoX$qtk1mgc' "key"
assert_failure $E_INVALID
}
@test "is_access_key_id_format_valid LHF" {
run is_access_key_id_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_user_format_valid valid" {
run is_user_format_valid 'hxh54SKbALne4s69VsqJRMbMd8Br' "key"
assert_success
}
@test "is_user_format_valid short" {
run is_user_format_valid 'hxh54SKbALne4s69VsqJR' "key"
assert_success
}
@test "is_user_format_valid long" {
run is_user_format_valid 'hxh54SKbALne4s69VsqJRMbMd8Braaa' "key"
assert_failure $E_INVALID
}
@test "is_user_format_valid dash" {
run is_user_format_valid 'hxh54SKbALne4-s6-VsqJRMbMd8Br' "key"
assert_success
}
@test "is_user_format_valid dash repeat" {
run is_user_format_valid 'hxh54SKbALne4s6--VsqJRMbMd8Br' "key"
assert_success
}
@test "is_user_format_valid dash start" {
run is_user_format_valid '-hxh54SKbALne4s6VsqJRMbMd8Br' "key"
assert_failure $E_INVALID
}
@test "is_user_format_valid dash end" {
run is_user_format_valid 'hxh54SKbALne4s6VsqJRMbMd8Br-' "key"
assert_failure $E_INVALID
}
@test "is_user_format_valid LHF" {
run is_user_format_valid 'M0ocDoIK
soXSqtk1mgc' "key"
assert_failure $E_INVALID
}
@test "is_fw_action_format_valid ACCEPT" {
run is_fw_action_format_valid 'ACCEPT' "key"
assert_success
}
@test "is_fw_action_format_valid DROP" {
run is_fw_action_format_valid 'DROP' "key"
assert_success
}
@test "is_fw_action_format_valid TEST" {
run is_fw_action_format_valid 'TEST' "key"
assert_failure $E_INVALID
}
@test "is_fw_action_format_valid LHF" {
run is_fw_protocol_format_valid 'M0ocDoIK
soXSqtk1mgc' "key"
assert_failure $E_INVALID
}
@test "is_fw_protocol_format_valid ICMP" {
run is_fw_protocol_format_valid 'ICMP' "key"
assert_success
}
@test "is_fw_protocol_format_valid UDP" {
run is_fw_protocol_format_valid 'UDP' "key"
assert_success
}
@test "is_fw_protocol_format_valid TCP" {
run is_fw_protocol_format_valid 'TCP' "key"
assert_success
}
@test "is_fw_protocol_format_valid TEST" {
run is_fw_protocol_format_valid 'TEST' "key"
assert_failure $E_INVALID
}
@test "is_domain_format_valid success" {
run is_domain_format_valid 'hestiacp.com' "key"
assert_success
}
@test "is_domain_format_valid www" {
run is_domain_format_valid 'www' "key"
assert_failure $E_INVALID
}
@test "is_domain_format_valid number" {
run is_domain_format_valid '12345' "key"
assert_failure $E_INVALID
}
@test "is_domain_format_valid .." {
run is_domain_format_valid '..' "key"
assert_failure $E_INVALID
}
@test "is_domain_format_valid hestiacp.com." {
run is_domain_format_valid 'mx.hestiacp.com.' "key"
assert_success
}
@test "is_domain_format_valid LF." {
run is_domain_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_dns_record_format_valid" {
rtype='MX'
priority=1;
run is_dns_record_format_valid 'mx.hestiacp.com.'
assert_success
}
@test "is_dns_record_format_valid test" {
rtype='MX'
priority=1;
run is_dns_record_format_valid 'c
1eshutdown
r'
assert_failure $E_INVALID
}
@test "is_alias_format_valid success" {
run is_alias_format_valid 'hestiacp.com' "key"
assert_success
}
@test "is_alias_format_valid success www.domain.com" {
run is_alias_format_valid 'www.hestiacp.com' "key"
assert_success
}
@test "is_alias_format_valid success hestiacp.com,www.hestiacp.com" {
run is_alias_format_valid 'hestiacp.com,www.hestiacp.com' "key"
assert_success
}
@test "is_alias_format_valid success *.hestiacp.com" {
run is_alias_format_valid '*.hestiacp.com' "key"
assert_success
}
@test "is_alias_format_valid success www.hestiacp.com,*.hestiacp.com" {
run is_alias_format_valid 'www.hestiacp.com,*.hestiacp.com' "key"
assert_success
}
@test "is_extention_format_valid test" {
run is_extention_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_string_format_valid test" {
run is_string_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_database_format_valid test" {
run is_database_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_date_format_valid test" {
run is_date_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_dbuser_format_valid test" {
run is_dbuser_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_dns_type_format_valid test" {
run is_dns_type_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_email_format_valid test" {
run is_email_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_fw_port_format_valid test" {
run is_fw_port_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_int_format_valid test" {
run is_int_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_interface_format_valid test" {
run is_interface_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_ip_status_format_valid test" {
run is_ip_status_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_cron_format_valid test" {
run is_cron_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_name_format_valid test" {
run is_name_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_role_valid test" {
run is_role_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_object_format_valid test" {
run is_object_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_common_format_valid test" {
run is_common_format_valid 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "format_no_quotes test2" {
run format_no_quotes 'test bericht' "key"
assert_success
}
@test "format_no_quotes .." {
run format_no_quotes '..' "key"
assert_success
}
@test "format_no_quotes text." {
run format_no_quotes 'text.' "key"
assert_success
}
@test "is_common_format_valid text" {
run is_common_format_valid 'text' "key"
assert_success
}
@test "format_no_quotes test" {
run format_no_quotes 'c
1eshutdown
r' "key"
assert_failure $E_INVALID
}
@test "is_type_valid" {
run is_type_valid 'c
1eshutdown
r' "test,key"
assert_failure $E_INVALID
}
@test "is_command_valid_format v-list-users" {
run is_command_valid_format 'v-list-users'
assert_success
}
@test "is_command_valid_format v-list--users (Fail)" {
run is_command_valid_format 'v-list--users'
assert_failure $E_INVALID
}
@test "is_command_valid_format h-list-users (Fail)" {
run is_command_valid_format 'h-list-users'
assert_failure $E_INVALID
}
@test "is_command_valid_format list-users (Fail)" {
run is_command_valid_format 'list-users'
assert_failure $E_INVALID
}
@test "is_command_valid_format vlist-users (Fail)" {
run is_command_valid_format 'vlist-users'
assert_failure $E_INVALID
}
@test "is_command_valid_format LF (Fail)" {
run is_command_valid_format 'v-
1eshutdown
r' "key"
assert_failure $E_INVALID
}