lumberg 1.0.1 → 2.0.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (248) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +8 -7
  3. data/LICENSE +1 -1
  4. data/README.md +130 -23
  5. data/Rakefile +3 -1
  6. data/lib/lumberg/config.rb +19 -0
  7. data/lib/lumberg/cpanel/addon_domain.rb +50 -0
  8. data/lib/lumberg/cpanel/backups.rb +16 -0
  9. data/lib/lumberg/cpanel/base.rb +56 -0
  10. data/lib/lumberg/cpanel/box_trapper.rb +18 -0
  11. data/lib/lumberg/cpanel/branding.rb +89 -0
  12. data/lib/lumberg/cpanel/contact.rb +38 -0
  13. data/lib/lumberg/cpanel/cron.rb +89 -0
  14. data/lib/lumberg/cpanel/dns_lookup.rb +23 -0
  15. data/lib/lumberg/cpanel/domain_keys.rb +37 -0
  16. data/lib/lumberg/cpanel/domain_lookup.rb +71 -0
  17. data/lib/lumberg/cpanel/email.rb +491 -0
  18. data/lib/lumberg/cpanel/file_manager.rb +146 -0
  19. data/lib/lumberg/cpanel/gpg.rb +36 -0
  20. data/lib/lumberg/cpanel/locale.rb +15 -0
  21. data/lib/lumberg/cpanel/mime.rb +34 -0
  22. data/lib/lumberg/cpanel/mysql.rb +66 -0
  23. data/lib/lumberg/cpanel/net.rb +28 -0
  24. data/lib/lumberg/cpanel/park.rb +58 -0
  25. data/lib/lumberg/cpanel/password.rb +52 -0
  26. data/lib/lumberg/cpanel/random_data.rb +25 -0
  27. data/lib/lumberg/cpanel/redirect.rb +44 -0
  28. data/lib/lumberg/cpanel/ssl.rb +206 -0
  29. data/lib/lumberg/cpanel/sub_domain.rb +61 -0
  30. data/lib/lumberg/cpanel/support.rb +29 -0
  31. data/lib/lumberg/cpanel/zone_edit.rb +134 -0
  32. data/lib/lumberg/cpanel.rb +29 -0
  33. data/lib/lumberg/format_whm.rb +125 -0
  34. data/lib/lumberg/version.rb +1 -1
  35. data/lib/lumberg/whm/account.rb +28 -105
  36. data/lib/lumberg/whm/base.rb +3 -7
  37. data/lib/lumberg/whm/cert.rb +76 -0
  38. data/lib/lumberg/whm/dns.rb +49 -77
  39. data/lib/lumberg/whm/reseller.rb +24 -117
  40. data/lib/lumberg/whm/server.rb +111 -230
  41. data/lib/lumberg/whm.rb +2 -1
  42. data/lib/lumberg.rb +34 -8
  43. data/lumberg.gemspec +7 -4
  44. data/spec/config_spec.rb +28 -0
  45. data/spec/cpanel/addon_domain_spec.rb +84 -0
  46. data/spec/cpanel/backups_spec.rb +22 -0
  47. data/spec/cpanel/base_spec.rb +128 -0
  48. data/spec/cpanel/box_trapper_spec.rb +22 -0
  49. data/spec/cpanel/branding_spec.rb +46 -0
  50. data/spec/cpanel/contact_spec.rb +50 -0
  51. data/spec/cpanel/cron_spec.rb +161 -0
  52. data/spec/cpanel/dns_lookup_spec.rb +22 -0
  53. data/spec/cpanel/domain_keys_spec.rb +46 -0
  54. data/spec/cpanel/domain_lookup_spec.rb +77 -0
  55. data/spec/cpanel/email_spec.rb +615 -0
  56. data/spec/cpanel/file_manager_spec.rb +73 -0
  57. data/spec/cpanel/gpg_spec.rb +48 -0
  58. data/spec/cpanel/locale_spec.rb +23 -0
  59. data/spec/cpanel/mime_spec.rb +0 -0
  60. data/spec/cpanel/mysql_spec.rb +0 -0
  61. data/spec/cpanel/net_spec.rb +30 -0
  62. data/spec/cpanel/park_spec.rb +94 -0
  63. data/spec/cpanel/password_spec.rb +35 -0
  64. data/spec/cpanel/random_data_spec.rb +24 -0
  65. data/spec/cpanel/redirect_spec.rb +0 -0
  66. data/spec/cpanel/ssl_spec.rb +148 -0
  67. data/spec/cpanel/sub_domain_spec.rb +72 -0
  68. data/spec/cpanel/support_spec.rb +38 -0
  69. data/spec/cpanel/zone_edit_spec.rb +0 -0
  70. data/spec/sample_certs/cpanel.crt +28 -0
  71. data/spec/sample_certs/cpanel.key +28 -0
  72. data/spec/sample_certs/main.crt +27 -0
  73. data/spec/sample_certs/sample.crt +26 -0
  74. data/spec/sample_certs/sample.key +27 -0
  75. data/spec/spec_helper.rb +9 -3
  76. data/spec/support/cpanel_matchers.rb +17 -0
  77. data/spec/vcr_cassettes/cpanel/addon_domain/add.yml +77 -0
  78. data/spec/vcr_cassettes/cpanel/addon_domain/list.yml +77 -0
  79. data/spec/vcr_cassettes/cpanel/addon_domain/remove.yml +77 -0
  80. data/spec/vcr_cassettes/cpanel/backups/list.yml +40 -0
  81. data/spec/vcr_cassettes/cpanel/box_trapper/list.yml +40 -0
  82. data/spec/vcr_cassettes/cpanel/branding/list_icons.yml +40 -0
  83. data/spec/vcr_cassettes/cpanel/branding/list_image_types.yml +40 -0
  84. data/spec/vcr_cassettes/cpanel/branding/list_object_types.yml +40 -0
  85. data/spec/vcr_cassettes/cpanel/branding/list_pkgs.yml +40 -0
  86. data/spec/vcr_cassettes/cpanel/branding/list_sprites.yml +40 -0
  87. data/spec/vcr_cassettes/cpanel/contact/show.yml +40 -0
  88. data/spec/vcr_cassettes/cpanel/contact/update.yml +40 -0
  89. data/spec/vcr_cassettes/cpanel/cron/add.yml +77 -0
  90. data/spec/vcr_cassettes/cpanel/cron/edit.yml +114 -0
  91. data/spec/vcr_cassettes/cpanel/cron/email.yml +77 -0
  92. data/spec/vcr_cassettes/cpanel/cron/list.yml +77 -0
  93. data/spec/vcr_cassettes/cpanel/cron/remove.yml +151 -0
  94. data/spec/vcr_cassettes/cpanel/cron/set_email.yml +77 -0
  95. data/spec/vcr_cassettes/cpanel/dns_lookup/name_to_ip.yml +40 -0
  96. data/spec/vcr_cassettes/cpanel/domain_keys/add.yml +40 -0
  97. data/spec/vcr_cassettes/cpanel/domain_keys/available.yml +40 -0
  98. data/spec/vcr_cassettes/cpanel/domain_keys/installed.yml +40 -0
  99. data/spec/vcr_cassettes/cpanel/domain_keys/remove.yml +40 -0
  100. data/spec/vcr_cassettes/cpanel/domain_lookup/count.yml +40 -0
  101. data/spec/vcr_cassettes/cpanel/domain_lookup/docroot.yml +40 -0
  102. data/spec/vcr_cassettes/cpanel/domain_lookup/docroots.yml +40 -0
  103. data/spec/vcr_cassettes/cpanel/domain_lookup/document_root.yml +40 -0
  104. data/spec/vcr_cassettes/cpanel/domain_lookup/document_roots.yml +40 -0
  105. data/spec/vcr_cassettes/cpanel/domain_lookup/list.yml +40 -0
  106. data/spec/vcr_cassettes/cpanel/email/acceptable_encodings.yml +40 -0
  107. data/spec/vcr_cassettes/cpanel/email/accounts.yml +188 -0
  108. data/spec/vcr_cassettes/cpanel/email/add_account.yml +77 -0
  109. data/spec/vcr_cassettes/cpanel/email/add_filter.yml +77 -0
  110. data/spec/vcr_cassettes/cpanel/email/add_forwarder.yml +77 -0
  111. data/spec/vcr_cassettes/cpanel/email/add_mailing_list.yml +73 -0
  112. data/spec/vcr_cassettes/cpanel/email/add_mx.yml +40 -0
  113. data/spec/vcr_cassettes/cpanel/email/change_mx.yml +40 -0
  114. data/spec/vcr_cassettes/cpanel/email/check_local_delivery_local.yml +77 -0
  115. data/spec/vcr_cassettes/cpanel/email/check_local_delivery_remote.yml +77 -0
  116. data/spec/vcr_cassettes/cpanel/email/default_address.yml +40 -0
  117. data/spec/vcr_cassettes/cpanel/email/delete_mx.yml +40 -0
  118. data/spec/vcr_cassettes/cpanel/email/disk_usage.yml +77 -0
  119. data/spec/vcr_cassettes/cpanel/email/domains.yml +40 -0
  120. data/spec/vcr_cassettes/cpanel/email/domains_with_aliases.yml +77 -0
  121. data/spec/vcr_cassettes/cpanel/email/edit_quota.yml +112 -0
  122. data/spec/vcr_cassettes/cpanel/email/filters.yml +114 -0
  123. data/spec/vcr_cassettes/cpanel/email/forwarders.yml +77 -0
  124. data/spec/vcr_cassettes/cpanel/email/mail_dir.yml +77 -0
  125. data/spec/vcr_cassettes/cpanel/email/mail_dirs.yml +77 -0
  126. data/spec/vcr_cassettes/cpanel/email/mailing_lists.yml +73 -0
  127. data/spec/vcr_cassettes/cpanel/email/main_discard.yml +40 -0
  128. data/spec/vcr_cassettes/cpanel/email/mx.yml +40 -0
  129. data/spec/vcr_cassettes/cpanel/email/remove.yml +77 -0
  130. data/spec/vcr_cassettes/cpanel/email/set_mail_delivery_local.yml +77 -0
  131. data/spec/vcr_cassettes/cpanel/email/set_mail_delivery_remote.yml +77 -0
  132. data/spec/vcr_cassettes/cpanel/email/set_mx_type.yml +40 -0
  133. data/spec/vcr_cassettes/cpanel/file_manager/disk_usage.yml +38 -0
  134. data/spec/vcr_cassettes/cpanel/file_manager/list.yml +38 -0
  135. data/spec/vcr_cassettes/cpanel/file_manager/operate.yml +77 -0
  136. data/spec/vcr_cassettes/cpanel/file_manager/show.yml +40 -0
  137. data/spec/vcr_cassettes/cpanel/file_manager/stat.yml +38 -0
  138. data/spec/vcr_cassettes/cpanel/gpg/count.yml +40 -0
  139. data/spec/vcr_cassettes/cpanel/gpg/count_private.yml +40 -0
  140. data/spec/vcr_cassettes/cpanel/gpg/list.yml +40 -0
  141. data/spec/vcr_cassettes/cpanel/gpg/list_private.yml +40 -0
  142. data/spec/vcr_cassettes/cpanel/locale/show.yml +40 -0
  143. data/spec/vcr_cassettes/cpanel/net/query_hostname.yml +40 -0
  144. data/spec/vcr_cassettes/cpanel/net/traceroute.yml +40 -0
  145. data/spec/vcr_cassettes/cpanel/park/add.yml +77 -0
  146. data/spec/vcr_cassettes/cpanel/park/list.yml +77 -0
  147. data/spec/vcr_cassettes/cpanel/park/list_addon_domains.yml +77 -0
  148. data/spec/vcr_cassettes/cpanel/park/remove.yml +77 -0
  149. data/spec/vcr_cassettes/cpanel/password/digest_authentication.yml +77 -0
  150. data/spec/vcr_cassettes/cpanel/password/modify.yml +77 -0
  151. data/spec/vcr_cassettes/cpanel/random_data/show.yml +40 -0
  152. data/spec/vcr_cassettes/cpanel/ssl/fetchcabundle.yml +40 -0
  153. data/spec/vcr_cassettes/cpanel/ssl/gencrt.yml +43 -0
  154. data/spec/vcr_cassettes/cpanel/ssl/gencsr.yml +43 -0
  155. data/spec/vcr_cassettes/cpanel/ssl/genkey.yml +40 -0
  156. data/spec/vcr_cassettes/cpanel/ssl/installssl.yml +40 -0
  157. data/spec/vcr_cassettes/cpanel/ssl/listcrts.yml +40 -0
  158. data/spec/vcr_cassettes/cpanel/ssl/listcsrs.yml +40 -0
  159. data/spec/vcr_cassettes/cpanel/ssl/listkeys.yml +40 -0
  160. data/spec/vcr_cassettes/cpanel/ssl/listsslitems.yml +40 -0
  161. data/spec/vcr_cassettes/cpanel/ssl/showcrt.yml +38 -0
  162. data/spec/vcr_cassettes/cpanel/ssl/showcsr.yml +38 -0
  163. data/spec/vcr_cassettes/cpanel/ssl/showkey.yml +38 -0
  164. data/spec/vcr_cassettes/cpanel/ssl/uploadcrt.yml +40 -0
  165. data/spec/vcr_cassettes/cpanel/sub_domain/add.yml +77 -0
  166. data/spec/vcr_cassettes/cpanel/sub_domain/list.yml +77 -0
  167. data/spec/vcr_cassettes/cpanel/sub_domain/remove.yml +77 -0
  168. data/spec/vcr_cassettes/cpanel/support/contactable.yml +40 -0
  169. data/spec/vcr_cassettes/whm/account/accountsummary.yml +41 -29
  170. data/spec/vcr_cassettes/whm/account/changepackage.yml +73 -43
  171. data/spec/vcr_cassettes/whm/account/createacct.yml +101 -31
  172. data/spec/vcr_cassettes/whm/account/domainuserdata.yml +43 -29
  173. data/spec/vcr_cassettes/whm/account/editquota.yml +78 -57
  174. data/spec/vcr_cassettes/whm/account/limitbw.yml +79 -57
  175. data/spec/vcr_cassettes/whm/account/listaccts.yml +195 -100
  176. data/spec/vcr_cassettes/whm/account/listsuspended.yml +41 -29
  177. data/spec/vcr_cassettes/whm/account/modifyacct.yml +61 -42
  178. data/spec/vcr_cassettes/whm/account/myprivs.yml +41 -29
  179. data/spec/vcr_cassettes/whm/account/passwd.yml +44 -29
  180. data/spec/vcr_cassettes/whm/account/removeacct.yml +134 -57
  181. data/spec/vcr_cassettes/whm/account/restoreaccount.yml +310 -135
  182. data/spec/vcr_cassettes/whm/account/setsiteip.yml +166 -127
  183. data/spec/vcr_cassettes/whm/account/suspend.yml +75 -43
  184. data/spec/vcr_cassettes/whm/account/unsuspend.yml +46 -29
  185. data/spec/vcr_cassettes/whm/cert/fetchsslinfo.yml +38 -0
  186. data/spec/vcr_cassettes/whm/cert/generatessl.yml +94 -0
  187. data/spec/vcr_cassettes/whm/cert/installssl.yml +38 -0
  188. data/spec/vcr_cassettes/whm/cert/listcrts.yml +38 -0
  189. data/spec/vcr_cassettes/whm/dns/adddns.yml +61 -43
  190. data/spec/vcr_cassettes/whm/dns/addzonerecord.yml +42 -29
  191. data/spec/vcr_cassettes/whm/dns/dumpzone.yml +44 -29
  192. data/spec/vcr_cassettes/whm/dns/editzonerecord.yml +61 -43
  193. data/spec/vcr_cassettes/whm/dns/getzonerecord.yml +60 -43
  194. data/spec/vcr_cassettes/whm/dns/killdns.yml +42 -29
  195. data/spec/vcr_cassettes/whm/dns/listmxs.yml +23 -15
  196. data/spec/vcr_cassettes/whm/dns/listzones.yml +22 -15
  197. data/spec/vcr_cassettes/whm/dns/lookupnsip.yml +40 -29
  198. data/spec/vcr_cassettes/whm/dns/removezonerecord.yml +61 -43
  199. data/spec/vcr_cassettes/whm/dns/resetzone.yml +42 -29
  200. data/spec/vcr_cassettes/whm/dns/resolvedomainname.yml +40 -29
  201. data/spec/vcr_cassettes/whm/dns/savemxs.yml +23 -15
  202. data/spec/vcr_cassettes/whm/reseller/acctcounts.yml +41 -29
  203. data/spec/vcr_cassettes/whm/reseller/listacls.yml +22 -15
  204. data/spec/vcr_cassettes/whm/reseller/listresellers.yml +22 -15
  205. data/spec/vcr_cassettes/whm/reseller/resellerstats.yml +42 -29
  206. data/spec/vcr_cassettes/whm/reseller/saveacllist.yml +76 -57
  207. data/spec/vcr_cassettes/whm/reseller/setacls.yml +40 -29
  208. data/spec/vcr_cassettes/whm/reseller/setresellerips.yml +42 -28
  209. data/spec/vcr_cassettes/whm/reseller/setresellerlimits.yml +41 -29
  210. data/spec/vcr_cassettes/whm/reseller/setresellermainip.yml +59 -43
  211. data/spec/vcr_cassettes/whm/reseller/setresellernameservers.yml +58 -43
  212. data/spec/vcr_cassettes/whm/reseller/setresellerpackagelimit.yml +61 -43
  213. data/spec/vcr_cassettes/whm/reseller/setupreseller.yml +41 -29
  214. data/spec/vcr_cassettes/whm/reseller/suspendreseller.yml +75 -44
  215. data/spec/vcr_cassettes/whm/reseller/terminatereseller.yml +83 -46
  216. data/spec/vcr_cassettes/whm/reseller/unsetupreseller.yml +41 -29
  217. data/spec/vcr_cassettes/whm/reseller/unsuspendreseller.yml +46 -29
  218. data/spec/vcr_cassettes/whm/server/addip.yml +24 -15
  219. data/spec/vcr_cassettes/whm/server/applist.yml +22 -15
  220. data/spec/vcr_cassettes/whm/server/delip.yml +23 -15
  221. data/spec/vcr_cassettes/whm/server/gethostname.yml +22 -15
  222. data/spec/vcr_cassettes/whm/server/getlanglist.yml +22 -15
  223. data/spec/vcr_cassettes/whm/server/gettweaksetting.yml +44 -0
  224. data/spec/vcr_cassettes/whm/server/listips.yml +22 -15
  225. data/spec/vcr_cassettes/whm/server/loadavg.yml +26 -19
  226. data/spec/vcr_cassettes/whm/server/my_function.yml +59 -43
  227. data/spec/vcr_cassettes/whm/server/nvget.yml +22 -15
  228. data/spec/vcr_cassettes/whm/server/nvset.yml +22 -15
  229. data/spec/vcr_cassettes/whm/server/reboot.yml +22 -15
  230. data/spec/vcr_cassettes/whm/server/sethostname.yml +24 -15
  231. data/spec/vcr_cassettes/whm/server/setresolvers.yml +23 -15
  232. data/spec/vcr_cassettes/whm/server/settweaksetting.yml +44 -0
  233. data/spec/vcr_cassettes/whm/server/showbw.yml +22 -15
  234. data/spec/vcr_cassettes/whm/server/systemloadavg.yml +40 -29
  235. data/spec/vcr_cassettes/whm/server/themes.yml +38 -0
  236. data/spec/vcr_cassettes/whm/server/version.yml +22 -15
  237. data/spec/whm/account_spec.rb +40 -199
  238. data/spec/whm/base_spec.rb +0 -4
  239. data/spec/whm/cert_spec.rb +99 -0
  240. data/spec/whm/dns_spec.rb +5 -123
  241. data/spec/whm/reseller_spec.rb +11 -79
  242. data/spec/whm/server_spec.rb +85 -142
  243. metadata +367 -47
  244. data/.rvmrc +0 -49
  245. data/lib/lumberg/whm/args.rb +0 -113
  246. data/lib/net_http_hacked.rb +0 -42
  247. data/spec/vcr_cassettes/whm/server/response_type.yml +0 -85
  248. data/spec/whm/args_spec.rb +0 -179
@@ -16,7 +16,7 @@ module Lumberg
16
16
  @whm.host.should == @login[:host]
17
17
  end
18
18
 
19
- it "should set the url" do
19
+ it "sets the url" do
20
20
  @whm.base_url.should == "https://#{@login[:host]}:2087/json-api/"
21
21
  end
22
22
 
@@ -37,6 +37,23 @@ module Lumberg
37
37
  @whm = Whm::Server.new(@login.merge(:basic_auth => true))
38
38
  @whm.basic_auth.should be_true
39
39
  end
40
+
41
+ it "raises message for invalid domain" do
42
+ Resolv.stub(:getaddress).and_raise(Resolv::ResolvError)
43
+ expect do
44
+ Whm::Server.new(:host => "nxdomain.tld", :hash => "")
45
+ end.to raise_error(
46
+ Lumberg::WhmArgumentError, "Unable to resolve nxdomain.tld"
47
+ )
48
+ end
49
+ end
50
+
51
+ describe "setting timeout" do
52
+ it "allows setting of timeout" do
53
+ Whm::Server.new(
54
+ @login.merge(:timeout => 1000)
55
+ ).timeout.should == 1000
56
+ end
40
57
  end
41
58
 
42
59
  describe "#format_url" do
@@ -57,8 +74,8 @@ module Lumberg
57
74
 
58
75
  describe "#format_hash" do
59
76
  it "raises an error if hash is not a string" do
60
- expect{ Whm::Server.new(:host => @whm_host, :hash => nil) }.to
61
- raise_error(Lumberg::WhmArgumentError, "Missing WHM hash")
77
+ expect{ Whm::Server.new(:host => @whm_host, :hash => nil) }.
78
+ to raise_error(Lumberg::WhmArgumentError, "Missing WHM hash")
62
79
  end
63
80
 
64
81
  it "removes \\n's from the hash" do
@@ -86,25 +103,22 @@ module Lumberg
86
103
  @whm.perform_request('my_function')
87
104
  @whm.function.should == 'my_function'
88
105
  @whm.params.should be_empty
89
- @whm.raw_response.should be_a(Net::HTTPOK)
90
106
  end
91
107
 
92
108
  it "calls the proper URL and arguments" do
93
109
  JSON.should_receive(:parse).with("[]").and_return([])
94
110
  @whm.perform_request('my_function', :arg1 => 1, :arg2 => 'test')
95
111
  @whm.function.should == 'my_function'
96
- @whm.params.should == "arg1=1&arg2=test"
97
- @whm.raw_response.should be_a(Net::HTTPOK)
112
+ @whm.params.should == {:arg1 => 1, :arg2 => 'test'}
98
113
  end
99
114
 
100
115
  it "changes params to booleans when given a block" do
101
116
  req = @whm.perform_request('my_function', :block => 1) do |p|
102
117
  p.boolean_params = :true, :false
103
118
  end
104
-
105
- @whm.boolean_params.should include(:true, :false)
106
119
  req[:params].should include(:true => true, :false => false, :other => 2)
107
120
  end
121
+
108
122
  end
109
123
  end
110
124
 
@@ -124,83 +138,46 @@ module Lumberg
124
138
  end
125
139
  end
126
140
 
127
- context "calling applist" do
128
- use_vcr_cassette "whm/server/applist"
129
-
130
- it "sets a response message" do
131
- @whm = Whm::Server.new(:host => @whm_host, :hash => @whm_hash)
132
- @whm.perform_request('applist')
133
- @whm.function.should == 'applist'
141
+ describe "@timeout" do
142
+ it "is nil by default" do
143
+ @whm.timeout.should be_nil
134
144
  end
135
- end
136
- end
137
-
138
- describe "#response_type" do
139
-
140
- use_vcr_cassette "whm/server/response_type"
141
-
142
- it "detects an action function" do
143
- @whm.perform_request('testing')
144
- @whm.send(:response_type).should == :action
145
- end
146
145
 
147
- it "detects an error function" do
148
- @whm.perform_request('testing_error')
149
- @whm.send(:response_type).should == :error
150
- end
146
+ describe "setting HTTP timeout" do
147
+ let(:net_http) { double(Net::HTTP).as_null_object }
151
148
 
152
- it "detects a query function" do
153
- @whm.perform_request('testing_query')
154
- @whm.send(:response_type).should == :query
155
- end
149
+ use_vcr_cassette "whm/server/applist"
156
150
 
157
- it "detects an unknown function" do
158
- @whm.perform_request('testing_unknown')
159
- @whm.send(:response_type).should == :unknown
160
- end
161
-
162
- it "forces response type" do
163
- @whm.force_response_type = :magic
164
- @whm.send(:response_type).should == :magic
165
- @whm.perform_request('testing')
166
- end
151
+ before(:each) do
152
+ Net::HTTP.stub(:new) { net_http }
153
+ end
167
154
 
168
- it "resets response_type each request" do
169
- @whm.force_response_type.should be_nil
170
- @whm.force_response_type = :magic
171
- @whm.send(:response_type).should == :magic
155
+ it "sets HTTP timeout when assigned" do
156
+ @whm.timeout = 1000
172
157
 
173
- @whm.force_response_type = :magic
174
- @whm.perform_request('testing')
175
- @whm.force_response_type.should be_nil
176
- end
158
+ net_http.should_receive(:read_timeout=).with(1000)
159
+ net_http.should_receive(:open_timeout=).with(1000)
177
160
 
161
+ @whm.perform_request("applist")
162
+ end
178
163
 
179
- it "returns true for a successful :action" do
180
- @whm.perform_request('testing')
181
- response = @whm.send(:format_response)
182
- response[:success].should be(true)
183
- end
164
+ it "uses default HTTP timeout when not assigned" do
165
+ net_http.should_not_receive(:read_timeout=)
166
+ net_http.should_not_receive(:open_timeout=)
184
167
 
185
- it "returns true for a successful :query" do
186
- @whm.perform_request('testing_query')
187
- response = @whm.send(:format_response)
188
- response[:success].should be(true)
189
- response[:params].should have_key(:acct)
168
+ @whm.perform_request("applist")
169
+ end
170
+ end
190
171
  end
191
172
 
192
- it "returns false on :error" do
193
- @whm.perform_request('testing_error')
194
- response = @whm.send(:format_response)
195
- response[:success].should be(false)
196
- response[:message].should match(/Unknown App Req/)
197
- end
173
+ context "calling applist" do
174
+ use_vcr_cassette "whm/server/applist"
198
175
 
199
- it "returns false on :unknown" do
200
- @whm.perform_request('testing_unknown')
201
- response = @whm.send(:format_response)
202
- response[:success].should be(false)
203
- response[:message].should match(/Unknown error occurred .*wtf.*/)
176
+ it "sets a response message" do
177
+ @whm = Whm::Server.new(:host => @whm_host, :hash => @whm_hash)
178
+ @whm.perform_request('applist')
179
+ @whm.function.should == 'applist'
180
+ end
204
181
  end
205
182
  end
206
183
 
@@ -255,74 +232,42 @@ module Lumberg
255
232
  end
256
233
  end
257
234
 
235
+ describe "#themes" do
236
+ use_vcr_cassette "whm/server/themes"
237
+
238
+ it "returns list of themes" do
239
+ result = @whm.themes
240
+ result[:params].should include :x3
241
+ end
242
+ end
243
+
258
244
  describe "#account" do
259
245
  it "has an account accessor" do
260
246
  @whm.account.should be_an(Whm::Account)
261
247
  end
262
248
 
263
- it "returns the same thing twice" do
264
- @whm.account.should be_a(Whm::Account)
265
- @whm.account.should respond_to(:list)
266
-
267
- @whm.account.should be_a(Whm::Account)
268
- @whm.account.should respond_to(:list)
249
+ it "sets the server" do
250
+ @whm.account.server.should == @whm
269
251
  end
270
-
271
252
  end
272
253
 
273
254
  describe "#dns" do
274
255
  it "has an dns accessor" do
275
256
  @whm.dns.should be_an(Whm::Dns)
276
257
  end
258
+
259
+ it "sets the server" do
260
+ @whm.dns.server.should == @whm
261
+ end
277
262
  end
278
263
 
279
264
  describe "#reseller" do
280
265
  it "has an reseller accessor" do
281
266
  @whm.reseller.should be_an(Whm::Reseller)
282
267
  end
283
- end
284
-
285
- describe "#method_missing" do
286
- it "caches @vars" do
287
- Whm.should_receive(:const_get).once.and_return(Whm::Account)
288
- @whm.account
289
- @whm.account
290
- end
291
268
 
292
- it "raises to super" do
293
- expect { @whm.asdf }.to raise_error(NoMethodError)
294
- end
295
- end
296
-
297
- describe "#prepare_request" do
298
- context "when @basic_auth is true" do
299
- before do
300
- @whm.basic_auth = true
301
- @req = @whm.instance_eval {
302
- prepare_request(URI.parse("http://example.com/"))
303
- }
304
- end
305
-
306
- it "sets Authorization header to 'Basic {base64text}'" do
307
- test_auth = Base64.encode64("#{@whm.user}:#{@whm.hash}")
308
- auth = @req['Authorization']
309
- auth.should_not be_nil
310
- auth.should == "Basic #{test_auth}"
311
- end
312
- end
313
-
314
- context "when @basic_auth is false" do
315
- before do
316
- @req = @whm.instance_eval {
317
- prepare_request(URI.parse("http://example.com/"))
318
- }
319
- end
320
- it "sets Authorization header to 'WHM user:hash'" do
321
- test_auth = "#{@whm.user}:#{@whm.hash}"
322
- auth = @req['Authorization']
323
- auth.should_not be_nil
324
- auth.should == "WHM #{test_auth}"
325
- end
269
+ it "sets the server" do
270
+ @whm.reseller.server.should == @whm
326
271
  end
327
272
  end
328
273
 
@@ -340,14 +285,6 @@ module Lumberg
340
285
  describe "#add_ip" do
341
286
  use_vcr_cassette "whm/server/addip"
342
287
 
343
- it "requires an ip address" do
344
- requires_attr('ip') { @whm.add_ip(:netmask => '255.255.255.250') }
345
- end
346
-
347
- it "requires a netmask" do
348
- requires_attr('netmask') { @whm.add_ip(:ip => '123.123.123.123') }
349
- end
350
-
351
288
  it "adds the ip address" do
352
289
  result = @whm.add_ip(:ip => '208.77.188.166', :netmask => '255.255.255.0')
353
290
  result[:success].should be_true
@@ -357,10 +294,6 @@ module Lumberg
357
294
  describe "#delete_ip" do
358
295
  use_vcr_cassette "whm/server/delip"
359
296
 
360
- it "requires an ip address" do
361
- requires_attr('ip') { @whm.delete_ip }
362
- end
363
-
364
297
  it "deletes the ip address" do
365
298
  result = @whm.delete_ip(:ip => '208.77.188.166')
366
299
  result[:success].should be_true
@@ -370,22 +303,32 @@ module Lumberg
370
303
  describe "#set_hostname" do
371
304
  use_vcr_cassette "whm/server/sethostname"
372
305
 
373
- it "requires a hostname" do
374
- requires_attr('hostname') { @whm.set_hostname }
375
- end
376
-
377
306
  it "changes the server's hostname" do
378
307
  result = @whm.set_hostname(:hostname => "myhost.com")
379
308
  result[:success].should be_true
380
309
  end
381
310
  end
382
311
 
383
- describe "#set_resolvers" do
384
- use_vcr_cassette "whm/server/setresolvers"
312
+ describe "#get_tweaksetting" do
313
+ use_vcr_cassette "whm/server/gettweaksetting"
385
314
 
386
- it "requires a nameserver1" do
387
- requires_attr('nameserver1') { @whm.set_resolvers }
315
+ it "gets a tweak setting" do
316
+ result = @whm.get_tweaksetting(:key => 'skipwebalizer')
317
+ result[:success].should be_true
318
+ end
319
+ end
320
+
321
+ describe "#set_tweaksetting" do
322
+ use_vcr_cassette "whm/server/settweaksetting"
323
+
324
+ it "sets a tweak setting" do
325
+ result = @whm.set_tweaksetting(:key => 'skipwebalizer', :value => 0)
326
+ result[:success].should be_true
388
327
  end
328
+ end
329
+
330
+ describe "#set_resolvers" do
331
+ use_vcr_cassette "whm/server/setresolvers"
389
332
 
390
333
  it "configures the nameservers" do
391
334
  result = @whm.set_resolvers(:nameserver1 => "123.123.123.123", :nameserver2 => "123.123.123.124")