postfix_admin 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +25 -17
- data/lib/postfix_admin/base.rb +34 -5
- data/lib/postfix_admin/cli.rb +98 -17
- data/lib/postfix_admin/doveadm.rb +32 -0
- data/lib/postfix_admin/models.rb +42 -12
- data/lib/postfix_admin/runner.rb +48 -9
- data/lib/postfix_admin/version.rb +1 -1
- data/postfix_admin.gemspec +3 -2
- data/spec/base_spec.rb +36 -18
- data/spec/cli_spec.rb +51 -33
- data/spec/doveadm_spec.rb +35 -0
- data/spec/models_spec.rb +50 -1
- data/spec/runner_spec.rb +155 -14
- data/spec/spec_helper.rb +71 -45
- metadata +40 -22
@@ -0,0 +1,35 @@
|
|
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
|
data/spec/models_spec.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2
2
|
require 'postfix_admin/models'
|
3
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
|
+
|
4
11
|
describe PostfixAdmin::Admin do
|
5
12
|
before do
|
6
13
|
db_initialize
|
@@ -12,6 +19,14 @@ describe PostfixAdmin::Admin do
|
|
12
19
|
Admin.exist?('unknown@example.com').should === false
|
13
20
|
end
|
14
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
|
+
|
15
30
|
it "#super_admin?" do
|
16
31
|
Admin.find('admin@example.com').super_admin?.should === false
|
17
32
|
Admin.find('all@example.com').super_admin?.should === true
|
@@ -25,7 +40,7 @@ describe PostfixAdmin::Admin do
|
|
25
40
|
|
26
41
|
it "should not delete 'ALL' domain" do
|
27
42
|
Admin.find('all@example.com').super_admin = false
|
28
|
-
Domain.exist?('ALL').should
|
43
|
+
Domain.exist?('ALL').should be true
|
29
44
|
end
|
30
45
|
|
31
46
|
it "disable super admin flag" do
|
@@ -69,6 +84,14 @@ describe PostfixAdmin::Domain do
|
|
69
84
|
Domain.exist?('unknown.example.com').should === false
|
70
85
|
end
|
71
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
|
+
|
72
95
|
describe "#num_total_aliases and .num_total_aliases" do
|
73
96
|
it "when only alias@example.com" do
|
74
97
|
Domain.num_total_aliases.should be(1)
|
@@ -103,6 +126,22 @@ describe PostfixAdmin::Mailbox do
|
|
103
126
|
db_initialize
|
104
127
|
end
|
105
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
|
+
|
106
145
|
describe ".exist?" do
|
107
146
|
it "returns true for exist account (mailbox)" do
|
108
147
|
Mailbox.exist?('user@example.com').should === true
|
@@ -123,6 +162,16 @@ describe PostfixAdmin::Alias do
|
|
123
162
|
db_initialize
|
124
163
|
end
|
125
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
|
+
|
126
175
|
describe ".exist?" do
|
127
176
|
it "returns true when exist alias and account" do
|
128
177
|
Alias.exist?('user@example.com').should === true
|
data/spec/runner_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
1
3
|
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2
4
|
require 'postfix_admin/runner'
|
3
5
|
|
@@ -15,17 +17,21 @@ describe PostfixAdmin::Runner do
|
|
15
17
|
capture(:stdout){ Runner.start(["summary", "example.com"]) }.should =~ /\[Summary of example.com\]/
|
16
18
|
end
|
17
19
|
|
20
|
+
it "schemes" do
|
21
|
+
capture(:stdout){ Runner.start(["schemes"]) }.should =~ /CLEARTEXT/
|
22
|
+
end
|
23
|
+
|
18
24
|
describe "show" do
|
19
25
|
it "shows information of example.com" do
|
20
26
|
capture(:stdout){ Runner.start(["show"]) }.should =~ /example.com\s+1\s+\/\s+30\s+1\s+\/\s+30\s+100/
|
21
27
|
end
|
22
28
|
|
23
29
|
it "shows information of admin@example.com" do
|
24
|
-
capture(:stdout){ Runner.start(["show"]) }.should =~ /admin@example.com\s+1\s+
|
30
|
+
capture(:stdout){ Runner.start(["show"]) }.should =~ /admin@example.com\s+1\s+YES/
|
25
31
|
end
|
26
32
|
|
27
33
|
it "show the detail of example.com" do
|
28
|
-
capture(:stdout){ Runner.start(["show", "example.com"]) }.should =~ /user@example.com\s+100\s+
|
34
|
+
capture(:stdout){ Runner.start(["show", "example.com"]) }.should =~ /user@example.com\s+100\s+YES/
|
29
35
|
end
|
30
36
|
|
31
37
|
it "when no admins, no aliases and no addresses" do
|
@@ -36,10 +42,18 @@ describe PostfixAdmin::Runner do
|
|
36
42
|
out.should =~ /No aliases/
|
37
43
|
end
|
38
44
|
|
45
|
+
it "shows information of an admin" do
|
46
|
+
capture(:stdout){ Runner.start(["show", "admin@example.com"]) }.should =~ /admin@example.com/
|
47
|
+
end
|
48
|
+
|
39
49
|
it "shows information of an account" do
|
40
50
|
capture(:stdout){ Runner.start(["show", "user@example.com"]) }.should =~ /user@example.com/
|
41
51
|
end
|
42
52
|
|
53
|
+
it "shows information of an alias" do
|
54
|
+
capture(:stdout){ Runner.start(["show", "alias@example.com"]) }.should =~ /alias@example.com/
|
55
|
+
end
|
56
|
+
|
43
57
|
it "when no domains" do
|
44
58
|
capture(:stdout){ Runner.start(['delete_domain', 'example.com']) }.should =~ EX_DELETED
|
45
59
|
capture(:stdout){ Runner.start(['delete_domain', 'example.org']) }.should =~ EX_DELETED
|
@@ -83,6 +97,7 @@ describe PostfixAdmin::Runner do
|
|
83
97
|
describe "account_passwd" do
|
84
98
|
it "can change password of an account" do
|
85
99
|
capture(:stdout){ Runner.start(['account_passwd', 'user@example.com', 'new_password']) }.should =~ /successfully changed/
|
100
|
+
Mailbox.find('user@example.com').password.should == CRAM_MD5_NEW_PASS
|
86
101
|
end
|
87
102
|
|
88
103
|
it "can not use too short password (< 5)" do
|
@@ -110,8 +125,35 @@ describe PostfixAdmin::Runner do
|
|
110
125
|
end
|
111
126
|
|
112
127
|
describe "add_admin" do
|
128
|
+
before do
|
129
|
+
@args = ['add_admin', 'admin@example.jp', 'password']
|
130
|
+
end
|
131
|
+
|
113
132
|
it "can add an new admin" do
|
114
|
-
capture(:stdout){ Runner.start(
|
133
|
+
capture(:stdout){ Runner.start(@args) }.should =~ EX_REGISTERED
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "scheme option" do
|
137
|
+
it "--scheme does not show error" do
|
138
|
+
capture(:stderr){ Runner.start(@args + ['--scheme', 'CRAM-MD5']) }.should == ""
|
139
|
+
Admin.find('admin@example.jp').password.should == CRAM_MD5_PASS
|
140
|
+
end
|
141
|
+
|
142
|
+
it "--shceme can resister admin" do
|
143
|
+
capture(:stdout){ Runner.start(@args + ['--scheme', 'CRAM-MD5']) }.should =~ EX_REGISTERED
|
144
|
+
end
|
145
|
+
|
146
|
+
it "-s does not show error" do
|
147
|
+
capture(:stderr){ Runner.start(@args + ['-s', 'CRAM-MD5']) }.should == ""
|
148
|
+
end
|
149
|
+
|
150
|
+
it "-s can resister admin" do
|
151
|
+
capture(:stdout){ Runner.start(@args + ['-s', 'CRAM-MD5']) }.should =~ EX_REGISTERED
|
152
|
+
end
|
153
|
+
|
154
|
+
it "-s require argument" do
|
155
|
+
capture(:stderr){ Runner.start(@args + ['-s']) }.should =~ /Specify password scheme/
|
156
|
+
end
|
115
157
|
end
|
116
158
|
|
117
159
|
it "can use long password" do
|
@@ -119,11 +161,11 @@ describe PostfixAdmin::Runner do
|
|
119
161
|
end
|
120
162
|
|
121
163
|
it "--super option" do
|
122
|
-
capture(:stdout){ Runner.start(
|
164
|
+
capture(:stdout){ Runner.start(@args + ['--super']) }.should =~ /registered as a super admin/
|
123
165
|
end
|
124
166
|
|
125
|
-
it "-
|
126
|
-
capture(:stdout){ Runner.start(
|
167
|
+
it "-S (--super) option" do
|
168
|
+
capture(:stdout){ Runner.start(@args + ['-S']) }.should =~ /registered as a super admin/
|
127
169
|
end
|
128
170
|
end
|
129
171
|
|
@@ -133,11 +175,11 @@ describe PostfixAdmin::Runner do
|
|
133
175
|
end
|
134
176
|
|
135
177
|
it "can edit limitations of domain" do
|
136
|
-
capture(:stdout){ Runner.start(['edit_domain', 'example.com', '--aliases', '40', '--mailboxes', '40', '--maxquota', '400']) }.should =~
|
178
|
+
capture(:stdout){ Runner.start(['edit_domain', 'example.com', '--aliases', '40', '--mailboxes', '40', '--maxquota', '400']) }.should =~ EX_UPDATED
|
137
179
|
end
|
138
180
|
|
139
181
|
it "aliases options -a, -m, -q" do
|
140
|
-
capture(:stdout){ Runner.start(['edit_domain', 'example.com', '-a', '40', '-m', '40', '-m', '400']) }.should =~
|
182
|
+
capture(:stdout){ Runner.start(['edit_domain', 'example.com', '-a', '40', '-m', '40', '-m', '400']) }.should =~ EX_UPDATED
|
141
183
|
end
|
142
184
|
|
143
185
|
it "can not use unknown domain" do
|
@@ -146,18 +188,45 @@ describe PostfixAdmin::Runner do
|
|
146
188
|
end
|
147
189
|
|
148
190
|
describe "edit_account" do
|
191
|
+
before do
|
192
|
+
@args = ['edit_account', 'user@example.com']
|
193
|
+
end
|
194
|
+
|
149
195
|
it "when no options, shows usage" do
|
150
|
-
capture(:stderr){ Runner.start(
|
196
|
+
capture(:stderr){ Runner.start(@args) }.should =~ /Use one or more options/
|
151
197
|
end
|
152
198
|
|
153
199
|
it "can edit quota limitation" do
|
154
|
-
output = capture(:stdout){ Runner.start(
|
155
|
-
output.should =~
|
200
|
+
output = capture(:stdout){ Runner.start(@args + ['--quota', '50'])}
|
201
|
+
output.should =~ EX_UPDATED
|
156
202
|
output.should =~ /Quota/
|
157
203
|
end
|
158
204
|
|
159
205
|
it "can use alias -q option" do
|
160
|
-
capture(:stdout){ Runner.start(
|
206
|
+
capture(:stdout){ Runner.start(@args + ['-q', '50'])}.should =~ EX_UPDATED
|
207
|
+
end
|
208
|
+
|
209
|
+
it "-q option require an argment" do
|
210
|
+
capture(:stderr){ Runner.start(@args + ['-q'])}.should_not == ""
|
211
|
+
end
|
212
|
+
|
213
|
+
it "can update name using --name option" do
|
214
|
+
capture(:stdout){ Runner.start(@args + ['--name', 'Hitoshi Kurokawa'])}.should =~ EX_UPDATED
|
215
|
+
Mailbox.find('user@example.com').name.should == 'Hitoshi Kurokawa'
|
216
|
+
end
|
217
|
+
|
218
|
+
it "can update name using -n option" do
|
219
|
+
capture(:stdout){ Runner.start(@args + ['-n', 'Hitoshi Kurokawa'])}.should =~ EX_UPDATED
|
220
|
+
Mailbox.find('user@example.com').name.should == 'Hitoshi Kurokawa'
|
221
|
+
end
|
222
|
+
|
223
|
+
it "-n option supports Japanese" do
|
224
|
+
capture(:stdout){ Runner.start(@args + ['-n', '黒川 仁'])}.should =~ EX_UPDATED
|
225
|
+
Mailbox.find('user@example.com').name.should == '黒川 仁'
|
226
|
+
end
|
227
|
+
|
228
|
+
it "-n option require an argument" do
|
229
|
+
capture(:stderr){ Runner.start(@args + ['-n'])}.should_not == ""
|
161
230
|
end
|
162
231
|
end
|
163
232
|
|
@@ -178,8 +247,68 @@ describe PostfixAdmin::Runner do
|
|
178
247
|
capture(:stdout){ Runner.start(['delete_account', 'user2@example.com']) }.should =~ EX_DELETED
|
179
248
|
end
|
180
249
|
|
181
|
-
|
182
|
-
|
250
|
+
describe "add_account" do
|
251
|
+
before do
|
252
|
+
@user = 'user2@example.com'
|
253
|
+
@args = ['add_account', @user, 'password']
|
254
|
+
@name = 'Hitoshi Kurokawa'
|
255
|
+
end
|
256
|
+
|
257
|
+
it "default scheme (CRAM-MD5) is applied" do
|
258
|
+
capture(:stdout){ Runner.start(@args) }.should =~ /scheme: CRAM-MD5/
|
259
|
+
Mailbox.find('user2@example.com').password.should == CRAM_MD5_PASS
|
260
|
+
end
|
261
|
+
|
262
|
+
it "add_account can use long password" do
|
263
|
+
capture(:stdout){ Runner.start(['add_account', 'user2@example.com', '9c5e77f2da26fc03e9fa9e13ccd77aeb50c85539a4d90b70812715aea9ebda1d']) }.should =~ EX_REGISTERED
|
264
|
+
end
|
265
|
+
|
266
|
+
describe "name option" do
|
267
|
+
it "--name options does not raise error" do
|
268
|
+
capture(:stderr){ Runner.start(@args + ['--name', @name]) }.should == ""
|
269
|
+
end
|
270
|
+
|
271
|
+
it "-n options does not raise error" do
|
272
|
+
capture(:stderr){ Runner.start(@args + ['-n', @name]) }.should == ""
|
273
|
+
end
|
274
|
+
|
275
|
+
it "require an argument" do
|
276
|
+
capture(:stderr){ Runner.start(@args + ['-n']) }.should_not == ""
|
277
|
+
end
|
278
|
+
|
279
|
+
it "can change full name" do
|
280
|
+
Runner.start(@args + ['-n', @name])
|
281
|
+
Mailbox.find(@user).name.should == @name
|
282
|
+
end
|
283
|
+
|
284
|
+
it "can use Japanese" do
|
285
|
+
capture(:stderr){ Runner.start(@args + ['-n', '黒川 仁']) }.should == ""
|
286
|
+
Mailbox.find(@user).name.should == '黒川 仁'
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
describe "scheme" do
|
291
|
+
it "--scheme require argument" do
|
292
|
+
capture(:stderr){ Runner.start(@args + ['--scheme']) }.should =~ /Specify password scheme/
|
293
|
+
end
|
294
|
+
|
295
|
+
it "can use CRAM-MD5 using --scheme" do
|
296
|
+
capture(:stdout){ Runner.start(@args + ['--scheme', 'CRAM-MD5']) }.should =~ EX_REGISTERED
|
297
|
+
Mailbox.find('user2@example.com').password.should == CRAM_MD5_PASS
|
298
|
+
end
|
299
|
+
|
300
|
+
it "can use CRAM-MD5 using -s" do
|
301
|
+
capture(:stdout){ Runner.start(@args + ['-s', 'CRAM-MD5']) }.should =~ EX_REGISTERED
|
302
|
+
Mailbox.find('user2@example.com').password.should == CRAM_MD5_PASS
|
303
|
+
end
|
304
|
+
|
305
|
+
it "can use MD5-CRYPT using -s" do
|
306
|
+
result = capture(:stdout){ Runner.start(@args + ['-s', 'MD5-CRYPT']) }
|
307
|
+
result.should =~ EX_REGISTERED
|
308
|
+
result.should =~ /scheme: MD5-CRYPT/
|
309
|
+
Mailbox.find('user2@example.com').password.should =~ EX_MD5_CRYPT
|
310
|
+
end
|
311
|
+
end
|
183
312
|
end
|
184
313
|
|
185
314
|
it "add and delete methods" do
|
@@ -191,4 +320,16 @@ describe PostfixAdmin::Runner do
|
|
191
320
|
lambda { Runner.start(['add_account', 'user2@example.net', 'password']) }.should_not raise_error
|
192
321
|
lambda { Runner.start(['delete_domain', 'example.net']) }.should_not raise_error
|
193
322
|
end
|
323
|
+
|
324
|
+
describe "dump" do
|
325
|
+
it "does not raise error" do
|
326
|
+
capture(:stderr){ Runner.start(['dump']) }.should == ""
|
327
|
+
end
|
328
|
+
|
329
|
+
it "all data" do
|
330
|
+
result = capture(:stdout){ Runner.start(['dump']) }
|
331
|
+
result.should =~ /Domains/
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
194
335
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,9 +4,11 @@ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
|
4
4
|
require 'postfix_admin'
|
5
5
|
require 'postfix_admin/cli'
|
6
6
|
|
7
|
-
|
8
7
|
include PostfixAdmin
|
9
8
|
|
9
|
+
# CRAM-MD5
|
10
|
+
SAMPLE_PASSWORD = "9186d855e11eba527a7a52ca82b313e180d62234f0acc9051b527243d41e2740"
|
11
|
+
|
10
12
|
# [fixtures]
|
11
13
|
# Domain:
|
12
14
|
# ALL
|
@@ -28,6 +30,7 @@ def config_initialize
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def db_clear
|
33
|
+
::PostfixAdmin::Config.all.destroy
|
31
34
|
DomainAdmin.all.destroy
|
32
35
|
Mailbox.all.destroy
|
33
36
|
Alias.all.destroy
|
@@ -35,7 +38,7 @@ def db_clear
|
|
35
38
|
Admin.all.destroy
|
36
39
|
end
|
37
40
|
|
38
|
-
def create_domain(domain_name)
|
41
|
+
def create_domain(domain_name, active=true)
|
39
42
|
domain = Domain.new
|
40
43
|
domain.attributes = {
|
41
44
|
:domain_name => domain_name,
|
@@ -43,69 +46,88 @@ def create_domain(domain_name)
|
|
43
46
|
:maxaliases => 30,
|
44
47
|
:maxmailboxes => 30,
|
45
48
|
:maxquota => 100,
|
49
|
+
:active => active
|
46
50
|
}
|
47
51
|
domain.save
|
48
52
|
end
|
49
53
|
|
50
|
-
def
|
51
|
-
|
54
|
+
def create_alias_base(address, goto, active)
|
55
|
+
Alias.new.attributes = {
|
56
|
+
:address => address,
|
57
|
+
:goto => goto,
|
58
|
+
:active => active
|
59
|
+
}
|
60
|
+
end
|
52
61
|
|
53
|
-
|
54
|
-
|
55
|
-
|
62
|
+
def create_alias(address, active=true)
|
63
|
+
create_alias_base(address, 'goto@example.jp', active)
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_mailbox_alias(address, active=true)
|
67
|
+
create_alias_base(address, address, active)
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_mailbox(address, in_path=nil, active=true)
|
71
|
+
path = in_path || "#{address.split('@').last}/#{address}/"
|
72
|
+
Mailbox.new.attributes = {
|
73
|
+
:username => address,
|
74
|
+
:password => SAMPLE_PASSWORD,
|
75
|
+
:name => '',
|
76
|
+
:maildir => path,
|
77
|
+
:quota => 100 * KB_TO_MB,
|
78
|
+
# :local_part => user,
|
79
|
+
:active => active
|
80
|
+
}
|
81
|
+
end
|
56
82
|
|
57
|
-
|
83
|
+
def create_admin(username, active=true)
|
58
84
|
admin = Admin.new
|
59
85
|
admin.attributes = {
|
60
86
|
:username => username,
|
61
|
-
:password =>
|
87
|
+
:password => SAMPLE_PASSWORD,
|
88
|
+
:active => active
|
62
89
|
}
|
63
90
|
admin.save
|
91
|
+
admin
|
92
|
+
end
|
64
93
|
|
65
|
-
|
66
|
-
|
67
|
-
|
94
|
+
class ::PostfixAdmin::Mailbox
|
95
|
+
property :local_part, String
|
96
|
+
end
|
97
|
+
|
98
|
+
def db_initialize
|
99
|
+
db_clear
|
68
100
|
|
69
|
-
|
70
|
-
|
71
|
-
:
|
72
|
-
:
|
101
|
+
config = ::PostfixAdmin::Config.new
|
102
|
+
config.attributes = {
|
103
|
+
:id => 1,
|
104
|
+
:name => "version",
|
105
|
+
:value => "740"
|
73
106
|
}
|
74
|
-
|
107
|
+
config.save
|
108
|
+
|
109
|
+
create_domain('ALL')
|
110
|
+
create_domain('example.com')
|
111
|
+
create_domain('example.org')
|
75
112
|
|
113
|
+
all_admin = create_admin('all@example.com')
|
76
114
|
all_domain = Domain.find('ALL')
|
77
115
|
all_domain.admins << all_admin
|
78
|
-
all_domain.save
|
79
|
-
|
80
|
-
address = "user@example.com"
|
81
|
-
mail_alias = Alias.new
|
82
|
-
mail_alias.attributes = {
|
83
|
-
:address => address,
|
84
|
-
:goto => address,
|
85
|
-
}
|
86
|
-
domain.aliases << mail_alias
|
87
116
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
:goto => 'goto@example.jp',
|
92
|
-
}
|
93
|
-
domain.aliases << forward
|
117
|
+
unless all_domain.save
|
118
|
+
raise "Could not save all_domain"
|
119
|
+
end
|
94
120
|
|
95
|
-
|
121
|
+
admin = create_admin('admin@example.com')
|
122
|
+
domain = Domain.find('example.com')
|
123
|
+
domain.admins << admin
|
124
|
+
domain.aliases << create_alias('alias@example.com')
|
125
|
+
domain.aliases << create_alias('user@example.com')
|
126
|
+
domain.mailboxes << create_mailbox('user@example.com')
|
96
127
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
:username => address,
|
101
|
-
:password => 'password',
|
102
|
-
:name => '',
|
103
|
-
:maildir => path,
|
104
|
-
:quota => 100 * KB_TO_MB,
|
105
|
-
# :local_part => user,
|
106
|
-
}
|
107
|
-
domain.mailboxes << mailbox
|
108
|
-
domain.save
|
128
|
+
unless domain.save
|
129
|
+
raise "Could not save domain"
|
130
|
+
end
|
109
131
|
end
|
110
132
|
|
111
133
|
DataMapper.setup(:default, 'sqlite::memory:')
|
@@ -126,8 +148,12 @@ module PostfixAdmin
|
|
126
148
|
end
|
127
149
|
end
|
128
150
|
|
151
|
+
CRAM_MD5_PASS = '9186d855e11eba527a7a52ca82b313e180d62234f0acc9051b527243d41e2740'
|
152
|
+
CRAM_MD5_NEW_PASS = '820de4c70957274d41111c5fbcae4c87240c9f047fc56f3e720f103571be6cbc'
|
129
153
|
EX_DELETED = /successfully deleted/
|
130
154
|
EX_REGISTERED = /successfully registered/
|
155
|
+
EX_UPDATED = /Successfully updated/
|
156
|
+
EX_MD5_CRYPT = /^\$1\$[\.\/0-9A-Za-z]{8}\$[\.\/0-9A-Za-z]{22}$/
|
131
157
|
|
132
158
|
RSpec.configure do |config|
|
133
159
|
config.before do
|