forked from github.com/pypiserver
Add matrix auth exceptions
This commit is contained in:
parent
c79dd18ef6
commit
29c1803eae
@ -15,6 +15,7 @@ import textwrap
|
||||
import warnings
|
||||
|
||||
import functools as ft
|
||||
import ast
|
||||
|
||||
|
||||
warnings.filterwarnings("ignore", "Python 2.5 support may be dropped in future versions of Bottle")
|
||||
@ -201,8 +202,16 @@ def main(argv=None):
|
||||
sys.exit("Invalid port(%r) due to: %s" % (v, err))
|
||||
elif k in ("-a", "--authenticate"):
|
||||
if '{' in v:
|
||||
import ast
|
||||
v = ast.literal_eval(v)
|
||||
try:
|
||||
v = ast.literal_eval(v)
|
||||
except SyntaxError:
|
||||
message = 'Could not parse auth string %s! Please ensure string is correctly formatted.' % v
|
||||
print(message)
|
||||
sys.exit(message)
|
||||
if (not isinstance(v, dict) or not all([isinstance(i, list) for i in v.values()])):
|
||||
message = 'Matrix auth string must be a dict of lists. Please see the README for details.'
|
||||
print(message)
|
||||
sys.exit(message)
|
||||
if isinstance(v, dict):
|
||||
c.authenticated = {}
|
||||
for user in v:
|
||||
|
@ -193,3 +193,19 @@ def test_matrix_auth_list_multiple_actions(main, monkeypatch):
|
||||
monkeypatch.setitem(sys.modules, 'passlib.apache', mock.MagicMock())
|
||||
main(["-P", "pswd-file", "-a", "{'a': ['update', 'list'], 'b': ['download', 'update']}"])
|
||||
assert main.app.module.config.authenticated == {'a': ['update', 'list'], 'b': ['download', 'update']}
|
||||
|
||||
def test_matrix_auth_action_list_incorrect_format(capsys, main, monkeypatch):
|
||||
monkeypatch.setitem(sys.modules, 'passlib', mock.MagicMock())
|
||||
monkeypatch.setitem(sys.modules, 'passlib.apache', mock.MagicMock())
|
||||
with pytest.raises(SystemExit):
|
||||
main(["-P", "pswd-file", "-a", "{'a': ['update', 'list'], 'b': 'download'}"])
|
||||
out, err = capsys.readouterr()
|
||||
assert out.split('\n')[1] == 'Matrix auth string must be a dict of lists. Please see the README for details.'
|
||||
|
||||
def test_matrix_auth_string_is_not_parsable(capsys, main, monkeypatch):
|
||||
monkeypatch.setitem(sys.modules, 'passlib', mock.MagicMock())
|
||||
monkeypatch.setitem(sys.modules, 'passlib.apache', mock.MagicMock())
|
||||
with pytest.raises(SystemExit):
|
||||
main(["-P", "pswd-file", "-a", "{'a': ['update', 'list', 'b': 'download'}"])
|
||||
out, err = capsys.readouterr()
|
||||
assert out.split('\n')[1] == 'Could not parse auth string {\'a\': [\'update\', \'list\', \'b\': \'download\'}! Please ensure string is correctly formatted.'
|
||||
|
Loading…
Reference in New Issue
Block a user