2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
2019-06-21 23:04:04 +02:00
|
|
|
from .config import config_type, get_config, value_list, global_owner
|
2015-07-24 17:54:10 +02:00
|
|
|
|
2016-03-19 21:27:37 +01:00
|
|
|
import warnings, sys
|
2013-05-08 18:14:42 +02:00
|
|
|
from py.test import raises
|
|
|
|
|
2019-03-08 07:11:56 +01:00
|
|
|
from tiramisu import Config, DomainnameOption, EmailOption, URLOption, OptionDescription
|
2014-10-26 09:38:17 +01:00
|
|
|
from tiramisu.error import ValueWarning
|
2014-12-07 14:51:51 +01:00
|
|
|
from tiramisu.i18n import _
|
2018-10-31 08:00:19 +01:00
|
|
|
from tiramisu.storage import list_sessions
|
|
|
|
|
|
|
|
|
|
|
|
def teardown_function(function):
|
|
|
|
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
2019-06-21 23:04:04 +02:00
|
|
|
def test_domainname(config_type):
|
2013-05-08 18:14:42 +02:00
|
|
|
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)
|
2019-03-08 07:11:56 +01:00
|
|
|
h = DomainnameOption('h', '', allow_ip=True, cidr=True)
|
|
|
|
od = OptionDescription('a', '', [d, f, g, h])
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg = Config(od)
|
|
|
|
cfg.property.read_write()
|
2019-06-21 23:04:04 +02:00
|
|
|
cfg = get_config(cfg, config_type)
|
2019-03-08 07:11:56 +01:00
|
|
|
#
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('d').value.set('toto.com')
|
|
|
|
raises(ValueError, "cfg.option('d').value.set('toto')")
|
|
|
|
cfg.option('d').value.set('toto3.com')
|
|
|
|
raises(ValueError, "cfg.option('d').value.set('toto_super.com')")
|
|
|
|
cfg.option('d').value.set('toto-.com')
|
|
|
|
raises(ValueError, "cfg.option('d').value.set('toto..com')")
|
2013-10-01 10:13:17 +02:00
|
|
|
#
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('f').value.set('toto.com')
|
|
|
|
cfg.option('f').value.set('toto')
|
|
|
|
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
|
|
|
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
|
|
|
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
|
|
|
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
|
|
|
raises(ValueError, "cfg.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')")
|
|
|
|
cfg.option('f').value.set('d')
|
|
|
|
cfg.option('f').value.set('d.t')
|
2014-02-06 22:17:20 +01:00
|
|
|
#
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')")
|
2019-03-08 07:11:56 +01:00
|
|
|
raises(ValueError, "cfg.option('f').value.set('192.168.1.0/24')")
|
|
|
|
#
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('g').value.set('toto.com')
|
|
|
|
cfg.option('g').value.set('192.168.1.0')
|
|
|
|
cfg.option('g').value.set('192.168.1.29')
|
2019-03-08 07:11:56 +01:00
|
|
|
raises(ValueError, "cfg.option('g').value.set('192.168.1.0/24')")
|
|
|
|
#
|
|
|
|
cfg.option('h').value.set('toto.com')
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
raises(ValueError, "cfg.option('h').value.set('192.168.1.0')")
|
|
|
|
raises(ValueError, "cfg.option('h').value.set('192.168.1.29')")
|
2019-03-08 07:11:56 +01:00
|
|
|
cfg.option('h').value.set('192.168.1.0/24')
|
2013-05-08 18:14:42 +02:00
|
|
|
|
2014-10-26 09:38:17 +01:00
|
|
|
|
2019-06-21 23:04:04 +02:00
|
|
|
def test_domainname_upper(config_type):
|
2014-12-07 14:51:51 +01:00
|
|
|
d = DomainnameOption('d', '')
|
|
|
|
od = OptionDescription('a', '', [d])
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg = Config(od)
|
|
|
|
cfg.property.read_write()
|
2019-06-21 23:04:04 +02:00
|
|
|
cfg = get_config(cfg, config_type)
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('d').value.set('toto.com')
|
2014-12-07 14:51:51 +01:00
|
|
|
msg = _('some characters are uppercase')
|
|
|
|
has_error = False
|
|
|
|
try:
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('d').value.set('TOTO.COM')
|
2016-03-19 21:27:37 +01:00
|
|
|
except ValueError as err:
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
assert msg in str(err)
|
2014-12-07 14:51:51 +01:00
|
|
|
has_error = True
|
|
|
|
assert has_error is True
|
|
|
|
has_error = False
|
|
|
|
try:
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('d').value.set('toTo.com')
|
2016-03-19 21:27:37 +01:00
|
|
|
except ValueError as err:
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
assert msg in str(err)
|
2014-12-07 14:51:51 +01:00
|
|
|
has_error = True
|
|
|
|
assert has_error is True
|
|
|
|
|
|
|
|
|
2019-06-21 23:04:04 +02:00
|
|
|
def test_domainname_warning(config_type):
|
2014-10-26 09:38:17 +01:00
|
|
|
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)
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg = Config(od)
|
|
|
|
cfg.property.read_write()
|
2019-06-21 23:04:04 +02:00
|
|
|
cfg = get_config(cfg, config_type)
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('d').value.set('toto.com')
|
|
|
|
raises(ValueError, "cfg.option('d').value.set('toto')")
|
|
|
|
cfg.option('d').value.set('toto3.com')
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
|
|
|
cfg.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:
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('d').value.set('toto-.com')
|
2018-03-19 08:33:53 +01:00
|
|
|
assert len(w) == 0
|
2018-08-14 23:07:07 +02:00
|
|
|
raises(ValueError, "cfg.option('d').value.set('toto..com')")
|
2014-10-26 09:38:17 +01:00
|
|
|
#
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('f').value.set('toto.com')
|
|
|
|
cfg.option('f').value.set('toto')
|
|
|
|
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
|
|
|
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
|
|
|
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
|
|
|
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')")
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('f').value.set('d')
|
|
|
|
cfg.option('f').value.set('d.t')
|
2014-10-26 09:38:17 +01:00
|
|
|
#
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')")
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('g').value.set('toto.com')
|
|
|
|
cfg.option('g').value.set('192.168.1.0')
|
|
|
|
cfg.option('g').value.set('192.168.1.29')
|
2014-10-26 09:38:17 +01:00
|
|
|
|
|
|
|
|
2019-06-21 23:04:04 +02:00
|
|
|
def test_special_domain_name(config_type):
|
2014-02-25 15:20:03 +01:00
|
|
|
"""domain name option that starts with a number or not
|
2014-02-25 14:19:54 +01:00
|
|
|
"""
|
|
|
|
d = DomainnameOption('d', '')
|
2014-02-25 15:20:03 +01:00
|
|
|
e = DomainnameOption('e', '', type_='netbios')
|
2014-10-26 09:38:17 +01:00
|
|
|
od = OptionDescription('a', '', [d, e])
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg = Config(od)
|
|
|
|
cfg.property.read_write()
|
2019-06-21 23:04:04 +02:00
|
|
|
cfg = get_config(cfg, config_type)
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('d').value.set('1toto.com')
|
|
|
|
cfg.option('d').value.set('123toto.com')
|
|
|
|
cfg.option('e').value.set('toto')
|
|
|
|
cfg.option('e').value.set('1toto')
|
2014-02-25 15:20:03 +01:00
|
|
|
|
2013-05-08 18:14:42 +02:00
|
|
|
|
2019-06-21 23:04:04 +02:00
|
|
|
def test_domainname_netbios(config_type):
|
2013-05-08 18:14:42 +02:00
|
|
|
d = DomainnameOption('d', '', type_='netbios')
|
2013-05-10 09:27:54 +02:00
|
|
|
e = DomainnameOption('e', '', "toto", type_='netbios')
|
|
|
|
od = OptionDescription('a', '', [d, e])
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg = Config(od)
|
|
|
|
cfg.property.read_write()
|
2019-06-21 23:04:04 +02:00
|
|
|
cfg = get_config(cfg, config_type)
|
2018-08-14 23:07:07 +02:00
|
|
|
raises(ValueError, "cfg.option('d').value.set('toto.com')")
|
|
|
|
cfg.option('d').value.set('toto')
|
|
|
|
raises(ValueError, "cfg.option('d').value.set('domainnametoolong')")
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
2019-06-21 23:04:04 +02:00
|
|
|
def test_domainname_hostname(config_type):
|
2013-05-08 18:14:42 +02:00
|
|
|
d = DomainnameOption('d', '', type_='hostname')
|
2013-05-10 09:27:54 +02:00
|
|
|
e = DomainnameOption('e', '', "toto", type_='hostname')
|
|
|
|
od = OptionDescription('a', '', [d, e])
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg = Config(od)
|
|
|
|
cfg.property.read_write()
|
2019-06-21 23:04:04 +02:00
|
|
|
cfg = get_config(cfg, config_type)
|
2018-08-14 23:07:07 +02:00
|
|
|
raises(ValueError, "cfg.option('d').value.set('toto.com')")
|
|
|
|
cfg.option('d').value.set('toto')
|
|
|
|
cfg.option('d').value.set('domainnametoolong')
|
2013-09-30 19:41:56 +02:00
|
|
|
|
|
|
|
|
2019-06-21 23:04:04 +02:00
|
|
|
def test_email(config_type):
|
2013-09-30 19:41:56 +02:00
|
|
|
e = EmailOption('e', '')
|
|
|
|
od = OptionDescription('a', '', [e])
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg = Config(od)
|
|
|
|
cfg.property.read_write()
|
2019-06-21 23:04:04 +02:00
|
|
|
cfg = get_config(cfg, config_type)
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('e').value.set('foo-bar.baz@example.com')
|
|
|
|
cfg.option('e').value.set('root@foo.com')
|
|
|
|
cfg.option('e').value.set('root@domain')
|
|
|
|
raises(ValueError, "cfg.option('e').value.set(1)")
|
|
|
|
raises(ValueError, "cfg.option('e').value.set('root')")
|
|
|
|
raises(ValueError, "cfg.option('e').value.set('root[]@domain')")
|
2013-09-30 19:41:56 +02:00
|
|
|
|
|
|
|
|
2019-06-21 23:04:04 +02:00
|
|
|
def test_url(config_type):
|
2013-09-30 19:41:56 +02:00
|
|
|
u = URLOption('u', '')
|
|
|
|
od = OptionDescription('a', '', [u])
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg = Config(od)
|
|
|
|
cfg.property.read_write()
|
2019-06-21 23:04:04 +02:00
|
|
|
cfg = get_config(cfg, config_type)
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('u').value.set('http://foo.com')
|
|
|
|
cfg.option('u').value.set('https://foo.com')
|
|
|
|
cfg.option('u').value.set('https://foo.com/')
|
|
|
|
raises(ValueError, "cfg.option('u').value.set(1)")
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
raises(ValueError, "cfg.option('u').value.set('ftp://foo.com')")
|
|
|
|
raises(ValueError, "cfg.option('u').value.set('foo.com')")
|
|
|
|
raises(ValueError, "cfg.option('u').value.set(':/foo.com')")
|
|
|
|
raises(ValueError, "cfg.option('u').value.set('foo.com/http://')")
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('u').value.set('https://foo.com/index.html')
|
|
|
|
cfg.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
raises(ValueError, "cfg.option('u').value.set('https://foo.com/index\\n.html')")
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('u').value.set('https://foo.com:8443')
|
|
|
|
cfg.option('u').value.set('https://foo.com:8443/')
|
|
|
|
cfg.option('u').value.set('https://foo.com:8443/index.html')
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
raises(ValueError, "cfg.option('u').value.set('https://foo.com:84438989')")
|
2018-08-14 23:07:07 +02:00
|
|
|
cfg.option('u').value.set('https://foo.com:8443/INDEX')
|
2019-06-21 23:04:04 +02:00
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
# FIXME
|
|
|
|
raises(ValueError, "cfg.option('u').value.set('https://FOO.COM:8443')")
|