1+ #! /usr/bin/env bats
2+
3+ if [ " ${PATH#*/ usr/ local/ hestia/ bin* } " = " $PATH " ]; then
4+ . /etc/profile.d/hestia.sh
5+ fi
6+
7+ load ' test_helper/bats-support/load'
8+ load ' test_helper/bats-assert/load'
9+ load ' test_helper/bats-file/load'
10+
11+
12+ function random() {
13+ head /dev/urandom | tr -dc 0-9 | head -c$1
14+ }
15+
16+ function setup() {
17+ source /tmp/hestia-api-env.sh
18+ source $HESTIA /func/main.sh
19+ source $HESTIA /conf/hestia.conf
20+ source $HESTIA /func/ip.sh
21+ }
22+
23+ @test " [Success][ Admin/password ] List users" {
24+ 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"
25+ assert_success
26+ assert_output --partial " admin"
27+ }
28+
29+ @test " [Success][ Hash ] List users" {
30+ 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"
31+ assert_success
32+ assert_output --partial " admin"
33+ }
34+
35+ @test " [Fail][ APIV2 ] Create new user" {
36+ 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"
37+ assert_success
38+ assert_output --partial " don't have permission to run the command v-add-user"
39+ }
40+
41+ @test " [Success][ Hash ] Create tmp file" {
42+ 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"
43+ assert_success
44+ assert_output --partial " OK"
45+ }
46+
47+ @test " [Success][ Hash ] Create new user" {
48+ 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"
49+ assert_success
50+ assert_output --partial " OK"
51+ }
52+
53+ @test " [Success][ Hash ] Check password" {
54+ 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"
55+ assert_success
56+ assert_output --partial " OK"
57+ }
58+
59+
60+ @test " [Success][ Local ] Add user" {
61+ run v-add-user hestiatest 1234BCD info@hestiacp.com
62+ assert_success
63+ }
64+
65+ @test " [Success][ Local ] Add DNS domain" {
66+ run v-add-dns-domain hestiatest ilovehestiacp.com 127.0.0.1
67+ assert_success
68+ }
69+
70+ @test " [Success][ APIV2 ] Add remote DNS host" {
71+ run v-add-remote-dns-host $server $port " $accesskey " ' ' api ' hestiatest'
72+ assert_success
73+ }
74+
75+ @test " [Success][ APIV2 ] Sync DNS cluster 1" {
76+ run v-sync-dns-cluster
77+ assert_success
78+ }
79+
80+ @test " [Success][ Local ] nslookup ilovehestiacp.com" {
81+ run nslookup ilovehestiacp.com $server
82+ assert_success
83+ assert_output --partial " 127.0.0.1"
84+ }
85+
86+ @test " [Success][ Local ] Add DNS domain 2" {
87+ run v-add-dns-domain hestiatest ilovehestiacp.org 127.0.0.1
88+ assert_success
89+ }
90+
91+ @test " [Success][ Local ] Add DNS record" {
92+ run v-add-dns-record hestiatest ilovehestiacp.org test A 127.0.0.1 yes 20
93+ assert_success
94+ }
95+
96+ @test " [Success][ Local ] nslookup test.ilovehestiacp.org" {
97+ run nslookup test.ilovehestiacp.org $server
98+ assert_failure 1
99+ assert_output --partial " REFUSED"
100+
101+ run nslookup test.ilovehestiacp.org localhost
102+ assert_success
103+ assert_output --partial " 127.0.0.1"
104+ }
105+
106+ @test " [Success][ APIV2 ] Sync DNS cluster 2" {
107+ run v-sync-dns-cluster
108+ assert_success
109+
110+ run nslookup test.ilovehestiacp.org $server
111+ assert_success
112+ assert_output --partial " 127.0.0.1"
113+ }
114+
115+ @test " [Success][ Local ] Delete DNS record" {
116+ run v-delete-dns-record hestiatest ilovehestiacp.org 20
117+ assert_success
118+ }
119+
120+ @test " [Success][ Local ] nslookup test.ilovehestiacp.org 2" {
121+ run nslookup test.ilovehestiacp.org $server
122+ assert_success
123+ assert_output --partial " 127.0.0.1"
124+
125+ run nslookup test.ilovehestiacp.org localhost
126+ assert_failure
127+ }
128+
129+ @test " [Success][ APIV2 ] Sync DNS cluster 3" {
130+ run v-sync-dns-cluster
131+ assert_success
132+
133+ run nslookup test.ilovehestiacp.org $server
134+ assert_failure
135+ }
136+
137+
138+ @test " [Success][ APIV2 ] Delete remote DNS host" {
139+ run v-delete-remote-dns-host $server
140+ assert_success
141+ }
142+
143+
144+ @test " [Success][ Local ] Delete user" {
145+ run v-delete-user hestiatest
146+ assert_success
147+ }
148+
149+ @test " [Success][ Hash ] Delete user" {
150+ 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"
151+ }
0 commit comments