mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
tor: tests: Convert to pytest style tests from class based tests
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
37b9e21e30
commit
3aae4b39d6
@ -11,72 +11,64 @@ from django.core.exceptions import ValidationError
|
|||||||
from plinth.modules.tor import forms, utils
|
from plinth.modules.tor import forms, utils
|
||||||
|
|
||||||
|
|
||||||
class TestTor:
|
@patch('plinth.app.App.get')
|
||||||
"""Test cases for testing the Tor module."""
|
@pytest.mark.usefixtures('needs_root', 'load_cfg')
|
||||||
|
def test_get_status(_app_get):
|
||||||
|
"""Test that get_status does not raise any unhandled exceptions.
|
||||||
|
|
||||||
@staticmethod
|
This should work regardless of whether tor is installed, or
|
||||||
@patch('plinth.app.App.get')
|
/etc/tor/instances/plinth/torrc exists.
|
||||||
@pytest.mark.usefixtures('needs_root', 'load_cfg')
|
"""
|
||||||
def test_get_status(_app_get):
|
utils.get_status()
|
||||||
"""Test that get_status does not raise any unhandled exceptions.
|
|
||||||
|
|
||||||
This should work regardless of whether tor is installed, or
|
|
||||||
/etc/tor/instances/plinth/torrc exists.
|
|
||||||
"""
|
|
||||||
utils.get_status()
|
|
||||||
|
|
||||||
|
|
||||||
class TestTorForm:
|
def test_bridge_validator():
|
||||||
"""Test whether Tor configration form works."""
|
"""Test upstream bridges' form field validator."""
|
||||||
|
validator = forms.bridges_validator
|
||||||
|
|
||||||
@staticmethod
|
# Just IP:port
|
||||||
def test_bridge_validator():
|
validator('73.237.165.184:9001')
|
||||||
"""Test upstream bridges' form field validator."""
|
validator('73.237.165.184')
|
||||||
validator = forms.bridges_validator
|
validator('[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443')
|
||||||
|
validator('[2001:db8:85a3:8d3:1319:8a2e:370:7348]')
|
||||||
|
|
||||||
# Just IP:port
|
# With fingerprint
|
||||||
validator('73.237.165.184:9001')
|
validator('73.237.165.184:9001 '
|
||||||
validator('73.237.165.184')
|
'0D04F10F497E68D2AF32375BB763EC3458A908C8')
|
||||||
validator('[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443')
|
|
||||||
validator('[2001:db8:85a3:8d3:1319:8a2e:370:7348]')
|
|
||||||
|
|
||||||
# With fingerprint
|
# With transport type
|
||||||
validator('73.237.165.184:9001 '
|
validator('obfs4 73.237.165.184:9001 '
|
||||||
'0D04F10F497E68D2AF32375BB763EC3458A908C8')
|
'0D04F10F497E68D2AF32375BB763EC3458A908C8')
|
||||||
|
|
||||||
# With transport type
|
# With transport type and extra options
|
||||||
validator('obfs4 73.237.165.184:9001 '
|
validator('obfs4 10.1.1.1:30000 '
|
||||||
'0D04F10F497E68D2AF32375BB763EC3458A908C8')
|
'0123456789ABCDEF0123456789ABCDEF01234567 '
|
||||||
|
'cert=A/b+1 iat-mode=0')
|
||||||
|
|
||||||
# With transport type and extra options
|
# Leading, trailing spaces and empty lines
|
||||||
validator('obfs4 10.1.1.1:30000 '
|
validator('\n'
|
||||||
'0123456789ABCDEF0123456789ABCDEF01234567 '
|
' \n'
|
||||||
'cert=A/b+1 iat-mode=0')
|
'73.237.165.184:9001 '
|
||||||
|
'0D04F10F497E68D2AF32375BB763EC3458A908C8'
|
||||||
|
' \n'
|
||||||
|
'73.237.165.184:9001 '
|
||||||
|
'0D04F10F497E68D2AF32375BB763EC3458A908C8'
|
||||||
|
' \n'
|
||||||
|
'\n')
|
||||||
|
|
||||||
# Leading, trailing spaces and empty lines
|
# Invalid number for parts
|
||||||
validator('\n'
|
with pytest.raises(ValidationError):
|
||||||
' \n'
|
validator(' ')
|
||||||
'73.237.165.184:9001 '
|
|
||||||
'0D04F10F497E68D2AF32375BB763EC3458A908C8'
|
|
||||||
' \n'
|
|
||||||
'73.237.165.184:9001 '
|
|
||||||
'0D04F10F497E68D2AF32375BB763EC3458A908C8'
|
|
||||||
' \n'
|
|
||||||
'\n')
|
|
||||||
|
|
||||||
# Invalid number for parts
|
# Invalid IP address/port
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
validator(' ')
|
validator('73.237.165.384:9001')
|
||||||
|
|
||||||
# Invalid IP address/port
|
with pytest.raises(ValidationError):
|
||||||
with pytest.raises(ValidationError):
|
validator('73.237.165.184:90001')
|
||||||
validator('73.237.165.384:9001')
|
|
||||||
|
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
validator('73.237.165.184:90001')
|
validator('[a2001:db8:85a3:8d3:1319:8a2e:370:7348]:443')
|
||||||
|
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
validator('[a2001:db8:85a3:8d3:1319:8a2e:370:7348]:443')
|
validator('[2001:db8:85a3:8d3:1319:8a2e:370:7348]:90443')
|
||||||
|
|
||||||
with pytest.raises(ValidationError):
|
|
||||||
validator('[2001:db8:85a3:8d3:1319:8a2e:370:7348]:90443')
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user