lumberg 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. data/.gitignore +9 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +98 -0
  6. data/LICENSE +20 -0
  7. data/README.md +178 -0
  8. data/Rakefile +49 -0
  9. data/lib/cacert.pem +3910 -0
  10. data/lib/lumberg.rb +23 -0
  11. data/lib/lumberg/exceptions.rb +6 -0
  12. data/lib/lumberg/version.rb +3 -0
  13. data/lib/lumberg/whm.rb +70 -0
  14. data/lib/lumberg/whm/account.rb +329 -0
  15. data/lib/lumberg/whm/args.rb +113 -0
  16. data/lib/lumberg/whm/base.rb +28 -0
  17. data/lib/lumberg/whm/dns.rb +205 -0
  18. data/lib/lumberg/whm/reseller.rb +268 -0
  19. data/lib/lumberg/whm/server.rb +290 -0
  20. data/lib/net_http_hacked.rb +42 -0
  21. data/lumberg.gemspec +28 -0
  22. data/spec/lumberg_spec.rb +9 -0
  23. data/spec/spec_helper.rb +33 -0
  24. data/spec/vcr_cassettes/whm/account/accountsummary.yml +43 -0
  25. data/spec/vcr_cassettes/whm/account/changepackage.yml +64 -0
  26. data/spec/vcr_cassettes/whm/account/createacct.yml +43 -0
  27. data/spec/vcr_cassettes/whm/account/domainuserdata.yml +43 -0
  28. data/spec/vcr_cassettes/whm/account/editquota.yml +85 -0
  29. data/spec/vcr_cassettes/whm/account/limitbw.yml +85 -0
  30. data/spec/vcr_cassettes/whm/account/listaccts.yml +147 -0
  31. data/spec/vcr_cassettes/whm/account/listsuspended.yml +43 -0
  32. data/spec/vcr_cassettes/whm/account/modifyacct.yml +63 -0
  33. data/spec/vcr_cassettes/whm/account/myprivs.yml +43 -0
  34. data/spec/vcr_cassettes/whm/account/passwd.yml +43 -0
  35. data/spec/vcr_cassettes/whm/account/removeacct.yml +85 -0
  36. data/spec/vcr_cassettes/whm/account/restoreaccount.yml +198 -0
  37. data/spec/vcr_cassettes/whm/account/setsiteip.yml +190 -0
  38. data/spec/vcr_cassettes/whm/account/suspend.yml +64 -0
  39. data/spec/vcr_cassettes/whm/account/unsuspend.yml +43 -0
  40. data/spec/vcr_cassettes/whm/dns/adddns.yml +64 -0
  41. data/spec/vcr_cassettes/whm/dns/addzonerecord.yml +43 -0
  42. data/spec/vcr_cassettes/whm/dns/dumpzone.yml +43 -0
  43. data/spec/vcr_cassettes/whm/dns/editzonerecord.yml +64 -0
  44. data/spec/vcr_cassettes/whm/dns/getzonerecord.yml +64 -0
  45. data/spec/vcr_cassettes/whm/dns/killdns.yml +43 -0
  46. data/spec/vcr_cassettes/whm/dns/listmxs.yml +22 -0
  47. data/spec/vcr_cassettes/whm/dns/listzones.yml +22 -0
  48. data/spec/vcr_cassettes/whm/dns/lookupnsip.yml +43 -0
  49. data/spec/vcr_cassettes/whm/dns/removezonerecord.yml +64 -0
  50. data/spec/vcr_cassettes/whm/dns/resetzone.yml +43 -0
  51. data/spec/vcr_cassettes/whm/dns/resolvedomainname.yml +43 -0
  52. data/spec/vcr_cassettes/whm/dns/savemxs.yml +22 -0
  53. data/spec/vcr_cassettes/whm/reseller/acctcounts.yml +43 -0
  54. data/spec/vcr_cassettes/whm/reseller/listacls.yml +22 -0
  55. data/spec/vcr_cassettes/whm/reseller/listresellers.yml +22 -0
  56. data/spec/vcr_cassettes/whm/reseller/resellerstats.yml +43 -0
  57. data/spec/vcr_cassettes/whm/reseller/saveacllist.yml +85 -0
  58. data/spec/vcr_cassettes/whm/reseller/setacls.yml +43 -0
  59. data/spec/vcr_cassettes/whm/reseller/setresellerips.yml +42 -0
  60. data/spec/vcr_cassettes/whm/reseller/setresellerlimits.yml +43 -0
  61. data/spec/vcr_cassettes/whm/reseller/setresellermainip.yml +64 -0
  62. data/spec/vcr_cassettes/whm/reseller/setresellernameservers.yml +64 -0
  63. data/spec/vcr_cassettes/whm/reseller/setresellerpackagelimit.yml +64 -0
  64. data/spec/vcr_cassettes/whm/reseller/setupreseller.yml +43 -0
  65. data/spec/vcr_cassettes/whm/reseller/suspendreseller.yml +64 -0
  66. data/spec/vcr_cassettes/whm/reseller/terminatereseller.yml +64 -0
  67. data/spec/vcr_cassettes/whm/reseller/unsetupreseller.yml +43 -0
  68. data/spec/vcr_cassettes/whm/reseller/unsuspendreseller.yml +43 -0
  69. data/spec/vcr_cassettes/whm/server/applist.yml +22 -0
  70. data/spec/vcr_cassettes/whm/server/gethostname.yml +22 -0
  71. data/spec/vcr_cassettes/whm/server/getlanglist.yml +22 -0
  72. data/spec/vcr_cassettes/whm/server/loadavg.yml +28 -0
  73. data/spec/vcr_cassettes/whm/server/my_function.yml +64 -0
  74. data/spec/vcr_cassettes/whm/server/response_type.yml +85 -0
  75. data/spec/vcr_cassettes/whm/server/systemloadavg.yml +43 -0
  76. data/spec/vcr_cassettes/whm/server/version.yml +22 -0
  77. data/spec/whm/account_spec.rb +577 -0
  78. data/spec/whm/args_spec.rb +179 -0
  79. data/spec/whm/base_spec.rb +28 -0
  80. data/spec/whm/dns_spec.rb +352 -0
  81. data/spec/whm/reseller_spec.rb +359 -0
  82. data/spec/whm/server_spec.rb +288 -0
  83. data/spec/whm/whm_spec.rb +41 -0
  84. metadata +265 -0
@@ -0,0 +1,359 @@
1
+ require 'spec_helper'
2
+
3
+ module Lumberg
4
+ describe Whm::Reseller do
5
+ before(:each) do
6
+ @login = { :host => @whm_host, :hash => @whm_hash }
7
+ @whm = Whm::Server.new(@login.dup)
8
+ @reseller = Whm::Reseller.new(:server => @whm)
9
+ end
10
+
11
+ describe "#setup_reseller" do
12
+ use_vcr_cassette "whm/reseller/setupreseller"
13
+
14
+ it "requires username" do
15
+ requires_attr('username') { @reseller.create }
16
+ end
17
+
18
+ it "fails when the user doesn't exist" do
19
+ result = @reseller.create(:username => 'invalid')
20
+ result[:success].should be_false
21
+ result[:message].should match(/does not exist/i)
22
+ end
23
+
24
+ it "creates a reseller" do
25
+ result = @reseller.create(:username => 'bob')
26
+ result[:success].should be_true
27
+ end
28
+
29
+ it "accepts makeowner option" do
30
+ @reseller.server.should_receive(:perform_request).with('setupreseller', hash_including(:makeowner => true))
31
+ @reseller.create(:username => 'bob', :makeowner => true)
32
+ end
33
+ end
34
+
35
+ describe "#list" do
36
+ use_vcr_cassette "whm/reseller/listresellers"
37
+
38
+ it "lists all resellers" do
39
+ result = @reseller.list
40
+ result[:success].should be_true
41
+ result[:params][:resellers].should have(2).resellers
42
+ result[:params][:resellers].should include('bob', 'ted')
43
+ end
44
+ end
45
+
46
+ describe "#setresellerips" do
47
+ use_vcr_cassette "whm/reseller/setresellerips"
48
+
49
+ it "requires a username" do
50
+ requires_attr('username') { @reseller.add_ips }
51
+ end
52
+
53
+ it "adds the ip address to the reseller account" do
54
+ result = @reseller.add_ips(:username => 'bob', :ips =>'192.1.2.3')
55
+ result[:message].should match(/Successfully configured IP addresses delegation to reseller/i)
56
+ end
57
+
58
+ it "returns an error for invalid ip addresses" do
59
+ result = @reseller.add_ips(:username => 'bob', :ips =>'1.2.3.4')
60
+ result[:message].should match(/The list of supplied IP addresses contains inappropriate values/i)
61
+ end
62
+ end
63
+
64
+ describe "#setresellerlimits" do
65
+ use_vcr_cassette "whm/reseller/setresellerlimits"
66
+
67
+ it "requires a username" do
68
+ requires_attr('username') { @reseller.set_limits }
69
+ end
70
+
71
+ it "sets the limits" do
72
+ result = @reseller.set_limits(:username => 'bob', :diskspace_limit => 1024, :enable_overselling => true,
73
+ :enable_overselling_diskspace => true)
74
+ result[:success].should be_true
75
+ result[:message].should match(/Successfully set reseller account .*limits/i)
76
+ end
77
+ end
78
+
79
+ describe "#terminate" do
80
+ use_vcr_cassette "whm/reseller/terminatereseller"
81
+
82
+ it "requires a reseller" do
83
+ requires_attr('reseller') { @reseller.terminate }
84
+ end
85
+
86
+ it "terminates the reseller" do
87
+ result = @reseller.terminate(:reseller => 'terminat')
88
+ result[:success].should be_true
89
+ result[:message].should match(/account terminations complete/i)
90
+ result[:params][:accts].should be_empty
91
+ end
92
+
93
+ it "terminates the main account" do
94
+ result = @reseller.terminate(:reseller => 'terminat', :terminatereseller => true)
95
+ result[:success].should be_true
96
+ result[:message].should match(/account terminations complete/i)
97
+ result[:params][:accts][:terminat][:rawout].should match(/Account Removal Complete/i)
98
+ end
99
+
100
+ it "errors on non-existaet user" do
101
+ result = @reseller.terminate(:reseller => 'what')
102
+ result[:success].should be_false
103
+ result[:message].should match(/does not exist/i)
104
+ end
105
+
106
+ end
107
+
108
+ describe "#setresellermainip" do
109
+ use_vcr_cassette "whm/reseller/setresellermainip"
110
+
111
+ it "requires a username" do
112
+ requires_attr('username') { @reseller.set_main_ip(:ip => '192.1.2.3') }
113
+ end
114
+
115
+ it "requires an ip" do
116
+ requires_attr('ip') { @reseller.set_main_ip(:username => 'bob') }
117
+ end
118
+
119
+ it "sets the main ip" do
120
+ result = @reseller.set_main_ip(:username => 'bob', :ip => '192.1.2.3')
121
+ result[:success].should be_true
122
+ result[:message].should match(/Successfully set main IP address of the reseller/i)
123
+ end
124
+
125
+ it "returns an error when the IP is invalid" do
126
+ result = @reseller.set_main_ip(:username => 'bob', :ip => '10')
127
+ result[:success].should be_false
128
+ result[:message].should match(/Supplied IP address is invalid/)
129
+ end
130
+
131
+ it "returns an error when the user is invalid" do
132
+ result = @reseller.set_main_ip(:username => 'notexists', :ip => '192.1.2.3')
133
+ result[:success].should be_false
134
+ result[:message].should match(/Specified user is not a reseller/i)
135
+ end
136
+ end
137
+
138
+ describe "#setresellerpackagelimit" do
139
+ use_vcr_cassette "whm/reseller/setresellerpackagelimit"
140
+
141
+ it "requires a username" do
142
+ requires_attr('username') { @reseller.set_package_limit(:no_limit => true, :package => 'gold') }
143
+ end
144
+
145
+ it "requires no_limit" do
146
+ requires_attr('no_limit') { @reseller.set_package_limit(:username => 'bob', :package => 'gold') }
147
+ end
148
+
149
+ it "requires package" do
150
+ requires_attr('package') { @reseller.set_package_limit(:username => 'bob', :no_limit => true) }
151
+ end
152
+
153
+ it "sets the package limit" do
154
+ result = @reseller.set_package_limit(:username => 'bob', :no_limit => false, :package => 'gold', :allowed => true)
155
+ result[:success].should be_true
156
+ result[:message].should match(/Successfully set reseller package limit/i)
157
+ end
158
+
159
+ it "sets no limit" do
160
+ result = @reseller.set_package_limit(:username => 'bob', :no_limit => true, :package => 'gold')
161
+ result[:success].should be_true
162
+ result[:message].should match(/Successfully set reseller package limit/i)
163
+ end
164
+ end
165
+
166
+ describe "#suspendreseller" do
167
+ use_vcr_cassette "whm/reseller/suspendreseller"
168
+
169
+ it "requires a username" do
170
+ requires_attr('username') { @reseller.suspend }
171
+ end
172
+
173
+ it "suspends the reseller" do
174
+ result = @reseller.suspend(:username => 'bob')
175
+ result[:success].should be_true
176
+ result[:message].should match(/Finished suspending reseller/i)
177
+ end
178
+
179
+ it "can take a reason" do
180
+ result = @reseller.suspend(:username => 'bob', :reason => 'some reason')
181
+ result[:success].should be_true
182
+ result[:message].should match(/Finished suspending reseller/i)
183
+ end
184
+
185
+ it "returns an error when the user is invalid" do
186
+ result = @reseller.suspend(:username => 'notexists')
187
+ result[:success].should be_false
188
+ result[:message].should match(/Specified user is not a reseller/i)
189
+ end
190
+ end
191
+
192
+ describe "#unsuspendreseller" do
193
+ use_vcr_cassette "whm/reseller/unsuspendreseller"
194
+
195
+ it "requires a username" do
196
+ requires_attr('username') { @reseller.unsuspend }
197
+ end
198
+
199
+ it "should unsuspend the user" do
200
+ result = @reseller.unsuspend(:username => 'bob')
201
+ result[:success].should be_true
202
+ result[:message].should match(/Finished unsuspending reseller/i)
203
+ end
204
+
205
+ it "return an error when the user is invalid" do
206
+ result = @reseller.unsuspend(:username => 'notexists')
207
+ result[:success].should be_false
208
+ result[:message].should match(/Specified user is not a reseller/i)
209
+ end
210
+ end
211
+
212
+ describe "#acctcounts" do
213
+ use_vcr_cassette "whm/reseller/acctcounts"
214
+
215
+ it "requires a username" do
216
+ requires_attr('username') { @reseller.account_counts }
217
+ end
218
+
219
+ it "returns the account counts" do
220
+ result = @reseller.account_counts(:username => 'bob')
221
+ result[:success].should be_true
222
+ result[:message].should match(/Obtained reseller account counts/i)
223
+ result[:params][:account].should == "bob"
224
+ result[:params][:suspended].to_i.should == 0
225
+ result[:params][:active].to_i.should == 0
226
+ result[:params][:limit].should == ""
227
+ end
228
+
229
+ it "returns an error when the user is invalid" do
230
+ result = @reseller.account_counts(:username => 'notexists')
231
+ result[:success].should be_false
232
+ result[:message].should match(/Specified user is not a reseller/i)
233
+ end
234
+ end
235
+
236
+ describe "#setresellernameservers" do
237
+ use_vcr_cassette "whm/reseller/setresellernameservers"
238
+
239
+ it "requires a username" do
240
+ requires_attr('username') { @reseller.set_nameservers }
241
+ end
242
+
243
+ it "sets the default nameservers" do
244
+ result = @reseller.set_nameservers(:username => 'bob')
245
+ result[:success].should be_true
246
+ result[:message].should match(/Set resellers nameservers/i)
247
+ end
248
+
249
+ it "sets the specified nameservers" do
250
+ result = @reseller.set_nameservers(:username => 'bob', :nameservers => 'ns1.example.com')
251
+ result[:success].should be_true
252
+ result[:message].should match(/Set resellers nameservers/i)
253
+ end
254
+
255
+ it "returns an error for an invalid username" do
256
+ result = @reseller.account_counts(:username => 'notexists')
257
+ result[:success].should be_false
258
+ result[:message].should match(/Specified user is not a reseller/i)
259
+ end
260
+ end
261
+
262
+ describe "#resellerstats" do
263
+ use_vcr_cassette "whm/reseller/resellerstats"
264
+
265
+ it "requires a reseller" do
266
+ requires_attr('reseller') { @reseller.stats }
267
+ end
268
+
269
+ it "returns the stats of the reseller" do
270
+ result = @reseller.stats(:reseller => 'bob')
271
+ result[:success].should be_true
272
+ result[:message].should match(/Fetched Reseller Data OK/i)
273
+ result[:params][:diskquota].to_i.should == 0
274
+ result[:params][:diskoverselling].to_i.should == 1
275
+ result[:params][:bandwidthlimit].to_i.should == 0
276
+ end
277
+
278
+ it "returns an error for an invalid reseller" do
279
+ result = @reseller.stats(:reseller => 'notexists')
280
+ result[:success].should be_false
281
+ result[:message].should match(/Reseller Does Not Exist/i)
282
+ end
283
+ end
284
+
285
+ describe "#listacls" do
286
+ use_vcr_cassette "whm/reseller/listacls"
287
+
288
+ it "lists the saved reseller ACL lists" do
289
+ result = @reseller.list_acls
290
+ result[:params].size.should == 1
291
+ result[:params][:testacllist][:add_pkg].to_i.should == 1
292
+ result[:params][:testacllist][:add_pkg_ip].to_i.should == 1
293
+ result[:params][:testacllist][:edit_mx].to_i.should == 0
294
+ end
295
+ end
296
+
297
+ describe "#saveacllist" do
298
+ use_vcr_cassette "whm/reseller/saveacllist"
299
+
300
+ it "requires an acllist name" do
301
+ requires_attr('acllist') { @reseller.save_acl_list }
302
+ end
303
+
304
+ it "creates a new reseller ACL list" do
305
+ result = @reseller.save_acl_list(:acllist => 'testacllist')
306
+ result[:success].should be_true
307
+ result[:message].should match(/ACL List testacllist saved/i)
308
+ end
309
+
310
+ it "creates a new reseller ACL list with optional settings" do
311
+ result = @reseller.save_acl_list(:acllist => 'testacllist',
312
+ "acl-ssl".to_sym => true,
313
+ "acl-add-pkg".to_sym => true,
314
+ "acl-stats".to_sym => true)
315
+ result[:success].should be_true
316
+ result[:message].should match(/ACL List testacllist saved/i)
317
+ end
318
+ end
319
+
320
+ describe "#setacls" do
321
+ use_vcr_cassette "whm/reseller/setacls"
322
+
323
+ it "requires a reseller" do
324
+ requires_attr('reseller') { @reseller.set_acls }
325
+ end
326
+
327
+ it "sets the ACL for the reseller" do
328
+ result = @reseller.set_acls(:reseller => 'bob', :acllist => 'testacllist')
329
+ result[:success].should be_true
330
+ result[:message].should match(/Reseller Acls Saved/i)
331
+ end
332
+
333
+ it "returns an error for an invalid reseller" do
334
+ result = @reseller.set_acls(:reseller => 'notexists')
335
+ result[:success].should be_false
336
+ result[:message].should match(/Not a reseller/i)
337
+ end
338
+ end
339
+
340
+ describe "#unsetupreseller" do
341
+ use_vcr_cassette "whm/reseller/unsetupreseller"
342
+
343
+ it "requires a username" do
344
+ requires_attr('username') { @reseller.unsetup }
345
+ end
346
+
347
+ it "removes the reseller status from the user" do
348
+ result = @reseller.unsetup(:username => 'bob')
349
+ result[:success].should be_true
350
+ end
351
+
352
+ it "returns an error if the user does not exist" do
353
+ result = @reseller.unsetup(:username => 'notexists')
354
+ result[:success].should be_false
355
+ result[:message].should match(/called for a user that does not exist/i)
356
+ end
357
+ end
358
+ end
359
+ end
@@ -0,0 +1,288 @@
1
+ require 'spec_helper'
2
+
3
+ # Requests will need an "Authorization" header with
4
+ # WHM username:hash"
5
+ module Lumberg
6
+ describe Whm::Server do
7
+ before(:each) do
8
+ @login = { :host => @whm_host, :hash => @whm_hash }
9
+ @whm = Whm::Server.new(@login.dup)
10
+ @url_base = "https://myhost.com:2087/json-api"
11
+ end
12
+
13
+ context "Setting up the server host, username, url, and hash" do
14
+ it "should setup host and hash" do
15
+ @whm.hash.should == @login[:hash]
16
+ @whm.host.should == @login[:host]
17
+ end
18
+
19
+ it "should set the url" do
20
+ @whm.base_url.should == "https://#{@login[:host]}:2087/json-api/"
21
+ end
22
+
23
+ it "should default to 'root' as the username" do
24
+ @whm.user.should == 'root'
25
+ end
26
+
27
+ it "should allow setting of the username" do
28
+ @whm = Whm::Server.new(@login.merge(:user => 'bob'))
29
+ @whm.user.should == 'bob'
30
+ end
31
+ end
32
+
33
+ describe "#format_url" do
34
+ it "converts the host into an SSL URL by default" do
35
+ @whm.send(:format_url).should == "https://myhost.com:2087/json-api/"
36
+ end
37
+
38
+ it "converts the host into an SSL URL when asked" do
39
+ @whm = Whm::Server.new(@login.dup.merge(:ssl => true))
40
+ @whm.send(:format_url).should == "https://myhost.com:2087/json-api/"
41
+ end
42
+
43
+ it "converts the host into a non SSL URL when asked" do
44
+ @whm = Whm::Server.new(@login.dup.merge(:ssl => false))
45
+ @whm.send(:format_url).should == "http://myhost.com:2086/json-api/"
46
+ end
47
+ end
48
+
49
+ describe "#format_hash" do
50
+ it "raises an error if hash is not a string" do
51
+ expect{ Whm::Server.new(:host => @whm_host, :hash => nil) }.to
52
+ raise_error(Lumberg::WhmArgumentError, "Missing WHM hash")
53
+ end
54
+
55
+ it "removes \\n's from the hash" do
56
+ hash = "my\nhash\n\n\n\n"
57
+ @whm = Whm::Server.new(:host => @whm_host, :hash => hash)
58
+ @whm.hash.should == 'myhash'
59
+ end
60
+
61
+ it "removes whitespace from the hash" do
62
+ hash = " my hash "
63
+ @whm = Whm::Server.new(:host => @whm_host, :hash => hash)
64
+ @whm.hash.should == 'myhash'
65
+ end
66
+ end
67
+
68
+ describe "#perform_request" do
69
+ # These tests are skipped when running against
70
+ # a real WHM server
71
+ unless live_test?
72
+ describe "my_function" do
73
+ use_vcr_cassette "whm/server/my_function"
74
+
75
+ it "calls the proper URL" do
76
+ JSON.should_receive(:parse).with("[]").and_return([])
77
+ @whm.perform_request('my_function')
78
+ @whm.function.should == 'my_function'
79
+ @whm.params.should be_empty
80
+ @whm.raw_response.should be_a(Net::HTTPOK)
81
+ end
82
+
83
+ it "calls the proper URL and arguments" do
84
+ JSON.should_receive(:parse).with("[]").and_return([])
85
+ @whm.perform_request('my_function', :arg1 => 1, :arg2 => 'test')
86
+ @whm.function.should == 'my_function'
87
+ @whm.params.should == "arg1=1&arg2=test"
88
+ @whm.raw_response.should be_a(Net::HTTPOK)
89
+ end
90
+
91
+ it "changes params to booleans when given a block" do
92
+ req = @whm.perform_request('my_function', :block => 1) do |p|
93
+ p.boolean_params = :true, :false
94
+ end
95
+
96
+ @whm.boolean_params.should include(:true, :false)
97
+ req[:params].should include(:true => true, :false => false, :other => 2)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "@ssl_verify" do
103
+ it "does not verify SSL certs for HTTP requests by default" do
104
+ @whm.ssl_verify.should be(false)
105
+ end
106
+
107
+ it "verifies SSL certs for HTTP requests when asked" do
108
+ @whm.ssl_verify = true
109
+ @whm.ssl_verify.should be(true)
110
+ end
111
+
112
+ it "does not verify SSL certs for HTTP requests when asked" do
113
+ @whm.ssl_verify = false
114
+ @whm.ssl_verify.should be(false)
115
+ end
116
+ end
117
+
118
+ context "calling applist" do
119
+ use_vcr_cassette "whm/server/applist"
120
+
121
+ it "sets a response message" do
122
+ @whm = Whm::Server.new(:host => @whm_host, :hash => @whm_hash)
123
+ @whm.perform_request('applist')
124
+ @whm.function.should == 'applist'
125
+ end
126
+ end
127
+ end
128
+
129
+ describe "#response_type" do
130
+
131
+ use_vcr_cassette "whm/server/response_type"
132
+
133
+ it "detects an action function" do
134
+ @whm.perform_request('testing')
135
+ @whm.send(:response_type).should == :action
136
+ end
137
+
138
+ it "detects an error function" do
139
+ @whm.perform_request('testing_error')
140
+ @whm.send(:response_type).should == :error
141
+ end
142
+
143
+ it "detects a query function" do
144
+ @whm.perform_request('testing_query')
145
+ @whm.send(:response_type).should == :query
146
+ end
147
+
148
+ it "detects an unknown function" do
149
+ @whm.perform_request('testing_unknown')
150
+ @whm.send(:response_type).should == :unknown
151
+ end
152
+
153
+ it "forces response type" do
154
+ @whm.force_response_type = :magic
155
+ @whm.send(:response_type).should == :magic
156
+ @whm.perform_request('testing')
157
+ end
158
+
159
+ it "resets response_type each request" do
160
+ @whm.force_response_type.should be_nil
161
+ @whm.force_response_type = :magic
162
+ @whm.send(:response_type).should == :magic
163
+
164
+ @whm.force_response_type = :magic
165
+ @whm.perform_request('testing')
166
+ @whm.force_response_type.should be_nil
167
+ end
168
+
169
+
170
+ it "returns true for a successful :action" do
171
+ @whm.perform_request('testing')
172
+ response = @whm.send(:format_response)
173
+ response[:success].should be(true)
174
+ end
175
+
176
+ it "returns true for a successful :query" do
177
+ @whm.perform_request('testing_query')
178
+ response = @whm.send(:format_response)
179
+ response[:success].should be(true)
180
+ response[:params].should have_key(:acct)
181
+ end
182
+
183
+ it "returns false on :error" do
184
+ @whm.perform_request('testing_error')
185
+ response = @whm.send(:format_response)
186
+ response[:success].should be(false)
187
+ response[:message].should match(/Unknown App Req/)
188
+ end
189
+
190
+ it "returns false on :unknown" do
191
+ @whm.perform_request('testing_unknown')
192
+ response = @whm.send(:format_response)
193
+ response[:success].should be(false)
194
+ response[:message].should match(/Unknown error occurred .*wtf.*/)
195
+ end
196
+ end
197
+
198
+ describe "#gethostname" do
199
+ use_vcr_cassette "whm/server/gethostname"
200
+
201
+ it "returns the hostname" do
202
+ result = @whm.get_hostname
203
+ result[:success].should be_true
204
+ result[:params][:hostname].should == "myhost.com"
205
+ end
206
+ end
207
+
208
+ describe "#version" do
209
+ use_vcr_cassette "whm/server/version"
210
+
211
+ it "returns the version of cPanel and WHM" do
212
+ result = @whm.version
213
+ result[:success].should be_true
214
+ result[:params][:version].should == "11.28.64"
215
+ end
216
+ end
217
+
218
+ describe "#loadavg" do
219
+ use_vcr_cassette "whm/server/loadavg"
220
+
221
+ it "returns the server's load average" do
222
+ result = @whm.load_average
223
+ result[:success].should be_true
224
+ result[:params].should include(:one, :five, :fifteen)
225
+ end
226
+ end
227
+
228
+ describe "#systemloadavg" do
229
+ use_vcr_cassette "whm/server/systemloadavg"
230
+
231
+ it "returns the server's load average with metadata" do
232
+ result = @whm.system_load_average("api.version".to_sym => 1)
233
+ result[:params][:one].should == "0.00"
234
+ result[:params][:five].should == "0.04"
235
+ result[:params][:fifteen].should == "0.01"
236
+ end
237
+ end
238
+
239
+ describe "#getlanglist" do
240
+ use_vcr_cassette "whm/server/getlanglist"
241
+
242
+ it "returns the list of languages" do
243
+ result = @whm.languages
244
+ result[:params].size.to_i.should == 19
245
+ result[:params].should include "english"
246
+ end
247
+ end
248
+
249
+ describe "#account" do
250
+ it "has an account accessor" do
251
+ @whm.account.should be_an(Whm::Account)
252
+ end
253
+
254
+ it "returns the same thing twice" do
255
+ @whm.account.should be_a(Whm::Account)
256
+ @whm.account.should respond_to(:list)
257
+
258
+ @whm.account.should be_a(Whm::Account)
259
+ @whm.account.should respond_to(:list)
260
+ end
261
+
262
+ end
263
+
264
+ describe "#dns" do
265
+ it "has an dns accessor" do
266
+ @whm.dns.should be_an(Whm::Dns)
267
+ end
268
+ end
269
+
270
+ describe "#reseller" do
271
+ it "has an reseller accessor" do
272
+ @whm.reseller.should be_an(Whm::Reseller)
273
+ end
274
+ end
275
+
276
+ describe "#method_missing" do
277
+ it "caches @vars" do
278
+ Whm.should_receive(:const_get).once.and_return(Whm::Account)
279
+ @whm.account
280
+ @whm.account
281
+ end
282
+
283
+ it "raises to super" do
284
+ expect { @whm.asdf }.to raise_error(NoMethodError)
285
+ end
286
+ end
287
+ end
288
+ end