def test_isc_controls_statement_python_list_passing(self):
     """ Clause controls; Python List, passing mode """
     test_data = """
                 controls { inet * allow { any; }; };
         controls { inet 128.0.0.1 allow { }; };
         controls { inet 128.0.0.2 allow {localhost;}; };
         controls { inet 128.0.0.4 port 8004 allow { 128.0.0.5; 128.0.0.6;} keys { public_rndc_key3; }; };
     """
     expected_result = {
         'controls': [{
             'inet': {
                 'allow': {
                     'aml': [{
                         'addr': '128.0.0.5'
                     }, {
                         'addr': '128.0.0.6'
                     }]
                 },
                 'control_server_addr': '128.0.0.4',
                 'ip_port_w': 8004,
                 'keys': [{
                     'key_id': 'public_rndc_key3'
                 }]
             }
         }]
     }
     my_csc = clause_stmt_control_series.setWhitespaceChars(' \t\n')
     assertParserResultDict(my_csc, test_data, expected_result, True)
 def test_isc_controls_key_passing(self):
     """ Clause controls; Element key; passing mode """
     test_data = 'keys { rndc-key; }'
     expected_result = {'keys': [{'key_id': 'rndc-key'}]}
     assertParserResultDict(controls_keys_element, test_data,
                            expected_result, True)
     test_data = 'keys { \'quoted-key_id\'; }'
     expected_result = {'keys': [{'key_id': '\'quoted-key_id\''}]}
     assertParserResultDict(controls_keys_element, test_data,
                            expected_result, True)
     test_data = 'keys { "quoted-key_id"; }'
     expected_result = {'keys': [{'key_id': '\"quoted-key_id\"'}]}
     assertParserResultDict(controls_keys_element, test_data,
                            expected_result, True)
     test_data = 'keys { unquoted-key_id; }'
     expected_result = {'keys': [{'key_id': 'unquoted-key_id'}]}
     assertParserResultDict(controls_keys_element, test_data,
                            expected_result, True)
     test_data = 'keys { rndc-key; second_key; third_key;}'
     expected_result = {
         'keys': [{
             'key_id': 'rndc-key'
         }, {
             'key_id': 'second_key'
         }, {
             'key_id': 'third_key'
         }]
     }
     assertParserResultDict(controls_keys_element, test_data,
                            expected_result, True)
예제 #3
0
    def test_isc_clause_stmt_dyndb_multiple_passing(self):
        """ Clause dyndb; Element Dynamic Database; passing """
        test_data = """
dyndb My_Custom_database_name "My_Custom_module_name" { unspecified-text };
dyndb hyperfast_mariadb "/usr/lib/libmariadb.so" { max_soconn=4 };
dyndb "example-ldap" "/usr/lib64/bind/ldap.so" {
    uri "ldap://ldap.example.com";
    base "cn=dns, dc=example,dc=com";
    auth_method "none";
};
"""
        expected_result = {
            'dyndb': [{
                'db_name': 'My_Custom_database_name',
                'driver_parameters': 'unspecified-text ',
                'module_filename': '"My_Custom_module_name"'
            }, {
                'db_name': 'hyperfast_mariadb',
                'driver_parameters': 'max_soconn=4 ',
                'module_filename': '"/usr/lib/libmariadb.so"'
            }, {
                'db_name':
                '"example-ldap"',
                'driver_parameters':
                'uri '
                '"ldap://ldap.example.com";\n'
                '    base "cn=dns, '
                'dc=example,dc=com";\n'
                '    auth_method "none";\n',
                'module_filename':
                '"/usr/lib64/bind/ldap.so"'
            }]
        }
        assertParserResultDict(clause_stmt_dyndb_series, test_data,
                               expected_result, True)
예제 #4
0
 def test_isc_options_stmt_acache_cleaning_interval_passing(self):
     """ Clause options; Statement acache-cleaning-interface; passing mode """
     assertParserResultDict(options_stmt_acache_cleaning_interval,
                            'acache-cleaning-interval 15;',
                            {'acache_cleaning_interval': 15}, True)
     assertParserResultDictTrue(options_stmt_acache_cleaning_interval,
                                'acache-cleaning-interval 123;',
                                {'acache_cleaning_interval': 123})
예제 #5
0
 def test_isc_options_stmt_avoid_v6_udp_ports_passing(self):
     """ Clause options; Statement avoid-v4-udp-ports; passing mode """
     assertParserResultDict(options_stmt_avoid_v6_udp_ports,
                            'avoid-v6-udp-ports { 15; 43; 50; };',
                            {'avoid_v6_udp_ports': [15, 43, 50]}, True)
     assertParserResultDictTrue(options_stmt_avoid_v6_udp_ports,
                                'avoid-v6-udp-ports { 54; 123; };',
                                {'avoid_v6_udp_ports': [54, 123]})
 def test_isc_clause_controls_controls_inet_set_failing(self):
     """ Clause controls; Element controls_inet_set; passing """
     test_data = 'inet localhost allow { };'
     expected_result = {'inet': [{'addr': 'localhost', 'allow': []}]}
     assertParserResultDict(controls_inet_set, test_data, expected_result,
                            False)
     test_data = 'inet any allow { };'
     expected_result = {'inet': [{'addr': 'any', 'allow': []}]}
     assertParserResultDict(controls_inet_set, test_data, expected_result,
                            False)
예제 #7
0
 def test_isc_dyndb_dynamic_module_passing(self):
     """ Clause dyndb; Element Dynamic Module; passing """
     test_data = '"my_driver.so"'
     expected_result = {'module_filename': '"my_driver.so"'}
     assertParserResultDict(dyndb_dynamic_module_name, test_data,
                            expected_result, True)
     test_data = "'my_driver.so'"
     expected_result = {'module_filename': '\'my_driver.so\''}
     assertParserResultDict(dyndb_dynamic_module_name, test_data,
                            expected_result, True)
예제 #8
0
    def test_isc_aml_aml_nesting_part2_failing(self):
        """ Clause ACL; Element AML spacing; failing """

        test_data = ['{ oops };']
        result = aml_nesting.runTests(test_data, failureTests=True)
        self.assertTrue(result[0])
        test_data = [
            """        {
               key DDNS_UPDATER;
               };
   """
        ]
        result = aml_nesting.runTests(test_data, failureTests=False)
        self.assertTrue(result[0])

        test_data = """{
             localhost;
             127.0.0.1;
             10.0.0.1/8;
             {
                 master_nameservers;
                 slave_bastion_host;
             };
             {
                 any;
                 none;
                 localnets;
             };
         };"""
        #  Must be in same ordering as expected result
        expected_result = {
            'aml': [{
                'addr': 'localhost'
            }, {
                'addr': '127.0.0.1'
            }, {
                'addr': '10.0.0.1/8'
            }, {
                'aml': [{
                    'acl_name_WRONG': 'master_nameservers'
                }, {
                    'acl_name': 'slave_bastion_host'
                }]
            }, {
                'aml': [{
                    'addr': 'any'
                }, {
                    'addr': 'none'
                }, {
                    'addr': 'localnets'
                }]
            }]
        }
        assertParserResultDict(aml_nesting, test_data, expected_result, False)
예제 #9
0
 def test_aml_nesting_first_combo(self):
     test_data = """ { localhost; { none; }; };"""
     expected_result = {
         'aml': [{
             'addr': 'localhost'
         }, {
             'aml': [{
                 'addr': 'none'
             }]
         }]
     }
     assertParserResultDict(aml_nesting, test_data, expected_result, True)
예제 #10
0
 def test_isc_controls_unix_group_passing(self):
     """ Clause controls; Element inet group; passing mode """
     test_data = 'unix "/tmp/x" perm 0666 owner 101 group 101;'
     expected_result = {
         'unix': {
             'gid': 101,
             'path_name': '"/tmp/x"',
             'perm': 666,
             'uid': 101
         }
     }
     assertParserResultDict(controls_unix_set, test_data, expected_result,
                            True)
예제 #11
0
 def test_isc_clause_stmt_dyndb_passing(self):
     """ Clause dyndb; Element Dynamic Database; passing """
     test_data = 'dyndb My_Custom_database_name "My_Custom_module_name" { unspecified-text };'
     expected_result = {
         'dyndb': [{
             'db_name': 'My_Custom_database_name',
             'driver_parameters': 'unspecified-text ',
             # Aha, there is a space before the '}' that we must test for
             'module_filename': '"My_Custom_module_name"'
         }]
     }
     assertParserResultDict(clause_stmt_dyndb_series, test_data,
                            expected_result, True)
예제 #12
0
    def test_isc_controls_statement_python_list2_passing(self):
        """ Clause controls; Python List, passing mode """
        test_data = """
controls {
    unix "/tmp/x" perm 0770 owner 222 group 333;
    inet 128.0.0.13 allow {localhost;};
    inet * port 8008 allow {"rndc-users";} keys {"rndc-remote5";};
    unix "/tmp/x" perm 0444 owner 555 group 666;
    };
"""
        expected_result = {
            'controls': [{
                'unix': {
                    'gid': 333,
                    'path_name': '"/tmp/x"',
                    'perm': 770,
                    'uid': 222
                }
            }, {
                'inet': {
                    'allow': {
                        'aml': [{
                            'addr': 'localhost'
                        }]
                    },
                    'control_server_addr': '128.0.0.13'
                }
            }, {
                'inet': {
                    'allow': {
                        'aml': [{
                            'acl_name': '"rndc-users"'
                        }]
                    },
                    'control_server_addr': '*',
                    'ip_port_w': 8008,
                    'keys': [{
                        'key_id': '"rndc-remote5"'
                    }]
                }
            }, {
                'unix': {
                    'gid': 666,
                    'path_name': '"/tmp/x"',
                    'perm': 444,
                    'uid': 555
                }
            }]
        }
        my_csc = clause_stmt_control_series.setWhitespaceChars(' \t\n')
        assertParserResultDict(my_csc, test_data, expected_result, True)
예제 #13
0
 def test_isc_controls_allow_passing(self):
     """ Clause controls; Element inet allow; passing mode """
     test_data = 'allow { 127.0.0.1; }'
     expected_result = {
         'allow': {  # noticed no '[', because there is exactly ONE 'allow'
             'aml': [{
                 'addr': '127.0.0.1'
             }]
         }
     }
     assertParserResultDict(controls_inet_allow_element, test_data,
                            expected_result, True)
     test_data = 'allow { }'
     expected_result = {'allow': []}
     assertParserResultDict(controls_inet_allow_element, test_data,
                            expected_result, True)
예제 #14
0
    def test_isc_aml_aml_nesting_failing(self):
        """Purposely failing Address Match List (AML) name"""
        test_data = """ {
            acl_mast!er_nameservers;
            1.1,1.1;
            acl_nameX&&&
            { &^%$#; }; }; """
        expected_result = {}
        assertParserResultDict(aml_nesting, test_data, expected_result, False)

        assertParserResultDict(aml_nesting, '{ 5.5.5.5/55; }',
                               {'aml': [{'5.5.5.5/55'}]}, False)
        assertParserResultDict(aml_nesting, '{ 6.6.6.6/0;}', {'6.6.6.6/0'},
                               False)  # w/o 'aml':
        assertParserResultDict(aml_nesting, '7.7.7', {}, False)
        assertParserResultDict(aml_nesting, '{ 8.8.8.8 };', {}, False)
예제 #15
0
    def test_isc_dyndb_driver_config_passing(self):
        """ Clause dyndb; Element Driver Configuration; passing """
        test_data = """ {
    uri "ldap://ldap.example.com";
    base "cn=dns, dc=example,dc=com";
    auth_method "none";
    }
"""
        expected_result = {
            'driver_parameters':
            'uri "ldap://ldap.example.com";\n'
            '    base "cn=dns, dc=example,dc=com";\n'
            '    auth_method "none";\n'
            '    '
        }
        assertParserResultDict(dyndb_custom_driver_configuration, test_data,
                               expected_result, True)
예제 #16
0
 def test_acl_names_failing(self):
     """ Type ACL Name; failing """
     assertParserResultDict(acl_name, 'example.com!', {}, False)
     assertParserResultDict(
         acl_name, 'ex;mple', {},
         False)  # obviously cannot use semicolon in acl_name/master_id/aml
     assertParserResultDict(acl_name, 'subdir/example', {}, False)
     assertParserResultDict(
         acl_name, 'ex#mple', {},
         False)  # obviously cannot use hash in acl_name/master_id/aml
예제 #17
0
 def test_isc_clause_controls_controls_inet_set_passing(self):
     """ Clause controls; Element controls_inet_set; passing """
     test_data = 'inet * allow { };'
     expected_result = {'inet': {'control_server_addr': '*', 'allow': []}}
     assertParserResultDict(controls_inet_set, test_data, expected_result,
                            True)
     test_data = 'inet 8.8.8.8 allow { any; };'
     expected_result = {
         'inet': {
             'control_server_addr': '8.8.8.8',
             'allow': {
                 'aml': [{
                     'addr': 'any'
                 }]
             }
         }
     }
     assertParserResultDict(controls_inet_set, test_data, expected_result,
                            True)
예제 #18
0
 def test_aml_nesting_forward_passing(self):
     assertParserResultDict(
         aml_nesting, '{ 1.1.1.1; { 127.0.0.1;}; };',
         {'aml': [{
             'addr': '1.1.1.1'
         }, {
             'aml': [{
                 'addr': '127.0.0.1'
             }]
         }]}, True)
     assertParserResultDict(aml_nesting, '{ { 8.8.8.8; }; };',
                            {'aml': [{
                                'aml': [{
                                    'addr': '8.8.8.8'
                                }]
                            }]}, True)
     assertParserResultDict(
         aml_nesting, '{ { { 9.9.9.9; }; }; };',
         {'aml': [{
             'aml': [{
                 'aml': [{
                     'addr': '9.9.9.9'
                 }]
             }]
         }]}, True)
예제 #19
0
 def test_aml_choices2_failing(self):
     assertParserResultDict(aml_choices, 'master/nameservers_acl;', {},
                            False)
     assertParserResultDict(aml_choices, 'master_nameservers#acl;', {},
                            False)
     assertParserResultDict(aml_choices, 'master;nameservers_acl;', {},
                            False)
예제 #20
0
 def test_aml_choices_failing(self):
     """ Element AML; Choices AML; failing """
     assertParserResultDict(aml_choices, 'master/nameservers_acl', {},
                            False)
     assertParserResultDict(aml_choices, 'master_nameservers#acl', {},
                            False)
     assertParserResultDict(aml_choices, 'master;nameservers_acl', {},
                            False)
예제 #21
0
 def test_isc_controls_statement_multiple_element_passing(self):
     """ Clause controls; Multiple Element statement, passing mode """
     test_data = 'controls { unix "/tmp/x" perm 0666 owner 101 group 101; inet 128.0.0.12 allow {localhost;}; };'
     expected_result = {
         'controls': [{
             'unix': {
                 'gid': 101,
                 'path_name': '"/tmp/x"',
                 'perm': 666,
                 'uid': 101
             }
         }, {
             'inet': {
                 'allow': {
                     'aml': [{
                         'addr': 'localhost'
                     }]
                 },
                 'control_server_addr': '128.0.0.12'
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
예제 #22
0
 def test_isc_clause_stmt_dyndb_failing(self):
     """ Clause dyndb; Element Dynamic Database; failing """
     test_data = 'dyndb database_name module_name { }'
     expected_result = {}
     assertParserResultDict(clause_stmt_dyndb_series, test_data,
                            expected_result, False)
예제 #23
0
 def test_isc_dyndb_database_name_passing(self):
     """ Clause dyndb: Element Database Name; passing """
     assertParserResultDict(dyndb_database_name, 'custom_driver_data',
                            {'db_name': 'custom_driver_data'}, True)
예제 #24
0
 def test_isc_options_stmt_bindkeys_file(self):
     """ Clause options; Statement bindkeys-file; passing mode """
     assertParserResultDict(options_stmt_bindkeys_file,
               'bindkeys-file "/dev/null";',
                            {'bindkeys_file': '"/dev/null"'},
                            True)
예제 #25
0
 def test_isc_clause_controls_controls_inet_read_only_element_passing(self):
     """ Clause controls; Element controls_inet_read_only_element; passing """
     test_data = 'read-only true'
     expected_result = {'read-only': 'True'}
     assertParserResultDict(controls_inet_read_only_element, test_data,
                            expected_result, True)
예제 #26
0
 def test_isc_aml_key_id_keyword_and_name_element_failing(self):
     """ Element AML; Type key_id; passing"""
     assertParserResultDict(key_id_keyword_and_name_pair, 'key myKey3',
                            {'key_id_WRONG': 'myKey3'}, False)
예제 #27
0
 def test_aml_choices_passing(self):
     assertParserResultDict(aml_choices, 'any', {'addr': 'any'}, True)
     assertParserResultDict(aml_choices, 'none', {'addr': 'none'}, True)
     assertParserResultDict(aml_choices, 'localhost', {'addr': 'localhost'},
                            True)
     assertParserResultDict(aml_choices, 'localnets', {'addr': 'localnets'},
                            True)
     assertParserResultDict(aml_choices, '1.1.1.1', {'addr': '1.1.1.1'},
                            True)
     assertParserResultDict(aml_choices, '2.2.2.2/2', {'addr': '2.2.2.2/2'},
                            True)
     assertParserResultDict(aml_choices, 'fe03::3', {'addr': 'fe03::3'},
                            True)
     assertParserResultDict(aml_choices, 'master_nameservers_acl',
                            {'acl_name': 'master_nameservers_acl'}, True)
     assertParserResultDict(aml_choices, 'example', {'acl_name': 'example'},
                            True)
     assertParserResultDict(aml_choices, 'key MyKeyId',
                            {'key_id': ['MyKeyId']}, True)
     test_datas = [['key myKeyId', {
         'key_id': ['myKeyId']
     }], ['127.0.0.1', {
         'addr': '127.0.0.1'
     }], ['localnets', {
         'addr': 'localnets'
     }], ['any', {
         'addr': 'any'
     }], ['none', {
         'addr': 'none'
     }], ['localhost', {
         'addr': 'localhost'
     }], ['10.0.0.1/8', {
         'addr': '10.0.0.1/8'
     }], ['example.com', {
         'acl_name': 'example.com'
     }]
                   # FQDN-style are valid master name, but treated lik a hostname
                   ]
     for this_test_data, this_expected_result in test_datas:
         assertParserResultDict(aml_choices, this_test_data,
                                this_expected_result, True)
예제 #28
0
 def test_isc_controls_statement_single_passing(self):
     """ Clause controls; Single statement, passing mode """
     test_data = 'controls { inet 128.0.0.1 allow {}; };'
     expected_result = {
         'controls': [{
             'inet': {
                 'control_server_addr': '128.0.0.1',
                 'allow': []
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
     test_data = 'controls { inet 128.0.0.4 port 8004 allow { 128.0.0.5; 128.0.0.6;} keys { public-rndc-key3; }; };'
     expected_result = {
         'controls': [{
             'inet': {
                 'allow': {
                     'aml': [{
                         'addr': '128.0.0.5'
                     }, {
                         'addr': '128.0.0.6'
                     }]
                 },
                 'control_server_addr': '128.0.0.4',
                 'ip_port_w': 8004,
                 'keys': [{
                     'key_id': 'public-rndc-key3'
                 }]
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
     test_data = 'controls { inet 128.0.0.2 allow {localhost;}; };'
     expected_result = {
         'controls': [{
             'inet': {
                 'allow': {
                     'aml': [{
                         'addr': 'localhost'
                     }]
                 },
                 'control_server_addr': '128.0.0.2'
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
     test_data = 'controls { inet * port 8001 allow {} keys { my-key;};};'
     expected_result = {
         'controls': [{
             'inet': {
                 'allow': [],
                 'control_server_addr': '*',
                 'ip_port_w': 8001,
                 'keys': [{
                     'key_id': 'my-key'
                 }]
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
     test_data = "controls { inet * port 8002 allow {'rndc-users';} keys {'rndc-remote';};};"
     expected_result = {
         'controls': [{
             'inet': {
                 'allow': {
                     'aml': [{
                         'acl_name': "'rndc-users'"
                     }]
                 },
                 'control_server_addr': '*',
                 'ip_port_w': 8002,
                 'keys': [{
                     'key_id': "'rndc-remote'"
                 }]
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
     test_data = 'controls { inet 128.0.0.3 allow {}; inet * port 8003 allow {} keys { mykey2;};};'
     expected_result = {
         'controls': [{
             'inet': {
                 'allow': [],
                 'control_server_addr': '128.0.0.3'
             }
         }, {
             'inet': {
                 'allow': [],
                 'control_server_addr': '*',
                 'ip_port_w': 8003,
                 'keys': [{
                     'key_id': 'mykey2'
                 }]
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
     test_data = 'controls { inet 128.0.0.7 port 8005 allow { 128.0.0.8; } keys { rndc-key4; };};'
     expected_result = {
         'controls': [{
             'inet': {
                 'allow': {
                     'aml': [{
                         'addr': '128.0.0.8'
                     }]
                 },
                 'control_server_addr': '128.0.0.7',
                 'ip_port_w': 8005,
                 'keys': [{
                     'key_id': 'rndc-key4'
                 }]
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
     test_data = 'controls { inet 128.0.0.9 port 8006 allow { 128.0.0.10; 128.0.0.11;} read-only yes; };'
     expected_result = {
         'controls': [{
             'inet': {
                 'allow': {
                     'aml': [{
                         'addr': '128.0.0.10'
                     }, {
                         'addr': '128.0.0.11'
                     }]
                 },
                 'control_server_addr': '128.0.0.9',
                 'ip_port_w': 8006,
                 'read-only': 'yes'
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
     test_data = 'controls { inet 128.0.0.12 allow {localhost;};'\
                 + ' inet * port 8007 allow {"rndc-users";} keys {"rndc-remote5";};};'
     expected_result = {
         'controls': [{
             'inet': {
                 'allow': {
                     'aml': [{
                         'addr': 'localhost'
                     }]
                 },
                 'control_server_addr': '128.0.0.12'
             }
         }, {
             'inet': {
                 'allow': {
                     'aml': [{
                         'acl_name': '"rndc-users"'
                     }]
                 },
                 'control_server_addr': '*',
                 'ip_port_w': 8007,
                 'keys': [{
                     'key_id': '"rndc-remote5"'
                 }]
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
     test_data = 'controls { unix "/tmp/x" perm 0666 owner 101 group 101; };'
     expected_result = {
         'controls': [{
             'unix': {
                 'gid': 101,
                 'path_name': '"/tmp/x"',
                 'perm': 666,
                 'uid': 101
             }
         }]
     }
     assertParserResultDict(clause_stmt_control_series, test_data,
                            expected_result, True)
예제 #29
0
 def test_isc_aml_key_id_keyword_and_name_element_passing(self):
     """ Element AML; Type key_id; passing"""
     assertParserResultDict(key_id_keyword_and_name_pair, 'key myKey2',
                            {'key_id': 'myKey2'}, True)
예제 #30
0
 def test_isc_controls_controls_inet_addr_and_port_passing(self):
     """ Clause controls; inet address; passing mode """
     test_data = '127.0.0.1'
     expected_result = {'control_server_addr': '127.0.0.1'}
     assertParserResultDict(controls_inet_addr_and_port, test_data,
                            expected_result, True)