postfix_admin 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,300 +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_details" do
58
- it "shows information of an account" do
59
- lambda { @cli.show_account_details('user@example.com') }.should_not raise_error
60
- result = capture(:stdout){ @cli.show_account_details('user@example.com') }
61
- result.should =~ /Name/
62
- result.should =~ /Quota/
63
- end
64
-
65
- it "raises error when unknown account" do
66
- lambda { @cli.show_account_details('unknown@example.com') }.should raise_error Error
67
- end
68
- end
69
-
70
- describe "#show_summary" do
71
- it "show summary of all domain" do
72
- lambda { @cli.show_summary }.should_not raise_error
73
- end
74
-
75
- it "show summary of domain" do
76
- lambda { @cli.show_summary('example.com') }.should_not raise_error
77
- end
78
-
79
- it "upcase will convert to downcase" do
80
- lambda { @cli.show_summary('example.COM') }.should_not raise_error
81
- end
82
-
83
- it "when unknown domain, raises Error" do
84
- lambda { @cli.show_summary('unknown.example.com') }.should raise_error Error
85
- end
86
- end
87
-
88
- it "#show_admin" do
89
- lambda { @cli.show_admin }.should_not raise_error
90
- end
91
-
92
- it "#show_address" do
93
- lambda { @cli.show_address('example.com') }.should_not raise_error
94
- lambda { @cli.show_address('unknown.example.com') }.should raise_error Error
95
- end
96
-
97
- it "#show_admin_domain" do
98
- lambda { @cli.show_admin_domain('admin@example.com') }.should_not raise_error
99
- end
100
-
101
- it "#show_alias" do
102
- lambda { @cli.show_alias('example.com') }.should_not raise_error
103
- lambda { @cli.show_alias('unknown.example.com') }.should raise_error Error
104
- end
105
-
106
- it "#change_admin_password" do
107
- lambda { @cli.change_admin_password('admin@example.com', 'new_password') }.should_not raise_error
108
- Admin.find('admin@example.com').password.should == CRAM_MD5_NEW_PASS
109
- lambda { @cli.change_admin_password('unknown_admin@example.com', 'new_password') }.should raise_error Error
110
-
111
- lambda { @cli.change_admin_password('admin@example.com', '1234') }.should raise_error ArgumentError
112
- end
113
-
114
- it "#change_account_password" do
115
- lambda { @cli.change_account_password('user@example.com', 'new_password') }.should_not raise_error
116
- Mailbox.find('user@example.com').password.should == CRAM_MD5_NEW_PASS
117
- lambda { @cli.change_account_password('unknown@example.com', 'new_password') }.should raise_error Error
118
- lambda { @cli.change_account_password('user@example.com', '1234') }.should raise_error ArgumentError
119
- end
120
-
121
- describe "#add_admin" do
122
- it "can add a new admin" do
123
- lambda { @cli.add_admin('new_admin@example.com', 'password') }.should_not raise_error
124
- Admin.exist?('new_admin@example.com').should be true
125
- end
126
-
127
- it "can not add exist admin" do
128
- lambda { @cli.add_admin('admin@example.com', 'password') }.should raise_error Error
129
- end
130
-
131
- it "does not allow too short password (<5)" do
132
- lambda { @cli.add_admin('admin@example.com', '1234') }.should raise_error ArgumentError
133
- end
134
- end
135
-
136
- describe "#delete_admin" do
137
- it "can delete an admin" do
138
- lambda { @cli.delete_admin('admin@example.com') }.should_not raise_error
139
- Admin.exist?('admin@example.com').should be false
140
- end
141
-
142
- it "can delete a super admin" do
143
- lambda { @cli.delete_admin('all@example.com') }.should_not raise_error
144
- Admin.exist?('all@example.com').should be false
145
- end
146
-
147
- it "can delete an admin whish has multiple domains" do
148
- @cli.add_admin_domain('admin@example.com', 'example.org')
149
- lambda { @cli.delete_admin('admin@example.com') }.should_not raise_error
150
- Admin.exist?('admin@example.com').should be false
151
- end
152
-
153
- it "can not delete unknown admin" do
154
- lambda { @cli.delete_admin('unknown_admin@example.com') }.should raise_error Error
155
- end
156
- end
157
-
158
- it "#add_alias and #delete_alias" do
159
- lambda { @cli.add_alias('user@example.com', 'goto@example.jp') }.should raise_error Error
160
- lambda { @cli.delete_alias('user@example.com') }.should raise_error Error
161
- lambda { @cli.delete_alias('unknown@example.com') }.should raise_error Error
162
-
163
- lambda { @cli.add_alias('new_alias@example.com', 'goto@example.jp') }.should_not raise_error
164
- Alias.exist?('new_alias@example.com').should be true
165
-
166
- lambda { @cli.delete_alias('new_alias@example.com') }.should_not raise_error
167
- Alias.exist?('new_alias@example.com').should be false
168
- end
169
-
170
- describe "#add_account" do
171
- it "can add an account" do
172
- lambda { @cli.add_account('new_user@example.com', 'password') }.should_not raise_error
173
- Mailbox.exist?('new_user@example.com').should be true
174
- Alias.exist?('new_user@example.com').should be true
175
- end
176
-
177
- it "can not add account of unknown domain" do
178
- lambda { @cli.add_account('user@unknown.example.com', 'password') }.should raise_error Error
179
- end
180
-
181
- it "does not allow too short password (<5)" do
182
- lambda { @cli.add_account('new_user@example.com', '1234') }.should raise_error ArgumentError
183
- end
184
- end
185
-
186
- describe "#delete_accont" do
187
- it "can delete an account" do
188
- lambda { @cli.delete_account('user@example.com') }.should_not raise_error
189
- Mailbox.exist?('user@example.com').should be false
190
- Alias.exist?('user@example.com').should be false
191
- end
192
-
193
- it "can not delete unknown account" do
194
- lambda { @cli.delete_account('unknown@example.com') }.should raise_error Error
195
- end
196
- end
197
-
198
- describe "#add_domain" do
199
- it "can add a new domain" do
200
- lambda { @cli.add_domain('example.net') }.should_not raise_error
201
- end
202
-
203
- it "upcase will convert to downcase" do
204
- lambda{ @cli.add_domain('ExAmPle.NeT') }.should_not raise_error
205
- Domain.exist?('example.net').should be true
206
- end
207
-
208
- it "can not add exist domain" do
209
- lambda{ @cli.add_domain('example.com') }.should raise_error Error
210
- lambda{ @cli.add_domain('ExAmPle.Com') }.should raise_error Error
211
- end
212
- end
213
-
214
- describe "#edit_domain" do
215
- it "can update domain limitations" do
216
- lambda{ @cli.edit_domain('example.com', {aliases: 40, mailboxes: 40, maxquota: 400, active: false}) }.should_not raise_error
217
- domain = Domain.find('example.com')
218
- domain.maxaliases.should == 40
219
- domain.maxmailboxes.should == 40
220
- domain.maxquota.should == 400
221
- expect(domain.active).to be false
222
- end
223
- end
224
-
225
- describe "#edit_account" do
226
- it "can update account" do
227
- lambda { @cli.edit_account('user@example.com', {quota: 50, active: false}) }.should_not raise_error
228
- mailbox = Mailbox.find('user@example.com')
229
- mailbox.quota.should == 50 * KB_TO_MB
230
- expect(mailbox.active).to be false
231
- end
232
-
233
- it "raise error when unknown account" do
234
- lambda { @cli.edit_account('unknown@example.com', {:quota => 50}) }.should raise_error Error
235
- end
236
- end
237
-
238
- describe "#edit_admin" do
239
- it "can update admin" do
240
- expect { @cli.edit_admin('admin@example.com', {super: true, active: false}) }.not_to raise_error
241
- admin = Admin.find('admin@example.com')
242
- expect(admin.super_admin?).to be true
243
- expect(admin.active).to be false
244
- end
245
- end
246
-
247
- describe "#delete_domain" do
248
- it "can delete exist domain" do
249
- lambda { @cli.delete_domain('example.com') }.should_not raise_error
250
- Domain.exist?('example.net').should be false
251
- end
252
-
253
- it "upcase will convert to downcase" do
254
- lambda { @cli.delete_domain('eXaMplE.cOm') }.should_not raise_error
255
- Domain.exist?('example.com').should be false
256
- end
257
-
258
- it "can delete related admins, addresses and aliases" do
259
- @cli.add_admin('admin@example.org', 'password')
260
- @cli.add_admin_domain('admin@example.org', 'example.org')
261
- @cli.add_account('user2@example.com', 'password')
262
-
263
- @cli.add_admin('other_admin@example.com', 'password')
264
- @cli.add_admin_domain('other_admin@example.com', 'example.com')
265
-
266
- @cli.add_admin('no_related@example.com', 'password')
267
-
268
- lambda { @cli.delete_domain('example.com') }.should_not raise_error
269
- Admin.exist?('admin@example.com').should be false
270
- Admin.exist?('admin@example.org').should be true
271
- Admin.exist?('other_admin@example.com').should be false
272
- Admin.exist?('no_related@example.com').should be true
273
-
274
- # aliases should be removed
275
- Alias.exist?('alias@example.com').should be false
276
- Alias.exist?('user@example.com').should be false
277
- Alias.exist?('user2@example.com').should be false
278
-
279
- # mailboxes should be removed
280
- Mailbox.exist?('user@example.com').should be false
281
- Mailbox.exist?('user2@example.com').should be false
282
- end
283
- end
284
-
285
- describe "#dump" do
286
- it do
287
- lambda { @cli.dump }.should_not raise_error
288
- end
289
-
290
- it "print infomation of all domains" do
291
- result = capture(:stdout){ @cli.dump }
292
- result.should =~ /example.com,100,true/
293
- result.should =~ /example.org,100,true/
294
- result.should =~ /admin@example.com,"9186d855e11eba527a7a52ca82b313e180d62234f0acc9051b527243d41e2740",false,true/
295
- result.should =~ /user@example.com,"","9186d855e11eba527a7a52ca82b313e180d62234f0acc9051b527243d41e2740",102400000,"example.com\/user@example.com\/",true/
296
- result.should =~ /alias@example.com,"goto@example.jp",true/
297
- result.should =~ /user@example.com,"goto@example.jp",true/
298
- end
299
- end
300
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
- require 'postfix_admin/doveadm'
3
-
4
- describe PostfixAdmin::Doveadm do
5
- describe "schemes" do
6
- it "return Array" do
7
- PostfixAdmin::Doveadm.schemes.class.should == Array
8
- end
9
-
10
- it "return supported schemes" do
11
- PostfixAdmin::Doveadm.schemes.should == %W!CRYPT MD5 MD5-CRYPT SHA SHA1 SHA256 SHA512 SMD5 SSHA SSHA256 SSHA512 PLAIN CLEAR CLEARTEXT PLAIN-TRUNC CRAM-MD5 SCRAM-SHA-1 HMAC-MD5 DIGEST-MD5 PLAIN-MD4 PLAIN-MD5 LDAP-MD5 LANMAN NTLM OTP SKEY RPA!
12
- end
13
- end
14
-
15
- describe "password" do
16
- it "CRAM-MD5" do
17
- PostfixAdmin::Doveadm.password('password', 'CRAM-MD5').should == CRAM_MD5_PASS
18
- PostfixAdmin::Doveadm.password('dovecot', 'CRAM-MD5').should == '2dc40f88a4c2142c3b10cc4b4d11382a648f600301b78a4070172782192898d6'
19
- end
20
-
21
- it "SHA256" do
22
- PostfixAdmin::Doveadm.password('password', 'SHA256').should == 'XohImNooBHFR0OVvjcYpJ3NgPQ1qq73WKhHvch0VQtg='
23
- PostfixAdmin::Doveadm.password('dovecot', 'SHA256').should == 'KN7aHmDsiQ/Ko+HzLzHcKoPqkjk7bditnD433YQYhcs='
24
- end
25
-
26
- it "MD5-CRYPT" do
27
- PostfixAdmin::Doveadm.password('password', 'MD5-CRYPT').should =~ EX_MD5_CRYPT
28
- PostfixAdmin::Doveadm.password('dovecot', 'MD5-CRYPT').should =~ EX_MD5_CRYPT
29
- end
30
-
31
- it "unknown scheme raise error" do
32
- lambda{ PostfixAdmin::Doveadm.password('password', 'UNKNOWN-SCHEME') }.should raise_error Error
33
- end
34
- end
35
- end
@@ -1,195 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
- require 'postfix_admin/models'
3
-
4
- describe PostfixAdmin do
5
- it "flag_str" do
6
- PostfixAdmin.flag_str(true).should == "YES"
7
- PostfixAdmin.flag_str(false).should == "NO"
8
- end
9
- end
10
-
11
- describe PostfixAdmin::Admin do
12
- before do
13
- db_initialize
14
- end
15
-
16
- it ".exist?" do
17
- Admin.exist?('admin@example.com').should === true
18
- Admin.exist?('all@example.com').should === true
19
- Admin.exist?('unknown@example.com').should === false
20
- end
21
-
22
- it "active" do
23
- Admin.find('admin@example.com').active.should === true
24
- Admin.find('all@example.com').active.should === true
25
- non_active_admin = create_admin('non_active_admin@example.com', false)
26
-
27
- Admin.find('non_active_admin@example.com').active.should === false
28
- end
29
-
30
- it "#super_admin?" do
31
- Admin.find('admin@example.com').super_admin?.should === false
32
- Admin.find('all@example.com').super_admin?.should === true
33
- end
34
-
35
- describe "#super_admin=" do
36
- it "enable super admin flag" do
37
- lambda{ Admin.find('all@example.com').super_admin = false }.should_not raise_error
38
- Admin.find('all@example.com').super_admin?.should === false
39
- end
40
-
41
- it "should not delete 'ALL' domain" do
42
- Admin.find('all@example.com').super_admin = false
43
- Domain.exist?('ALL').should be true
44
- end
45
-
46
- it "disable super admin flag" do
47
- lambda{ Admin.find('admin@example.com').super_admin = true }.should_not raise_error
48
- Admin.find('admin@example.com').super_admin?.should === true
49
- end
50
- end
51
-
52
- describe "#has_domain?" do
53
- it "returns true when the admin has privileges for the domain" do
54
- Admin.find('admin@example.com').has_domain?('example.com').should === true
55
- end
56
-
57
- it "returns false when the admin does not have privileges for the domain" do
58
- Admin.find('admin@example.com').has_domain?('example.org').should === false
59
- end
60
-
61
- it "returns false when unknown domain" do
62
- Admin.find('admin@example.com').has_domain?('unknown.example.com').should === false
63
- end
64
-
65
- it "returns true when super admin and exist domain" do
66
- Admin.find('all@example.com').has_domain?('example.com').should === true
67
- end
68
-
69
- it "returns false when super admin and unknown domain" do
70
- Admin.find('all@example.com').has_domain?('unknown.example.com').should === false
71
- end
72
- end
73
- end
74
-
75
- describe PostfixAdmin::Domain do
76
- before do
77
- db_initialize
78
- @base = PostfixAdmin::Base.new({'database' => 'sqlite::memory:'})
79
- end
80
-
81
- it ".exist?" do
82
- Domain.exist?('example.com').should === true
83
- Domain.exist?('example.org').should === true
84
- Domain.exist?('unknown.example.com').should === false
85
- end
86
-
87
- it "active" do
88
- Domain.find('example.com').active.should == true
89
- Domain.find('example.org').active.should == true
90
-
91
- create_domain('non-active.example.com', false)
92
- Domain.find('non-active.example.com').active.should == false
93
- end
94
-
95
- describe "#num_total_aliases and .num_total_aliases" do
96
- it "when only alias@example.com" do
97
- Domain.num_total_aliases.should be(1)
98
- Domain.find('example.com').num_total_aliases.should be(1)
99
- end
100
-
101
- it "should increase one if you add an alias" do
102
- @base.add_alias('new_alias@example.com', 'goto@example.jp')
103
- Domain.num_total_aliases.should be(2)
104
- Domain.find('example.com').num_total_aliases.should be(2)
105
- end
106
-
107
- it "should not increase if you add an account" do
108
- @base.add_account('user2@example.com', 'password')
109
- Domain.num_total_aliases.should be(1)
110
- Domain.find('example.com').num_total_aliases.should be(1)
111
- end
112
-
113
- it ".num_total_aliases should not increase if you add an account and an aliase for other domain" do
114
- @base.add_account('user@example.org', 'password')
115
- Domain.num_total_aliases.should be(1)
116
- Domain.find('example.com').num_total_aliases.should be(1)
117
- @base.add_alias('new_alias@example.org', 'goto@example.jp')
118
- Domain.num_total_aliases.should be(2)
119
- Domain.find('example.com').num_total_aliases.should be(1)
120
- end
121
- end
122
- end
123
-
124
- describe PostfixAdmin::Mailbox do
125
- before do
126
- db_initialize
127
- end
128
-
129
- it "active" do
130
- Mailbox.find('user@example.com').active.should == true
131
- domain = Domain.find('example.com')
132
- domain.mailboxes << create_mailbox('non_active_user@example.com', nil, false)
133
- domain.aliases << create_mailbox_alias('non_active_user@example.com', false)
134
- domain.save
135
-
136
- Mailbox.find('non_active_user@example.com').active.should == false
137
- end
138
-
139
- it "can use long maildir" do
140
- domain = Domain.find('example.com')
141
- domain.mailboxes << create_mailbox('long_maildir_user@example.com', 'looooooooooooong_path/example.com/long_maildir_user@example.com/')
142
- domain.save.should == true
143
- end
144
-
145
- describe ".exist?" do
146
- it "returns true for exist account (mailbox)" do
147
- Mailbox.exist?('user@example.com').should === true
148
- end
149
-
150
- it "returns false for alias" do
151
- Mailbox.exist?('alias@example.com').should === false
152
- end
153
-
154
- it "returns false for unknown account (mailbox)" do
155
- Mailbox.exist?('unknown@unknown.example.com').should === false
156
- end
157
- end
158
- end
159
-
160
- describe PostfixAdmin::Alias do
161
- before do
162
- db_initialize
163
- end
164
-
165
- it "active" do
166
- domain = Domain.find('example.com')
167
- domain.aliases << create_alias('non_active_alias@example.com', false)
168
- domain.save
169
-
170
- Alias.find('user@example.com').active.should == true
171
- Alias.find('alias@example.com').active.should == true
172
- Alias.find('non_active_alias@example.com').active.should == false
173
- end
174
-
175
- describe ".exist?" do
176
- it "returns true when exist alias and account" do
177
- Alias.exist?('user@example.com').should === true
178
- Alias.exist?('alias@example.com').should === true
179
- end
180
-
181
- it "returns false when unknown alias" do
182
- Alias.exist?('unknown@unknown.example.com').should === false
183
- end
184
- end
185
-
186
- describe ".mailbox?" do
187
- it "when there is same address in maiboxes returns true" do
188
- Alias.find('user@example.com').mailbox?.should === true
189
- end
190
-
191
- it "when there is no same address in maiboxes returns false" do
192
- Alias.find('alias@example.com').mailbox?.should === false
193
- end
194
- end
195
- end