postfix_admin 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'postfix_admin/runner'
4
-
5
- begin
6
- PostfixAdmin::Runner.start
7
- rescue => e
8
- warn e.message
9
- end
@@ -1,218 +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 * 1024 * 1000
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').domains.find do |domain|
116
- domain.domain_name == 'example.org'
117
- end.should be_true
118
- end
119
-
120
- it "can not add unknown domain for an admin" do
121
- lambda{ @base.add_admin_domain('admin@example.com', 'unknown.example.com') }.should raise_error Error
122
- end
123
-
124
- it "can not add domain for unknown admin" do
125
- lambda{ @base.add_admin_domain('unknown_admin@example.com', 'example.net') }.should raise_error Error
126
- end
127
-
128
- it "can not add a domain which the admin has already privileges for" do
129
- lambda{ @base.add_admin_domain('admin@example.com', 'example.com') }.should raise_error Error
130
- end
131
- end
132
-
133
- describe "#add_alias" do
134
- it "can add a new alias" do
135
- num_aliases = Alias.count
136
- lambda { @base.add_alias('new_alias@example.com', 'goto@example.jp') }.should_not raise_error
137
- (Alias.count - num_aliases).should be(1)
138
- Alias.exist?('new_alias@example.com').should be_true
139
- end
140
-
141
- it "can not add an alias which has a same name as a mailbox" do
142
- lambda { @base.add_alias('user@example.com', 'goto@example.jp') }.should raise_error Error
143
- end
144
-
145
- it "can not add an alias which has a sama name as other alias" do
146
- @base.add_alias('new_alias@example.com', 'goto@example.jp')
147
- lambda { @base.add_alias('new_alias@example.com', 'goto@example.jp') }.should raise_error Error
148
- end
149
-
150
- it "can not add an alias of unknown domain" do
151
- lambda { @base.add_alias('new_alias@unknown.example.com', 'goto@example.jp') }.should raise_error Error
152
- end
153
- end
154
-
155
- describe "#delete_alias" do
156
- it "can delete an alias" do
157
- lambda{ @base.delete_alias('alias@example.com') }.should_not raise_error
158
- Alias.exist?('alias@example.com').should be_false
159
- end
160
-
161
- it "can not delete mailbox" do
162
- lambda{ @base.delete_alias('user@example.com') }.should raise_error Error
163
- end
164
-
165
- it "can not delete unknown alias" do
166
- lambda{ @base.delete_alias('unknown@example.com') }.should raise_error Error
167
- end
168
- end
169
-
170
- describe "#delete_domain" do
171
- before do
172
- @base.add_account('user2@example.com', 'password')
173
- @base.add_account('user3@example.com', 'password')
174
-
175
- @base.add_alias('alias2@example.com', 'goto2@example.jp')
176
- @base.add_alias('alias3@example.com', 'goto3@example.jp')
177
- end
178
-
179
- it "can delete a domain" do
180
- lambda{ @base.delete_domain('example.com') }.should_not raise_error
181
-
182
- Domain.exist?('example.com').should be_false
183
- Admin.exist?('admin@example.com').should be_false
184
-
185
- Alias.all(:domain_name => 'example.com').count.should be(0)
186
- Mailbox.all(:domain_name => 'example.com').count.should be(0)
187
-
188
- DomainAdmin.all(:username => 'admin@example.com', :domain_name => 'example.com').count.should be(0)
189
- end
190
-
191
- it "can not delete unknown domain" do
192
- lambda{ @base.delete_domain('unknown.example.com') }.should raise_error Error
193
- end
194
- end
195
-
196
- describe "#delete_admin" do
197
- it "can delete an admin" do
198
- lambda{ @base.delete_admin('admin@example.com') }.should_not raise_error
199
- Admin.exist?('admin@example.com').should be_false
200
- end
201
-
202
- it "can not delete unknown admin" do
203
- lambda{ @base.delete_admin('unknown_admin@example.com') }.should raise_error Error
204
- end
205
- end
206
-
207
- describe "#delete_account" do
208
- it "can delete an account" do
209
- lambda{ @base.delete_account('user@example.com') }.should_not raise_error
210
- Mailbox.exist?('user@example.com').should be_false
211
- Alias.exist?('user@example.com').should be_false
212
- end
213
-
214
- it "can not delete unknown account" do
215
- lambda{ @base.delete_account('unknown@example.com') }.should raise_error Error
216
- end
217
- end
218
- end
@@ -1,165 +0,0 @@
1
-
2
- require 'postfix_admin/cli'
3
-
4
- describe PostfixAdmin::CLI do
5
- before do
6
- db_initialize
7
- @cli = PostfixAdmin::CLI.new
8
- end
9
-
10
- it "#show_domain" do
11
- lambda { @cli.show_domain }.should_not raise_error
12
- capture(:stdout){ @cli.show_domain }.should_not =~ /ALL/
13
- end
14
-
15
- it "#show_summary" do
16
- lambda { @cli.show_summary }.should_not raise_error
17
- lambda { @cli.show_summary('unknown.example.com') }.should raise_error Error
18
- end
19
-
20
- it "#show_admin" do
21
- lambda { @cli.show_admin }.should_not raise_error
22
- end
23
-
24
- it "#show_address" do
25
- lambda { @cli.show_address('example.com') }.should_not raise_error
26
- lambda { @cli.show_address('unknown.example.com') }.should raise_error Error
27
- end
28
-
29
- it "#show_admin_domain" do
30
- lambda { @cli.show_admin_domain('admin@example.com') }.should_not raise_error
31
- end
32
-
33
- it "#show_alias" do
34
- lambda { @cli.show_alias('example.com') }.should_not raise_error
35
- lambda { @cli.show_alias('unknown.example.com') }.should raise_error Error
36
- end
37
-
38
- describe "#super_admin" do
39
- it "enables super admin flag of an admin" do
40
- lambda{ @cli.super_admin('admin@example.com', false) }.should_not raise_error
41
- Admin.find('admin@example.com').super_admin?.should be_true
42
- end
43
-
44
- it "disable super admin flag of an admin" do
45
- lambda{ @cli.super_admin('all@example.com', true) }.should_not raise_error
46
- Admin.find('all@example.com').super_admin?.should be_false
47
- end
48
-
49
- it "can not user for unknown admin" do
50
- lambda{ @cli.super_admin('unknown_admin@example.com', false) }.should raise_error Error
51
- end
52
- end
53
-
54
- it "#change_admin_password" do
55
- lambda { @cli.change_admin_password('admin@example.com', 'new_password') }.should_not raise_error
56
- Admin.find('admin@example.com').password.should == 'new_password'
57
- lambda { @cli.change_admin_password('unknown_admin@example.com', 'new_password') }.should raise_error Error
58
-
59
- lambda { @cli.change_admin_password('admin@example.com', '1234') }.should raise_error ArgumentError
60
- end
61
-
62
- it "#change_account_password" do
63
- lambda { @cli.change_account_password('user@example.com', 'new_password') }.should_not raise_error
64
- Mailbox.find('user@example.com').password.should == 'new_password'
65
- lambda { @cli.change_account_password('unknown@example.com', 'new_password') }.should raise_error Error
66
- lambda { @cli.change_account_password('user@example.com', '1234') }.should raise_error ArgumentError
67
- end
68
-
69
- describe "#add_admin" do
70
- it "can add a new admin" do
71
- lambda { @cli.add_admin('new_admin@example.com', 'password') }.should_not raise_error
72
- Admin.exist?('new_admin@example.com').should be_true
73
- end
74
-
75
- it "can not add exist admin" do
76
- lambda { @cli.add_admin('admin@example.com', 'password') }.should raise_error Error
77
- end
78
-
79
- it "does not allow too short password (<5)" do
80
- lambda { @cli.add_admin('admin@example.com', '1234') }.should raise_error ArgumentError
81
- end
82
- end
83
-
84
- describe "#delete_admin" do
85
- it "can delete an admin" do
86
- lambda { @cli.delete_admin('admin@example.com') }.should_not raise_error
87
- Admin.exist?('admin@example.com').should be_false
88
- end
89
-
90
- it "can not delete unknown admin" do
91
- lambda { @cli.delete_admin('unknown_admin@example.com') }.should raise_error Error
92
- end
93
- end
94
-
95
- it "#add_alias and #delete_alias" do
96
- lambda { @cli.add_alias('user@example.com', 'goto@example.jp') }.should raise_error
97
- lambda { @cli.delete_alias('user@example.com') }.should raise_error
98
- lambda { @cli.delete_alias('unknown@example.com') }.should raise_error
99
-
100
- lambda { @cli.add_alias('new_alias@example.com', 'goto@example.jp') }.should_not raise_error
101
- Alias.exist?('new_alias@example.com').should be_true
102
-
103
- lambda { @cli.delete_alias('new_alias@example.com') }.should_not raise_error
104
- Alias.exist?('new_alias@example.com').should be_false
105
- end
106
-
107
- describe "#add_account" do
108
- it "can add an account" do
109
- lambda { @cli.add_account('new_user@example.com', 'password') }.should_not raise_error
110
- Mailbox.exist?('new_user@example.com').should be_true
111
- Alias.exist?('new_user@example.com').should be_true
112
- end
113
-
114
- it "can not add account of unknown domain" do
115
- lambda { @cli.add_account('user@unknown.example.com', 'password') }.should raise_error Error
116
- end
117
-
118
- it "does not allow too short password (<5)" do
119
- lambda { @cli.add_account('new_user@example.com', '1234') }.should raise_error ArgumentError
120
- end
121
- end
122
-
123
- describe "#delete_accont" do
124
- it "can delete an account" do
125
- lambda { @cli.delete_account('user@example.com') }.should_not raise_error
126
- Mailbox.exist?('user@example.com').should be_false
127
- Alias.exist?('user@example.com').should be_false
128
- end
129
-
130
- it "can not delete unknown account" do
131
- lambda { @cli.delete_account('unknown@example.com') }.should raise_error Error
132
- end
133
- end
134
-
135
- it "add and delete methods" do
136
- lambda { @cli.add_domain('example.net') }.should_not raise_error
137
-
138
- lambda { @cli.add_admin('admin@example.net', 'password') }.should_not raise_error
139
- lambda { @cli.add_admin_domain('admin@example.net', 'example.net') }.should_not raise_error
140
-
141
- @cli.add_admin('admin2@example.net', 'password')
142
- @cli.add_admin_domain('admin2@example.net', 'example.net')
143
-
144
- @cli.add_admin('common@example.net', 'password')
145
- @cli.add_admin_domain('common@example.net', 'example.com')
146
- @cli.add_admin_domain('common@example.net', 'example.net')
147
- lambda { @cli.delete_admin('common@example.net') }.should_not raise_error
148
- Admin.exist?('common@example.net').should be_false
149
-
150
- @cli.add_admin('common@example.net', 'password')
151
- @cli.add_admin_domain('common@example.net', 'example.com')
152
- @cli.add_admin_domain('common@example.net', 'example.net')
153
-
154
- lambda { @cli.add_account('user1@example.net', 'password') }.should_not raise_error
155
- lambda { @cli.add_account('user2@example.net', 'password') }.should_not raise_error
156
-
157
- lambda { @cli.delete_domain('example.net') }.should_not raise_error
158
- Admin.exist?('admin@example.net').should be_false
159
- Admin.exist?('admin2@example.net').should be_false
160
-
161
- Admin.exist?('common@example.net').should be_true
162
- lambda { @cli.delete_admin('common@example.net') }.should_not raise_error
163
- Admin.exist?('common@example.net').should be_false
164
- end
165
- end
@@ -1,136 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
- require 'postfix_admin/models'
3
-
4
- describe PostfixAdmin::Admin do
5
- before do
6
- db_initialize
7
- end
8
-
9
- it ".exist?" do
10
- Admin.exist?('admin@example.com').should === true
11
- Admin.exist?('all@example.com').should === true
12
- Admin.exist?('unknown@example.com').should === false
13
- end
14
-
15
- it "#super_admin?" do
16
- Admin.find('admin@example.com').super_admin?.should === false
17
- Admin.find('all@example.com').super_admin?.should === true
18
- end
19
-
20
- describe "#super_admin=" do
21
- it "enable super admin flag" do
22
- lambda{ Admin.find('all@example.com').super_admin = false }.should_not raise_error
23
- Admin.find('all@example.com').super_admin?.should === false
24
- end
25
-
26
- it "should not delete 'ALL' domain" do
27
- Admin.find('all@example.com').super_admin = false
28
- Domain.exist?('ALL').should be_true
29
- end
30
-
31
- it "disable super admin flag" do
32
- lambda{ Admin.find('admin@example.com').super_admin = true }.should_not raise_error
33
- Admin.find('admin@example.com').super_admin?.should === true
34
- end
35
- end
36
-
37
- describe "#has_domain?" do
38
- it "returns true when the admin has privileges for the domain" do
39
- Admin.find('admin@example.com').has_domain?('example.com').should === true
40
- end
41
-
42
- it "returns false when the admin does not have privileges for the domain" do
43
- Admin.find('admin@example.com').has_domain?('example.org').should === false
44
- end
45
-
46
- it "returns false when unknown domain" do
47
- Admin.find('admin@example.com').has_domain?('unknown.example.com').should === false
48
- end
49
-
50
- it "returns true when super admin and exist domain" do
51
- Admin.find('all@example.com').has_domain?('example.com').should === true
52
- end
53
-
54
- it "returns false when super admin and unknown domain" do
55
- Admin.find('all@example.com').has_domain?('unknown.example.com').should === false
56
- end
57
- end
58
- end
59
-
60
- describe PostfixAdmin::Domain do
61
- before do
62
- db_initialize
63
- @base = PostfixAdmin::Base.new({'database' => 'sqlite::memory:'})
64
- end
65
-
66
- it ".exist?" do
67
- Domain.exist?('example.com').should === true
68
- Domain.exist?('example.org').should === true
69
- Domain.exist?('unknown.example.com').should === false
70
- end
71
-
72
- describe "#num_total_aliases and .num_total_aliases" do
73
- it "when only alias@example.com" do
74
- Domain.num_total_aliases.should be(1)
75
- Domain.find('example.com').num_total_aliases.should be(1)
76
- end
77
-
78
- it "should increase one if you add an alias" do
79
- @base.add_alias('new_alias@example.com', 'goto@example.jp')
80
- Domain.num_total_aliases.should be(2)
81
- Domain.find('example.com').num_total_aliases.should be(2)
82
- end
83
-
84
- it "should not increase if you add an account" do
85
- @base.add_account('user2@example.com', 'password')
86
- Domain.num_total_aliases.should be(1)
87
- Domain.find('example.com').num_total_aliases.should be(1)
88
- end
89
-
90
- it ".num_total_aliases should not increase if you add an account and an aliase for other domain" do
91
- @base.add_account('user@example.org', 'password')
92
- Domain.num_total_aliases.should be(1)
93
- Domain.find('example.com').num_total_aliases.should be(1)
94
- @base.add_alias('new_alias@example.org', 'goto@example.jp')
95
- Domain.num_total_aliases.should be(2)
96
- Domain.find('example.com').num_total_aliases.should be(1)
97
- end
98
- end
99
- end
100
-
101
- describe PostfixAdmin::Mailbox do
102
- before do
103
- db_initialize
104
- end
105
-
106
- describe ".exist?" do
107
- it "returns true for exist account (mailbox)" do
108
- Mailbox.exist?('user@example.com').should === true
109
- end
110
-
111
- it "returns false for alias" do
112
- Mailbox.exist?('alias@example.com').should === false
113
- end
114
-
115
- it "returns false for unknown account (mailbox)" do
116
- Mailbox.exist?('unknown@unknown.example.com').should === false
117
- end
118
- end
119
- end
120
-
121
- describe PostfixAdmin::Alias do
122
- before do
123
- db_initialize
124
- end
125
-
126
- describe ".exist?" do
127
- it "returns true when exist alias and account" do
128
- Alias.exist?('user@example.com').should === true
129
- Alias.exist?('alias@example.com').should === true
130
- end
131
-
132
- it "returns false when unknown alias" do
133
- Alias.exist?('unknown@unknown.example.com').should === false
134
- end
135
- end
136
- end