Skip to content

Commit

Permalink
Fixes #47 ParseException for filter-aaaa-on-v4
Browse files Browse the repository at this point in the history
  • Loading branch information
egberts committed Dec 15, 2022
1 parent dd9fe1a commit dff1c9b
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 4 deletions.
36 changes: 35 additions & 1 deletion bind9_parser/isc_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Description: Various 'options' statement that is used
only by 'options' clause.
"""
from pyparsing import Group, Keyword, Optional, \
from pyparsing import Group, Keyword, Optional, Combine, \
ZeroOrMore, OneOrMore, Literal, ungroup, CaselessLiteral
from pyparsing import pyparsing_common
from bind9_parser.isc_utils import lbrack, rbrack, semicolon, size_spec, \
Expand Down Expand Up @@ -339,6 +339,37 @@
)
options_stmt_fake_iquery.setName('fake-iquery <boolean>;')

# filter-aaaa-on-v4 ( break-dnssec | <boolean> ); // not configured
options_stmt_filter_aaaa_on_v4 = (
Keyword('filter-aaaa-on-v4').suppress()
- Combine(
isc_boolean()
| Keyword('break-dnssec')
)('filter_aaaa_on_v4')
+ semicolon
)
options_stmt_filter_aaaa_on_v4.setName('filter-aaaa-on-v4 { break-dnssec | <boolean> );')

# filter-aaaa-on-v6 ( break-dnssec | <boolean> ); // not configured
options_stmt_filter_aaaa_on_v6 = (
Keyword('filter-aaaa-on-v6').suppress()
- Combine(
isc_boolean()
| Keyword('break-dnssec')
)('filter_aaaa_on_v6')
+ semicolon
)
options_stmt_filter_aaaa_on_v6.setName('filter-aaaa-on-v6 { break-dnssec | <boolean> );')

# filter-aaaa { <address_match_element>; ... }; // not configured
options_stmt_filter_aaaa = (
Keyword('filter-aaaa').suppress()
- Group(
aml_nesting('')
)('filter_aaaa')
)
options_stmt_filter_aaaa.setName('filter-aaaa { <aml>; .... };')

# flush-zones-on-shutdown <boolean>; [ Opt ] # v9.3+
options_stmt_flush_zones_on_shutdown = (
Keyword('flush-zones-on-shutdown').suppress()
Expand Down Expand Up @@ -977,6 +1008,9 @@
^ options_stmt_dscp
^ options_stmt_dump_file
^ options_stmt_fake_iquery
^ options_stmt_filter_aaaa_on_v4
^ options_stmt_filter_aaaa_on_v6
^ options_stmt_filter_aaaa
^ options_stmt_flush_zones_on_shutdown
^ options_stmt_geoip_directory
^ options_stmt_has_old_clients
Expand Down
1 change: 0 additions & 1 deletion examples/rough-draft/namedconfglobal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2582,7 +2582,6 @@
'topic': 'ancient, filtering',
'comment':
"""Specifies a list of addresses to which
filter-aaaa-on-v4 is applies.
The default is any.
Option 'filter-aaaa' activated at v9.12.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'bind9_parser',
]

bind9_parser_version = '0.99.1'
bind9_parser_version = '0.99.2'

setup( # Distribution meta-data
name='bind9_parser',
Expand Down
70 changes: 69 additions & 1 deletion tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
options_stmt_dnstap_version, \
options_stmt_dscp, \
options_stmt_dump_file, \
options_stmt_fake_iquery, options_stmt_flush_zones_on_shutdown, \
options_stmt_fake_iquery, \
options_stmt_filter_aaaa_on_v4, options_stmt_filter_aaaa_on_v6, options_stmt_filter_aaaa, \
options_stmt_flush_zones_on_shutdown, \
options_stmt_geoip_directory, \
options_stmt_has_old_clients, \
options_stmt_http_listener_clients, \
Expand Down Expand Up @@ -83,6 +85,8 @@ def test_isc_options_all_booleans(self):
['deallocate-on-exit', options_stmt_deallocate_on_exit, ],
['fake-iquery', options_stmt_fake_iquery, ],
['flush-zones-on-shutdown', options_stmt_flush_zones_on_shutdown, ],
['filter-aaaa-on-v4', options_stmt_flush_zones_on_shutdown, ],
['filter-aaaa-on-v6', options_stmt_flush_zones_on_shutdown, ],
['has-old-clients', options_stmt_has_old_clients, ],
['hostname-statistics', options_stmt_hostname_statistics, ],
['hostname-statistics-max', options_stmt_hostname_statistics_max, ],
Expand Down Expand Up @@ -325,6 +329,70 @@ def test_isc_options_stmt_dump_file_passing(self):
assert_parser_result_dict_true(options_stmt_dump_file, 'dump-file "/tmp/crapola";',
{'dump_file': '/tmp/crapola'})

def test_isc_options_stmt_filter_aaaa_on_v4_passing(self):
assert_parser_result_dict_true(
options_stmt_filter_aaaa_on_v4,
'filter-aaaa-on-v4 yes;',
{'filter_aaaa_on_v4': 'yes'}
)

def test_isc_options_stmt_filter_aaaa_on_v4_2_passing(self):
assert_parser_result_dict_true(
options_stmt_filter_aaaa_on_v4,
'filter-aaaa-on-v4 false;',
{'filter_aaaa_on_v4': 'False'}
)

def test_isc_options_stmt_filter_aaaa_on_v4_3_passing(self):
assert_parser_result_dict_true(
options_stmt_filter_aaaa_on_v4,
'filter-aaaa-on-v4 break-dnssec;',
{'filter_aaaa_on_v4': 'break-dnssec'}
)

def test_isc_options_stmt_filter_aaaa_on_v6_passing(self):
assert_parser_result_dict_true(
options_stmt_filter_aaaa_on_v6,
'filter-aaaa-on-v6 yes;',
{'filter_aaaa_on_v6': 'yes'}
)

def test_isc_options_stmt_filter_aaaa_on_v6_2_passing(self):
assert_parser_result_dict_true(
options_stmt_filter_aaaa_on_v6,
'filter-aaaa-on-v6 false;',
{'filter_aaaa_on_v6': 'False'}
)

def test_isc_options_stmt_filter_aaaa_on_v6_3_passing(self):
assert_parser_result_dict_true(
options_stmt_filter_aaaa_on_v6,
'filter-aaaa-on-v6 break-dnssec;',
{'filter_aaaa_on_v6': 'break-dnssec'}
)

def test_isc_options_stmt_filter_aaaa_passing(self):
assert_parser_result_dict_true(
options_stmt_filter_aaaa,
'filter-aaaa { };',
{'filter_aaaa': {'aml': []}}
)

def test_isc_options_stmt_filter_aaaa_2_passing(self):
assert_parser_result_dict_true(
options_stmt_filter_aaaa,
'filter-aaaa { 1.1.1.1; };',
{'filter_aaaa': {'aml': [{'ip4_addr': '1.1.1.1'}]}}
)

def test_isc_options_stmt_filter_aaaa_3_passing(self):
assert_parser_result_dict_true(
options_stmt_filter_aaaa,
'filter-aaaa { 1.2.3.4; 5.6.7.8; };',
{'filter_aaaa': {'aml': [{'ip4_addr': '1.2.3.4'},
{'ip4_addr': '5.6.7.8'}]}}
)

def test_isc_options_stmt_geoip_directory(self):
""" Clause options; Statement geoip-directory; passing mode """
assert_parser_result_dict(
Expand Down

0 comments on commit dff1c9b

Please sign in to comment.