checks.bats 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. #!/usr/bin/env bats
  2. if [ "${PATH#*/usr/local/hestia/bin*}" = "$PATH" ]; then
  3. . /etc/profile.d/hestia.sh
  4. fi
  5. load 'test_helper/bats-support/load'
  6. load 'test_helper/bats-assert/load'
  7. load 'test_helper/bats-file/load'
  8. function random() {
  9. head /dev/urandom | tr -dc 0-9 | head -c$1
  10. }
  11. function setup() {
  12. # echo "# Setup_file" > &3
  13. if [ $BATS_TEST_NUMBER = 1 ]; then
  14. echo 'user=test-5285' > /tmp/hestia-test-env.sh
  15. echo 'user2=test-5286' >> /tmp/hestia-test-env.sh
  16. echo 'userbk=testbk-5285' >> /tmp/hestia-test-env.sh
  17. echo 'userpass1=test-5285' >> /tmp/hestia-test-env.sh
  18. echo 'userpass2=t3st-p4ssw0rd' >> /tmp/hestia-test-env.sh
  19. echo 'HESTIA=/usr/local/hestia' >> /tmp/hestia-test-env.sh
  20. echo 'domain=test-5285.hestiacp.com' >> /tmp/hestia-test-env.sh
  21. echo 'domainuk=test-5285.hestiacp.com.uk' >> /tmp/hestia-test-env.sh
  22. echo 'rootdomain=testhestiacp.com' >> /tmp/hestia-test-env.sh
  23. echo 'subdomain=cdn.testhestiacp.com' >> /tmp/hestia-test-env.sh
  24. echo 'database=test-5285_database' >> /tmp/hestia-test-env.sh
  25. echo 'dbuser=test-5285_dbuser' >> /tmp/hestia-test-env.sh
  26. fi
  27. source /tmp/hestia-test-env.sh
  28. source $HESTIA/func/main.sh
  29. source $HESTIA/conf/hestia.conf
  30. source $HESTIA/func/ip.sh
  31. }
  32. @test "is_hash_format_valid accesskey:secret valid" {
  33. run is_hash_format_valid 'bxDaKPyAfLPRgSkoqlkI:Pc8czGPRECp3GxTNMr3LF6zWc8cjfPrNHy_-=A' "hash"
  34. assert_success
  35. }
  36. @test "is_access_key_id_format_valid valid" {
  37. run is_access_key_id_format_valid 'M0ocDoIKbsoXSqtk1mgc' "key"
  38. assert_success
  39. }
  40. @test "is_access_key_id_format_valid short" {
  41. run is_access_key_id_format_valid 'M0ocDoIKbsoXSqtk1mg' "key"
  42. assert_failure $E_INVALID
  43. }
  44. @test "is_access_key_id_format_valid long" {
  45. run is_access_key_id_format_valid 'M0ocDoIKbsoXSqtk1mgca' "key"
  46. assert_failure $E_INVALID
  47. }
  48. @test "is_access_key_id_format_valid non alpha" {
  49. run is_access_key_id_format_valid 'M0ocDoIKbsoX$qtk1mgc' "key"
  50. assert_failure $E_INVALID
  51. }
  52. @test "is_access_key_id_format_valid LHF" {
  53. run is_access_key_id_format_valid 'c
  54. 1eshutdown
  55. r' "key"
  56. assert_failure $E_INVALID
  57. }
  58. @test "is_user_format_valid valid" {
  59. run is_user_format_valid 'hxh54SKbALne4s69VsqJRMbMd8Br' "key"
  60. assert_success
  61. }
  62. @test "is_user_format_valid short" {
  63. run is_user_format_valid 'hxh54SKbALne4s69VsqJR' "key"
  64. assert_success
  65. }
  66. @test "is_user_format_valid long" {
  67. run is_user_format_valid 'hxh54SKbALne4s69VsqJRMbMd8Braaa' "key"
  68. assert_failure $E_INVALID
  69. }
  70. @test "is_user_format_valid dash" {
  71. run is_user_format_valid 'hxh54SKbALne4-s6-VsqJRMbMd8Br' "key"
  72. assert_success
  73. }
  74. @test "is_user_format_valid dash repeat" {
  75. run is_user_format_valid 'hxh54SKbALne4s6--VsqJRMbMd8Br' "key"
  76. assert_success
  77. }
  78. @test "is_user_format_valid dash start" {
  79. run is_user_format_valid '-hxh54SKbALne4s6VsqJRMbMd8Br' "key"
  80. assert_failure $E_INVALID
  81. }
  82. @test "is_user_format_valid dash end" {
  83. run is_user_format_valid 'hxh54SKbALne4s6VsqJRMbMd8Br-' "key"
  84. assert_failure $E_INVALID
  85. }
  86. @test "is_user_format_valid LHF" {
  87. run is_user_format_valid 'M0ocDoIK
  88. soXSqtk1mgc' "key"
  89. assert_failure $E_INVALID
  90. }
  91. @test "is_fw_action_format_valid ACCEPT" {
  92. run is_fw_action_format_valid 'ACCEPT' "key"
  93. assert_success
  94. }
  95. @test "is_fw_action_format_valid DROP" {
  96. run is_fw_action_format_valid 'DROP' "key"
  97. assert_success
  98. }
  99. @test "is_fw_action_format_valid TEST" {
  100. run is_fw_action_format_valid 'TEST' "key"
  101. assert_failure $E_INVALID
  102. }
  103. @test "is_fw_action_format_valid LHF" {
  104. run is_fw_protocol_format_valid 'M0ocDoIK
  105. soXSqtk1mgc' "key"
  106. assert_failure $E_INVALID
  107. }
  108. @test "is_fw_protocol_format_valid ICMP" {
  109. run is_fw_protocol_format_valid 'ICMP' "key"
  110. assert_success
  111. }
  112. @test "is_fw_protocol_format_valid UDP" {
  113. run is_fw_protocol_format_valid 'UDP' "key"
  114. assert_success
  115. }
  116. @test "is_fw_protocol_format_valid TCP" {
  117. run is_fw_protocol_format_valid 'TCP' "key"
  118. assert_success
  119. }
  120. @test "is_fw_protocol_format_valid TEST" {
  121. run is_fw_protocol_format_valid 'TEST' "key"
  122. assert_failure $E_INVALID
  123. }
  124. @test "is_domain_format_valid success" {
  125. run is_domain_format_valid 'hestiacp.com' "key"
  126. assert_success
  127. }
  128. @test "is_domain_format_valid www" {
  129. run is_domain_format_valid 'www' "key"
  130. assert_failure $E_INVALID
  131. }
  132. @test "is_domain_format_valid number" {
  133. run is_domain_format_valid '12345' "key"
  134. assert_failure $E_INVALID
  135. }
  136. @test "is_domain_format_valid .." {
  137. run is_domain_format_valid '..' "key"
  138. assert_failure $E_INVALID
  139. }
  140. @test "is_domain_format_valid hestiacp.com." {
  141. run is_domain_format_valid 'mx.hestiacp.com.' "key"
  142. assert_success
  143. }
  144. @test "is_domain_format_valid LF." {
  145. run is_domain_format_valid 'c
  146. 1eshutdown
  147. r' "key"
  148. assert_failure $E_INVALID
  149. }
  150. @test "is_dns_record_format_valid" {
  151. rtype='MX'
  152. priority=1;
  153. run is_dns_record_format_valid 'mx.hestiacp.com.'
  154. assert_success
  155. }
  156. @test "is_dns_record_format_valid MX missing priority" {
  157. rtype='MX'
  158. priority=''
  159. run is_dns_record_format_valid 'mx.hestiacp.com.'
  160. assert_failure $E_INVALID
  161. }
  162. @test "is_dns_record_format_valid SRV 4-field" {
  163. rtype='SRV'
  164. priority=''
  165. run is_dns_record_format_valid '10 20 5060 srv.hestiacp.com.'
  166. assert_success
  167. }
  168. @test "is_dns_record_format_valid SRV invalid priority" {
  169. rtype='SRV'
  170. priority=''
  171. run is_dns_record_format_valid 'abc 20 5060 srv.hestiacp.com.'
  172. assert_failure $E_INVALID
  173. }
  174. @test "is_dns_record_format_valid SRV null target" {
  175. rtype='SRV'
  176. priority=''
  177. run is_dns_record_format_valid '0 5 0 .'
  178. assert_success
  179. }
  180. @test "is_dns_record_format_valid TXT newline" {
  181. rtype='TXT'
  182. priority=''
  183. run is_dns_record_format_valid 'foo
  184. bar'
  185. assert_failure $E_INVALID
  186. }
  187. @test "is_dns_record_format_valid TXT single quote" {
  188. rtype='TXT'
  189. priority=''
  190. run is_dns_record_format_valid "foo'bar"
  191. assert_success
  192. }
  193. @test "is_dns_record_format_valid TXT empty" {
  194. rtype='TXT'
  195. priority=''
  196. run is_dns_record_format_valid ''
  197. assert_failure $E_INVALID
  198. }
  199. @test "is_dns_record_format_valid TXT non-ascii" {
  200. rtype='TXT'
  201. priority=''
  202. run is_dns_record_format_valid 'café'
  203. assert_failure $E_INVALID
  204. }
  205. @test "is_dns_record_format_valid DNSKEY valid" {
  206. rtype='DNSKEY'
  207. priority=''
  208. run is_dns_record_format_valid '257 3 13 AwEAAc1='
  209. assert_success
  210. }
  211. @test "is_dns_record_format_valid DNSKEY invalid protocol" {
  212. rtype='DNSKEY'
  213. priority=''
  214. run is_dns_record_format_valid '257 1 13 AwEAAc1'
  215. assert_failure $E_INVALID
  216. }
  217. @test "is_dns_record_format_valid DS invalid hex" {
  218. rtype='DS'
  219. priority=''
  220. run is_dns_record_format_valid '12345 8 1 ZZZZ'
  221. assert_failure $E_INVALID
  222. }
  223. @test "is_dns_record_format_valid TLSA valid" {
  224. rtype='TLSA'
  225. priority=''
  226. run is_dns_record_format_valid '3 1 1 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
  227. assert_success
  228. }
  229. @test "is_dns_record_format_valid CAA missing value" {
  230. rtype='CAA'
  231. priority=''
  232. run is_dns_record_format_valid '0 issue'
  233. assert_failure $E_INVALID
  234. }
  235. @test "is_dns_record_format_valid IPSECKEY valid" {
  236. rtype='IPSECKEY'
  237. priority=''
  238. run is_dns_record_format_valid '10 1 2 192.0.2.1 AQIDBA=='
  239. assert_success
  240. }
  241. @test "is_dns_record_format_valid IPSECKEY invalid gateway" {
  242. rtype='IPSECKEY'
  243. priority=''
  244. run is_dns_record_format_valid '10 1 2 not-an-ip AQIDBA=='
  245. assert_failure $E_INVALID
  246. }
  247. @test "is_dns_record_format_valid IPSECKEY algorithm0 with key fails" {
  248. rtype='IPSECKEY'
  249. priority=''
  250. run is_dns_record_format_valid '10 1 0 192.0.2.1 AQIDBA=='
  251. assert_failure $E_INVALID
  252. }
  253. @test "is_dns_record_format_valid TLSA type1 wrong length" {
  254. rtype='TLSA'
  255. priority=''
  256. run is_dns_record_format_valid '3 1 1 0123'
  257. assert_failure $E_INVALID
  258. }
  259. @test "is_dns_record_format_valid TLSA matching_type plus sign wrong length" {
  260. rtype='TLSA'
  261. priority=''
  262. run is_dns_record_format_valid '3 1 +1 0123'
  263. assert_failure $E_INVALID
  264. }
  265. @test "is_dns_record_format_valid DS type1 wrong length" {
  266. rtype='DS'
  267. priority=''
  268. run is_dns_record_format_valid '12345 8 1 012345'
  269. assert_failure $E_INVALID
  270. }
  271. @test "is_dns_record_format_valid DS type2 correct length" {
  272. rtype='DS'
  273. priority=''
  274. run is_dns_record_format_valid '12345 8 2 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
  275. assert_success
  276. }
  277. @test "is_dns_record_format_valid KEY algorithm0 empty key" {
  278. rtype='KEY'
  279. priority=''
  280. run is_dns_record_format_valid '256 3 0'
  281. assert_success
  282. }
  283. @test "is_dns_record_format_valid KEY algorithm0 with key fails" {
  284. rtype='KEY'
  285. priority=''
  286. run is_dns_record_format_valid '256 3 0 AQID'
  287. assert_failure $E_INVALID
  288. }
  289. @test "is_dns_record_format_valid KEY algorithm1 missing key fails" {
  290. rtype='KEY'
  291. priority=''
  292. run is_dns_record_format_valid '256 3 1'
  293. assert_failure $E_INVALID
  294. }
  295. @test "is_dns_record_format_valid test" {
  296. rtype='MX'
  297. priority=1;
  298. run is_dns_record_format_valid 'c
  299. 1eshutdown
  300. r'
  301. assert_failure $E_INVALID
  302. }
  303. @test "is_alias_format_valid success" {
  304. run is_alias_format_valid 'hestiacp.com' "key"
  305. assert_success
  306. }
  307. @test "is_alias_format_valid success www.domain.com" {
  308. run is_alias_format_valid 'www.hestiacp.com' "key"
  309. assert_success
  310. }
  311. @test "is_alias_format_valid success hestiacp.com,www.hestiacp.com" {
  312. run is_alias_format_valid 'hestiacp.com,www.hestiacp.com' "key"
  313. assert_success
  314. }
  315. @test "is_alias_format_valid success *.hestiacp.com" {
  316. run is_alias_format_valid '*.hestiacp.com' "key"
  317. assert_success
  318. }
  319. @test "is_alias_format_valid success www.hestiacp.com,*.hestiacp.com" {
  320. run is_alias_format_valid 'www.hestiacp.com,*.hestiacp.com' "key"
  321. assert_success
  322. }
  323. @test "is_extention_format_valid test" {
  324. run is_extention_format_valid 'c
  325. 1eshutdown
  326. r' "key"
  327. assert_failure $E_INVALID
  328. }
  329. @test "is_string_format_valid test" {
  330. run is_string_format_valid 'c
  331. 1eshutdown
  332. r' "key"
  333. assert_failure $E_INVALID
  334. }
  335. @test "is_database_format_valid test" {
  336. run is_database_format_valid 'c
  337. 1eshutdown
  338. r' "key"
  339. assert_failure $E_INVALID
  340. }
  341. @test "is_date_format_valid test" {
  342. run is_date_format_valid 'c
  343. 1eshutdown
  344. r' "key"
  345. assert_failure $E_INVALID
  346. }
  347. @test "is_dbuser_format_valid test" {
  348. run is_dbuser_format_valid 'c
  349. 1eshutdown
  350. r' "key"
  351. assert_failure $E_INVALID
  352. }
  353. @test "is_dns_type_format_valid test" {
  354. run is_dns_type_format_valid 'c
  355. 1eshutdown
  356. r' "key"
  357. assert_failure $E_INVALID
  358. }
  359. @test "is_email_format_valid test" {
  360. run is_email_format_valid 'c
  361. 1eshutdown
  362. r' "key"
  363. assert_failure $E_INVALID
  364. }
  365. @test "is_fw_port_format_valid test" {
  366. run is_fw_port_format_valid 'c
  367. 1eshutdown
  368. r' "key"
  369. assert_failure $E_INVALID
  370. }
  371. @test "is_int_format_valid test" {
  372. run is_int_format_valid 'c
  373. 1eshutdown
  374. r' "key"
  375. assert_failure $E_INVALID
  376. }
  377. @test "is_interface_format_valid test" {
  378. run is_interface_format_valid 'c
  379. 1eshutdown
  380. r' "key"
  381. assert_failure $E_INVALID
  382. }
  383. @test "is_ip_status_format_valid test" {
  384. run is_ip_status_format_valid 'c
  385. 1eshutdown
  386. r' "key"
  387. assert_failure $E_INVALID
  388. }
  389. @test "is_cron_format_valid test" {
  390. run is_cron_format_valid 'c
  391. 1eshutdown
  392. r' "key"
  393. assert_failure $E_INVALID
  394. }
  395. @test "is_name_format_valid test" {
  396. run is_name_format_valid 'c
  397. 1eshutdown
  398. r' "key"
  399. assert_failure $E_INVALID
  400. }
  401. @test "is_role_valid test" {
  402. run is_role_valid 'c
  403. 1eshutdown
  404. r' "key"
  405. assert_failure $E_INVALID
  406. }
  407. @test "is_object_format_valid test" {
  408. run is_object_format_valid 'c
  409. 1eshutdown
  410. r' "key"
  411. assert_failure $E_INVALID
  412. }
  413. @test "is_common_format_valid test" {
  414. run is_common_format_valid 'c
  415. 1eshutdown
  416. r' "key"
  417. assert_failure $E_INVALID
  418. }
  419. @test "format_no_quotes test2" {
  420. run format_no_quotes 'test bericht' "key"
  421. assert_success
  422. }
  423. @test "format_no_quotes .." {
  424. run format_no_quotes '..' "key"
  425. assert_success
  426. }
  427. @test "format_no_quotes text." {
  428. run format_no_quotes 'text.' "key"
  429. assert_success
  430. }
  431. @test "is_common_format_valid text" {
  432. run is_common_format_valid 'text' "key"
  433. assert_success
  434. }
  435. @test "format_no_quotes test" {
  436. run format_no_quotes 'c
  437. 1eshutdown
  438. r' "key"
  439. assert_failure $E_INVALID
  440. }
  441. @test "is_type_valid" {
  442. run is_type_valid 'c
  443. 1eshutdown
  444. r' "test,key"
  445. assert_failure $E_INVALID
  446. }
  447. @test "is_command_valid_format v-list-users" {
  448. run is_command_valid_format 'v-list-users'
  449. assert_success
  450. }
  451. @test "is_command_valid_format v-list--users (Fail)" {
  452. run is_command_valid_format 'v-list--users'
  453. assert_failure $E_INVALID
  454. }
  455. @test "is_command_valid_format h-list-users (Fail)" {
  456. run is_command_valid_format 'h-list-users'
  457. assert_failure $E_INVALID
  458. }
  459. @test "is_command_valid_format list-users (Fail)" {
  460. run is_command_valid_format 'list-users'
  461. assert_failure $E_INVALID
  462. }
  463. @test "is_command_valid_format vlist-users (Fail)" {
  464. run is_command_valid_format 'vlist-users'
  465. assert_failure $E_INVALID
  466. }
  467. @test "is_command_valid_format LF (Fail)" {
  468. run is_command_valid_format 'v-
  469. 1eshutdown
  470. r' "key"
  471. assert_failure $E_INVALID
  472. }