checks.bats 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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_access_key_id_format_valid valid" {
  33. run is_access_key_id_format_valid 'M0ocDoIKbsoXSqtk1mgc' "key"
  34. assert_success
  35. }
  36. @test "is_access_key_id_format_valid short" {
  37. run is_access_key_id_format_valid 'M0ocDoIKbsoXSqtk1mg' "key"
  38. assert_failure $E_INVALID
  39. }
  40. @test "is_access_key_id_format_valid long" {
  41. run is_access_key_id_format_valid 'M0ocDoIKbsoXSqtk1mgca' "key"
  42. assert_failure $E_INVALID
  43. }
  44. @test "is_access_key_id_format_valid non alpha" {
  45. run is_access_key_id_format_valid 'M0ocDoIKbsoX$qtk1mgc' "key"
  46. assert_failure $E_INVALID
  47. }
  48. @test "is_access_key_id_format_valid LHF" {
  49. run is_access_key_id_format_valid 'c
  50. 1eshutdown
  51. r' "key"
  52. assert_failure $E_INVALID
  53. }
  54. @test "is_user_format_valid valid" {
  55. run is_user_format_valid 'hxh54SKbALne4s69VsqJRMbMd8Br' "key"
  56. assert_success
  57. }
  58. @test "is_user_format_valid short" {
  59. run is_user_format_valid 'hxh54SKbALne4s69VsqJR' "key"
  60. assert_success
  61. }
  62. @test "is_user_format_valid long" {
  63. run is_user_format_valid 'hxh54SKbALne4s69VsqJRMbMd8Braaa' "key"
  64. assert_failure $E_INVALID
  65. }
  66. @test "is_user_format_valid dash" {
  67. run is_user_format_valid 'hxh54SKbALne4-s6-VsqJRMbMd8Br' "key"
  68. assert_success
  69. }
  70. @test "is_user_format_valid dash repeat" {
  71. run is_user_format_valid 'hxh54SKbALne4s6--VsqJRMbMd8Br' "key"
  72. assert_success
  73. }
  74. @test "is_user_format_valid dash start" {
  75. run is_user_format_valid '-hxh54SKbALne4s6VsqJRMbMd8Br' "key"
  76. assert_failure $E_INVALID
  77. }
  78. @test "is_user_format_valid dash end" {
  79. run is_user_format_valid 'hxh54SKbALne4s6VsqJRMbMd8Br-' "key"
  80. assert_failure $E_INVALID
  81. }
  82. @test "is_user_format_valid LHF" {
  83. run is_user_format_valid 'M0ocDoIK
  84. soXSqtk1mgc' "key"
  85. assert_failure $E_INVALID
  86. }
  87. @test "is_fw_action_format_valid ACCEPT" {
  88. run is_fw_action_format_valid 'ACCEPT' "key"
  89. assert_success
  90. }
  91. @test "is_fw_action_format_valid DROP" {
  92. run is_fw_action_format_valid 'DROP' "key"
  93. assert_success
  94. }
  95. @test "is_fw_action_format_valid TEST" {
  96. run is_fw_action_format_valid 'TEST' "key"
  97. assert_failure $E_INVALID
  98. }
  99. @test "is_fw_action_format_valid LHF" {
  100. run is_fw_protocol_format_valid 'M0ocDoIK
  101. soXSqtk1mgc' "key"
  102. assert_failure $E_INVALID
  103. }
  104. @test "is_fw_protocol_format_valid ICMP" {
  105. run is_fw_protocol_format_valid 'ICMP' "key"
  106. assert_success
  107. }
  108. @test "is_fw_protocol_format_valid UDP" {
  109. run is_fw_protocol_format_valid 'UDP' "key"
  110. assert_success
  111. }
  112. @test "is_fw_protocol_format_valid TCP" {
  113. run is_fw_protocol_format_valid 'TCP' "key"
  114. assert_success
  115. }
  116. @test "is_fw_protocol_format_valid TEST" {
  117. run is_fw_protocol_format_valid 'TEST' "key"
  118. assert_failure $E_INVALID
  119. }
  120. @test "is_domain_format_valid success" {
  121. run is_domain_format_valid 'hestiacp.com' "key"
  122. assert_success
  123. }
  124. @test "is_domain_format_valid www" {
  125. run is_domain_format_valid 'www' "key"
  126. assert_failure $E_INVALID
  127. }
  128. @test "is_domain_format_valid number" {
  129. run is_domain_format_valid '12345' "key"
  130. assert_failure $E_INVALID
  131. }
  132. @test "is_domain_format_valid .." {
  133. run is_domain_format_valid '..' "key"
  134. assert_failure $E_INVALID
  135. }
  136. @test "is_domain_format_valid LF." {
  137. run is_domain_format_valid 'c
  138. 1eshutdown
  139. r' "key"
  140. assert_failure $E_INVALID
  141. }
  142. @test "is_alias_format_valid success" {
  143. run is_domain_format_valid 'hestiacp.com' "key"
  144. assert_success
  145. }
  146. @test "is_alias_format_valid www" {
  147. run is_domain_format_valid 'www' "key"
  148. assert_failure $E_INVALID
  149. }
  150. @test "is_alias_format_valid number" {
  151. run is_domain_format_valid '12345' "key"
  152. assert_failure $E_INVALID
  153. }
  154. @test "is_alias_format_valid .." {
  155. run is_domain_format_valid '..' "key"
  156. assert_failure $E_INVALID
  157. }
  158. @test "is_alias_format_valid LF." {
  159. run is_domain_format_valid 'c
  160. 1eshutdown
  161. r' "key"
  162. assert_failure $E_INVALID
  163. }
  164. @test "is_extention_format_valid test" {
  165. run is_extention_format_valid 'c
  166. 1eshutdown
  167. r' "key"
  168. assert_failure $E_INVALID
  169. }
  170. @test "is_string_format_valid test" {
  171. run is_string_format_valid 'c
  172. 1eshutdown
  173. r' "key"
  174. assert_failure $E_INVALID
  175. }
  176. @test "is_database_format_valid test" {
  177. run is_database_format_valid 'c
  178. 1eshutdown
  179. r' "key"
  180. assert_failure $E_INVALID
  181. }
  182. @test "is_date_format_valid test" {
  183. run is_date_format_valid 'c
  184. 1eshutdown
  185. r' "key"
  186. assert_failure $E_INVALID
  187. }
  188. @test "is_dbuser_format_valid test" {
  189. run is_dbuser_format_valid 'c
  190. 1eshutdown
  191. r' "key"
  192. assert_failure $E_INVALID
  193. }
  194. @test "is_dns_type_format_valid test" {
  195. run is_dns_type_format_valid 'c
  196. 1eshutdown
  197. r' "key"
  198. assert_failure $E_INVALID
  199. }
  200. @test "is_dns_record_format_valid test" {
  201. run is_dns_record_format_valid 'c
  202. 1eshutdown
  203. r' "key"
  204. assert_failure $E_INVALID
  205. }
  206. @test "is_email_format_valid test" {
  207. run is_email_format_valid 'c
  208. 1eshutdown
  209. r' "key"
  210. assert_failure $E_INVALID
  211. }
  212. @test "is_fw_port_format_valid test" {
  213. run is_fw_port_format_valid 'c
  214. 1eshutdown
  215. r' "key"
  216. assert_failure $E_INVALID
  217. }
  218. @test "is_int_format_valid test" {
  219. run is_int_format_valid 'c
  220. 1eshutdown
  221. r' "key"
  222. assert_failure $E_INVALID
  223. }
  224. @test "is_interface_format_valid test" {
  225. run is_interface_format_valid 'c
  226. 1eshutdown
  227. r' "key"
  228. assert_failure $E_INVALID
  229. }
  230. @test "is_ip_status_format_valid test" {
  231. run is_ip_status_format_valid 'c
  232. 1eshutdown
  233. r' "key"
  234. assert_failure $E_INVALID
  235. }
  236. @test "is_cron_format_valid test" {
  237. run is_cron_format_valid 'c
  238. 1eshutdown
  239. r' "key"
  240. assert_failure $E_INVALID
  241. }
  242. @test "is_name_format_valid test" {
  243. run is_name_format_valid 'c
  244. 1eshutdown
  245. r' "key"
  246. assert_failure $E_INVALID
  247. }
  248. @test "is_role_valid test" {
  249. run is_role_valid 'c
  250. 1eshutdown
  251. r' "key"
  252. assert_failure $E_INVALID
  253. }
  254. @test "is_object_format_valid test" {
  255. run is_object_format_valid 'c
  256. 1eshutdown
  257. r' "key"
  258. assert_failure $E_INVALID
  259. }
  260. @test "is_common_format_valid test" {
  261. run is_common_format_valid 'c
  262. 1eshutdown
  263. r' "key"
  264. assert_failure $E_INVALID
  265. }
  266. @test "format_no_quotes test" {
  267. run format_no_quotes 'c
  268. 1eshutdown
  269. r' "key"
  270. assert_failure $E_INVALID
  271. }
  272. @test "is_type_valid" {
  273. run is_type_valid 'c
  274. 1eshutdown
  275. r' "test,key"
  276. assert_failure $E_INVALID
  277. }
  278. @test "is_command_valid_format v-list-users" {
  279. run is_command_valid_format 'v-list-users'
  280. assert_success
  281. }
  282. @test "is_command_valid_format v-list--users (Fail)" {
  283. run is_command_valid_format 'v-list--users'
  284. assert_failure $E_INVALID
  285. }
  286. @test "is_command_valid_format h-list-users (Fail)" {
  287. run is_command_valid_format 'h-list-users'
  288. assert_failure $E_INVALID
  289. }
  290. @test "is_command_valid_format list-users (Fail)" {
  291. run is_command_valid_format 'list-users'
  292. assert_failure $E_INVALID
  293. }
  294. @test "is_command_valid_format vlist-users (Fail)" {
  295. run is_command_valid_format 'vlist-users'
  296. assert_failure $E_INVALID
  297. }
  298. @test "is_command_valid_format LF (Fail)" {
  299. run is_command_valid_format 'v-
  300. 1eshutdown
  301. r' "key"
  302. assert_failure $E_INVALID
  303. }