api.bats 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. source /tmp/hestia-api-env.sh
  13. source $HESTIA/func/main.sh
  14. source $HESTIA/conf/hestia.conf
  15. source $HESTIA/func/ip.sh
  16. }
  17. @test "[Success][ Admin/password ] List users" {
  18. run curl -k -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "user=admin&password=$password&returncode=no&cmd=v-list-users&arg1=plain" "https://$server:$port/api/index.php"
  19. assert_success
  20. assert_output --partial "admin"
  21. }
  22. @test "[Success][ Hash ] List users" {
  23. run curl -k -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "hash=$apikey&returncode=no&cmd=v-list-users&arg1=plain" "https://$server:$port/api/index.php"
  24. assert_success
  25. assert_output --partial "admin"
  26. }
  27. @test "[Fail][ APIV2 ] Create new user" {
  28. run curl -k -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "hash=$accesskey&returncode=yes&cmd=v-add-user&arg1=hestiatest&arg2=strongpassword&arg3=info@hestiacp.com" "https://$server:$port/api/index.php"
  29. assert_success
  30. assert_output --partial "don't have permission to run the command v-add-user"
  31. }
  32. @test "[Success][ Hash ] Create tmp file" {
  33. run curl -k -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "hash=$apikey&cmd=v-make-tmp-file&arg1=strongpassword&arg2=clusterpassword" "https://$server:$port/api/index.php"
  34. assert_success
  35. assert_output --partial "OK"
  36. }
  37. @test "[Success][ Hash ] Create new user" {
  38. run curl -k -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "hash=$apikey&cmd=v-add-user&arg1=hestiatest&arg2=/tmp/clusterpassword&arg3=info@hestiacp.com&arg4=default" "https://$server:$port/api/index.php"
  39. assert_success
  40. assert_output --partial "OK"
  41. }
  42. @test "[Success][ Hash ] Check password" {
  43. run curl -k -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "hash=$apikey&cmd=v-check-user-password&arg1=hestiatest&arg2=strongpassword" "https://$server:$port/api/index.php"
  44. assert_success
  45. assert_output --partial "OK"
  46. }
  47. @test "[Success][ Local ] Add user" {
  48. run v-add-user hestiatest 1234BCD info@hestiacp.com
  49. assert_success
  50. }
  51. @test "[Success][ Local ] Add DNS domain" {
  52. run v-add-dns-domain hestiatest ilovehestiacp.com 127.0.0.1
  53. assert_success
  54. }
  55. @test "[Success][ APIV2 ] Add remote DNS host" {
  56. run v-add-remote-dns-host $server $port "$accesskey" '' api 'hestiatest'
  57. assert_success
  58. }
  59. @test "[Success][ APIV2 ] Sync DNS cluster 1" {
  60. run v-sync-dns-cluster
  61. assert_success
  62. }
  63. @test "[Success][ Local ] nslookup ilovehestiacp.com" {
  64. run nslookup ilovehestiacp.com $server
  65. assert_success
  66. assert_output --partial "127.0.0.1"
  67. }
  68. @test "[Success][ Local ] Add DNS domain 2" {
  69. run v-add-dns-domain hestiatest ilovehestiacp.org 127.0.0.1
  70. assert_success
  71. }
  72. @test "[Success][ Local ] Add DNS record" {
  73. run v-add-dns-record hestiatest ilovehestiacp.org test A 127.0.0.1 yes 20
  74. assert_success
  75. }
  76. @test "[Success][ Local ] nslookup test.ilovehestiacp.org" {
  77. run nslookup test.ilovehestiacp.org $server
  78. assert_failure 1
  79. assert_output --partial "REFUSED"
  80. run nslookup test.ilovehestiacp.org localhost
  81. assert_success
  82. assert_output --partial "127.0.0.1"
  83. }
  84. @test "[Success][ APIV2 ] Sync DNS cluster 2" {
  85. run v-sync-dns-cluster
  86. assert_success
  87. run nslookup test.ilovehestiacp.org $server
  88. assert_success
  89. assert_output --partial "127.0.0.1"
  90. }
  91. @test "[Success][ Local ] Delete DNS record" {
  92. run v-delete-dns-record hestiatest ilovehestiacp.org 20
  93. assert_success
  94. }
  95. @test "[Success][ Local ] nslookup test.ilovehestiacp.org 2" {
  96. run nslookup test.ilovehestiacp.org $server
  97. assert_success
  98. assert_output --partial "127.0.0.1"
  99. run nslookup test.ilovehestiacp.org localhost
  100. assert_failure
  101. }
  102. @test "[Success][ APIV2 ] Sync DNS cluster 3" {
  103. run v-sync-dns-cluster
  104. assert_success
  105. run nslookup test.ilovehestiacp.org $server
  106. assert_failure
  107. }
  108. @test "[Success][ APIV2 ] Delete remote DNS host" {
  109. run v-delete-remote-dns-host $server
  110. assert_success
  111. }
  112. @test "[Success][ Local ] Delete user" {
  113. run v-delete-user hestiatest
  114. assert_success
  115. }
  116. @test "[Success][ Hash ] Delete user" {
  117. run curl -k -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "hash=$apikey&cmd=v-delete-user&arg1=hestiatest" "https://$server:$port/api/index.php"
  118. }