1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# Copyright (C) 2014-2015 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
"""Test system configuration read-only access."""
__all__ = [
'TestSystemConfiguration',
]
import unittest
from mailman.testing.helpers import call_api
from mailman.testing.layers import RESTLayer
from urllib.error import HTTPError
class TestSystemConfiguration(unittest.TestCase):
layer = RESTLayer
maxDiff = None
def test_basic_system_configuration(self):
# Read some basic system configuration value, just to prove that the
# infrastructure works.
url = 'http://localhost:9001/3.0/system/configuration/mailman'
json, response = call_api(url)
# There must be an `http_etag` key, but we don't care about its value.
self.assertIn('http_etag', json)
del json['http_etag']
self.assertEqual(json, dict(
default_language='en',
email_commands_max_lines='10',
filtered_messages_are_preservable='no',
html_to_plain_text_command='/usr/bin/lynx -dump $filename',
layout='testing',
noreply_address='noreply',
pending_request_life='3d',
post_hook='',
pre_hook='',
sender_headers='from from_ reply-to sender',
site_owner='noreply@example.com',
))
def test_dotted_section(self):
# A dotted section works too.
url = 'http://localhost:9001/3.0/system/configuration/language.fr'
json, response = call_api(url)
# There must be an `http_etag` key, but we don't care about its value.
self.assertIn('http_etag', json)
del json['http_etag']
self.assertEqual(json, dict(
description='French',
charset='iso-8859-1',
enabled='yes',
))
def test_multiline(self):
# Some values contain multiple lines. It is up to the client to split
# on whitespace.
url = 'http://localhost:9001/3.0/system/configuration/nntp'
json, response = call_api(url)
value = json['remove_headers']
self.assertEqual(sorted(value.split()), [
'date-received',
'nntp-posting-date',
'nntp-posting-host',
'posted',
'posting-version',
'received',
'relay-version',
'x-complaints-to',
'x-trace',
'xref',
])
def test_all_sections(self):
# Getting the top level configuration object returns a list of all
# existing sections.
url = 'http://localhost:9001/3.0/system/configuration'
json, response = call_api(url)
self.assertIn('http_etag', json)
self.assertEqual(sorted(json['sections']), [
'antispam',
'archiver.mail_archive',
'archiver.master',
'archiver.mhonarc',
'archiver.prototype',
'bounces',
'database',
'devmode',
'digests',
'language.ar',
'language.ast',
'language.ca',
'language.cs',
'language.da',
'language.de',
'language.el',
'language.en',
'language.es',
'language.et',
'language.eu',
'language.fi',
'language.fr',
'language.gl',
'language.he',
'language.hr',
'language.hu',
'language.ia',
'language.it',
'language.ja',
'language.ko',
'language.lt',
'language.nl',
'language.no',
'language.pl',
'language.pt',
'language.pt_BR',
'language.ro',
'language.ru',
'language.sk',
'language.sl',
'language.sr',
'language.sv',
'language.tr',
'language.uk',
'language.vi',
'language.zh_CN',
'language.zh_TW',
'logging.archiver',
'logging.bounce',
'logging.config',
'logging.database',
'logging.debug',
'logging.error',
'logging.fromusenet',
'logging.http',
'logging.locks',
'logging.mischief',
'logging.root',
'logging.runner',
'logging.smtp',
'logging.subscribe',
'logging.vette',
'mailman',
'mta',
'nntp',
'passwords',
'paths.dev',
'paths.fhs',
'paths.here',
'paths.local',
'paths.testing',
'runner.archive',
'runner.bad',
'runner.bounces',
'runner.command',
'runner.digest',
'runner.in',
'runner.lmtp',
'runner.nntp',
'runner.out',
'runner.pipeline',
'runner.rest',
'runner.retry',
'runner.shunt',
'runner.virgin',
'shell',
'styles',
'webservice',
])
def test_no_such_section(self):
# A bogus section returns a 404.
url = 'http://localhost:9001/3.0/system/configuration/nosuchsection'
with self.assertRaises(HTTPError) as cm:
call_api(url)
self.assertEqual(cm.exception.code, 404)
def test_too_many_path_components(self):
# More than two path components is an error, even if they name a valid
# configuration variable.
url = 'http://localhost:9001/3.0/system/configuration/mailman/layout'
with self.assertRaises(HTTPError) as cm:
call_api(url)
self.assertEqual(cm.exception.code, 400)
def test_read_only(self):
# The entire configuration is read-only.
url = 'http://localhost:9001/3.0/system/configuration'
with self.assertRaises(HTTPError) as cm:
call_api(url, {'foo': 'bar'})
# 405 is Method Not Allowed.
self.assertEqual(cm.exception.code, 405)
def test_section_read_only(self):
# Sections are also read-only.
url = 'http://localhost:9001/3.0/system/configuration/mailman'
with self.assertRaises(HTTPError) as cm:
call_api(url, {'foo': 'bar'})
# 405 is Method Not Allowed.
self.assertEqual(cm.exception.code, 405)
|