1
# Copyright (C) 2014 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your option)
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18
"""Test system configuration read-only access."""
21
'TestSystemConfiguration',
27
from mailman.testing.helpers import call_api
28
from mailman.testing.layers import RESTLayer
29
from six.moves.urllib_error import HTTPError
33
class TestSystemConfiguration(unittest.TestCase):
37
def test_basic_system_configuration(self):
38
# Read some basic system configuration value, just to prove that the
39
# infrastructure works.
40
url = 'http://localhost:9001/3.0/system/configuration/mailman'
41
json, response = call_api(url)
42
# There must be an `http_etag` key, but we don't care about its value.
43
self.assertIn('http_etag', json)
45
self.assertEqual(json, dict(
46
site_owner='noreply@example.com',
47
noreply_address='noreply',
48
default_language='en',
49
sender_headers='from from_ reply-to sender',
50
email_commands_max_lines='10',
51
pending_request_life='3d',
55
filtered_messages_are_preservable='no',
58
def test_dotted_section(self):
59
# A dotted section works too.
60
url = 'http://localhost:9001/3.0/system/configuration/language.fr'
61
json, response = call_api(url)
62
# There must be an `http_etag` key, but we don't care about its value.
63
self.assertIn('http_etag', json)
65
self.assertEqual(json, dict(
71
def test_multiline(self):
72
# Some values contain multiple lines. It is up to the client to split
74
url = 'http://localhost:9001/3.0/system/configuration/nntp'
75
json, response = call_api(url)
76
value = json['remove_headers']
77
self.assertEqual(sorted(value.split()), [
91
def test_all_sections(self):
92
# Getting the top level configuration object returns a list of all
94
url = 'http://localhost:9001/3.0/system/configuration'
95
json, response = call_api(url)
96
self.assertIn('http_etag', json)
97
self.assertEqual(sorted(json['sections']), [
99
'archiver.mail_archive',
102
'archiver.prototype',
116
'logging.fromusenet',
153
def test_no_such_section(self):
154
# A bogus section returns a 404.
155
url = 'http://localhost:9001/3.0/system/configuration/nosuchsection'
156
with self.assertRaises(HTTPError) as cm:
158
self.assertEqual(cm.exception.code, 404)
160
def test_too_many_path_components(self):
161
# More than two path components is an error, even if they name a valid
162
# configuration variable.
163
url = 'http://localhost:9001/3.0/system/configuration/mailman/layout'
164
with self.assertRaises(HTTPError) as cm:
166
self.assertEqual(cm.exception.code, 400)
168
def test_read_only(self):
169
# The entire configuration is read-only.
170
url = 'http://localhost:9001/3.0/system/configuration'
171
with self.assertRaises(HTTPError) as cm:
172
call_api(url, {'foo': 'bar'})
173
# 405 is Method Not Allowed.
174
self.assertEqual(cm.exception.code, 405)
176
def test_section_read_only(self):
177
# Sections are also read-only.
178
url = 'http://localhost:9001/3.0/system/configuration/mailman'
179
with self.assertRaises(HTTPError) as cm:
180
call_api(url, {'foo': 'bar'})
181
# 405 is Method Not Allowed.
182
self.assertEqual(cm.exception.code, 405)