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,201 +0,0 @@
1
-
2
- $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
-
4
- require 'postfix_admin'
5
- require 'postfix_admin/cli'
6
-
7
- include PostfixAdmin
8
-
9
- # CRAM-MD5
10
- SAMPLE_PASSWORD = "9186d855e11eba527a7a52ca82b313e180d62234f0acc9051b527243d41e2740"
11
-
12
- # [fixtures]
13
- # Domain:
14
- # ALL
15
- # example.com
16
- # example.org
17
- #
18
- # Admin:
19
- # all@example.com Super Admin
20
- # admin@example.com
21
- #
22
- # Mailbox, Alias:
23
- # user@example.com
24
- #
25
- # Alias:
26
- # alias@example.com -> goto@example.jp
27
-
28
- def config_initialize
29
- CLI.config_file = File.join(File.dirname(__FILE__) , 'postfix_admin.conf')
30
- end
31
-
32
- def db_clear
33
- ::PostfixAdmin::Config.all.destroy
34
- DomainAdmin.all.destroy
35
- Mailbox.all.destroy
36
- Alias.all.destroy
37
- Domain.all.destroy
38
- Admin.all.destroy
39
- end
40
-
41
- def create_domain(domain_name, active=true)
42
- domain = Domain.new
43
- domain.attributes = {
44
- :domain_name => domain_name,
45
- :description => domain_name,
46
- :maxaliases => 30,
47
- :maxmailboxes => 30,
48
- :maxquota => 100,
49
- :active => active
50
- }
51
- domain.save
52
- end
53
-
54
- def create_alias_base(address, goto, active)
55
- Alias.new.attributes = {
56
- :address => address,
57
- :goto => goto,
58
- :active => active
59
- }
60
- end
61
-
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
82
-
83
- def create_admin(username, active=true)
84
- admin = Admin.new
85
- admin.attributes = {
86
- :username => username,
87
- :password => SAMPLE_PASSWORD,
88
- :active => active
89
- }
90
- admin.save
91
- admin
92
- end
93
-
94
- class ::PostfixAdmin::Mailbox
95
- property :local_part, String
96
- end
97
-
98
- def db_initialize
99
- db_clear
100
-
101
- config = ::PostfixAdmin::Config.new
102
- config.attributes = {
103
- :id => 1,
104
- :name => "version",
105
- :value => "740"
106
- }
107
- config.save
108
-
109
- create_domain('ALL')
110
- create_domain('example.com')
111
- create_domain('example.org')
112
-
113
- all_admin = create_admin('all@example.com')
114
- all_domain = Domain.find('ALL')
115
- all_domain.admins << all_admin
116
-
117
- unless all_domain.save
118
- raise "Could not save all_domain"
119
- end
120
-
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')
127
-
128
- unless domain.save
129
- raise "Could not save domain"
130
- end
131
- end
132
-
133
- DataMapper.setup(:default, 'sqlite::memory:')
134
- DataMapper.finalize
135
- DataMapper.auto_migrate!
136
- db_initialize
137
- config_initialize
138
-
139
- module PostfixAdmin
140
- class Base
141
-
142
- # without DataMapper setup
143
- def db_setup(database)
144
- unless database
145
- raise ArgumentError
146
- end
147
- end
148
- end
149
- end
150
-
151
- CRAM_MD5_PASS = '9186d855e11eba527a7a52ca82b313e180d62234f0acc9051b527243d41e2740'
152
- CRAM_MD5_NEW_PASS = '820de4c70957274d41111c5fbcae4c87240c9f047fc56f3e720f103571be6cbc'
153
- EX_DELETED = /successfully deleted/
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}$/
157
-
158
- RSpec.configure do |config|
159
- config.before do
160
- ARGV.replace []
161
- end
162
-
163
- def capture(stream)
164
- begin
165
- stream = stream.to_s
166
- eval "$#{stream} = StringIO.new"
167
- $stderr = StringIO.new if stream != "stderr"
168
- yield
169
- result = eval("$#{stream}").string
170
- rescue SystemExit => e
171
- message = $stderr.string
172
- message += e.message
173
- raise message
174
- ensure
175
- eval("$#{stream} = #{stream.upcase}")
176
- end
177
-
178
- result
179
- end
180
-
181
- def exit_capture
182
- begin
183
- $stderr = StringIO.new
184
- yield
185
- rescue SystemExit => e
186
- ensure
187
- result = $stderr.string
188
- end
189
- result
190
- end
191
-
192
- def source_root
193
- File.join(File.dirname(__FILE__), 'fixtures')
194
- end
195
-
196
- def destination_root
197
- File.join(File.dirname(__FILE__), 'sandbox')
198
- end
199
-
200
- alias :silence :capture
201
- end