diff --git a/bind9_parser/isc_utils.py b/bind9_parser/isc_utils.py index a66eb34..ee0d3c5 100755 --- a/bind9_parser/isc_utils.py +++ b/bind9_parser/isc_utils.py @@ -578,8 +578,26 @@ charset_master_name_base = alphanums + '_-' master_name_base = Word(charset_master_name_base, max=62) +master_name = copy.deepcopy(master_name_base('master_name')) + +master_name_base_dequoted = ( + ( + Char('"').suppress() + - Word(charset_master_name_base, max=62) + - Char('"').suppress() + ) + ^ ( + Char("'").suppress() + - Word(charset_master_name_base, max=62) + - Char("'").suppress() + ) +) + +master_name_dequotable = ( + master_name_base_dequoted + ^ master_name +)('master_name').setName('') -master_name = master_name_base('master_name') master_name.setName('') # iso8601 is not a naive nor aware ISO time-interval diff --git a/bind9_parser/isc_zone.py b/bind9_parser/isc_zone.py index 5eebea0..b838988 100755 --- a/bind9_parser/isc_zone.py +++ b/bind9_parser/isc_zone.py @@ -15,7 +15,7 @@ isc_boolean, view_name, isc_file_name,\ number_type, check_options, \ key_id_keyword_and_name_pair, squote, dquote, \ - krb5_realm_name, master_name + krb5_realm_name, master_name_dequotable from bind9_parser.isc_inet import ip4_addr,\ ip6_addr, inet_ip_port_keyword_and_number_element,\ inet_dscp_port_keyword_and_number_element,\ @@ -114,7 +114,7 @@ ip6_addr - Optional(inet_ip_port_keyword_and_number_element('ip_port')) )('ip6') - ^ master_name('master_name') + ^ master_name_dequotable('master_name') )('') - Optional(key_id_keyword_and_name_pair) )('') @@ -145,14 +145,14 @@ + zone_masters_series + rbrack ) - | ( + ^ ( inet_ip_port_keyword_and_number_element + Optional(inet_dscp_port_keyword_and_number_element) - lbrack - zone_masters_series + rbrack ) - | ( + ^ ( inet_dscp_port_keyword_and_number_element + Optional(inet_ip_port_keyword_and_number_element) - lbrack diff --git a/examples/rough-draft/namedconfglobal.py b/examples/rough-draft/namedconfglobal.py index 29b768b..b74d901 100644 --- a/examples/rough-draft/namedconfglobal.py +++ b/examples/rough-draft/namedconfglobal.py @@ -3274,6 +3274,7 @@ 'validity': {'function': 'masters_zone'}, 'found-in': {'zone'}, 'introduced': '9.0.0', + 'obsoleted': '9.18.0', # got renamed to 'primaries' instead 'topic': 'masters', 'zone-type': {'slave', 'mirror', 'stub', 'redirect', 'secondary'}, 'occurs-multiple-times': False, diff --git a/tests/test_clause_zone.py b/tests/test_clause_zone.py index 2b9cd08..e2f77fa 100755 --- a/tests/test_clause_zone.py +++ b/tests/test_clause_zone.py @@ -11,10 +11,9 @@ """ import unittest from pyparsing import cppStyleComment, pythonStyleComment -from bind9_parser.isc_utils import assert_parser_result_dict_false, assert_parser_result_dict_true +from bind9_parser.isc_utils import assert_parser_result_dict_true from bind9_parser.isc_clause_zone import \ zone_all_stmts_set,\ - zone_all_stmts_series,\ clause_stmt_zone_standalone,\ clause_stmt_zone_series @@ -30,6 +29,7 @@ class TestClauseZone(unittest.TestCase): | optviewzoneserver_statements_set | viewzone_statements_set )""" + def test_isc_clause_zone__all_stmts_set_file(self): """ Clause zone; All Zone statement file from isc_zone.py via zone_statements_set; passing mode """ test_string = 'file "a.b.type";' @@ -41,7 +41,8 @@ def test_isc_clause_zone__all_stmts_set_file(self): ) def test_isc_clause_zone__all_stmts_set_notify_to_soa(self): - """ Clause zone; All Zone statement 'notify-to-soa' (from isc_optzone.py via 'optzone_statements_set'dd); passing mode """ + """ Clause zone; All Zone statement 'notify-to-soa' (from isc_optzone.py via \ + 'optzone_statements_set'dd); passing mode """ test_string = """notify-to-soa yes;""" expected_result = {'notify_to_soa': 'yes'} assert_parser_result_dict_true( @@ -51,7 +52,8 @@ def test_isc_clause_zone__all_stmts_set_notify_to_soa(self): ) def test_isc_clause_zone__all_stmts_set_also_notify(self): - """ Clause zone; All Zone statement 'also-notify' (from isc_optzoneserver.py via 'optzoneserver_statements_set'dd); passing mode """ + """ Clause zone; All Zone statement 'also-notify' (from isc_optzoneserver.py via \ + 'optzoneserver_statements_set'dd); passing mode """ test_string = """also-notify {mymaster; 1.2.3.4;};""" assert_parser_result_dict_true( zone_all_stmts_set, @@ -61,7 +63,8 @@ def test_isc_clause_zone__all_stmts_set_also_notify(self): ) def test_isc_clause_zone__all_stmts_set_database(self): - """ Clause zone; All Zone statement 'database' (from isc_viewzone.py via 'viewzone_statements_set'dd); passing mode """ + """ Clause zone; All Zone statement 'database' (from isc_viewzone.py via \ + 'viewzone_statements_set'dd); passing mode """ test_string = """database abcd;""" expected_result = {'database': 'abcd'} assert_parser_result_dict_true( @@ -125,7 +128,6 @@ def test_isc_clause_zone__clause_stmt_zone_series_3_passing(self): 'zone_name': 'white.com'}]} ) - def test_isc_clause_zone__clause_stmt_zone_standalone_dict_passing(self): """ Clause zone; Statement zone standalone dict; passing mode """ assert_parser_result_dict_true( @@ -163,12 +165,11 @@ def test_isc_clause_zone__clause_zone_standalone_passing_dict_5(self): {'keyword': 'none'} ] }, - 'class': 'IN', - 'file': '/var/lib/bind/internal/master/db.home', - 'type': 'master', - 'zone_name': 'home' - } - ] + 'class': 'IN', + 'file': '/var/lib/bind/internal/master/db.home', + 'type': 'master', + 'zone_name': 'home' + }] } ) @@ -299,6 +300,23 @@ def test_isc_clause_stmt_zone_series_multiplezone_passing(self): 'zone_name': 'fifth_zone'}]} ) + def test_isc_clause_stmt_zone_series_issue35(self): + """ Clause, All; Zone Statements group; passing """ + assert_parser_result_dict_true( + clause_stmt_zone_series, + """zone "umichtest.net" { +type slave; +file "oncampus/net.umichtest"; +masters { +"DNS123" ; +}; +};""", + {'zones': [{'file': 'oncampus/net.umichtest', + 'masters_zone': {'zone_master_list': [{'master_name': ['DNS123']}]}, + 'type': 'slave', + 'zone_name': 'umichtest.net'}]} + ) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_zone.py b/tests/test_zone.py index b4abc5d..1cf6206 100755 --- a/tests/test_zone.py +++ b/tests/test_zone.py @@ -184,7 +184,6 @@ def test_isc_zone_stmt_ixfr_base_failing(self): result = zone_stmt_ixfr_base.runTests(test_string, failureTests=True) self.assertTrue(result[0]) - def test_isc_zone_stmt_ixfr_from_differences_passing(self): """ Test Clause Zone; Statement ixfr-from-differences; passing """ test_string = [ @@ -231,6 +230,16 @@ def test_isc_zone_stmt_journal_failing(self): self.assertTrue(result[0]) pass + def test_isc_zone_stmt_element_github_issue35(self): + """ """ + assert_parser_result_dict_true( + zone_masters_set, + """ + "DNS123" ; + """, + {'master_name': ['DNS123']} + ) + # zone_masters_set def test_isc_zone_stmt_masters_name_by_ipv6_passing(self): """ Test Clause Zone; Name, masters; by IPv6; passing """ @@ -325,8 +334,8 @@ def test_isc_zone_stmt_masters_series_singleset_keyid_passing(self): zone_masters_series, 'another_bastion_host_group key priv_dns_chan_key0;', {'zone_master_list': [{'key_id': 'priv_dns_chan_key0', - 'master_name': 'another_bastion_host_group'}, - ] + 'master_name': 'another_bastion_host_group'}, + ] } ) @@ -349,7 +358,7 @@ def test_isc_zone_stmt_masters_series_two_mixed_passing(self): zone_masters_series, 'another_bastion_host_group; 128.0.0.1;', {'zone_master_list': [{'master_name': 'another_bastion_host_group'}, - {'ip4': '128.0.0.1'}]} + {'ip4': '128.0.0.1'}]} ) def test_isc_zone_stmt_masters_series_two_mixed_w_key_passing(self): @@ -886,7 +895,6 @@ def test_isc_zone_statements_series_passing_2(self): } assert_parser_result_dict_true(zone_statements_series, test_string, expected_result) - def test_isc_zone_stmt_statements_series_failing(self): """ Test Clause Zone; Statement statements_series; failing """ test_string = [ @@ -909,5 +917,19 @@ def test_isc_zone_stmt_statements_github_issue1(self): 'type': 'slave'} ) + def test_isc_zone_stmt_statements_github_issue35(self): + assert_parser_result_dict_true( + zone_statements_series, + """type slave; +file "oncampus/net.umichtest"; +masters { +"DNS123" ; +};""", + {'file': 'oncampus/net.umichtest', + 'masters_zone': {'zone_master_list': [{'master_name': ['DNS123']}]}, + 'type': 'slave'} + ) + + if __name__ == '__main__': unittest.main()