diff options
Diffstat (limited to 'tests/unit/test_qutebrowser.py')
-rw-r--r-- | tests/unit/test_qutebrowser.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/unit/test_qutebrowser.py b/tests/unit/test_qutebrowser.py index 5a792a6d2..9f9b9adec 100644 --- a/tests/unit/test_qutebrowser.py +++ b/tests/unit/test_qutebrowser.py @@ -22,6 +22,8 @@ (Mainly commandline flag parsing) """ +import re + import pytest from qutebrowser import qutebrowser @@ -60,3 +62,61 @@ class TestLogFilter: _out, err = capsys.readouterr() print(err) assert 'Invalid log category invalid - valid categories' in err + + +class TestValidateUntrustedArgs: + + @pytest.mark.parametrize('args', [ + [], + [':nop'], + [':nop', '--untrusted-args'], + [':nop', '--debug', '--untrusted-args'], + [':nop', '--untrusted-args', 'foo'], + ['--debug', '--untrusted-args', 'foo'], + ['foo', '--untrusted-args', 'bar'], + ]) + def test_valid(self, args): + qutebrowser._validate_untrusted_args(args) + + @pytest.mark.parametrize('args, message', [ + ( + ['--untrusted-args', '--debug'], + "Found --debug after --untrusted-args, aborting.", + ), + ( + ['--untrusted-args', ':nop'], + "Found :nop after --untrusted-args, aborting.", + ), + ( + ['--debug', '--untrusted-args', '--debug'], + "Found --debug after --untrusted-args, aborting.", + ), + ( + [':nop', '--untrusted-args', '--debug'], + "Found --debug after --untrusted-args, aborting.", + ), + ( + [':nop', '--untrusted-args', ':nop'], + "Found :nop after --untrusted-args, aborting.", + ), + ( + [ + ':nop', + '--untrusted-args', + ':nop', + '--untrusted-args', + 'https://www.example.org', + ], + ( + "Found multiple arguments (:nop --untrusted-args " + "https://www.example.org) after --untrusted-args, aborting." + ) + ), + ( + ['--untrusted-args', 'okay1', 'okay2'], + "Found multiple arguments (okay1 okay2) after --untrusted-args, aborting.", + ), + ]) + def test_invalid(self, args, message): + with pytest.raises(SystemExit, match=re.escape(message)): + qutebrowser._validate_untrusted_args(args) |