checks.bats 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 test" {
  157. rtype='MX'
  158. priority=1;
  159. run is_dns_record_format_valid 'c
  160. 1eshutdown
  161. r'
  162. assert_failure $E_INVALID
  163. }
  164. @test "is_alias_format_valid success" {
  165. run is_alias_format_valid 'hestiacp.com' "key"
  166. assert_success
  167. }
  168. @test "is_alias_format_valid success www.domain.com" {
  169. run is_alias_format_valid 'www.hestiacp.com' "key"
  170. assert_success
  171. }
  172. @test "is_alias_format_valid success hestiacp.com,www.hestiacp.com" {
  173. run is_alias_format_valid 'hestiacp.com,www.hestiacp.com' "key"
  174. assert_success
  175. }
  176. @test "is_alias_format_valid success *.hestiacp.com" {
  177. run is_alias_format_valid '*.hestiacp.com' "key"
  178. assert_success
  179. }
  180. @test "is_alias_format_valid success www.hestiacp.com,*.hestiacp.com" {
  181. run is_alias_format_valid 'www.hestiacp.com,*.hestiacp.com' "key"
  182. assert_success
  183. }
  184. @test "is_extention_format_valid test" {
  185. run is_extention_format_valid 'c
  186. 1eshutdown
  187. r' "key"
  188. assert_failure $E_INVALID
  189. }
  190. @test "is_string_format_valid test" {
  191. run is_string_format_valid 'c
  192. 1eshutdown
  193. r' "key"
  194. assert_failure $E_INVALID
  195. }
  196. @test "is_database_format_valid test" {
  197. run is_database_format_valid 'c
  198. 1eshutdown
  199. r' "key"
  200. assert_failure $E_INVALID
  201. }
  202. @test "is_date_format_valid test" {
  203. run is_date_format_valid 'c
  204. 1eshutdown
  205. r' "key"
  206. assert_failure $E_INVALID
  207. }
  208. @test "is_dbuser_format_valid test" {
  209. run is_dbuser_format_valid 'c
  210. 1eshutdown
  211. r' "key"
  212. assert_failure $E_INVALID
  213. }
  214. @test "is_dns_type_format_valid test" {
  215. run is_dns_type_format_valid 'c
  216. 1eshutdown
  217. r' "key"
  218. assert_failure $E_INVALID
  219. }
  220. @test "is_email_format_valid test" {
  221. run is_email_format_valid 'c
  222. 1eshutdown
  223. r' "key"
  224. assert_failure $E_INVALID
  225. }
  226. @test "is_fw_port_format_valid test" {
  227. run is_fw_port_format_valid 'c
  228. 1eshutdown
  229. r' "key"
  230. assert_failure $E_INVALID
  231. }
  232. @test "is_int_format_valid test" {
  233. run is_int_format_valid 'c
  234. 1eshutdown
  235. r' "key"
  236. assert_failure $E_INVALID
  237. }
  238. @test "is_interface_format_valid test" {
  239. run is_interface_format_valid 'c
  240. 1eshutdown
  241. r' "key"
  242. assert_failure $E_INVALID
  243. }
  244. @test "is_ip_status_format_valid test" {
  245. run is_ip_status_format_valid 'c
  246. 1eshutdown
  247. r' "key"
  248. assert_failure $E_INVALID
  249. }
  250. @test "is_cron_format_valid test" {
  251. run is_cron_format_valid 'c
  252. 1eshutdown
  253. r' "key"
  254. assert_failure $E_INVALID
  255. }
  256. @test "is_name_format_valid test" {
  257. run is_name_format_valid 'c
  258. 1eshutdown
  259. r' "key"
  260. assert_failure $E_INVALID
  261. }
  262. @test "is_role_valid test" {
  263. run is_role_valid 'c
  264. 1eshutdown
  265. r' "key"
  266. assert_failure $E_INVALID
  267. }
  268. @test "is_object_format_valid test" {
  269. run is_object_format_valid 'c
  270. 1eshutdown
  271. r' "key"
  272. assert_failure $E_INVALID
  273. }
  274. @test "is_common_format_valid test" {
  275. run is_common_format_valid 'c
  276. 1eshutdown
  277. r' "key"
  278. assert_failure $E_INVALID
  279. }
  280. @test "format_no_quotes test2" {
  281. run format_no_quotes 'test bericht' "key"
  282. assert_success
  283. }
  284. @test "format_no_quotes .." {
  285. run format_no_quotes '..' "key"
  286. assert_success
  287. }
  288. @test "format_no_quotes text." {
  289. run format_no_quotes 'text.' "key"
  290. assert_success
  291. }
  292. @test "is_common_format_valid text" {
  293. run is_common_format_valid 'text' "key"
  294. assert_success
  295. }
  296. @test "format_no_quotes test" {
  297. run format_no_quotes 'c
  298. 1eshutdown
  299. r' "key"
  300. assert_failure $E_INVALID
  301. }
  302. @test "is_type_valid" {
  303. run is_type_valid 'c
  304. 1eshutdown
  305. r' "test,key"
  306. assert_failure $E_INVALID
  307. }
  308. @test "is_command_valid_format v-list-users" {
  309. run is_command_valid_format 'v-list-users'
  310. assert_success
  311. }
  312. @test "is_command_valid_format v-list--users (Fail)" {
  313. run is_command_valid_format 'v-list--users'
  314. assert_failure $E_INVALID
  315. }
  316. @test "is_command_valid_format h-list-users (Fail)" {
  317. run is_command_valid_format 'h-list-users'
  318. assert_failure $E_INVALID
  319. }
  320. @test "is_command_valid_format list-users (Fail)" {
  321. run is_command_valid_format 'list-users'
  322. assert_failure $E_INVALID
  323. }
  324. @test "is_command_valid_format vlist-users (Fail)" {
  325. run is_command_valid_format 'vlist-users'
  326. assert_failure $E_INVALID
  327. }
  328. @test "is_command_valid_format LF (Fail)" {
  329. run is_command_valid_format 'v-
  330. 1eshutdown
  331. r' "key"
  332. assert_failure $E_INVALID
  333. }