diff --git a/os_config_applier/os_config_applier.py b/os_config_applier/os_config_applier.py index 7ff72d1..40c5579 100755 --- a/os_config_applier/os_config_applier.py +++ b/os_config_applier/os_config_applier.py @@ -181,7 +181,8 @@ def parse_opts(argv): ' (may be used with --type and --key-default)') parser.add_argument('--type', default='default', help='exit with error if the specified --key does not' - ' match type. Valid types are ') + ' match type. Valid types are' + ' ') parser.add_argument('--key-default', help='This option only affects running with --key.' ' Print this if key is not found. This value is' diff --git a/os_config_applier/tests/test_value_type.py b/os_config_applier/tests/test_value_type.py index 97b3e81..c8529c7 100644 --- a/os_config_applier/tests/test_value_type.py +++ b/os_config_applier/tests/test_value_type.py @@ -43,3 +43,25 @@ class ValueTypeTestCase(testtools.TestCase): def test_raw_empty(self): self.assertEqual('', value_types.ensure_type('', 'raw')) + + def test_net_address_ipv4(self): + self.assertEqual('192.0.2.1', value_types.ensure_type('192.0.2.1', + 'netaddress')) + + def test_net_address_cidr(self): + self.assertEqual('192.0.2.0/24', + value_types.ensure_type('192.0.2.0/24', 'netaddress')) + + def test_ent_address_ipv6(self): + self.assertEqual('::', value_types.ensure_type('::', 'netaddress')) + self.assertEqual('2001:db8::2:1', value_types.ensure_type( + '2001:db8::2:1', 'netaddress')) + + def test_net_address_dns(self): + self.assertEqual('host.0domain-name.test', + value_types.ensure_type('host.0domain-name.test', + 'netaddress')) + + def test_net_address_bad(self): + self.assertRaises(config_exception.ConfigException, + value_types.ensure_type, "192.0.2.1;DROP TABLE foo") diff --git a/os_config_applier/value_types.py b/os_config_applier/value_types.py index 374ced0..3c5274a 100644 --- a/os_config_applier/value_types.py +++ b/os_config_applier/value_types.py @@ -20,6 +20,7 @@ from config_exception import ConfigException TYPES = { "int": "^[0-9]+$", "default": "^[A-Za-z0-9]*$", + "netaddress": "^[A-Za-z0-9/.:-]+$", "raw": "" }