f8e046f187f55534a74a2d64c23faaf057e23343
[mailshears.git] / test / test_rm.rb
1 # WARNING: Test output is dependent on the order these classes include
2 # certain modules; i.e. on the 'require' order.
3 require 'common/domain'
4 require 'common/user'
5 require 'mailshears_test'
6 require 'minitest/autorun'
7 require 'rm/plugins/agendav'
8 require 'rm/plugins/davical'
9 require 'rm/plugins/dovecot'
10 require 'rm/plugins/postfixadmin'
11 require 'rm/plugins/roundcube'
12 require 'rm/rm_runner'
13
14
15 class TestRm < MailshearsTest
16
17 def test_rm_user
18 cfg = configuration()
19 users = [ User.new("adam@example.net") ]
20
21 output_buffer = StringIO.new()
22
23 $stdout = output_buffer
24 RmPlugin.run(cfg, *users)
25 $stdout = STDOUT
26
27 actual = output_buffer.string()
28
29 expected =
30 "AgendavRm - Removed user adam@example.net.\n" +
31 "DavicalRm - User adam@example.net not found.\n" +
32 "DovecotRm - Removed user adam@example.net " +
33 "(#{cfg.dovecot_mail_root}/example.net/adam).\n" +
34 "PostfixadminRm - Removed user adam@example.net.\n" +
35 "RoundcubeRm - Removed user adam@example.net (User ID: 2).\n"
36
37 assert_equal(expected, actual)
38
39 # Now make sure the database has what we expect.
40
41 arm = AgendavRm.new(cfg)
42 actual = arm.list_users()
43 expected = []
44 assert_equal(expected, actual)
45
46 drm = DavicalRm.new(cfg)
47 actual = drm.list_users()
48 expected = [User.new('alice@example.com')]
49 assert_equal(expected, actual)
50
51 pfarm = PostfixadminRm.new(cfg)
52 actual = pfarm.list_users()
53 expected = [User.new('alice@example.com'),
54 User.new('bob@example.com'),
55 User.new('beth@example.net'),
56 User.new('carol@example.net')]
57 assert_equal(expected, actual)
58
59 actual = pfarm.list_domains()
60 expected = [Domain.new('example.com'), Domain.new('example.net')]
61 assert_equal(expected, actual)
62
63 actual = pfarm.list_aliases()
64 expected = [{'address' => 'alice@example.com',
65 'goto' => 'alice@example.com'},
66 {'address' => 'bob@example.com',
67 'goto' => 'bob@example.com'},
68 {'address' => 'beth@example.net',
69 'goto' => 'beth@example.net'},
70 {'address' => 'carol@example.net',
71 'goto' => 'carol@example.net'}]
72 assert_equal(expected, actual)
73
74 rrm = RoundcubeRm.new(cfg)
75 actual = rrm.list_users()
76 expected = [User.new('alice@example.com')]
77 assert_equal(expected, actual)
78
79 # Check that adam's directory is gone but that the rest remain.
80 assert(maildir_exists('example.com/alice'))
81 assert(maildir_exists('example.com/booger'))
82 assert(maildir_exists('example.com/jeremy'))
83 assert(!maildir_exists('example.net/adam'))
84 end
85
86
87 def test_rm_domain
88 cfg = configuration()
89 domains = [Domain.new("example.net")]
90
91 output_buffer = StringIO.new()
92
93 $stdout = output_buffer
94 RmPlugin.run(cfg, *domains)
95 $stdout = STDOUT
96
97 actual = output_buffer.string()
98
99 expected =
100 "AgendavRm - Removed domain example.net.\n" +
101 "DavicalRm - Domain example.net not found.\n" +
102 "DovecotRm - Removed domain example.net " +
103 "(#{cfg.dovecot_mail_root}/example.net).\n" +
104 "PostfixadminRm - Removed domain example.net.\n" +
105 "RoundcubeRm - Removed domain example.net.\n"
106
107 assert_equal(expected, actual)
108
109 # Now make sure the database has what we expect.
110
111 arm = AgendavRm.new(cfg)
112 actual = arm.list_users()
113 expected = []
114 assert_equal(expected, actual)
115
116 drm = DavicalRm.new(cfg)
117 actual = drm.list_users()
118 expected = [User.new('alice@example.com')]
119 assert_equal(expected, actual)
120
121 pfarm = PostfixadminRm.new(cfg)
122 actual = pfarm.list_users()
123 expected = [User.new('alice@example.com'),
124 User.new('bob@example.com')]
125 assert_equal(expected, actual)
126
127 actual = pfarm.list_domains()
128 expected = [Domain.new('example.com')]
129 assert_equal(expected, actual)
130
131 actual = pfarm.list_aliases()
132 expected = [{'address' => 'alice@example.com',
133 'goto' => 'alice@example.com'},
134 {'address' => 'bob@example.com',
135 'goto' => 'bob@example.com'}]
136 assert_equal(expected, actual)
137
138 rrm = RoundcubeRm.new(cfg)
139 actual = rrm.list_users()
140 expected = [User.new('alice@example.com')]
141 assert_equal(expected, actual)
142
143 # Check that example.net's directory is gone but that the rest remain.
144 assert(maildir_exists('example.com/alice'))
145 assert(maildir_exists('example.com/booger'))
146 assert(maildir_exists('example.com/jeremy'))
147 assert(!maildir_exists('example.net'))
148 end
149
150
151 end