09ebe2e37c4faefcb5ff68932c92883b6ab6fad8
[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 require 'rm/rm_dummy_runner'
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 mail_root = cfg.send('mail_root')
30 expected =
31 "AgendavRm - Removed user adam@example.net.\n" +
32 "DavicalRm - User adam@example.net not found.\n" +
33 "DovecotRm - Removed user adam@example.net " +
34 "(#{mail_root}/example.net/adam).\n" +
35 "PostfixadminRm - Removed user adam@example.net.\n" +
36 "RoundcubeRm - Removed user adam@example.net (User ID: 2).\n"
37
38 assert_equal(expected, actual)
39
40 # Now make sure the database has what we expect.
41
42 arm = AgendavRm.new(cfg)
43 actual = arm.list_users()
44 expected = []
45 assert_equal(expected, actual)
46
47 drm = DavicalRm.new(cfg)
48 actual = drm.list_users()
49 expected = [User.new('alice@example.com')]
50 assert_equal(expected, actual)
51
52 pfarm = PostfixadminRm.new(cfg)
53 actual = pfarm.list_users()
54 expected = [User.new('alice@example.com'),
55 User.new('bob@example.com'),
56 User.new('beth@example.net'),
57 User.new('carol@example.net')]
58 assert_equal(expected, actual)
59
60 actual = pfarm.list_domains()
61 expected = [Domain.new('example.com'), Domain.new('example.net')]
62 assert_equal(expected, actual)
63
64 actual = pfarm.list_aliases()
65 expected = [{'address' => 'alice@example.com',
66 'goto' => 'alice@example.com'},
67 {'address' => 'bob@example.com',
68 'goto' => 'bob@example.com'},
69 {'address' => 'beth@example.net',
70 'goto' => 'beth@example.net'},
71 {'address' => 'carol@example.net',
72 'goto' => 'carol@example.net'}]
73 assert_equal(expected, actual)
74
75 rrm = RoundcubeRm.new(cfg)
76 actual = rrm.list_users()
77 expected = [User.new('alice@example.com')]
78 assert_equal(expected, actual)
79
80 # Check that adam's directory is gone but that the rest remain.
81 assert(maildir_exists('example.com/alice'))
82 assert(maildir_exists('example.com/booger'))
83 assert(maildir_exists('example.com/jeremy'))
84 assert(!maildir_exists('example.net/adam'))
85 end
86
87
88 def test_rm_domain
89 cfg = configuration()
90 domains = [Domain.new("example.net")]
91
92 output_buffer = StringIO.new()
93
94 $stdout = output_buffer
95 RmPlugin.run(cfg, *domains)
96 $stdout = STDOUT
97
98 actual = output_buffer.string()
99
100 mail_root = cfg.send('mail_root')
101 expected =
102 "AgendavRm - Removed domain example.net.\n" +
103 "DavicalRm - Domain example.net not found.\n" +
104 "DovecotRm - Removed domain example.net " +
105 "(#{mail_root}/example.net).\n" +
106 "PostfixadminRm - Removed domain example.net.\n" +
107 "RoundcubeRm - Removed domain example.net.\n"
108
109 assert_equal(expected, actual)
110
111 # Now make sure the database has what we expect.
112
113 arm = AgendavRm.new(cfg)
114 actual = arm.list_users()
115 expected = []
116 assert_equal(expected, actual)
117
118 drm = DavicalRm.new(cfg)
119 actual = drm.list_users()
120 expected = [User.new('alice@example.com')]
121 assert_equal(expected, actual)
122
123 pfarm = PostfixadminRm.new(cfg)
124 actual = pfarm.list_users()
125 expected = [User.new('alice@example.com'),
126 User.new('bob@example.com')]
127 assert_equal(expected, actual)
128
129 actual = pfarm.list_domains()
130 expected = [Domain.new('example.com')]
131 assert_equal(expected, actual)
132
133 actual = pfarm.list_aliases()
134 expected = [{'address' => 'alice@example.com',
135 'goto' => 'alice@example.com'},
136 {'address' => 'bob@example.com',
137 'goto' => 'bob@example.com'}]
138 assert_equal(expected, actual)
139
140 rrm = RoundcubeRm.new(cfg)
141 actual = rrm.list_users()
142 expected = [User.new('alice@example.com')]
143 assert_equal(expected, actual)
144
145 # Check that example.net's directory is gone but that the rest remain.
146 assert(maildir_exists('example.com/alice'))
147 assert(maildir_exists('example.com/booger'))
148 assert(maildir_exists('example.com/jeremy'))
149 assert(!maildir_exists('example.net'))
150 end
151
152
153 end