diff options
author | Dharini Chandrasekar <dharini.chandrasekar@intel.com> | 2016-08-19 18:34:18 +0000 |
---|---|---|
committer | Dharini Chandrasekar <dharini.chandrasekar@intel.com> | 2016-12-07 03:27:45 +0000 |
commit | babff882c0794fab81665744bcc1aa155b90eed2 (patch) | |
tree | d7519df5396715499f30c6190128f88b89f03a0a /oslo_config/tests/test_types.py | |
parent | 23eaec2881b9cc315d06e8eca5fdd5e8d503368d (diff) | |
download | oslo-config-babff882c0794fab81665744bcc1aa155b90eed2.tar.gz |
Fixing HostName and adding support for HostAddress
When config options in different projects use IPOpt as the opt's
type, it restricts operators to only IP addresses.
When the opt is set to HostnameOpt type, currently even an
incomplete or invalid IP passes as a valid hostname. Also, currently
HostnameOpt does not make sure that there is a presense of at least one
non-numeric character in the provided host name.
According to RFC 1123, (https://tools.ietf.org/html/rfc1123),
a valid host name can never have the dotted-decimal form #.#.#.#,
since at least the highest-level component label will be alphabetic.
This patch fixes the existing Hostname Opt to abide by the stated RFC
and also adds a new opt type that would enable operators to provide
either a hostname or an IP and at the same time perform checks on
both IPOpt type and HostnameOpt type, by setting opt type to
"HostAddressOpt" type. This would ensure that an invalid IP does
not pass as a valid hostname and at the same time retains the rules
required to be followed for the validation of an acceptable hostname.
Change-Id: I77bdb64b7e6e56ce761d76696bc4448a9bd325eb
Closes-Bug: #1619044
Closes-Bug: #1615028
Diffstat (limited to 'oslo_config/tests/test_types.py')
-rw-r--r-- | oslo_config/tests/test_types.py | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/oslo_config/tests/test_types.py b/oslo_config/tests/test_types.py index 8457263..41edf6b 100644 --- a/oslo_config/tests/test_types.py +++ b/oslo_config/tests/test_types.py @@ -687,6 +687,32 @@ class IPv6AddressTypeTests(IPAddressTypeTests): self.assertInvalid('192.168.0.1') +class HostAddressTypeTests(TypeTestHelper, unittest.TestCase): + type = types.HostAddress() + + def test_invalid_host_addresses(self): + self.assertInvalid('-1') + self.assertInvalid('_foo') + self.assertInvalid('3.14') + self.assertInvalid('10.0') + self.assertInvalid('host..name') + self.assertInvalid('org.10') + self.assertInvalid('0.0.00') + + def test_valid_host_addresses(self): + self.assertConvertedValue('foo.bar', 'foo.bar') + self.assertConvertedValue('192.168.0.1', '192.168.0.1') + self.assertConvertedValue('abcd:ef::1', 'abcd:ef::1') + self.assertConvertedValue('home-site-here.org.com', + 'home-site-here.org.com') + self.assertConvertedValue('3com.com', '3com.com') + self.assertConvertedValue('10.org', '10.org') + self.assertConvertedValue('cell1.nova.site1', 'cell1.nova.site1') + self.assertConvertedValue('ab-c.com', 'ab-c.com') + self.assertConvertedValue('abc.com-org', 'abc.com-org') + self.assertConvertedValue('abc.0-0', 'abc.0-0') + + class HostnameTypeTests(TypeTestHelper, unittest.TestCase): type = types.Hostname() @@ -726,6 +752,12 @@ class HostnameTypeTests(TypeTestHelper, unittest.TestCase): self.assertInvalid(".host.name.com") self.assertInvalid("no spaces") + def test_invalid_hostnames_with_numeric_characters(self): + self.assertInvalid("10.0.0.0") + self.assertInvalid("3.14") + self.assertInvalid("org.10") + self.assertInvalid('0.0.00') + def test_no_start_end_hyphens(self): self.assertInvalid("-host.com") self.assertInvalid("-hostname.com-") @@ -739,9 +771,13 @@ class HostnameTypeTests(TypeTestHelper, unittest.TestCase): self.assertConvertedEqual('cell1.nova.site1') self.assertConvertedEqual('site01001') self.assertConvertedEqual('home-site-here.org.com') - self.assertConvertedEqual('192.168.0.1') - self.assertConvertedEqual('1.1.1') self.assertConvertedEqual('localhost') + self.assertConvertedEqual('3com.com') + self.assertConvertedEqual('10.org') + self.assertConvertedEqual('10ab.10ab') + self.assertConvertedEqual('ab-c.com') + self.assertConvertedEqual('abc.com-org') + self.assertConvertedEqual('abc.0-0') def test_max_segment_size(self): self.assertConvertedEqual('host.%s.com' % ('x' * 63)) |