lumberg 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +98 -0
- data/LICENSE +20 -0
- data/README.md +178 -0
- data/Rakefile +49 -0
- data/lib/cacert.pem +3910 -0
- data/lib/lumberg.rb +23 -0
- data/lib/lumberg/exceptions.rb +6 -0
- data/lib/lumberg/version.rb +3 -0
- data/lib/lumberg/whm.rb +70 -0
- data/lib/lumberg/whm/account.rb +329 -0
- data/lib/lumberg/whm/args.rb +113 -0
- data/lib/lumberg/whm/base.rb +28 -0
- data/lib/lumberg/whm/dns.rb +205 -0
- data/lib/lumberg/whm/reseller.rb +268 -0
- data/lib/lumberg/whm/server.rb +290 -0
- data/lib/net_http_hacked.rb +42 -0
- data/lumberg.gemspec +28 -0
- data/spec/lumberg_spec.rb +9 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/vcr_cassettes/whm/account/accountsummary.yml +43 -0
- data/spec/vcr_cassettes/whm/account/changepackage.yml +64 -0
- data/spec/vcr_cassettes/whm/account/createacct.yml +43 -0
- data/spec/vcr_cassettes/whm/account/domainuserdata.yml +43 -0
- data/spec/vcr_cassettes/whm/account/editquota.yml +85 -0
- data/spec/vcr_cassettes/whm/account/limitbw.yml +85 -0
- data/spec/vcr_cassettes/whm/account/listaccts.yml +147 -0
- data/spec/vcr_cassettes/whm/account/listsuspended.yml +43 -0
- data/spec/vcr_cassettes/whm/account/modifyacct.yml +63 -0
- data/spec/vcr_cassettes/whm/account/myprivs.yml +43 -0
- data/spec/vcr_cassettes/whm/account/passwd.yml +43 -0
- data/spec/vcr_cassettes/whm/account/removeacct.yml +85 -0
- data/spec/vcr_cassettes/whm/account/restoreaccount.yml +198 -0
- data/spec/vcr_cassettes/whm/account/setsiteip.yml +190 -0
- data/spec/vcr_cassettes/whm/account/suspend.yml +64 -0
- data/spec/vcr_cassettes/whm/account/unsuspend.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/adddns.yml +64 -0
- data/spec/vcr_cassettes/whm/dns/addzonerecord.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/dumpzone.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/editzonerecord.yml +64 -0
- data/spec/vcr_cassettes/whm/dns/getzonerecord.yml +64 -0
- data/spec/vcr_cassettes/whm/dns/killdns.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/listmxs.yml +22 -0
- data/spec/vcr_cassettes/whm/dns/listzones.yml +22 -0
- data/spec/vcr_cassettes/whm/dns/lookupnsip.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/removezonerecord.yml +64 -0
- data/spec/vcr_cassettes/whm/dns/resetzone.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/resolvedomainname.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/savemxs.yml +22 -0
- data/spec/vcr_cassettes/whm/reseller/acctcounts.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/listacls.yml +22 -0
- data/spec/vcr_cassettes/whm/reseller/listresellers.yml +22 -0
- data/spec/vcr_cassettes/whm/reseller/resellerstats.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/saveacllist.yml +85 -0
- data/spec/vcr_cassettes/whm/reseller/setacls.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/setresellerips.yml +42 -0
- data/spec/vcr_cassettes/whm/reseller/setresellerlimits.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/setresellermainip.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/setresellernameservers.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/setresellerpackagelimit.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/setupreseller.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/suspendreseller.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/terminatereseller.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/unsetupreseller.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/unsuspendreseller.yml +43 -0
- data/spec/vcr_cassettes/whm/server/applist.yml +22 -0
- data/spec/vcr_cassettes/whm/server/gethostname.yml +22 -0
- data/spec/vcr_cassettes/whm/server/getlanglist.yml +22 -0
- data/spec/vcr_cassettes/whm/server/loadavg.yml +28 -0
- data/spec/vcr_cassettes/whm/server/my_function.yml +64 -0
- data/spec/vcr_cassettes/whm/server/response_type.yml +85 -0
- data/spec/vcr_cassettes/whm/server/systemloadavg.yml +43 -0
- data/spec/vcr_cassettes/whm/server/version.yml +22 -0
- data/spec/whm/account_spec.rb +577 -0
- data/spec/whm/args_spec.rb +179 -0
- data/spec/whm/base_spec.rb +28 -0
- data/spec/whm/dns_spec.rb +352 -0
- data/spec/whm/reseller_spec.rb +359 -0
- data/spec/whm/server_spec.rb +288 -0
- data/spec/whm/whm_spec.rb +41 -0
- metadata +265 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://myhost.com:2087/json-api/systemloadavg
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- WHM root:iscool
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
server:
|
16
|
+
- cpsrvd/11.28.64
|
17
|
+
transfer-encoding:
|
18
|
+
- chunked
|
19
|
+
content-type:
|
20
|
+
- text/plain
|
21
|
+
body: "{\"error\":\"Unknown App Requested: systemloadavg\"}"
|
22
|
+
http_version: "1.1"
|
23
|
+
- !ruby/struct:VCR::HTTPInteraction
|
24
|
+
request: !ruby/struct:VCR::Request
|
25
|
+
method: :get
|
26
|
+
uri: https://myhost.com:2087/json-api/systemloadavg?api.version=1
|
27
|
+
body:
|
28
|
+
headers:
|
29
|
+
authorization:
|
30
|
+
- WHM root:iscool
|
31
|
+
response: !ruby/struct:VCR::Response
|
32
|
+
status: !ruby/struct:VCR::ResponseStatus
|
33
|
+
code: 200
|
34
|
+
message: OK
|
35
|
+
headers:
|
36
|
+
server:
|
37
|
+
- cpsrvd/11.28.64
|
38
|
+
transfer-encoding:
|
39
|
+
- chunked
|
40
|
+
content-type:
|
41
|
+
- text/plain
|
42
|
+
body: "{\"data\":{\"one\":\"0.00\",\"five\":\"0.04\",\"fifteen\":\"0.01\"},\"metadata\":{\"result\":1,\"reason\":\"OK\",\"version\":1,\"command\":\"systemloadavg\"}}"
|
43
|
+
http_version: "1.1"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://myhost.com:2087/json-api/version
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- WHM root:iscool
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
server:
|
16
|
+
- cpsrvd/11.28.64
|
17
|
+
transfer-encoding:
|
18
|
+
- chunked
|
19
|
+
content-type:
|
20
|
+
- text/plain
|
21
|
+
body: "{\"version\":\"11.28.64\"}"
|
22
|
+
http_version: "1.1"
|
@@ -0,0 +1,577 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'lumberg/whm'
|
3
|
+
|
4
|
+
module Lumberg
|
5
|
+
describe Whm::Account do
|
6
|
+
before(:each) do
|
7
|
+
@login = { :host => @whm_host, :hash => @whm_hash }
|
8
|
+
@server = Whm::Server.new(@login.dup)
|
9
|
+
@account = Whm::Account.new(:server => @server.dup)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#create" do
|
13
|
+
use_vcr_cassette "whm/account/createacct"
|
14
|
+
|
15
|
+
it "requires a username" do
|
16
|
+
requires_attr('username') { @account.create }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "requires a domain" do
|
20
|
+
requires_attr('domain') { @account.create(:username => 'user') }
|
21
|
+
end
|
22
|
+
|
23
|
+
it "requires a password" do
|
24
|
+
requires_attr('password') {
|
25
|
+
@account.create(:username => 'user', :domain => 'example.com')
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "creates the account with proper params" do
|
30
|
+
result = @account.create(:username => 'valid', :password => 'hummingbird123', :domain => 'valid-thing.com')
|
31
|
+
result[:success].should be_true
|
32
|
+
result[:message].should match(/Account Creation Ok/i)
|
33
|
+
result[:params].should_not be_empty
|
34
|
+
result[:params].should have_key(:options)
|
35
|
+
result[:params][:options].should include(:nameserver4, :nameserver, :nameserverentry2, :nameserverentry3,
|
36
|
+
:nameserverentry4, :nameserverentry, :ip, :nameservera2,
|
37
|
+
:nameservera3, :package, :nameservera4, :nameserver2,
|
38
|
+
:nameservera, :nameserver3)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns an error on duplicate accounts" do
|
42
|
+
@account.create(:username => 'invalid', :password => 'hummingbird123', :domain => 'invalid-thing.com')
|
43
|
+
result = @account.create(:username => 'invalid', :password => 'hummingbird123', :domain => 'invalid-thing.com')
|
44
|
+
result[:success].should be(false)
|
45
|
+
result[:message].should match(/username already exists/i)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#remove" do
|
50
|
+
use_vcr_cassette "whm/account/removeacct"
|
51
|
+
|
52
|
+
it "requires a username" do
|
53
|
+
requires_attr('username') { @account.remove }
|
54
|
+
end
|
55
|
+
|
56
|
+
it "removes a user and keeps DNS by default" do
|
57
|
+
result = @account.remove(:username => 'removeme')
|
58
|
+
result[:success].should be_true
|
59
|
+
result[:params][:rawout].should match(/Removing DNS Entries/i)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "removes a user and DNS when asked" do
|
63
|
+
result = @account.remove(:username => 'removeme', :keepdns => false)
|
64
|
+
result[:success].should be_true
|
65
|
+
result[:params][:rawout].should match(/Removing DNS Entries/i)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "removes a user but keep DNS" do
|
69
|
+
result = @account.remove(:username => 'removeme', :keepdns => true)
|
70
|
+
result[:success].should be_true
|
71
|
+
result[:params][:rawout].should_not match(/Removing DNS Entries/i)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns an error when the user doesn't exist" do
|
75
|
+
result = @account.remove(:username => 'notreal')
|
76
|
+
result[:success].should be(false)
|
77
|
+
result[:message].should match(/notreal does not exist/i)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#change_password" do
|
82
|
+
use_vcr_cassette "whm/account/passwd"
|
83
|
+
|
84
|
+
it "requires a username" do
|
85
|
+
requires_attr('username') { @account.change_password }
|
86
|
+
end
|
87
|
+
|
88
|
+
it "requires a password" do
|
89
|
+
requires_attr('password') { @account.change_password(:username => 'changeme') }
|
90
|
+
end
|
91
|
+
|
92
|
+
it "changes the password" do
|
93
|
+
result = @account.change_password(:username => 'changeme', :password => 'superpass')
|
94
|
+
result[:success].should be_true
|
95
|
+
result[:message].should match(/Password changed for user changeme/i)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "isn't successful when the user doesn't exist" do
|
99
|
+
result = @account.change_password(:username => 'dontchangeme', :password => 'superpass')
|
100
|
+
result[:success].should be(false)
|
101
|
+
result[:message].should match(/dontchangeme does not exist/i)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#limit bandwidth" do
|
106
|
+
use_vcr_cassette "whm/account/limitbw"
|
107
|
+
|
108
|
+
it "requires a user" do
|
109
|
+
requires_attr('username') { @account.limit_bandwidth(:bwlimit => 99999) }
|
110
|
+
end
|
111
|
+
|
112
|
+
it "requires a bandwidth" do
|
113
|
+
requires_attr('bwlimit') { @account.limit_bandwidth(:username => 'changeme') }
|
114
|
+
end
|
115
|
+
|
116
|
+
it "sets the bandwidth limit" do
|
117
|
+
result = @account.limit_bandwidth(:username => 'changeme', :bwlimit => 99999)
|
118
|
+
result[:success].should be_true
|
119
|
+
result[:message].should match(/Bandwidth Limit for changeme set to 99999/i)
|
120
|
+
result[:params][:bwlimit][:bwlimitenable].should equal(false)
|
121
|
+
result[:params][:bwlimit][:unlimited].should equal(true)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "isn't successful when the user doesn't exist" do
|
125
|
+
expect {
|
126
|
+
@account.limit_bandwidth(:username => 'notexists', :bwlimit => 99999)
|
127
|
+
}.to raise_error(WhmInvalidUser, /User notexists does not exist/i)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#list" do
|
132
|
+
use_vcr_cassette "whm/account/listaccts"
|
133
|
+
|
134
|
+
it "lists all accounts" do
|
135
|
+
result = @account.list
|
136
|
+
result[:success].should be_true
|
137
|
+
result[:params][:acct].should have(10).accounts
|
138
|
+
p result[:params][:acct].first[:ip].should_not be_false
|
139
|
+
end
|
140
|
+
|
141
|
+
it "returns data for the account" do
|
142
|
+
result = @account.list(:searchtype => 'user', :search => 'changeme')
|
143
|
+
result[:success].should be_true
|
144
|
+
account = result[:params][:acct].first
|
145
|
+
account[:email].should == "*unknown*"
|
146
|
+
account[:shell].should == "/usr/local/cpanel/bin/noshell"
|
147
|
+
account[:theme].should == "x3"
|
148
|
+
account[:plan].should == "default"
|
149
|
+
account[:suspended].should equal(false)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "lists accounts that match a regex search for the user" do
|
153
|
+
result = @account.list(:searchtype => 'user', :search => 'changeme')
|
154
|
+
result[:success].should be_true
|
155
|
+
result[:params][:acct].should have(1).account
|
156
|
+
end
|
157
|
+
|
158
|
+
it "lists accounts that match a regex search for the ip" do
|
159
|
+
result = @account.list(:searchtype => 'ip', :search => '192\..*?\.1\.20')
|
160
|
+
result[:success].should be_true
|
161
|
+
result[:params][:acct].should have(6).accounts
|
162
|
+
end
|
163
|
+
|
164
|
+
it "lists accounts that match a regex search for the domain" do
|
165
|
+
result = @account.list(:searchtype => 'domain', :search => 'ch.*?e.com')
|
166
|
+
result[:success].should be_true
|
167
|
+
result[:params][:acct].should have(1).account
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "#modify" do
|
172
|
+
use_vcr_cassette "whm/account/modifyacct"
|
173
|
+
|
174
|
+
it "allows domain modification" do
|
175
|
+
result = @account.modify(:username => 'changeme', :domain => 'example.com')
|
176
|
+
result[:success].should be_true
|
177
|
+
result[:params][:newcfg][:cpuser][:DOMAIN].should == 'example.com'
|
178
|
+
end
|
179
|
+
|
180
|
+
it "returns an error for an invalid user" do
|
181
|
+
result = @account.modify(:username => 'notexists')
|
182
|
+
result[:success].should_not be_true
|
183
|
+
result[:message].should match(/Unable to fetch the cPanel user file for notexists/)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "returns the bandwidth limit" do
|
187
|
+
result = @account.modify(:username => 'changeme')
|
188
|
+
result[:params][:newcfg][:cpuser][:BWLIMIT].should == "unlimited"
|
189
|
+
end
|
190
|
+
|
191
|
+
it "returns the primary contact email" do
|
192
|
+
result = @account.modify(:username => 'changeme')
|
193
|
+
result[:params][:newcfg][:cpuser][:CONTACTEMAIL].should == "user@address.com"
|
194
|
+
end
|
195
|
+
|
196
|
+
it "returns the secondary contact email" do
|
197
|
+
result = @account.modify(:username => 'changeme')
|
198
|
+
result[:params][:newcfg][:cpuser][:CONTACTEMAIL2].should == "user2@address.com"
|
199
|
+
end
|
200
|
+
|
201
|
+
it "returns the main domain" do
|
202
|
+
result = @account.modify(:username => 'changeme')
|
203
|
+
result[:params][:newcfg][:cpuser][:DOMAIN].should == "example.com"
|
204
|
+
end
|
205
|
+
|
206
|
+
it "returns whether or not the domain has CGI access" do
|
207
|
+
result = @account.modify(:username => 'changeme')
|
208
|
+
result[:params][:newcfg][:cpuser][:HASCGI].should be_true
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "#editquota" do
|
213
|
+
use_vcr_cassette "whm/account/editquota"
|
214
|
+
|
215
|
+
it "returns an error for an invalid user" do
|
216
|
+
result = @account.edit_quota(:username => 'notexists', :quota => 500)
|
217
|
+
result[:success].should_not be_true
|
218
|
+
result[:message].should match(/Invalid User\. Cannot set quota\./i)
|
219
|
+
end
|
220
|
+
|
221
|
+
it "changes the user's disk space usage quota" do
|
222
|
+
result = @account.edit_quota(:username => 'changeme', :quota => 500)
|
223
|
+
result[:success].should be_true
|
224
|
+
result[:message].should match(/Set quota for user./i)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "returns an error if a negative usage quota is passed" do
|
228
|
+
result = @account.edit_quota(:username => 'changeme', :quota => -1)
|
229
|
+
result[:success].should_not be_true
|
230
|
+
result[:message].should match(/Failed to set quota for user\./i)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "#summary" do
|
235
|
+
use_vcr_cassette "whm/account/accountsummary"
|
236
|
+
it "requires a user" do
|
237
|
+
requires_attr('username') { @account.create }
|
238
|
+
end
|
239
|
+
|
240
|
+
it "returns an error for invalid users" do
|
241
|
+
result = @account.summary(:username => 'notexists')
|
242
|
+
result[:success].should_not be_true
|
243
|
+
result[:message].should match(/does not exist/i)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "returns a summary" do
|
247
|
+
result = @account.summary(:username => 'summary')
|
248
|
+
result[:success].should be_true
|
249
|
+
result[:message].should match(/ok/i)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe "#suspend" do
|
254
|
+
use_vcr_cassette "whm/account/suspend"
|
255
|
+
|
256
|
+
it "requires a username" do
|
257
|
+
requires_attr('username') { @account.suspend }
|
258
|
+
end
|
259
|
+
|
260
|
+
it "returns an error for invalid users" do
|
261
|
+
result = @account.suspend(:username => 'notexists')
|
262
|
+
result[:success].should_not be_true
|
263
|
+
result[:message].should match(/does not exist/i)
|
264
|
+
end
|
265
|
+
|
266
|
+
it "suspends" do
|
267
|
+
result = @account.suspend(:username => 'suspendme')
|
268
|
+
result[:success].should be_true
|
269
|
+
result[:message].should match(/has been suspended/i)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "suspends with a reason" do
|
273
|
+
@account.server.should_receive(:perform_request).with('suspendacct', hash_including(:user => 'suspendme', :reason => 'abusive user'))
|
274
|
+
@account.suspend(:username => 'suspendme', :reason => 'abusive user')
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
describe "#unsuspend" do
|
279
|
+
use_vcr_cassette "whm/account/unsuspend"
|
280
|
+
it "require a username" do
|
281
|
+
requires_attr('username') { @account.unsuspend }
|
282
|
+
end
|
283
|
+
|
284
|
+
it "returns an error for invalid users" do
|
285
|
+
result = @account.unsuspend(:username => 'notexists')
|
286
|
+
result[:success].should_not be_true
|
287
|
+
result[:message].should match(/does not exist/i)
|
288
|
+
end
|
289
|
+
|
290
|
+
it "unsuspends" do
|
291
|
+
result = @account.unsuspend(:username => 'asdfasdf')
|
292
|
+
result[:success].should be_true
|
293
|
+
result[:message].should match(/unsuspending .* account/i)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe "#list_suspended" do
|
298
|
+
use_vcr_cassette 'whm/account/listsuspended'
|
299
|
+
it "returns non-empty result" do
|
300
|
+
# empty isn't a real param. VCR Hacks
|
301
|
+
result = @account.list_suspended(:empty => true)
|
302
|
+
result[:success].should be_true
|
303
|
+
result[:params][:accts].should_not be_empty
|
304
|
+
result[:params][:accts].first.should include(:user => 'removeme')
|
305
|
+
end
|
306
|
+
|
307
|
+
it "returns empty result" do
|
308
|
+
result = @account.list_suspended
|
309
|
+
result[:success].should be_true
|
310
|
+
result[:params][:accts].should be_empty
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "#change package" do
|
315
|
+
use_vcr_cassette "whm/account/changepackage"
|
316
|
+
|
317
|
+
it "returns an error for an invalid user" do
|
318
|
+
result = @account.change_package(:username => 'notexists', :pkg => 'default')
|
319
|
+
result[:success].should_not be_true
|
320
|
+
result[:message].should match(/user notexists does not exist/i)
|
321
|
+
end
|
322
|
+
|
323
|
+
it "requires a username" do
|
324
|
+
requires_attr('username') { @account.change_package(:pkg => '') }
|
325
|
+
end
|
326
|
+
|
327
|
+
it "requires a pkg" do
|
328
|
+
requires_attr('pkg') { @account.change_package(:username => 'changeme') }
|
329
|
+
end
|
330
|
+
|
331
|
+
it "fails if the package was not found" do
|
332
|
+
result = @account.change_package(:username => 'changeme', :pkg => 'fakepackage')
|
333
|
+
result[:success].should_not be_true
|
334
|
+
result[:message].should match(/package does not exist/i)
|
335
|
+
end
|
336
|
+
|
337
|
+
it "changes the package" do
|
338
|
+
result = @account.change_package(:username => 'changeme', :pkg => 'gold')
|
339
|
+
result[:success].should be_true
|
340
|
+
result[:message].should match(/Account Upgrade\/Downgrade Complete for changeme/i)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
describe "#privs" do
|
345
|
+
use_vcr_cassette 'whm/account/myprivs'
|
346
|
+
it "requires a user" do
|
347
|
+
requires_attr('username') { @account.privs }
|
348
|
+
end
|
349
|
+
|
350
|
+
it "has a result" do
|
351
|
+
result = @account.privs(:username => 'privs')
|
352
|
+
result[:success].should be_true
|
353
|
+
|
354
|
+
params = result[:params]
|
355
|
+
expected = {
|
356
|
+
:kill_dns => false, :edit_dns => false, :edit_mx => false, :add_pkg => false,
|
357
|
+
:suspend_acct => false, :add_pkg_shell => false, :viewglobalpackages => false,
|
358
|
+
:resftp => false, :list_accts => false, :all => true, :passwd => false, :quota => false,
|
359
|
+
:park_dns => false, :rearrange_accts => false, :allow_addoncreate => false, :demo => false,
|
360
|
+
:news => false, :edit_account => false, :allow_unlimited_disk_pkgs => false, :allow_parkedcreate => false,
|
361
|
+
:frontpage => false, :restart => false, :ssl_gencrt => false, :allow_unlimited_pkgs => false,
|
362
|
+
:add_pkg_ip => false, :disallow_shell => false, :res_cart => false, :ssl_buy => false, :kill_acct => false,
|
363
|
+
:allow_unlimited_bw_pkgs => false, :create_dns => false, :mailcheck => false, :clustering => false, :ssl => false,
|
364
|
+
:edit_pkg => false, :locale_edit => false, :show_bandwidth => false, :upgrade_account => false, :thirdparty => false,
|
365
|
+
:limit_bandwidth => false, :create_acct => false, :demo_setup => false, :stats => false}
|
366
|
+
|
367
|
+
params.should include(expected)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
describe "#domainuserdata" do
|
372
|
+
use_vcr_cassette "whm/account/domainuserdata"
|
373
|
+
|
374
|
+
it "returns an error for an unknown domain" do
|
375
|
+
result = @account.domain_user_data(:domain => 'notexists.com')
|
376
|
+
result[:success].should_not be_true
|
377
|
+
result[:message].should match(/Unable to determine account owner for domain\./i)
|
378
|
+
end
|
379
|
+
|
380
|
+
it "requires a domain" do
|
381
|
+
requires_attr('domain') { @account.domain_user_data }
|
382
|
+
end
|
383
|
+
|
384
|
+
it "returns the correct data" do
|
385
|
+
result = @account.domain_user_data(:domain => 'example.com')
|
386
|
+
result[:success].should be_true
|
387
|
+
result[:params][:documentroot].should == "/home/changeme/public_html"
|
388
|
+
result[:params][:group].should == "changeme"
|
389
|
+
result[:params][:hascgi].should_not be_true
|
390
|
+
result[:params][:homedir].should == "/home/changeme"
|
391
|
+
result[:params][:ip].should == "192.1.2.3"
|
392
|
+
result[:params][:owner].should == "root"
|
393
|
+
result[:params][:port].should == "80"
|
394
|
+
result[:params][:scriptalias].first[:path].should == "/home/changeme/public_html/cgi-bin"
|
395
|
+
result[:params][:scriptalias].first[:url].should == "/cgi-bin/"
|
396
|
+
result[:params][:serveradmin].should == "webmaster@example.com"
|
397
|
+
result[:params][:serveralias].should == "www.example.com"
|
398
|
+
result[:params][:servername].should == "example.com"
|
399
|
+
result[:params][:user].should == "changeme"
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
describe "#setsiteip" do
|
404
|
+
use_vcr_cassette "whm/account/setsiteip"
|
405
|
+
|
406
|
+
it "requires an ip" do
|
407
|
+
requires_attr('ip') { @account.set_site_ip }
|
408
|
+
end
|
409
|
+
|
410
|
+
it "requires a username or a domain" do
|
411
|
+
expect { @account.set_site_ip(:ip => '1.1.1.1') }.to raise_error(WhmArgumentError, /may include only one of 'username, domain'/i)
|
412
|
+
end
|
413
|
+
|
414
|
+
it "accepts a username for the account to use" do
|
415
|
+
result = @account.set_site_ip(:ip => '192.1.2.3', :username => 'changeme')
|
416
|
+
result[:success].should be_true
|
417
|
+
end
|
418
|
+
|
419
|
+
it "accepts a domain for the account to use" do
|
420
|
+
result = @account.set_site_ip(:ip => '192.1.2.3', :domain => 'example.com')
|
421
|
+
result[:success].should be_true
|
422
|
+
end
|
423
|
+
|
424
|
+
it "sets the site ip" do
|
425
|
+
result = @account.set_site_ip(:ip => '192.1.2.3', :username => 'changeme')
|
426
|
+
result[:success].should be_true
|
427
|
+
result[:message].should match(/OK/i)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
describe "#restore" do
|
432
|
+
# 11.27/11.28+ only
|
433
|
+
use_vcr_cassette "whm/account/restoreaccount"
|
434
|
+
it "requires api.version" do
|
435
|
+
requires_attr('api.version') {
|
436
|
+
@account.restore_account(:username => 'changeme',
|
437
|
+
:type => 'monthly',
|
438
|
+
:all => false,
|
439
|
+
:ip => false,
|
440
|
+
:mail => false,
|
441
|
+
:mysql => false,
|
442
|
+
:subs => false)
|
443
|
+
}
|
444
|
+
end
|
445
|
+
|
446
|
+
it "requires a username" do
|
447
|
+
requires_attr('username') {
|
448
|
+
@account.restore_account("api.version".to_sym => 1,
|
449
|
+
:type => 'monthly',
|
450
|
+
:all => false,
|
451
|
+
:ip => false,
|
452
|
+
:mail => false,
|
453
|
+
:mysql => false,
|
454
|
+
:subs => false)
|
455
|
+
}
|
456
|
+
end
|
457
|
+
|
458
|
+
it "requires type" do
|
459
|
+
requires_attr('type') {
|
460
|
+
@account.restore_account("api.version".to_sym => 1,
|
461
|
+
:username => 'changeme',
|
462
|
+
:all => false,
|
463
|
+
:ip => false,
|
464
|
+
:mail => false,
|
465
|
+
:mysql => false,
|
466
|
+
:subs => false)
|
467
|
+
}
|
468
|
+
end
|
469
|
+
|
470
|
+
it "requires all" do
|
471
|
+
requires_attr('all') {
|
472
|
+
@account.restore_account("api.version".to_sym => 1,
|
473
|
+
:username => 'changeme',
|
474
|
+
:type => 'monthly',
|
475
|
+
:ip => false,
|
476
|
+
:mail => false,
|
477
|
+
:mysql => false,
|
478
|
+
:subs => false)
|
479
|
+
}
|
480
|
+
end
|
481
|
+
|
482
|
+
it "requires ip" do
|
483
|
+
requires_attr('ip') {
|
484
|
+
@account.restore_account("api.version".to_sym => 1,
|
485
|
+
:username => 'changeme',
|
486
|
+
:type => 'monthly',
|
487
|
+
:all => false,
|
488
|
+
:mail => false,
|
489
|
+
:mysql => false,
|
490
|
+
:subs => false)
|
491
|
+
}
|
492
|
+
end
|
493
|
+
|
494
|
+
it "requires mail" do
|
495
|
+
requires_attr('mail') { @account.restore_account("api.version".to_sym => 1,
|
496
|
+
:username => 'changeme',
|
497
|
+
:type => 'monthly',
|
498
|
+
:all => false,
|
499
|
+
:ip => false,
|
500
|
+
:mysql => false,
|
501
|
+
:subs => false)
|
502
|
+
}
|
503
|
+
end
|
504
|
+
|
505
|
+
it "requires mysql" do
|
506
|
+
requires_attr('mysql') { @account.restore_account("api.version".to_sym => 1,
|
507
|
+
:username => 'changeme',
|
508
|
+
:type => 'monthly',
|
509
|
+
:all => false,
|
510
|
+
:ip => false,
|
511
|
+
:mail => false,
|
512
|
+
:subs => false)
|
513
|
+
}
|
514
|
+
end
|
515
|
+
|
516
|
+
it "require subs" do
|
517
|
+
requires_attr('subs') { @account.restore_account("api.version".to_sym => 1,
|
518
|
+
:username => 'changeme',
|
519
|
+
:type => 'monthly',
|
520
|
+
:all => false,
|
521
|
+
:ip => false,
|
522
|
+
:mail => false,
|
523
|
+
:mysql => false)
|
524
|
+
}
|
525
|
+
end
|
526
|
+
|
527
|
+
it "returns an error if it can't find the backup" do
|
528
|
+
result = @account.restore_account("api.version".to_sym => 1,
|
529
|
+
:username => 'notexists',
|
530
|
+
:type => 'daily',
|
531
|
+
:all => false,
|
532
|
+
:ip => false,
|
533
|
+
:mail => false,
|
534
|
+
:mysql => false,
|
535
|
+
:subs => false)
|
536
|
+
result[:params][:result].to_i.should == 0
|
537
|
+
result[:params][:reason].should match(/Unable to find archive/i)
|
538
|
+
end
|
539
|
+
|
540
|
+
it "restores the account" do
|
541
|
+
result = @account.restore_account("api.version".to_sym => 1,
|
542
|
+
:username => 'changeme',
|
543
|
+
:type => 'daily',
|
544
|
+
:all => false,
|
545
|
+
:ip => false,
|
546
|
+
:mail => false,
|
547
|
+
:mysql => false,
|
548
|
+
:subs => false)
|
549
|
+
result[:params][:result].to_i.should == 1
|
550
|
+
result[:params][:reason].should == "OK"
|
551
|
+
result[:params][:output][:raw].should match(/Account Restore Complete/i)
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
describe "#verify_user" do
|
556
|
+
use_vcr_cassette "whm/account/accountsummary"
|
557
|
+
|
558
|
+
before(:each) { @something = double() }
|
559
|
+
|
560
|
+
it "does not call the block if the user doesn't exist" do
|
561
|
+
@something.should_not_receive(:gold)
|
562
|
+
expect {
|
563
|
+
@account.send(:verify_user, 'notexists') do
|
564
|
+
@something.gold
|
565
|
+
end
|
566
|
+
}.to raise_error(WhmInvalidUser)
|
567
|
+
end
|
568
|
+
|
569
|
+
it "calls the block if the user does exist" do
|
570
|
+
@something.should_receive(:gold)
|
571
|
+
@account.send(:verify_user, 'summary') do
|
572
|
+
@something.gold
|
573
|
+
end
|
574
|
+
end
|
575
|
+
end
|
576
|
+
end
|
577
|
+
end
|