lumberg 1.1.1 → 2.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +1 -6
  3. data/README.md +130 -23
  4. data/lib/lumberg.rb +2 -0
  5. data/lib/lumberg/cpanel.rb +29 -0
  6. data/lib/lumberg/cpanel/addon_domain.rb +50 -0
  7. data/lib/lumberg/cpanel/backups.rb +16 -0
  8. data/lib/lumberg/cpanel/base.rb +56 -0
  9. data/lib/lumberg/cpanel/box_trapper.rb +18 -0
  10. data/lib/lumberg/cpanel/branding.rb +89 -0
  11. data/lib/lumberg/cpanel/contact.rb +38 -0
  12. data/lib/lumberg/cpanel/cron.rb +89 -0
  13. data/lib/lumberg/cpanel/dns_lookup.rb +23 -0
  14. data/lib/lumberg/cpanel/domain_keys.rb +37 -0
  15. data/lib/lumberg/cpanel/domain_lookup.rb +71 -0
  16. data/lib/lumberg/cpanel/email.rb +491 -0
  17. data/lib/lumberg/cpanel/file_manager.rb +146 -0
  18. data/lib/lumberg/cpanel/gpg.rb +36 -0
  19. data/lib/lumberg/cpanel/locale.rb +15 -0
  20. data/lib/lumberg/cpanel/mime.rb +34 -0
  21. data/lib/lumberg/cpanel/mysql.rb +66 -0
  22. data/lib/lumberg/cpanel/net.rb +28 -0
  23. data/lib/lumberg/cpanel/park.rb +58 -0
  24. data/lib/lumberg/cpanel/password.rb +52 -0
  25. data/lib/lumberg/cpanel/random_data.rb +25 -0
  26. data/lib/lumberg/cpanel/redirect.rb +44 -0
  27. data/lib/lumberg/cpanel/ssl.rb +198 -0
  28. data/lib/lumberg/cpanel/sub_domain.rb +61 -0
  29. data/lib/lumberg/cpanel/support.rb +29 -0
  30. data/lib/lumberg/cpanel/zone_edit.rb +134 -0
  31. data/lib/lumberg/format_whm.rb +24 -1
  32. data/lib/lumberg/version.rb +1 -1
  33. data/lib/lumberg/whm.rb +2 -1
  34. data/lib/lumberg/whm/account.rb +4 -4
  35. data/lib/lumberg/whm/cert.rb +69 -0
  36. data/lib/lumberg/whm/dns.rb +28 -4
  37. data/lib/lumberg/whm/reseller.rb +4 -4
  38. data/lib/lumberg/whm/server.rb +64 -15
  39. data/lumberg.gemspec +4 -3
  40. data/spec/config_spec.rb +2 -2
  41. data/spec/cpanel/addon_domain_spec.rb +84 -0
  42. data/spec/cpanel/backups_spec.rb +22 -0
  43. data/spec/cpanel/base_spec.rb +128 -0
  44. data/spec/cpanel/box_trapper_spec.rb +22 -0
  45. data/spec/cpanel/branding_spec.rb +46 -0
  46. data/spec/cpanel/contact_spec.rb +50 -0
  47. data/spec/cpanel/cron_spec.rb +161 -0
  48. data/spec/cpanel/dns_lookup_spec.rb +22 -0
  49. data/spec/cpanel/domain_keys_spec.rb +46 -0
  50. data/spec/cpanel/domain_lookup_spec.rb +77 -0
  51. data/spec/cpanel/email_spec.rb +615 -0
  52. data/spec/cpanel/file_manager_spec.rb +73 -0
  53. data/spec/cpanel/gpg_spec.rb +48 -0
  54. data/spec/cpanel/locale_spec.rb +23 -0
  55. data/spec/cpanel/mime_spec.rb +0 -0
  56. data/spec/cpanel/mysql_spec.rb +0 -0
  57. data/spec/cpanel/net_spec.rb +30 -0
  58. data/spec/cpanel/park_spec.rb +94 -0
  59. data/spec/cpanel/password_spec.rb +35 -0
  60. data/spec/cpanel/random_data_spec.rb +24 -0
  61. data/spec/cpanel/redirect_spec.rb +0 -0
  62. data/spec/cpanel/ssl_spec.rb +138 -0
  63. data/spec/cpanel/sub_domain_spec.rb +72 -0
  64. data/spec/cpanel/support_spec.rb +38 -0
  65. data/spec/cpanel/zone_edit_spec.rb +0 -0
  66. data/spec/sample_certs/cpanel.crt +28 -0
  67. data/spec/sample_certs/cpanel.key +28 -0
  68. data/spec/sample_certs/main.crt +27 -0
  69. data/spec/sample_certs/sample.crt +26 -0
  70. data/spec/sample_certs/sample.key +27 -0
  71. data/spec/spec_helper.rb +7 -1
  72. data/spec/support/cpanel_matchers.rb +17 -0
  73. data/spec/vcr_cassettes/cpanel/addon_domain/add.yml +77 -0
  74. data/spec/vcr_cassettes/cpanel/addon_domain/list.yml +77 -0
  75. data/spec/vcr_cassettes/cpanel/addon_domain/remove.yml +77 -0
  76. data/spec/vcr_cassettes/cpanel/backups/list.yml +40 -0
  77. data/spec/vcr_cassettes/cpanel/box_trapper/list.yml +40 -0
  78. data/spec/vcr_cassettes/cpanel/branding/list_icons.yml +40 -0
  79. data/spec/vcr_cassettes/cpanel/branding/list_image_types.yml +40 -0
  80. data/spec/vcr_cassettes/cpanel/branding/list_object_types.yml +40 -0
  81. data/spec/vcr_cassettes/cpanel/branding/list_pkgs.yml +40 -0
  82. data/spec/vcr_cassettes/cpanel/branding/list_sprites.yml +40 -0
  83. data/spec/vcr_cassettes/cpanel/contact/show.yml +40 -0
  84. data/spec/vcr_cassettes/cpanel/contact/update.yml +40 -0
  85. data/spec/vcr_cassettes/cpanel/cron/add.yml +77 -0
  86. data/spec/vcr_cassettes/cpanel/cron/edit.yml +114 -0
  87. data/spec/vcr_cassettes/cpanel/cron/email.yml +77 -0
  88. data/spec/vcr_cassettes/cpanel/cron/list.yml +77 -0
  89. data/spec/vcr_cassettes/cpanel/cron/remove.yml +151 -0
  90. data/spec/vcr_cassettes/cpanel/cron/set_email.yml +77 -0
  91. data/spec/vcr_cassettes/cpanel/dns_lookup/name_to_ip.yml +40 -0
  92. data/spec/vcr_cassettes/cpanel/domain_keys/add.yml +40 -0
  93. data/spec/vcr_cassettes/cpanel/domain_keys/available.yml +40 -0
  94. data/spec/vcr_cassettes/cpanel/domain_keys/installed.yml +40 -0
  95. data/spec/vcr_cassettes/cpanel/domain_keys/remove.yml +40 -0
  96. data/spec/vcr_cassettes/cpanel/domain_lookup/count.yml +40 -0
  97. data/spec/vcr_cassettes/cpanel/domain_lookup/docroot.yml +40 -0
  98. data/spec/vcr_cassettes/cpanel/domain_lookup/docroots.yml +40 -0
  99. data/spec/vcr_cassettes/cpanel/domain_lookup/document_root.yml +40 -0
  100. data/spec/vcr_cassettes/cpanel/domain_lookup/document_roots.yml +40 -0
  101. data/spec/vcr_cassettes/cpanel/domain_lookup/list.yml +40 -0
  102. data/spec/vcr_cassettes/cpanel/email/acceptable_encodings.yml +40 -0
  103. data/spec/vcr_cassettes/cpanel/email/accounts.yml +188 -0
  104. data/spec/vcr_cassettes/cpanel/email/add_account.yml +77 -0
  105. data/spec/vcr_cassettes/cpanel/email/add_filter.yml +77 -0
  106. data/spec/vcr_cassettes/cpanel/email/add_forwarder.yml +77 -0
  107. data/spec/vcr_cassettes/cpanel/email/add_mailing_list.yml +73 -0
  108. data/spec/vcr_cassettes/cpanel/email/add_mx.yml +40 -0
  109. data/spec/vcr_cassettes/cpanel/email/change_mx.yml +40 -0
  110. data/spec/vcr_cassettes/cpanel/email/check_local_delivery_local.yml +77 -0
  111. data/spec/vcr_cassettes/cpanel/email/check_local_delivery_remote.yml +77 -0
  112. data/spec/vcr_cassettes/cpanel/email/default_address.yml +40 -0
  113. data/spec/vcr_cassettes/cpanel/email/delete_mx.yml +40 -0
  114. data/spec/vcr_cassettes/cpanel/email/disk_usage.yml +77 -0
  115. data/spec/vcr_cassettes/cpanel/email/domains.yml +40 -0
  116. data/spec/vcr_cassettes/cpanel/email/domains_with_aliases.yml +77 -0
  117. data/spec/vcr_cassettes/cpanel/email/edit_quota.yml +112 -0
  118. data/spec/vcr_cassettes/cpanel/email/filters.yml +114 -0
  119. data/spec/vcr_cassettes/cpanel/email/forwarders.yml +77 -0
  120. data/spec/vcr_cassettes/cpanel/email/mail_dir.yml +77 -0
  121. data/spec/vcr_cassettes/cpanel/email/mail_dirs.yml +77 -0
  122. data/spec/vcr_cassettes/cpanel/email/mailing_lists.yml +73 -0
  123. data/spec/vcr_cassettes/cpanel/email/main_discard.yml +40 -0
  124. data/spec/vcr_cassettes/cpanel/email/mx.yml +40 -0
  125. data/spec/vcr_cassettes/cpanel/email/remove.yml +77 -0
  126. data/spec/vcr_cassettes/cpanel/email/set_mail_delivery_local.yml +77 -0
  127. data/spec/vcr_cassettes/cpanel/email/set_mail_delivery_remote.yml +77 -0
  128. data/spec/vcr_cassettes/cpanel/email/set_mx_type.yml +40 -0
  129. data/spec/vcr_cassettes/cpanel/file_manager/disk_usage.yml +38 -0
  130. data/spec/vcr_cassettes/cpanel/file_manager/list.yml +38 -0
  131. data/spec/vcr_cassettes/cpanel/file_manager/operate.yml +77 -0
  132. data/spec/vcr_cassettes/cpanel/file_manager/show.yml +40 -0
  133. data/spec/vcr_cassettes/cpanel/file_manager/stat.yml +38 -0
  134. data/spec/vcr_cassettes/cpanel/gpg/count.yml +40 -0
  135. data/spec/vcr_cassettes/cpanel/gpg/count_private.yml +40 -0
  136. data/spec/vcr_cassettes/cpanel/gpg/list.yml +40 -0
  137. data/spec/vcr_cassettes/cpanel/gpg/list_private.yml +40 -0
  138. data/spec/vcr_cassettes/cpanel/locale/show.yml +40 -0
  139. data/spec/vcr_cassettes/cpanel/net/query_hostname.yml +40 -0
  140. data/spec/vcr_cassettes/cpanel/net/traceroute.yml +40 -0
  141. data/spec/vcr_cassettes/cpanel/park/add.yml +77 -0
  142. data/spec/vcr_cassettes/cpanel/park/list.yml +77 -0
  143. data/spec/vcr_cassettes/cpanel/park/list_addon_domains.yml +77 -0
  144. data/spec/vcr_cassettes/cpanel/park/remove.yml +77 -0
  145. data/spec/vcr_cassettes/cpanel/password/digest_authentication.yml +77 -0
  146. data/spec/vcr_cassettes/cpanel/password/modify.yml +77 -0
  147. data/spec/vcr_cassettes/cpanel/random_data/show.yml +40 -0
  148. data/spec/vcr_cassettes/cpanel/ssl/fetchcabundle.yml +40 -0
  149. data/spec/vcr_cassettes/cpanel/ssl/gencrt.yml +40 -0
  150. data/spec/vcr_cassettes/cpanel/ssl/gencsr.yml +40 -0
  151. data/spec/vcr_cassettes/cpanel/ssl/genkey.yml +40 -0
  152. data/spec/vcr_cassettes/cpanel/ssl/installssl.yml +40 -0
  153. data/spec/vcr_cassettes/cpanel/ssl/listcrts.yml +40 -0
  154. data/spec/vcr_cassettes/cpanel/ssl/listcsrs.yml +40 -0
  155. data/spec/vcr_cassettes/cpanel/ssl/listkeys.yml +40 -0
  156. data/spec/vcr_cassettes/cpanel/ssl/listsslitems.yml +40 -0
  157. data/spec/vcr_cassettes/cpanel/ssl/showcrt.yml +38 -0
  158. data/spec/vcr_cassettes/cpanel/ssl/showcsr.yml +38 -0
  159. data/spec/vcr_cassettes/cpanel/ssl/showkey.yml +38 -0
  160. data/spec/vcr_cassettes/cpanel/ssl/uploadcrt.yml +40 -0
  161. data/spec/vcr_cassettes/cpanel/sub_domain/add.yml +77 -0
  162. data/spec/vcr_cassettes/cpanel/sub_domain/list.yml +77 -0
  163. data/spec/vcr_cassettes/cpanel/sub_domain/remove.yml +77 -0
  164. data/spec/vcr_cassettes/cpanel/support/contactable.yml +40 -0
  165. data/spec/vcr_cassettes/whm/cert/fetchsslinfo.yml +38 -0
  166. data/spec/vcr_cassettes/whm/cert/generatessl.yml +38 -0
  167. data/spec/vcr_cassettes/whm/cert/installssl.yml +38 -0
  168. data/spec/vcr_cassettes/whm/cert/listcrts.yml +38 -0
  169. data/spec/vcr_cassettes/whm/server/gettweaksetting.yml +44 -0
  170. data/spec/vcr_cassettes/whm/server/settweaksetting.yml +44 -0
  171. data/spec/vcr_cassettes/whm/server/themes.yml +38 -0
  172. data/spec/whm/cert_spec.rb +62 -0
  173. data/spec/whm/server_spec.rb +79 -3
  174. metadata +376 -34
  175. data/.rvmrc +0 -49
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ module Lumberg
4
+ describe Cpanel::DnsLookup do
5
+ let(:server) { Whm::Server.new(:host => @whm_host, :hash => @whm_hash) }
6
+ let(:api_username) { "lumberg" }
7
+ let(:dns_lookup) do
8
+ described_class.new(
9
+ :server => server,
10
+ :api_username => api_username
11
+ )
12
+ end
13
+
14
+ describe "#name_to_ip" do
15
+ use_vcr_cassette "cpanel/dns_lookup/name_to_ip"
16
+
17
+ subject { dns_lookup.name_to_ip({ :domain => 'google.com' })[:params][:data] }
18
+
19
+ it { should be_an(Array) }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ module Lumberg
4
+ describe Cpanel::DomainKeys do
5
+ let(:server) { Whm::Server.new(:host => @whm_host, :hash => @whm_hash) }
6
+ let(:api_username) { "lumberg" }
7
+ let(:domain_keys) do
8
+ described_class.new(
9
+ :server => server,
10
+ :api_username => api_username
11
+ )
12
+ end
13
+
14
+ describe "#installed" do
15
+ use_vcr_cassette "cpanel/domain_keys/installed"
16
+
17
+ it "checks if DomainKeys was installed for domain" do
18
+ domain_keys.installed[:params][:data][0][:installed].should == 1
19
+ end
20
+ end
21
+
22
+ describe "#available" do
23
+ use_vcr_cassette "cpanel/domain_keys/available"
24
+
25
+ it "checks if DomainKeys is available on local server" do
26
+ domain_keys.available[:params][:data][0][:available].should == 1
27
+ end
28
+ end
29
+
30
+ describe "#add" do
31
+ use_vcr_cassette "cpanel/domain_keys/add"
32
+
33
+ subject { domain_keys.add[:params][:data][0] }
34
+ it { should be_a(Hash) }
35
+ end
36
+
37
+ describe "#remove" do
38
+ use_vcr_cassette "cpanel/domain_keys/remove"
39
+
40
+ subject { domain_keys.add[:params][:data][0] }
41
+ it { should be_a(Hash) }
42
+ end
43
+
44
+ end
45
+ end
46
+
@@ -0,0 +1,77 @@
1
+ require "spec_helper"
2
+
3
+ module Lumberg
4
+ describe Cpanel::DomainLookup do
5
+ let(:server) { Whm::Server.new(:host => @whm_host, :hash => @whm_hash) }
6
+ let(:api_username) { "lumberg" }
7
+ let(:domain_lookup) do
8
+ described_class.new(
9
+ :server => server,
10
+ :api_username => api_username
11
+ )
12
+ end
13
+
14
+ let(:domain) { "lumberg-test.com" }
15
+ let(:document_root) { "/home/lumberg/public_html" }
16
+
17
+ describe "#list" do
18
+ use_vcr_cassette "cpanel/domain_lookup/list"
19
+
20
+ it "shows parked domains, addon domains and main domain" do
21
+ domain_lookup.list[:params][:data][0][:domain].should === domain
22
+ end
23
+ end
24
+
25
+ describe "#document_root" do
26
+ use_vcr_cassette "cpanel/domain_lookup/document_root"
27
+
28
+ it "gets DocumentRoot for domain" do
29
+ result = domain_lookup.document_root({ :domain => domain })
30
+
31
+ result[:params][:data][0][:docroot].should == document_root
32
+ end
33
+ end
34
+
35
+ describe "#docroot" do
36
+ use_vcr_cassette "cpanel/domain_lookup/docroot"
37
+
38
+ it "gets DocumentRoot for domain, as an alias for #document_root" do
39
+ result = domain_lookup.document_root({ :domain => domain })
40
+
41
+ result[:params][:data][0][:docroot].should == document_root
42
+ end
43
+ end
44
+
45
+
46
+ describe "#document_roots" do
47
+ use_vcr_cassette "cpanel/domain_lookup/document_roots"
48
+
49
+ subject { domain_lookup.document_roots[:params][:data] }
50
+
51
+ it "gets DocumentRoot for all domains" do
52
+ should be_an(Array)
53
+ end
54
+ end
55
+
56
+ describe "#docroots" do
57
+ use_vcr_cassette "cpanel/domain_lookup/docroots"
58
+
59
+ subject { domain_lookup.document_roots[:params][:data] }
60
+
61
+ it "gets DocumentRoot for all domains, as an alias for #document_roots" do
62
+ should be_an(Array)
63
+ end
64
+ end
65
+
66
+ describe "#count" do
67
+ use_vcr_cassette "cpanel/domain_lookup/count"
68
+
69
+ it "gets the total number of domains associated within a Cpanel account" do
70
+ result = domain_lookup.count
71
+
72
+ result[:params][:data][0][:count].should > 0
73
+ end
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,615 @@
1
+ require "spec_helper"
2
+
3
+ module Lumberg
4
+ describe Cpanel::Email do
5
+ let(:domain) { "lumberg-test.com" }
6
+ let(:server) { Whm::Server.new(:host => @whm_host, :hash => @whm_hash) }
7
+ let(:api_username) { "lumberg" }
8
+ let(:email) do
9
+ described_class.new(
10
+ :server => server,
11
+ :api_username => api_username
12
+ )
13
+ end
14
+
15
+ describe "#main_discard" do
16
+ use_vcr_cassette("cpanel/email/main_discard")
17
+
18
+ it "gets info about main email account undeliverable mail handling" do
19
+ email.main_discard[:params][:data][0].should have_key(:status)
20
+ end
21
+ end
22
+
23
+ describe "#add_mailing_list" do
24
+ use_vcr_cassette("cpanel/email/add_mailing_list")
25
+
26
+ it "adds a mailing list" do
27
+ email.add_mailing_list(
28
+ :list => "add-test",
29
+ :domain => domain,
30
+ :password => "s3cr3t5"
31
+ )
32
+
33
+ email.mailing_lists[:params][:data].find {|l|
34
+ l[:list] == "add-test@#{domain}"
35
+ }.should_not be_nil
36
+ end
37
+ end
38
+
39
+ describe "#mailing_lists" do
40
+ use_vcr_cassette("cpanel/email/mailing_lists")
41
+
42
+ before do
43
+ email.add_mailing_list(
44
+ :list => "test-list",
45
+ :domain => domain,
46
+ :password => "s3cr3t5"
47
+ )
48
+ end
49
+
50
+ it "returns a list of mailing lists" do
51
+ email.mailing_lists[:params][:data].find {|l|
52
+ l[:list] == "test-list@#{domain}"
53
+ }.should_not be_nil
54
+ end
55
+ end
56
+
57
+ describe "#add_forwarder" do
58
+ let(:local) { "fwd-test" }
59
+
60
+ use_vcr_cassette("cpanel/email/add_forwarder")
61
+
62
+ it "adds a forwarder" do
63
+ email.add_forwarder(
64
+ :domain => domain,
65
+ :email => local,
66
+ :fwdopt => :fwd,
67
+ :fwdemail => "foo@bar.com"
68
+ )
69
+
70
+ email.forwarders[:params][:data].find {|f|
71
+ f[:dest] == "#{local}@#{domain}"
72
+ }.should_not be_nil
73
+ end
74
+ end
75
+
76
+ describe "#forwarders" do
77
+ let(:local) { "test-fwd" }
78
+
79
+ use_vcr_cassette("cpanel/email/forwarders")
80
+
81
+ before do
82
+ email.add_forwarder(
83
+ :domain => domain,
84
+ :email => local,
85
+ :fwdopt => :fwd,
86
+ :fwdemail => "foo@bar.com"
87
+ )
88
+ end
89
+
90
+ it "returns a list of forwarders" do
91
+ email.forwarders[:params][:data].find {|f|
92
+ f[:dest] == "#{local}@#{domain}"
93
+ }.should_not be_nil
94
+ end
95
+ end
96
+
97
+ describe "#domains_with_aliases" do
98
+ let(:local) { "alias-test" }
99
+
100
+ use_vcr_cassette("cpanel/email/domains_with_aliases")
101
+
102
+ before do
103
+ email.add_forwarder(
104
+ :domain => domain,
105
+ :email => local,
106
+ :fwdopt => :fwd,
107
+ :fwdemail => "foo@bar.com"
108
+ )
109
+ end
110
+
111
+ it "gets a list of domains that have aliases" do
112
+ email.domains_with_aliases[:params][:data][0][:domain].should == domain
113
+ end
114
+ end
115
+
116
+ describe "#add_account" do
117
+ let(:local) { "account-test" }
118
+
119
+ use_vcr_cassette "cpanel/email/add_account"
120
+
121
+ it "adds an email account" do
122
+ email.add_account(
123
+ :domain => domain,
124
+ :email => local,
125
+ :password => "magicpants",
126
+ :quota => 0
127
+ )
128
+
129
+ email.accounts[:params][:data].find {|a|
130
+ a[:email] == "#{local}@#{domain}"
131
+ }.should_not be_nil
132
+ end
133
+ end
134
+
135
+ describe "#edit_quota" do
136
+ let(:local) { "account-test" }
137
+
138
+ use_vcr_cassette "cpanel/email/edit_quota"
139
+
140
+ it "modifies an email account quota" do
141
+ old_quota = email.accounts[:params][:data].find { |a|
142
+ a[:email] == "#{local}@#{domain}"
143
+ }[:_diskquota]
144
+
145
+ email.edit_quota(
146
+ :domain => domain,
147
+ :email => local,
148
+ :quota => 10
149
+ )
150
+
151
+ new_quota = email.accounts[:params][:data].find {|a|
152
+ a[:email] == "#{local}@#{domain}"
153
+ }[:_diskquota].to_i
154
+
155
+ new_quota.should_not == old_quota
156
+ end
157
+ end
158
+
159
+ describe "#remove" do
160
+ let(:local) { "account-test" }
161
+
162
+ use_vcr_cassette "cpanel/email/remove"
163
+
164
+ it "removes an email account" do
165
+ email.remove(
166
+ :domain => domain,
167
+ :email => "#{local}@#{domain}"
168
+ )
169
+
170
+ email.accounts[:params][:data].find {|a|
171
+ a[:email] == "#{local}@#{domain}"
172
+ }.should be_nil
173
+ end
174
+ end
175
+
176
+
177
+ describe "#accounts" do
178
+ let(:local) { "test-account" }
179
+ let(:email_address) { "#{local}@#{domain}" }
180
+
181
+ use_vcr_cassette("cpanel/email/accounts")
182
+
183
+ before(:each) do
184
+ email.add_account(
185
+ :domain => domain,
186
+ :email => local,
187
+ :password => "sauce",
188
+ :quota => 0
189
+ )
190
+ end
191
+
192
+ context ":style option is :with_disk" do
193
+ it "uses Email::listpopswithdisk" do
194
+ email.should_receive(:perform_request).with(
195
+ hash_including(:api_function => "listpopswithdisk")
196
+ )
197
+
198
+ email.accounts(:style => :with_disk)
199
+ end
200
+
201
+ it "is the default seting" do
202
+ email.should_receive(:perform_request).with(
203
+ hash_including(:api_function => "listpopswithdisk")
204
+ )
205
+
206
+ email.accounts
207
+ end
208
+
209
+ it "returns a list of email accounts" do
210
+ data = email.accounts(:style => :with_disk)[:params][:data]
211
+ data.any? {|d| d[:email] == email_address }.should be_true
212
+ end
213
+ end
214
+
215
+ context ":style option is :without_disk" do
216
+ it "uses Email::listpops" do
217
+ email.should_receive(:perform_request).with(
218
+ hash_including(:api_function => "listpops")
219
+ )
220
+
221
+ email.accounts(:style => :without_disk)
222
+ end
223
+
224
+ it "returns a list of email accounts" do
225
+ data = email.accounts(:style => :without_disk)[:params][:data]
226
+ data.any? {|d| d[:email] == email_address }.should be_true
227
+ end
228
+ end
229
+
230
+ context ":style option is :with_image" do
231
+ it "uses Email::listpopswithimage" do
232
+ email.should_receive(:perform_request).with(
233
+ hash_including(:api_function => "listpopswithimage")
234
+ )
235
+
236
+ email.accounts(:style => :with_image)
237
+ end
238
+
239
+ it "returns a list of email accounts" do
240
+ data = email.accounts(:style => :with_image)[:params][:data]
241
+ data.any? {|d| d[:email] == email_address }.should be_true
242
+ end
243
+ end
244
+
245
+ context ":style option is :single" do
246
+ it "uses Email::listpopssingle" do
247
+ email.should_receive(:perform_request).with(
248
+ hash_including(:api_function => "listpopssingle")
249
+ )
250
+
251
+ email.accounts(:style => :single)
252
+ end
253
+
254
+ it "returns a list of email accounts" do
255
+ data = email.accounts(:style => :single)[:params][:data]
256
+ data.any? {|d| d[:email] == email_address }.should be_true
257
+ end
258
+ end
259
+ end
260
+
261
+ describe "#domains" do
262
+ use_vcr_cassette("cpanel/email/domains")
263
+
264
+ it "returns a list of domains" do
265
+ email.domains[:params][:data].find {|d|
266
+ d[:domain] == domain
267
+ }.should_not be_nil
268
+ end
269
+ end
270
+
271
+ describe "#add_mx" do
272
+ use_vcr_cassette("cpanel/email/add_mx")
273
+
274
+ it "adds an mx record" do
275
+ email.add_mx(
276
+ :domain => domain,
277
+ :exchange => "mail.#{domain}",
278
+ :preference => 2
279
+ )[:params][:data][0][:status].should eq(1)
280
+ end
281
+ end
282
+
283
+ describe "#change_mx" do
284
+ use_vcr_cassette("cpanel/email/change_mx")
285
+
286
+ it "changes an existing mx record" do
287
+ email.add_mx(
288
+ :domain => domain,
289
+ :exchange => "mail.#{domain}",
290
+ :oldpreference => 2,
291
+ :preference => 1
292
+ )[:params][:data][0][:status].should eq(1)
293
+ end
294
+ end
295
+
296
+ describe "#mx" do
297
+ use_vcr_cassette("cpanel/email/mx")
298
+
299
+ it "returns info for each mail exchanger" do
300
+ email.mx[:params][:data][0][:entries].find {|m|
301
+ m[:domain] == domain
302
+ }.should_not be_nil
303
+ end
304
+ end
305
+
306
+ describe "#delete_mx" do
307
+ use_vcr_cassette("cpanel/email/delete_mx")
308
+
309
+ it "delete an existing mx record" do
310
+ email.delete_mx(
311
+ :domain => domain,
312
+ :exchange => "mail.#{domain}",
313
+ :preference => 1
314
+ )[:params][:data][0][:status].should eq(1)
315
+ end
316
+ end
317
+
318
+ describe "#set_mx_type" do
319
+ use_vcr_cassette("cpanel/email/set_mx_type")
320
+
321
+ it "sets an existing mx record to use remote" do
322
+ email.set_mx_type(
323
+ :domain => domain,
324
+ :mxcheck => "remote"
325
+ )[:params][:data][0][:detected].should == "remote"
326
+ end
327
+ end
328
+
329
+ describe "#set_mail_delivery" do
330
+ let(:detected) do
331
+ email.mx(:domain => domain)[:params][:data][0][:detected]
332
+ end
333
+
334
+ use_vcr_cassette("cpanel/email/set_mail_delivery")
335
+
336
+ context "remote delivery" do
337
+ use_vcr_cassette("cpanel/email/set_mail_delivery.remote")
338
+
339
+ it "sets remote mail delivery" do
340
+ email.set_mail_delivery(
341
+ :domain => domain,
342
+ :delivery => :remote
343
+ )
344
+
345
+ detected.should == "remote"
346
+ end
347
+ end
348
+
349
+ context "local delivery" do
350
+ use_vcr_cassette("cpanel/email/set_mail_delivery.local")
351
+
352
+ it "sets local mail delivery" do
353
+ email.set_mail_delivery(
354
+ :domain => domain,
355
+ :delivery => :local
356
+ )
357
+
358
+ detected.should == "local"
359
+ end
360
+ end
361
+ end
362
+
363
+ describe "#check_local_delivery" do
364
+ context "local delivery" do
365
+ use_vcr_cassette("cpanel/email/check_local_delivery.local")
366
+
367
+ before do
368
+ email.set_mail_delivery(
369
+ :domain => domain,
370
+ :delivery => :local
371
+ )
372
+ end
373
+
374
+ it "returns 1" do
375
+ email.check_local_delivery(
376
+ :domain => domain
377
+ )[:params][:data][0][:alwaysaccept].should == 1
378
+ end
379
+ end
380
+
381
+ context "remote delivery" do
382
+ use_vcr_cassette("cpanel/email/check_local_delivery.remote")
383
+
384
+ before do
385
+ email.set_mail_delivery(
386
+ :domain => domain,
387
+ :delivery => :remote
388
+ )
389
+ end
390
+
391
+ it "returns 0" do
392
+ email.check_local_delivery(
393
+ :domain => domain
394
+ )[:params][:data][0][:alwaysaccept].should == 0
395
+ end
396
+ end
397
+ end
398
+
399
+ describe "#add_filter" do
400
+ let(:local) { "filters-test" }
401
+ let(:filter_name) { "fail filter" }
402
+
403
+ use_vcr_cassette("cpanel/email/add_filter")
404
+
405
+ before do
406
+ email.add_account(
407
+ :email => local,
408
+ :domain => domain,
409
+ :password => "abcdefg",
410
+ :quota => 0
411
+ )
412
+ end
413
+
414
+ it "adds an email filter" do
415
+ result = email.add_filter(
416
+ :account => "#{local}@#{domain}",
417
+ :filtername => filter_name,
418
+ :action1 => "fail",
419
+ :match1 => "is",
420
+ :opt1 => "and",
421
+ :part1 => "$header_from:",
422
+ :val1 => "hi"
423
+ )[:params][:data][0]
424
+
425
+ result[:error].should == 0
426
+ result[:account].should == "#{local}@#{domain}"
427
+ result[:ok].should == 1
428
+ end
429
+ end
430
+
431
+ describe "#filters" do
432
+ let(:local) { "filters-test" }
433
+ let(:filter_name) { "fail filter" }
434
+
435
+ use_vcr_cassette("cpanel/email/filters")
436
+
437
+ before do
438
+ email.add_account(
439
+ :email => local,
440
+ :domain => domain,
441
+ :password => "abcdefg",
442
+ :quota => 0
443
+ )
444
+
445
+ email.add_filter(
446
+ :account => "#{local}@#{domain}",
447
+ :filtername => filter_name,
448
+ :action1 => "fail",
449
+ :match1 => "is",
450
+ :opt1 => "and",
451
+ :part1 => "$header_from:",
452
+ :val1 => "hi"
453
+ )
454
+ end
455
+
456
+ it "returns a list of email filters" do
457
+ email.filters(
458
+ :account => "#{local}@#{domain}"
459
+ )[:params][:data][0][:filtername].should == filter_name
460
+ end
461
+
462
+ context ":old_style option truthy" do
463
+ it "uses deprecated Email::listfilters" do
464
+ email.should_receive(:perform_request).with(
465
+ hash_including(:api_function => "listfilters")
466
+ )
467
+
468
+ email.filters(
469
+ :account => "#{local}@#{domain}",
470
+ :old_style => true
471
+ )
472
+ end
473
+ end
474
+
475
+ context ":old_style option falsy" do
476
+ it "uses Email::filterlist" do
477
+ email.should_receive(:perform_request).with(
478
+ hash_including(:api_function => "filterlist")
479
+ )
480
+
481
+ email.filters(
482
+ :account => "#{local}@#{domain}",
483
+ :old_style => false
484
+ )
485
+ end
486
+
487
+ it "is the default setting" do
488
+ email.should_receive(:perform_request).with(
489
+ hash_including(:api_function => "filterlist")
490
+ )
491
+
492
+ email.filters
493
+ end
494
+ end
495
+ end
496
+
497
+ describe "#acceptable_encodings" do
498
+ use_vcr_cassette "cpanel/email/acceptable_encodings"
499
+
500
+ subject do
501
+ email.acceptable_encodings[:params][:data].find { |m| m[:map] == "utf-8" }[:map]
502
+ end
503
+
504
+ it "lists Cpanel's acceptable character encodings" do
505
+ should == "utf-8"
506
+ end
507
+ end
508
+
509
+ describe "#listautoresponders" do
510
+ use_vcr_cassette("cpanel/email/listautoresponders")
511
+ subject { email.listautoresponders[:params][:data][0] }
512
+ should { be_nil }
513
+ end
514
+
515
+ describe "#listdomainforwards" do
516
+ use_vcr_cassette("cpanel/email/listdomainforwards")
517
+ subject { email.listdomainforwards[:params][:data][0] }
518
+ should { be_nil }
519
+ end
520
+
521
+ describe "#disk_usage" do
522
+ let(:local) { "disk-usage-test" }
523
+
524
+ use_vcr_cassette("cpanel/email/disk_usage")
525
+
526
+ before do
527
+ email.add_account(
528
+ :domain => domain,
529
+ :email => local,
530
+ :password => "s00pers3cr3t",
531
+ :quota => 0
532
+ )
533
+ end
534
+
535
+ it "gets disk usage information for an email account" do
536
+ email.disk_usage(
537
+ :domain => domain,
538
+ :login => local
539
+ )[:params][:data].find {|d|
540
+ d[:login] == local && d[:domain] == domain
541
+ }.should_not be_nil
542
+ end
543
+ end
544
+
545
+ describe "#mail_dir" do
546
+ let(:local) { "mail-dir-test" }
547
+
548
+ use_vcr_cassette("cpanel/email/mail_dir")
549
+
550
+ before do
551
+ email.add_account(
552
+ :domain => domain,
553
+ :email => local,
554
+ :password => "s00pers3cr3t",
555
+ :quota => 0
556
+ )
557
+ end
558
+
559
+ it "gets disk usage information for an email account" do
560
+ email.mail_dir(
561
+ :account => "#{local}@#{domain}"
562
+ )[:params][:data][0][:absdir].should match(
563
+ /\/mail\/#{domain}\/#{local}/
564
+ )
565
+ end
566
+ end
567
+
568
+ describe "#mail_dirs" do
569
+ let(:local) { "mail-dirs-test" }
570
+
571
+ use_vcr_cassette("cpanel/email/mail_dirs")
572
+
573
+ before do
574
+ email.add_account(
575
+ :domain => domain,
576
+ :email => local,
577
+ :password => "s00pers3cr3t",
578
+ :quota => 0
579
+ )
580
+ end
581
+
582
+ it "gets a list of mail-related directories" do
583
+ email.mail_dirs[:params][:data].find {|m|
584
+ m[:fullpath] =~ /\/mail\/#{domain}/
585
+ }.should_not be_nil
586
+ end
587
+ end
588
+
589
+ describe "#default_address" do
590
+ use_vcr_cassette("cpanel/email/default_address")
591
+
592
+ it "gets default address info for a domain" do
593
+ email.default_address(
594
+ :domain => domain
595
+ )[:params][:data][0][:domain].should == domain
596
+ end
597
+ end
598
+
599
+ describe "#listfilterbackups" do
600
+ pending
601
+ end
602
+
603
+ describe "#filterlist" do
604
+ pending
605
+ end
606
+
607
+ describe "#tracefilter" do
608
+ pending
609
+ end
610
+
611
+ describe "#fetchautoresponder" do
612
+ pending
613
+ end
614
+ end
615
+ end