Skip to content

Commit

Permalink
'primary'/'master' name can be quotable: issue #35
Browse files Browse the repository at this point in the history
  • Loading branch information
egberts committed Jun 1, 2022
1 parent 4de2cfc commit 5a9a08f
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 22 deletions.
20 changes: 19 additions & 1 deletion bind9_parser/isc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = master_name_base('master_name')
master_name.setName('<master_name>')

# iso8601 is not a naive nor aware ISO time-interval
Expand Down
8 changes: 4 additions & 4 deletions bind9_parser/isc_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,\
Expand Down Expand Up @@ -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)
)('')
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/rough-draft/namedconfglobal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 30 additions & 12 deletions tests/test_clause_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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";'
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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'
}]
}
)

Expand Down Expand Up @@ -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()
32 changes: 27 additions & 5 deletions tests/test_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 """
Expand Down Expand Up @@ -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'},
]
}
)

Expand All @@ -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):
Expand Down Expand Up @@ -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 = [
Expand All @@ -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()

0 comments on commit 5a9a08f

Please sign in to comment.