tiramisu/test/test_config_domain.py

181 lines
7.8 KiB
Python
Raw Normal View History

2017-07-09 09:49:03 +02:00
from .autopath import do_autopath
2015-07-24 17:54:10 +02:00
do_autopath()
2016-03-19 21:27:37 +01:00
import warnings, sys
from py.test import raises
2018-08-14 22:15:40 +02:00
from tiramisu import Config
from tiramisu.option import DomainnameOption, EmailOption, URLOption, OptionDescription
from tiramisu.error import ValueWarning
from tiramisu.i18n import _
2018-03-19 08:33:53 +01:00
from tiramisu import getapi
def test_domainname():
d = DomainnameOption('d', '')
2013-10-01 10:13:17 +02:00
f = DomainnameOption('f', '', allow_without_dot=True)
2014-02-06 22:17:20 +01:00
g = DomainnameOption('g', '', allow_ip=True)
od = OptionDescription('a', '', [d, f, g])
c = Config(od)
2018-03-19 08:33:53 +01:00
api = getapi(c)
api.property.read_write()
api.option('d').value.set('toto.com')
raises(ValueError, "api.option('d').value.set('toto')")
api.option('d').value.set('toto3.com')
raises(ValueError, "api.option('d').value.set('toto_super.com')")
api.option('d').value.set('toto-.com')
raises(ValueError, "api.option('d').value.set('toto..com')")
2013-10-01 10:13:17 +02:00
#
2018-03-19 08:33:53 +01:00
api.option('f').value.set('toto.com')
api.option('f').value.set('toto')
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
raises(ValueError, "api.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')")
api.option('f').value.set('d')
api.option('f').value.set('d.t')
2014-02-06 22:17:20 +01:00
#
2018-03-19 08:33:53 +01:00
raises(ValueError, "api.option('f').value.set('192.168.1.1')")
api.option('g').value.set('toto.com')
api.option('g').value.set('192.168.1.0')
api.option('g').value.set('192.168.1.29')
def test_domainname_upper():
d = DomainnameOption('d', '')
od = OptionDescription('a', '', [d])
c = Config(od)
2018-03-19 08:33:53 +01:00
api = getapi(c)
api.property.read_write()
api.option('d').value.set('toto.com')
msg = _('some characters are uppercase')
has_error = False
try:
2018-03-19 08:33:53 +01:00
api.option('d').value.set('TOTO.COM')
2016-03-19 21:27:37 +01:00
except ValueError as err:
2018-03-19 08:33:53 +01:00
assert msg in str(err)
has_error = True
assert has_error is True
has_error = False
try:
2018-03-19 08:33:53 +01:00
api.option('d').value.set('toTo.com')
2016-03-19 21:27:37 +01:00
except ValueError as err:
2018-03-19 08:33:53 +01:00
assert msg in str(err)
has_error = True
assert has_error is True
def test_domainname_warning():
d = DomainnameOption('d', '', warnings_only=True)
f = DomainnameOption('f', '', allow_without_dot=True, warnings_only=True)
g = DomainnameOption('g', '', allow_ip=True, warnings_only=True)
od = OptionDescription('a', '', [d, f, g])
warnings.simplefilter("always", ValueWarning)
c = Config(od)
2018-03-19 08:33:53 +01:00
api = getapi(c)
api.property.read_write()
api.option('d').value.set('toto.com')
raises(ValueError, "api.option('d').value.set('toto')")
api.option('d').value.set('toto3.com')
with warnings.catch_warnings(record=True) as w:
2018-03-19 08:33:53 +01:00
api.option('d').value.set('toto_super.com')
assert len(w) == 1
2018-03-19 08:33:53 +01:00
with warnings.catch_warnings(record=True) as w:
api.option('d').value.set('toto-.com')
assert len(w) == 0
raises(ValueError, "api.option('d').value.set('toto..com')")
#
2018-03-19 08:33:53 +01:00
api.option('f').value.set('toto.com')
api.option('f').value.set('toto')
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')")
api.option('f').value.set('d')
api.option('f').value.set('d.t')
#
2018-03-19 08:33:53 +01:00
raises(ValueError, "api.option('f').value.set('192.168.1.1')")
api.option('g').value.set('toto.com')
api.option('g').value.set('192.168.1.0')
api.option('g').value.set('192.168.1.29')
def test_special_domain_name():
"""domain name option that starts with a number or not
"""
d = DomainnameOption('d', '')
e = DomainnameOption('e', '', type_='netbios')
od = OptionDescription('a', '', [d, e])
c = Config(od)
2018-03-19 08:33:53 +01:00
api = getapi(c)
api.property.read_write()
api.option('d').value.set('1toto.com')
api.option('d').value.set('123toto.com')
api.option('e').value.set('toto')
api.option('e').value.set('1toto')
def test_domainname_netbios():
d = DomainnameOption('d', '', type_='netbios')
e = DomainnameOption('e', '', "toto", type_='netbios')
od = OptionDescription('a', '', [d, e])
c = Config(od)
2018-03-19 08:33:53 +01:00
api = getapi(c)
api.property.read_write()
raises(ValueError, "api.option('d').value.set('toto.com')")
api.option('d').value.set('toto')
raises(ValueError, "api.option('d').value.set('domainnametoolong')")
def test_domainname_hostname():
d = DomainnameOption('d', '', type_='hostname')
e = DomainnameOption('e', '', "toto", type_='hostname')
od = OptionDescription('a', '', [d, e])
c = Config(od)
2018-03-19 08:33:53 +01:00
api = getapi(c)
api.property.read_write()
raises(ValueError, "api.option('d').value.set('toto.com')")
api.option('d').value.set('toto')
api.option('d').value.set('domainnametoolong')
def test_email():
e = EmailOption('e', '')
od = OptionDescription('a', '', [e])
c = Config(od)
2018-03-19 08:33:53 +01:00
api = getapi(c)
api.property.read_write()
api.option('e').value.set('foo-bar.baz@example.com')
api.option('e').value.set('root@foo.com')
api.option('e').value.set('root@domain')
raises(ValueError, "api.option('e').value.set(1)")
raises(ValueError, "api.option('e').value.set('root')")
raises(ValueError, "api.option('e').value.set('root[]@domain')")
def test_url():
u = URLOption('u', '')
od = OptionDescription('a', '', [u])
c = Config(od)
2018-03-19 08:33:53 +01:00
api = getapi(c)
api.property.read_write()
api.option('u').value.set('http://foo.com')
api.option('u').value.set('https://foo.com')
api.option('u').value.set('https://foo.com/')
raises(ValueError, "api.option('u').value.set(1)")
raises(ValueError, "api.option('u').value.set('ftp://foo.com')")
raises(ValueError, "api.option('u').value.set('foo.com')")
raises(ValueError, "api.option('u').value.set(':/foo.com')")
raises(ValueError, "api.option('u').value.set('foo.com/http://')")
api.option('u').value.set('https://foo.com/index.html')
api.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
raises(ValueError, "api.option('u').value.set('https://foo.com/index\\n.html')")
api.option('u').value.set('https://foo.com:8443')
api.option('u').value.set('https://foo.com:8443/')
api.option('u').value.set('https://foo.com:8443/index.html')
raises(ValueError, "api.option('u').value.set('https://foo.com:84438989')")
api.option('u').value.set('https://foo.com:8443/INDEX')
raises(ValueError, "api.option('u').value.set('https://FOO.COM:8443')")