postfix_admin 0.1.1 → 0.2.1
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.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +37 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +22 -0
- data/README.md +47 -32
- data/Rakefile +6 -0
- data/bin/console +18 -0
- data/docker-admin/Dockerfile +6 -0
- data/docker-admin/config.local.php +21 -0
- data/docker-app-2.5/Dockerfile +15 -0
- data/docker-app/Dockerfile +25 -0
- data/docker-app/docker-entrypoint.sh +5 -0
- data/docker-app/my.cnf +5 -0
- data/docker-compose.yml +46 -0
- data/docker-db/postfix.v1841.sql +383 -0
- data/{spec/postfix_test.sql → docker-db/postfix.v352.sql} +1 -28
- data/docker-db/postfix.v740.sql +269 -0
- data/{bin → exe}/postfix_admin +1 -0
- data/lib/postfix_admin.rb +1 -1
- data/lib/postfix_admin/admin.rb +62 -0
- data/lib/postfix_admin/alias.rb +65 -0
- data/lib/postfix_admin/application_record.rb +44 -0
- data/lib/postfix_admin/base.rb +120 -75
- data/lib/postfix_admin/cli.rb +173 -58
- data/lib/postfix_admin/concerns/.keep +0 -0
- data/lib/postfix_admin/concerns/dovecot_cram_md5_password.rb +30 -0
- data/lib/postfix_admin/concerns/existing_timestamp.rb +18 -0
- data/lib/postfix_admin/domain.rb +98 -0
- data/lib/postfix_admin/domain_admin.rb +8 -0
- data/lib/postfix_admin/doveadm.rb +37 -0
- data/lib/postfix_admin/log.rb +5 -0
- data/lib/postfix_admin/mail_domain.rb +9 -0
- data/lib/postfix_admin/mailbox.rb +89 -0
- data/lib/postfix_admin/models.rb +10 -170
- data/lib/postfix_admin/quota.rb +6 -0
- data/lib/postfix_admin/runner.rb +108 -36
- data/lib/postfix_admin/version.rb +1 -1
- data/postfix_admin.gemspec +22 -12
- metadata +80 -55
- data/spec/base_spec.rb +0 -235
- data/spec/cli_spec.rb +0 -286
- data/spec/models_spec.rb +0 -146
- data/spec/postfix_admin.conf +0 -5
- data/spec/runner_spec.rb +0 -194
- data/spec/spec_helper.rb +0 -159
data/spec/base_spec.rb
DELETED
@@ -1,235 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2
|
-
require 'postfix_admin/base'
|
3
|
-
|
4
|
-
describe PostfixAdmin::Base do
|
5
|
-
before do
|
6
|
-
db_initialize
|
7
|
-
@base = PostfixAdmin::Base.new({'database' => 'sqlite::memory:'})
|
8
|
-
end
|
9
|
-
|
10
|
-
it "DEFAULT_CONFIG" do
|
11
|
-
PostfixAdmin::Base::DEFAULT_CONFIG.should == {
|
12
|
-
'database' => 'mysql://postfix:password@localhost/postfix',
|
13
|
-
'aliases' => 30,
|
14
|
-
'mailboxes' => 30,
|
15
|
-
'maxquota' => 100
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
it "#address_split" do
|
20
|
-
@base.address_split('user@example.com').should == ['user', 'example.com']
|
21
|
-
end
|
22
|
-
|
23
|
-
it "#new without config" do
|
24
|
-
lambda { PostfixAdmin::Base.new }.should raise_error(ArgumentError)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "#new without database config" do
|
28
|
-
lambda { PostfixAdmin::Base.new({}) }.should raise_error(ArgumentError)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "Default configuration should be correct" do
|
32
|
-
@base.config[:aliases].should == 30
|
33
|
-
@base.config[:mailboxes].should == 30
|
34
|
-
@base.config[:maxquota].should == 100
|
35
|
-
@base.config[:mailbox_quota].should == 100 * KB_TO_MB
|
36
|
-
end
|
37
|
-
|
38
|
-
it "#domain_exist?" do
|
39
|
-
Domain.exist?('example.com').should be_true
|
40
|
-
end
|
41
|
-
|
42
|
-
it "#alias_exist?" do
|
43
|
-
Alias.exist?('user@example.com').should be_true
|
44
|
-
Alias.exist?('unknown@example.com').should be_false
|
45
|
-
end
|
46
|
-
|
47
|
-
it "#mailbox_exist?" do
|
48
|
-
Mailbox.exist?('user@example.com').should be_true
|
49
|
-
Mailbox.exist?('unknown@example.com').should be_false
|
50
|
-
end
|
51
|
-
|
52
|
-
it "#admin_exist?" do
|
53
|
-
Admin.exist?('admin@example.com').should be_true
|
54
|
-
Admin.exist?('unknown_admin@example.com').should be_false
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "#add_domain" do
|
58
|
-
it "can add a new domain" do
|
59
|
-
num_domains = Domain.count
|
60
|
-
@base.add_domain('example.net')
|
61
|
-
(Domain.count - num_domains).should be(1)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "can not add exist domain" do
|
65
|
-
lambda{ @base.add_domain('example.com') }.should raise_error Error
|
66
|
-
end
|
67
|
-
|
68
|
-
it "can not add invalid domain" do
|
69
|
-
lambda{ @base.add_domain('localhost') }.should raise_error Error
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "#add_account" do
|
74
|
-
it "can add a new account" do
|
75
|
-
num_mailboxes = Mailbox.count
|
76
|
-
num_aliases = Alias.count
|
77
|
-
@base.add_account('new_user@example.com', 'password')
|
78
|
-
(Mailbox.count - num_mailboxes).should be(1)
|
79
|
-
(Alias.count - num_aliases).should be(1)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "can not add account which hsas invalid address" do
|
83
|
-
lambda{ @base.add_account('invalid.example.com', 'password') }.should raise_error Error
|
84
|
-
end
|
85
|
-
|
86
|
-
it "can not add account for unknown domain" do
|
87
|
-
lambda{ @base.add_account('user@unknown.example.com', 'password') }.should raise_error Error
|
88
|
-
end
|
89
|
-
|
90
|
-
it "can not add account which has same address as exist mailbox" do
|
91
|
-
lambda{ @base.add_account('user@example.com', 'password') }.should raise_error Error
|
92
|
-
end
|
93
|
-
|
94
|
-
it "can not add account which has same address as exist alias" do
|
95
|
-
lambda{ @base.add_account('alias@example.com', 'password') }.should raise_error Error
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "#add_admin" do
|
100
|
-
it "can add an new admin" do
|
101
|
-
num_admins = Admin.count
|
102
|
-
@base.add_admin('admin@example.net', 'password')
|
103
|
-
Admin.exist?('admin@example.net').should be_true
|
104
|
-
(Admin.count - num_admins).should be(1)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "can not add exist admin" do
|
108
|
-
lambda{ @base.add_admin('admin@example.com', 'password') }.should raise_error Error
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "#add_admin_domain" do
|
113
|
-
it "#add_admin_domain" do
|
114
|
-
@base.add_admin_domain('admin@example.com', 'example.org')
|
115
|
-
Admin.find('admin@example.com').has_domain?('example.org').should be_true
|
116
|
-
end
|
117
|
-
|
118
|
-
it "can not add unknown domain for an admin" do
|
119
|
-
lambda{ @base.add_admin_domain('admin@example.com', 'unknown.example.com') }.should raise_error Error
|
120
|
-
end
|
121
|
-
|
122
|
-
it "can not add domain for unknown admin" do
|
123
|
-
lambda{ @base.add_admin_domain('unknown_admin@example.com', 'example.net') }.should raise_error Error
|
124
|
-
end
|
125
|
-
|
126
|
-
it "can not add a domain which the admin has already privileges for" do
|
127
|
-
lambda{ @base.add_admin_domain('admin@example.com', 'example.com') }.should raise_error Error
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "#delete_admin_domain" do
|
132
|
-
it "#delete_admin_domain" do
|
133
|
-
lambda{ @base.delete_admin_domain('admin@example.com', 'example.com') }.should_not raise_error
|
134
|
-
Admin.find('admin@example.com').has_domain?('example.com').should be_false
|
135
|
-
end
|
136
|
-
|
137
|
-
it "can not delete not administrated domain" do
|
138
|
-
lambda{ @base.delete_admin_domain('admin@example.com', 'example.org') }.should raise_error Error
|
139
|
-
end
|
140
|
-
|
141
|
-
it "raise error when unknown admin" do
|
142
|
-
lambda{ @base.delete_admin_domain('unknown_admin@example.com', 'example.com') }.should raise_error Error
|
143
|
-
end
|
144
|
-
|
145
|
-
it "raise error when unknown domain" do
|
146
|
-
lambda{ @base.delete_admin_domain('admin@example.com', 'unknown.example.com') }.should raise_error Error
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "#add_alias" do
|
151
|
-
it "can add a new alias" do
|
152
|
-
num_aliases = Alias.count
|
153
|
-
lambda { @base.add_alias('new_alias@example.com', 'goto@example.jp') }.should_not raise_error
|
154
|
-
(Alias.count - num_aliases).should be(1)
|
155
|
-
Alias.exist?('new_alias@example.com').should be_true
|
156
|
-
end
|
157
|
-
|
158
|
-
it "can not add an alias which has a same name as a mailbox" do
|
159
|
-
lambda { @base.add_alias('user@example.com', 'goto@example.jp') }.should raise_error Error
|
160
|
-
end
|
161
|
-
|
162
|
-
it "can not add an alias which has a sama name as other alias" do
|
163
|
-
@base.add_alias('new_alias@example.com', 'goto@example.jp')
|
164
|
-
lambda { @base.add_alias('new_alias@example.com', 'goto@example.jp') }.should raise_error Error
|
165
|
-
end
|
166
|
-
|
167
|
-
it "can not add an alias of unknown domain" do
|
168
|
-
lambda { @base.add_alias('new_alias@unknown.example.com', 'goto@example.jp') }.should raise_error Error
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe "#delete_alias" do
|
173
|
-
it "can delete an alias" do
|
174
|
-
lambda{ @base.delete_alias('alias@example.com') }.should_not raise_error
|
175
|
-
Alias.exist?('alias@example.com').should be_false
|
176
|
-
end
|
177
|
-
|
178
|
-
it "can not delete mailbox" do
|
179
|
-
lambda{ @base.delete_alias('user@example.com') }.should raise_error Error
|
180
|
-
end
|
181
|
-
|
182
|
-
it "can not delete unknown alias" do
|
183
|
-
lambda{ @base.delete_alias('unknown@example.com') }.should raise_error Error
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
describe "#delete_domain" do
|
188
|
-
before do
|
189
|
-
@base.add_account('user2@example.com', 'password')
|
190
|
-
@base.add_account('user3@example.com', 'password')
|
191
|
-
|
192
|
-
@base.add_alias('alias2@example.com', 'goto2@example.jp')
|
193
|
-
@base.add_alias('alias3@example.com', 'goto3@example.jp')
|
194
|
-
end
|
195
|
-
|
196
|
-
it "can delete a domain" do
|
197
|
-
lambda{ @base.delete_domain('example.com') }.should_not raise_error
|
198
|
-
|
199
|
-
Domain.exist?('example.com').should be_false
|
200
|
-
Admin.exist?('admin@example.com').should be_false
|
201
|
-
|
202
|
-
Alias.all(:domain_name => 'example.com').count.should be(0)
|
203
|
-
Mailbox.all(:domain_name => 'example.com').count.should be(0)
|
204
|
-
|
205
|
-
DomainAdmin.all(:username => 'admin@example.com', :domain_name => 'example.com').count.should be(0)
|
206
|
-
end
|
207
|
-
|
208
|
-
it "can not delete unknown domain" do
|
209
|
-
lambda{ @base.delete_domain('unknown.example.com') }.should raise_error Error
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
describe "#delete_admin" do
|
214
|
-
it "can delete an admin" do
|
215
|
-
lambda{ @base.delete_admin('admin@example.com') }.should_not raise_error
|
216
|
-
Admin.exist?('admin@example.com').should be_false
|
217
|
-
end
|
218
|
-
|
219
|
-
it "can not delete unknown admin" do
|
220
|
-
lambda{ @base.delete_admin('unknown_admin@example.com') }.should raise_error Error
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
describe "#delete_account" do
|
225
|
-
it "can delete an account" do
|
226
|
-
lambda{ @base.delete_account('user@example.com') }.should_not raise_error
|
227
|
-
Mailbox.exist?('user@example.com').should be_false
|
228
|
-
Alias.exist?('user@example.com').should be_false
|
229
|
-
end
|
230
|
-
|
231
|
-
it "can not delete unknown account" do
|
232
|
-
lambda{ @base.delete_account('unknown@example.com') }.should raise_error Error
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
data/spec/cli_spec.rb
DELETED
@@ -1,286 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'postfix_admin/cli'
|
3
|
-
|
4
|
-
describe PostfixAdmin::CLI, "when config file does not exist" do
|
5
|
-
before do
|
6
|
-
config_initialize
|
7
|
-
@file = File.join(File.dirname(__FILE__) , 'tmp/postfix_admin.conf')
|
8
|
-
CLI.config_file = @file
|
9
|
-
FileUtils.rm(@file) if File.exist?(@file)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "::config_file#=" do
|
13
|
-
CLI.config_file.should == @file
|
14
|
-
end
|
15
|
-
|
16
|
-
it "#new should raise SystemExit and create config_file, permission should be 600" do
|
17
|
-
lambda { CLI.new }.should raise_error SystemExit
|
18
|
-
File.exist?(@file).should === true
|
19
|
-
("%o" % File.stat(@file).mode).should == "100600"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe PostfixAdmin::CLI do
|
24
|
-
before do
|
25
|
-
db_initialize
|
26
|
-
@cli = CLI.new
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#show" do
|
30
|
-
it "show all domains information by nil domain name" do
|
31
|
-
lambda { @cli.show(nil) }.should_not raise_error
|
32
|
-
end
|
33
|
-
|
34
|
-
it "show domain information" do
|
35
|
-
lambda { @cli.show('example.com') }.should_not raise_error
|
36
|
-
end
|
37
|
-
|
38
|
-
it "can use frozen domain name" do
|
39
|
-
domain = 'example.com'
|
40
|
-
lambda { @cli.show(domain.freeze) }.should_not raise_error
|
41
|
-
end
|
42
|
-
|
43
|
-
it "upcase will convert to downcase" do
|
44
|
-
lambda { @cli.show('ExAmpLe.CoM') }.should_not raise_error
|
45
|
-
end
|
46
|
-
|
47
|
-
it "when unknown domain, raises Error" do
|
48
|
-
lambda { @cli.show('unknown.example.com') }.should raise_error Error
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it "#show_domain" do
|
53
|
-
lambda { @cli.show_domain }.should_not raise_error
|
54
|
-
capture(:stdout){ @cli.show_domain }.should_not =~ /ALL/
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "#show_account" do
|
58
|
-
it "shows information of an account" do
|
59
|
-
lambda { @cli.show_account('user@example.com') }.should_not raise_error
|
60
|
-
capture(:stdout){ @cli.show_account('user@example.com') }.should =~ /Quota/
|
61
|
-
end
|
62
|
-
|
63
|
-
it "raises error when unknown account" do
|
64
|
-
lambda { @cli.show_account('unknown@example.com') }.should raise_error Error
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "#show_summary" do
|
69
|
-
it "show summary of all domain" do
|
70
|
-
lambda { @cli.show_summary }.should_not raise_error
|
71
|
-
end
|
72
|
-
|
73
|
-
it "show summary of domain" do
|
74
|
-
lambda { @cli.show_summary('example.com') }.should_not raise_error
|
75
|
-
end
|
76
|
-
|
77
|
-
it "upcase will convert to downcase" do
|
78
|
-
lambda { @cli.show_summary('example.COM') }.should_not raise_error
|
79
|
-
end
|
80
|
-
|
81
|
-
it "when unknown domain, raises Error" do
|
82
|
-
lambda { @cli.show_summary('unknown.example.com') }.should raise_error Error
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
it "#show_admin" do
|
87
|
-
lambda { @cli.show_admin }.should_not raise_error
|
88
|
-
end
|
89
|
-
|
90
|
-
it "#show_address" do
|
91
|
-
lambda { @cli.show_address('example.com') }.should_not raise_error
|
92
|
-
lambda { @cli.show_address('unknown.example.com') }.should raise_error Error
|
93
|
-
end
|
94
|
-
|
95
|
-
it "#show_admin_domain" do
|
96
|
-
lambda { @cli.show_admin_domain('admin@example.com') }.should_not raise_error
|
97
|
-
end
|
98
|
-
|
99
|
-
it "#show_alias" do
|
100
|
-
lambda { @cli.show_alias('example.com') }.should_not raise_error
|
101
|
-
lambda { @cli.show_alias('unknown.example.com') }.should raise_error Error
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "#super_admin" do
|
105
|
-
it "enables super admin flag of an admin" do
|
106
|
-
lambda{ @cli.super_admin('admin@example.com', false) }.should_not raise_error
|
107
|
-
Admin.find('admin@example.com').super_admin?.should be_true
|
108
|
-
end
|
109
|
-
|
110
|
-
it "disable super admin flag of an admin" do
|
111
|
-
lambda{ @cli.super_admin('all@example.com', true) }.should_not raise_error
|
112
|
-
Admin.find('all@example.com').super_admin?.should be_false
|
113
|
-
end
|
114
|
-
|
115
|
-
it "can not user for unknown admin" do
|
116
|
-
lambda{ @cli.super_admin('unknown_admin@example.com', false) }.should raise_error Error
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
it "#change_admin_password" do
|
121
|
-
lambda { @cli.change_admin_password('admin@example.com', 'new_password') }.should_not raise_error
|
122
|
-
Admin.find('admin@example.com').password.should == 'new_password'
|
123
|
-
lambda { @cli.change_admin_password('unknown_admin@example.com', 'new_password') }.should raise_error Error
|
124
|
-
|
125
|
-
lambda { @cli.change_admin_password('admin@example.com', '1234') }.should raise_error ArgumentError
|
126
|
-
end
|
127
|
-
|
128
|
-
it "#change_account_password" do
|
129
|
-
lambda { @cli.change_account_password('user@example.com', 'new_password') }.should_not raise_error
|
130
|
-
Mailbox.find('user@example.com').password.should == 'new_password'
|
131
|
-
lambda { @cli.change_account_password('unknown@example.com', 'new_password') }.should raise_error Error
|
132
|
-
lambda { @cli.change_account_password('user@example.com', '1234') }.should raise_error ArgumentError
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "#add_admin" do
|
136
|
-
it "can add a new admin" do
|
137
|
-
lambda { @cli.add_admin('new_admin@example.com', 'password') }.should_not raise_error
|
138
|
-
Admin.exist?('new_admin@example.com').should be_true
|
139
|
-
end
|
140
|
-
|
141
|
-
it "can not add exist admin" do
|
142
|
-
lambda { @cli.add_admin('admin@example.com', 'password') }.should raise_error Error
|
143
|
-
end
|
144
|
-
|
145
|
-
it "does not allow too short password (<5)" do
|
146
|
-
lambda { @cli.add_admin('admin@example.com', '1234') }.should raise_error ArgumentError
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "#delete_admin" do
|
151
|
-
it "can delete an admin" do
|
152
|
-
lambda { @cli.delete_admin('admin@example.com') }.should_not raise_error
|
153
|
-
Admin.exist?('admin@example.com').should be_false
|
154
|
-
end
|
155
|
-
|
156
|
-
it "can delete a super admin" do
|
157
|
-
lambda { @cli.delete_admin('all@example.com') }.should_not raise_error
|
158
|
-
Admin.exist?('all@example.com').should be_false
|
159
|
-
end
|
160
|
-
|
161
|
-
it "can delete an admin whish has multiple domains" do
|
162
|
-
@cli.add_admin_domain('admin@example.com', 'example.org')
|
163
|
-
lambda { @cli.delete_admin('admin@example.com') }.should_not raise_error
|
164
|
-
Admin.exist?('admin@example.com').should be_false
|
165
|
-
end
|
166
|
-
|
167
|
-
it "can not delete unknown admin" do
|
168
|
-
lambda { @cli.delete_admin('unknown_admin@example.com') }.should raise_error Error
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
it "#add_alias and #delete_alias" do
|
173
|
-
lambda { @cli.add_alias('user@example.com', 'goto@example.jp') }.should raise_error
|
174
|
-
lambda { @cli.delete_alias('user@example.com') }.should raise_error
|
175
|
-
lambda { @cli.delete_alias('unknown@example.com') }.should raise_error
|
176
|
-
|
177
|
-
lambda { @cli.add_alias('new_alias@example.com', 'goto@example.jp') }.should_not raise_error
|
178
|
-
Alias.exist?('new_alias@example.com').should be_true
|
179
|
-
|
180
|
-
lambda { @cli.delete_alias('new_alias@example.com') }.should_not raise_error
|
181
|
-
Alias.exist?('new_alias@example.com').should be_false
|
182
|
-
end
|
183
|
-
|
184
|
-
describe "#add_account" do
|
185
|
-
it "can add an account" do
|
186
|
-
lambda { @cli.add_account('new_user@example.com', 'password') }.should_not raise_error
|
187
|
-
Mailbox.exist?('new_user@example.com').should be_true
|
188
|
-
Alias.exist?('new_user@example.com').should be_true
|
189
|
-
end
|
190
|
-
|
191
|
-
it "can not add account of unknown domain" do
|
192
|
-
lambda { @cli.add_account('user@unknown.example.com', 'password') }.should raise_error Error
|
193
|
-
end
|
194
|
-
|
195
|
-
it "does not allow too short password (<5)" do
|
196
|
-
lambda { @cli.add_account('new_user@example.com', '1234') }.should raise_error ArgumentError
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
describe "#delete_accont" do
|
201
|
-
it "can delete an account" do
|
202
|
-
lambda { @cli.delete_account('user@example.com') }.should_not raise_error
|
203
|
-
Mailbox.exist?('user@example.com').should be_false
|
204
|
-
Alias.exist?('user@example.com').should be_false
|
205
|
-
end
|
206
|
-
|
207
|
-
it "can not delete unknown account" do
|
208
|
-
lambda { @cli.delete_account('unknown@example.com') }.should raise_error Error
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
describe "#add_domain" do
|
213
|
-
it "can add a new domain" do
|
214
|
-
lambda { @cli.add_domain('example.net') }.should_not raise_error
|
215
|
-
end
|
216
|
-
|
217
|
-
it "upcase will convert to downcase" do
|
218
|
-
lambda{ @cli.add_domain('ExAmPle.NeT') }.should_not raise_error
|
219
|
-
Domain.exist?('example.net').should be_true
|
220
|
-
end
|
221
|
-
|
222
|
-
it "can not add exist domain" do
|
223
|
-
lambda{ @cli.add_domain('example.com') }.should raise_error Error
|
224
|
-
lambda{ @cli.add_domain('ExAmPle.Com') }.should raise_error Error
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe "#edit_domain" do
|
229
|
-
it "can update domain limitations" do
|
230
|
-
lambda{ @cli.edit_domain('example.com', {:aliases => 40, :mailboxes => 40, :maxquota => 400}) }.should_not raise_error
|
231
|
-
domain = Domain.find('example.com')
|
232
|
-
domain.maxaliases.should == 40
|
233
|
-
domain.maxmailboxes.should == 40
|
234
|
-
domain.maxquota.should == 400
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
describe "#edit_account" do
|
239
|
-
it "can update account" do
|
240
|
-
lambda { @cli.edit_account('user@example.com', {:quota => 50}) }.should_not raise_error
|
241
|
-
Mailbox.find('user@example.com').quota.should == 50 * KB_TO_MB
|
242
|
-
end
|
243
|
-
|
244
|
-
it "raise error when unknown account" do
|
245
|
-
lambda { @cli.edit_account('unknown@example.com', {:quota => 50}) }.should raise_error Error
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe "#delete_domain" do
|
250
|
-
it "can delete exist domain" do
|
251
|
-
lambda { @cli.delete_domain('example.com') }.should_not raise_error
|
252
|
-
Domain.exist?('example.net').should be_false
|
253
|
-
end
|
254
|
-
|
255
|
-
it "upcase will convert to downcase" do
|
256
|
-
lambda { @cli.delete_domain('eXaMplE.cOm') }.should_not raise_error
|
257
|
-
Domain.exist?('example.com').should be_false
|
258
|
-
end
|
259
|
-
|
260
|
-
it "can delete related admins, addresses and aliases" do
|
261
|
-
@cli.add_admin('admin@example.org', 'password')
|
262
|
-
@cli.add_admin_domain('admin@example.org', 'example.org')
|
263
|
-
@cli.add_account('user2@example.com', 'password')
|
264
|
-
|
265
|
-
@cli.add_admin('other_admin@example.com', 'password')
|
266
|
-
@cli.add_admin_domain('other_admin@example.com', 'example.com')
|
267
|
-
|
268
|
-
@cli.add_admin('no_related@example.com', 'password')
|
269
|
-
|
270
|
-
lambda { @cli.delete_domain('example.com') }.should_not raise_error
|
271
|
-
Admin.exist?('admin@example.com').should be_false
|
272
|
-
Admin.exist?('admin@example.org').should be_true
|
273
|
-
Admin.exist?('other_admin@example.com').should be_false
|
274
|
-
Admin.exist?('no_related@example.com').should be_true
|
275
|
-
|
276
|
-
# aliases should be removed
|
277
|
-
Alias.exist?('alias@example.com').should be_false
|
278
|
-
Alias.exist?('user@example.com').should be_false
|
279
|
-
Alias.exist?('user2@example.com').should be_false
|
280
|
-
|
281
|
-
# mailboxes should be removed
|
282
|
-
Mailbox.exist?('user@example.com').should be_false
|
283
|
-
Mailbox.exist?('user2@example.com').should be_false
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|