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