mail-sympa 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +40 -0
- data/Gemfile +2 -0
- data/MANIFEST.md +22 -0
- data/README.md +190 -0
- data/Rakefile +44 -12
- data/certs/djberg96_pub.pem +26 -0
- data/docker/Dockerfile +24 -0
- data/docker/run_specs.rb +66 -0
- data/docker/seed_sympa.pl +60 -0
- data/docker/test-apache.conf +24 -0
- data/docker/test-sympa.conf +11 -0
- data/docker/test-syslog.conf +2 -0
- data/docker/test-topics.conf +5 -0
- data/lib/mail/sympa.rb +104 -55
- data/lib/mail-sympa.rb +1 -0
- data/mail-sympa.gemspec +28 -13
- data/spec/mail_sympa_spec.rb +511 -0
- data/spec/soap_integration_spec.rb +28 -0
- data/spec/spec_helper.rb +38 -0
- data.tar.gz.sig +0 -0
- metadata +133 -70
- metadata.gz.sig +0 -0
- data/CHANGES +0 -16
- data/MANIFEST +0 -7
- data/README +0 -50
- data/test/test_mail_sympa.rb +0 -335
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'mail/sympa'
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Mail::Sympa do
|
|
6
|
+
let(:endpoint) { ENV.fetch('SYMPA_ENDPOINT', 'http://localhost:8080/sympasoap') }
|
|
7
|
+
let(:sympa) { Mail::Sympa.new(endpoint) }
|
|
8
|
+
let(:test_user) { ENV.fetch('SYMPA_TEST_USER', 'postmaster@sympa.test') }
|
|
9
|
+
let(:test_password) { ENV.fetch('SYMPA_TEST_PASSWORD', 'test') }
|
|
10
|
+
let(:member_email) { "member-#{SecureRandom.hex(4)}@example.test" }
|
|
11
|
+
let(:test_list) { 'testlist' }
|
|
12
|
+
let(:empty_list) { 'partners' }
|
|
13
|
+
|
|
14
|
+
# Helper method to ensure the sympa instance is logged in
|
|
15
|
+
def login_sympa
|
|
16
|
+
sympa.login(test_user, test_password)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Fail clearly if provisioning did not create a required fixture.
|
|
20
|
+
def ensure_list_exists(list_name)
|
|
21
|
+
login_sympa
|
|
22
|
+
expect(sympa.info(list_name)).to include(list_address: "#{list_name}@sympa.test")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe 'class constants and attributes' do
|
|
26
|
+
it 'has the expected version constant' do
|
|
27
|
+
expect(Mail::Sympa::VERSION).to eq('1.2.0')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe '#initialize' do
|
|
32
|
+
it 'creates a new instance with an endpoint' do
|
|
33
|
+
expect(sympa).to be_a(Mail::Sympa)
|
|
34
|
+
expect(sympa.endpoint).to eq(endpoint)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'sets the default namespace' do
|
|
38
|
+
expect(sympa.namespace).to eq('urn:sympasoap')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'allows custom namespace' do
|
|
42
|
+
custom_sympa = Mail::Sympa.new(endpoint, 'custom:namespace')
|
|
43
|
+
expect(custom_sympa.namespace).to eq('custom:namespace')
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe '#endpoint' do
|
|
48
|
+
it 'responds to endpoint method' do
|
|
49
|
+
expect(sympa).to respond_to(:endpoint)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'returns the endpoint as a string' do
|
|
53
|
+
expect(sympa.endpoint).to be_a(String)
|
|
54
|
+
expect(sympa.endpoint).to eq(endpoint)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'is a readonly attribute' do
|
|
58
|
+
expect { sympa.endpoint = 'foo' }.to raise_error(NoMethodError)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe '#namespace' do
|
|
63
|
+
it 'responds to namespace method' do
|
|
64
|
+
expect(sympa).to respond_to(:namespace)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'returns the namespace as a string' do
|
|
68
|
+
expect(sympa.namespace).to be_a(String)
|
|
69
|
+
expect(sympa.namespace).to eq('urn:sympasoap')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'is a readonly attribute' do
|
|
73
|
+
expect { sympa.namespace = 'foo' }.to raise_error(NoMethodError)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe '#login' do
|
|
78
|
+
it 'responds to login method' do
|
|
79
|
+
expect(sympa).to respond_to(:login)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'works with valid credentials' do
|
|
83
|
+
expect { login_sympa }.not_to raise_error
|
|
84
|
+
expect(sympa.cookie).not_to be_nil
|
|
85
|
+
expect(sympa.cookie).to be_a(String)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'raises an error with invalid credentials' do
|
|
89
|
+
expect { sympa.login('bogus', 'bogus') }.to raise_error(Mail::Sympa::Error, /Authentication failed/)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'requires exactly two arguments' do
|
|
93
|
+
expect { sympa.login }.to raise_error(ArgumentError)
|
|
94
|
+
expect { sympa.login('bogus') }.to raise_error(ArgumentError)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'returns a session cookie string' do
|
|
98
|
+
result = login_sympa
|
|
99
|
+
expect(result).to be_a(String)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'clears the previous session after a failed login' do
|
|
103
|
+
login_sympa
|
|
104
|
+
expect { sympa.login(test_user, 'wrong-password') }.to raise_error(Mail::Sympa::Error)
|
|
105
|
+
expect(sympa.cookie).to be_nil
|
|
106
|
+
expect { sympa.lists }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'uses the canonical email for subsequent authenticated calls' do
|
|
110
|
+
sympa.login(test_user.upcase, test_password)
|
|
111
|
+
expect(sympa.review(test_list)).to include('reader@example.test')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'wraps transport failures in Mail::Sympa::Error' do
|
|
115
|
+
unavailable = Mail::Sympa.new('http://127.0.0.1:1/sympasoap')
|
|
116
|
+
expect { unavailable.login(test_user, test_password) }.to raise_error(Mail::Sympa::Error, /SOAP request failed/)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe '#lists' do
|
|
121
|
+
before { login_sympa }
|
|
122
|
+
|
|
123
|
+
it 'responds to lists method' do
|
|
124
|
+
expect(sympa).to respond_to(:lists)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'returns an array of lists' do
|
|
128
|
+
lists = sympa.lists
|
|
129
|
+
expect(lists).to be_a(Array)
|
|
130
|
+
expect(lists).to include(a_string_including('listAddress=testlist@sympa.test'))
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'accepts a topic argument' do
|
|
134
|
+
ensure_list_exists(test_list)
|
|
135
|
+
result = sympa.lists(test_list)
|
|
136
|
+
expect(result).to be_a(Array)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'accepts topic and subtopic arguments' do
|
|
140
|
+
ensure_list_exists(test_list)
|
|
141
|
+
result = sympa.lists(test_list, test_list)
|
|
142
|
+
expect(result).to include(a_string_including('listAddress=testlist@sympa.test'))
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it 'returns empty array for non-existent topic' do
|
|
146
|
+
result = sympa.lists('bogus_topic_that_does_not_exist')
|
|
147
|
+
expect(result).to eq([])
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it 'accepts maximum of two arguments' do
|
|
151
|
+
expect { sympa.lists('a', 'b', 'c') }.to raise_error(ArgumentError)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
describe '#complex_lists' do
|
|
156
|
+
before { login_sympa }
|
|
157
|
+
|
|
158
|
+
it 'responds to complex_lists method' do
|
|
159
|
+
expect(sympa).to respond_to(:complex_lists)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'has complexLists alias' do
|
|
163
|
+
expect(sympa).to respond_to(:complexLists)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'returns an array of complex objects' do
|
|
167
|
+
lists = sympa.complex_lists
|
|
168
|
+
expect(lists).to be_a(Array)
|
|
169
|
+
expect(lists).to include(include(list_address: 'testlist@sympa.test', subject: 'Test list testlist'))
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it 'accepts topic and subtopic arguments' do
|
|
173
|
+
result = sympa.complex_lists(test_list)
|
|
174
|
+
expect(result).to be_a(Array)
|
|
175
|
+
|
|
176
|
+
result = sympa.complex_lists(test_list, test_list)
|
|
177
|
+
expect(result).to be_a(Array)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'returns empty array for non-existent topic' do
|
|
181
|
+
result = sympa.complex_lists('bogus_topic_that_does_not_exist')
|
|
182
|
+
expect(result).to eq([])
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it 'accepts maximum of two arguments' do
|
|
186
|
+
expect { sympa.complex_lists('a', 'b', 'c') }.to raise_error(ArgumentError)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
describe '#info' do
|
|
191
|
+
before { login_sympa }
|
|
192
|
+
|
|
193
|
+
it 'responds to info method' do
|
|
194
|
+
expect(sympa).to respond_to(:info)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it 'returns information about a list' do
|
|
198
|
+
ensure_list_exists(test_list)
|
|
199
|
+
info = sympa.info(test_list)
|
|
200
|
+
expect(info).to include(list_address: 'testlist@sympa.test', subject: 'Test list testlist', is_owner: true)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'requires login' do
|
|
204
|
+
new_sympa = Mail::Sympa.new(endpoint)
|
|
205
|
+
expect { new_sympa.info(test_list) }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
describe '#review' do
|
|
210
|
+
before { login_sympa }
|
|
211
|
+
|
|
212
|
+
it 'responds to review method' do
|
|
213
|
+
expect(sympa).to respond_to(:review)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it 'returns an array of subscribers' do
|
|
217
|
+
ensure_list_exists(test_list)
|
|
218
|
+
subscribers = sympa.review(test_list)
|
|
219
|
+
expect(subscribers).to be_a(Array)
|
|
220
|
+
expect(subscribers).to include('reader@example.test')
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it 'returns no_subscribers for empty list' do
|
|
224
|
+
ensure_list_exists(empty_list)
|
|
225
|
+
subscribers = sympa.review(empty_list)
|
|
226
|
+
expect(subscribers).to eq(['no_subscribers'])
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it 'raises error for non-existent list' do
|
|
230
|
+
expect { sympa.review('bogus_list_xyz_123') }.to raise_error(Mail::Sympa::Error)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it 'requires login' do
|
|
234
|
+
new_sympa = Mail::Sympa.new(endpoint)
|
|
235
|
+
expect { new_sympa.review(test_list) }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
describe '#which' do
|
|
240
|
+
it 'responds to which method' do
|
|
241
|
+
expect(sympa).to respond_to(:which)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
it 'requires login' do
|
|
245
|
+
expect { sympa.which('user', 'app', 'pass') }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
it 'finds subscriptions through a trusted application' do
|
|
249
|
+
login_sympa
|
|
250
|
+
result = sympa.which('USER_EMAIL=reader@example.test', 'mail-sympa-tests', 'test-app-password')
|
|
251
|
+
expect(result).to include(a_string_including('testlist@sympa.test'))
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
it 'rejects an incorrect trusted application password' do
|
|
255
|
+
login_sympa
|
|
256
|
+
expect {
|
|
257
|
+
sympa.which('USER_EMAIL=reader@example.test', 'mail-sympa-tests', 'wrong-password')
|
|
258
|
+
}.to raise_error(Mail::Sympa::Error, /Authentication failed/)
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
describe '#complex_which' do
|
|
263
|
+
it 'responds to complex_which method' do
|
|
264
|
+
expect(sympa).to respond_to(:complex_which)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it 'has complexWhich alias' do
|
|
268
|
+
expect(sympa).to respond_to(:complexWhich)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
it 'requires login' do
|
|
272
|
+
expect { sympa.complex_which('user', 'app', 'pass') }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it 'returns structured subscriptions through a trusted application' do
|
|
276
|
+
login_sympa
|
|
277
|
+
result = sympa.complex_which('USER_EMAIL=reader@example.test', 'mail-sympa-tests', 'test-app-password')
|
|
278
|
+
expect(result).to include(include(list_address: 'testlist@sympa.test'))
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
describe '#am_i?' do
|
|
283
|
+
before { login_sympa }
|
|
284
|
+
|
|
285
|
+
it 'responds to am_i? method' do
|
|
286
|
+
expect(sympa).to respond_to(:am_i?)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it 'has amI alias' do
|
|
290
|
+
expect(sympa).to respond_to(:amI)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it 'returns a boolean result' do
|
|
294
|
+
ensure_list_exists(test_list)
|
|
295
|
+
result = sympa.am_i?(test_user, test_list)
|
|
296
|
+
expect([true, false]).to include(result)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
it 'accepts function parameter' do
|
|
300
|
+
ensure_list_exists(test_list)
|
|
301
|
+
result = sympa.am_i?(test_user, test_list, 'owner')
|
|
302
|
+
expect(result).to be(true)
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
it 'returns false for a user who is not an owner' do
|
|
306
|
+
expect(sympa.am_i?('reader@example.test', test_list, 'owner')).to be(false)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
it 'validates function parameter' do
|
|
310
|
+
expect { sympa.am_i?(test_user, test_list, 'bogus') }.to raise_error(Mail::Sympa::Error)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
it 'requires login' do
|
|
314
|
+
new_sympa = Mail::Sympa.new(endpoint)
|
|
315
|
+
expect { new_sympa.am_i?(test_user, test_list) }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
describe '#add' do
|
|
320
|
+
before { login_sympa }
|
|
321
|
+
|
|
322
|
+
it 'responds to add method' do
|
|
323
|
+
expect(sympa).to respond_to(:add)
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
it 'adds a subscriber and returns true' do
|
|
327
|
+
ensure_list_exists(test_list)
|
|
328
|
+
expect(sympa.add(member_email, test_list, 'Test User')).to be(true)
|
|
329
|
+
expect(sympa.review(test_list)).to include(member_email)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
it 'requires at least three arguments' do
|
|
333
|
+
expect { sympa.add }.to raise_error(ArgumentError)
|
|
334
|
+
expect { sympa.add('test@example.com') }.to raise_error(ArgumentError)
|
|
335
|
+
expect { sympa.add('test@example.com', test_list) }.to raise_error(ArgumentError)
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
it 'requires login' do
|
|
339
|
+
new_sympa = Mail::Sympa.new(endpoint)
|
|
340
|
+
expect { new_sympa.add('test@example.com', test_list, 'Test') }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
describe '#del' do
|
|
345
|
+
before { login_sympa }
|
|
346
|
+
|
|
347
|
+
it 'responds to del method' do
|
|
348
|
+
expect(sympa).to respond_to(:del)
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
it 'has delete alias' do
|
|
352
|
+
expect(sympa).to respond_to(:delete)
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
it 'removes a subscriber and returns true' do
|
|
356
|
+
ensure_list_exists(test_list)
|
|
357
|
+
sympa.add(member_email, test_list, 'Test User')
|
|
358
|
+
expect(sympa.del(member_email, test_list)).to be(true)
|
|
359
|
+
expect(sympa.review(test_list)).not_to include(member_email)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
it 'requires at least two arguments' do
|
|
363
|
+
expect { sympa.del }.to raise_error(ArgumentError)
|
|
364
|
+
expect { sympa.del('test@example.com') }.to raise_error(ArgumentError)
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
it 'requires login' do
|
|
368
|
+
new_sympa = Mail::Sympa.new(endpoint)
|
|
369
|
+
expect { new_sympa.del('test@example.com', test_list) }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
describe '#subscribe' do
|
|
374
|
+
before { login_sympa }
|
|
375
|
+
|
|
376
|
+
it 'responds to subscribe method' do
|
|
377
|
+
expect(sympa).to respond_to(:subscribe)
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
it 'subscribes the logged-in user' do
|
|
381
|
+
ensure_list_exists(test_list)
|
|
382
|
+
sympa.signoff(test_list) if sympa.review(test_list).include?(test_user)
|
|
383
|
+
expect(sympa.subscribe(test_list, 'Test User')).to be(true)
|
|
384
|
+
expect(sympa.review(test_list)).to include(test_user)
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
it 'requires at least one argument' do
|
|
388
|
+
expect { sympa.subscribe }.to raise_error(ArgumentError)
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
it 'requires login' do
|
|
392
|
+
new_sympa = Mail::Sympa.new(endpoint)
|
|
393
|
+
expect { new_sympa.subscribe(test_list) }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
394
|
+
end
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
describe '#signoff' do
|
|
398
|
+
before { login_sympa }
|
|
399
|
+
|
|
400
|
+
it 'responds to signoff method' do
|
|
401
|
+
expect(sympa).to respond_to(:signoff)
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
it 'has unsubscribe alias' do
|
|
405
|
+
expect(sympa).to respond_to(:unsubscribe)
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
it 'unsubscribes the logged-in user' do
|
|
409
|
+
ensure_list_exists(test_list)
|
|
410
|
+
sympa.subscribe(test_list, 'Test User') unless sympa.review(test_list).include?(test_user)
|
|
411
|
+
expect(sympa.signoff(test_list)).to be(true)
|
|
412
|
+
expect(sympa.review(test_list)).not_to include(test_user)
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
it 'requires exactly one argument' do
|
|
416
|
+
expect { sympa.signoff }.to raise_error(ArgumentError)
|
|
417
|
+
expect { sympa.signoff(test_list, 'extra') }.to raise_error(ArgumentError)
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
it 'requires login' do
|
|
421
|
+
new_sympa = Mail::Sympa.new(endpoint)
|
|
422
|
+
expect { new_sympa.signoff(test_list) }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
423
|
+
end
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
describe '#create_list' do
|
|
427
|
+
before { login_sympa }
|
|
428
|
+
|
|
429
|
+
it 'responds to create_list method' do
|
|
430
|
+
expect(sympa).to respond_to(:create_list)
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
it 'has createList alias' do
|
|
434
|
+
expect(sympa).to respond_to(:createList)
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
it 'creates a list with the requested subject' do
|
|
438
|
+
list_name = "test-#{SecureRandom.hex(6)}"
|
|
439
|
+
subject = 'Cømmunity & <Lists>'
|
|
440
|
+
result = sympa.create_list(list_name, subject, 'discussion_list', 'Integration test', 'testlist/testlist')
|
|
441
|
+
expect(result).to be(true)
|
|
442
|
+
expect(sympa.info(list_name)).to include(subject: subject, list_address: "#{list_name}@sympa.test")
|
|
443
|
+
expect(sympa.lists('testlist', 'testlist')).to include(a_string_including("listAddress=#{list_name}@sympa.test"))
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
it 'requires at least two arguments' do
|
|
447
|
+
expect { sympa.create_list }.to raise_error(ArgumentError)
|
|
448
|
+
expect { sympa.create_list("test-#{SecureRandom.hex(6)}") }.to raise_error(ArgumentError)
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
it 'requires login' do
|
|
452
|
+
new_sympa = Mail::Sympa.new(endpoint)
|
|
453
|
+
expect { new_sympa.create_list('test', 'Test') }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
454
|
+
end
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
describe '#close_list' do
|
|
458
|
+
before { login_sympa }
|
|
459
|
+
|
|
460
|
+
it 'responds to close_list method' do
|
|
461
|
+
expect(sympa).to respond_to(:close_list)
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
it 'has closeList alias' do
|
|
465
|
+
expect(sympa).to respond_to(:closeList)
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
it 'closes a list and removes it from the directory' do
|
|
469
|
+
list_name = "test-#{SecureRandom.hex(6)}"
|
|
470
|
+
sympa.create_list(list_name, 'Test List', 'discussion_list', 'Integration test', 'testlist/testlist')
|
|
471
|
+
expect(sympa.close_list(list_name)).to be(true)
|
|
472
|
+
expect(sympa.lists).not_to include(a_string_including("listAddress=#{list_name}@sympa.test"))
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
it 'requires exactly one argument' do
|
|
476
|
+
expect { sympa.close_list }.to raise_error(ArgumentError)
|
|
477
|
+
expect { sympa.close_list('list1', 'list2') }.to raise_error(ArgumentError)
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
it 'requires login' do
|
|
481
|
+
new_sympa = Mail::Sympa.new(endpoint)
|
|
482
|
+
expect { new_sympa.close_list('test') }.to raise_error(Mail::Sympa::Error, 'must login first')
|
|
483
|
+
end
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
describe '#authenticate_remote_app_and_run' do
|
|
487
|
+
it 'responds to authenticate_remote_app_and_run method' do
|
|
488
|
+
expect(sympa).to respond_to(:authenticate_remote_app_and_run)
|
|
489
|
+
end
|
|
490
|
+
|
|
491
|
+
it 'has authenticateRemoteAppAndRun alias' do
|
|
492
|
+
expect(sympa).to respond_to(:authenticateRemoteAppAndRun)
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
it 'requires exactly five arguments' do
|
|
496
|
+
expect { sympa.authenticate_remote_app_and_run }.to raise_error(ArgumentError)
|
|
497
|
+
expect { sympa.authenticate_remote_app_and_run('A') }.to raise_error(ArgumentError)
|
|
498
|
+
expect { sympa.authenticate_remote_app_and_run('A', 'B') }.to raise_error(ArgumentError)
|
|
499
|
+
expect { sympa.authenticate_remote_app_and_run('A', 'B', 'C') }.to raise_error(ArgumentError)
|
|
500
|
+
expect { sympa.authenticate_remote_app_and_run('A', 'B', 'C', 'D') }.to raise_error(ArgumentError)
|
|
501
|
+
expect { sympa.authenticate_remote_app_and_run('A', 'B', 'C', 'D', 'E', 'F') }.to raise_error(ArgumentError)
|
|
502
|
+
end
|
|
503
|
+
end
|
|
504
|
+
|
|
505
|
+
describe 'aliases' do
|
|
506
|
+
it 'has url alias for endpoint' do
|
|
507
|
+
expect(sympa).to respond_to(:url)
|
|
508
|
+
expect(sympa.url).to eq(sympa.endpoint)
|
|
509
|
+
end
|
|
510
|
+
end
|
|
511
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'Real Sympa SOAP integration' do
|
|
6
|
+
let(:endpoint) { ENV.fetch('SYMPA_ENDPOINT', 'http://localhost:8080/sympasoap') }
|
|
7
|
+
|
|
8
|
+
it 'publishes the real service contract through WWSympa' do
|
|
9
|
+
wsdl = Net::HTTP.get(URI(ENV.fetch('SYMPA_WSDL_URL', 'http://localhost:8080/sympa/wsdl')))
|
|
10
|
+
document = Nokogiri::XML(wsdl) { |config| config.strict.nonet }
|
|
11
|
+
operations = document.xpath('//*[local-name()="portType"]/*[local-name()="operation"]/@name').map(&:value)
|
|
12
|
+
expect(operations).to include('login', 'authenticateAndRun', 'authenticateRemoteAppAndRun', 'createList')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'rejects SOAP calls without authentication' do
|
|
16
|
+
client = Savon.client(endpoint: endpoint, namespace: 'urn:sympasoap')
|
|
17
|
+
expect {
|
|
18
|
+
client.call(:review, soap_action: 'urn:sympasoap#review', message: { list: 'testlist' })
|
|
19
|
+
}.to raise_error(Savon::SOAPFault, /User not authenticated/)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'rejects fabricated session cookies' do
|
|
23
|
+
sympa = Mail::Sympa.new(endpoint)
|
|
24
|
+
sympa.login(ENV.fetch('SYMPA_TEST_USER', 'postmaster@sympa.test'), ENV.fetch('SYMPA_TEST_PASSWORD', 'test'))
|
|
25
|
+
sympa.instance_variable_set(:@cookie, 'not-a-real-session')
|
|
26
|
+
expect { sympa.review('testlist') }.to raise_error(Mail::Sympa::Error, /Could not get email from cookie/)
|
|
27
|
+
end
|
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'rspec'
|
|
2
|
+
|
|
3
|
+
# Require mail/sympa with Savon support
|
|
4
|
+
require 'mail/sympa'
|
|
5
|
+
|
|
6
|
+
RSpec.configure do |config|
|
|
7
|
+
config.expect_with :rspec do |expectations|
|
|
8
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
12
|
+
|
|
13
|
+
# Custom matcher for boolean values
|
|
14
|
+
RSpec::Matchers.define :be_boolean do
|
|
15
|
+
match do |actual|
|
|
16
|
+
[true, false].include?(actual)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
description do
|
|
20
|
+
"be true or false"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
failure_message do |actual|
|
|
24
|
+
"expected #{actual.inspect} to be true or false"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
config.before(:suite) do
|
|
29
|
+
require 'net/http'
|
|
30
|
+
uri = URI(ENV.fetch('SYMPA_WSDL_URL', 'http://localhost:8080/sympa/wsdl'))
|
|
31
|
+
response = Net::HTTP.start(uri.host, uri.port, open_timeout: 3, read_timeout: 5) do |http|
|
|
32
|
+
http.get(uri.request_uri)
|
|
33
|
+
end
|
|
34
|
+
raise "Sympa WSDL unavailable at #{uri}: HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess) && response.body.include?('definitions')
|
|
35
|
+
|
|
36
|
+
puts "Testing real Sympa at #{ENV.fetch('SYMPA_ENDPOINT', 'http://localhost:8080/sympasoap')}"
|
|
37
|
+
end
|
|
38
|
+
end
|
data.tar.gz.sig
ADDED
|
Binary file
|