def test_isc_clause_zone__clause_stmt_zone_standalone_dict_passing(self): assertParserResultDictTrue( clause_stmt_zone_standalone, 'zone red { auto-dnssec maintain; };', {'zone': { 'auto_dnssec': 'maintain', 'zone_name': 'red', }})
def test_isc_optviewzone_stmt_forwarders_passing(self): """ Clause options/view/zone; Statement forwarders; passing """ test_string = [ 'forwarders { 1.1.1.1; };', 'forwarders { 1.1.1.2 port 53; };', 'forwarders { 1.1.1.3 port 54 dscp 6; };', 'forwarders { 1.1.1.4 dscp 5; };', 'forwarders { fe01::1; };', 'forwarders { fe01::2 port 55; };', 'forwarders { fe01::3 port 57 dscp 6; };', 'forwarders { fe01::4 dscp 5; };', 'forwarders port 53 { 1.1.1.1; };', 'forwarders port 53 dscp 1 { 1.1.1.2 port 53; };', 'forwarders dscp 2 { 1.1.1.3 port 54 dscp 6; };', 'forwarders port 54 { fe01::1; };', 'forwarders port 55 dscp 3 { fe01::2 port 55; };', 'forwarders dscp 4 { fe01::3 port 57 dscp 6; };', ] result = optviewzone_stmt_forwarders.runTests(test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( optviewzone_stmt_forwarders, 'forwarders port 44 dscp 4 { 2.2.2.2 port 53; fe08::8 dscp 3; };', {'fowarders': [{'dscp_port': 4, 'fwdr2': [{'addr': '2.2.2.2', 'ip_port': '53'}, {'addr': 'fe08::8', 'dscp_port': 3}], 'ip_port': '44'}]} )
def test_isc_optviewzone_stmt_transfer_source_v6_passing(self): """ Clause options/view/zone; Statement transfer-source-v6; passing """ test_string = [ 'transfer-source-v6 fe12::1;', 'transfer-source-v6 fe12::2 port 53;', 'transfer-source-v6 fe12::3 port *;', 'transfer-source-v6 fe12::4 port 53 dscp 1;', 'transfer-source-v6 fe12::5 port * dscp 1;', 'transfer-source-v6 fe12::6 dscp 2;', 'transfer-source-v6 *;', 'transfer-source-v6 * port 53;', 'transfer-source-v6 * port *;', 'transfer-source-v6 * port 53 dscp 1;', 'transfer-source-v6 * port * dscp 1;', 'transfer-source-v6 * dscp 2;', ] result = optviewzone_stmt_transfer_source_v6.runTests(test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( optviewzone_stmt_transfer_source_v6, 'transfer-source-v6 fe12::5 port * dscp 1;', {'transfer_source_v6': {'addr': 'fe12::5', 'dscp_port': 1, 'ip_port_w': '*'}} )
def test_isc_optview_stmt_rate_limit_passing(self): """ Clause options/view; Statement rate-limit; passing """ test_string = [ 'rate-limit { all-per-second 60; };', 'rate-limit { errors-per-second 60; };', 'rate-limit { exempt-clients { 4.4.4.4; }; };', 'rate-limit { ipv4-prefix-length 8; };', 'rate-limit { ipv6-prefix-length 8; };', 'rate-limit { log-only yes; };', 'rate-limit { max-table-size 1500; };', 'rate-limit { min-table-size 1500; };', 'rate-limit { nodata-per-second 5; };', 'rate-limit { nxdomains-per-second 5; };', 'rate-limit { qps-scale 5; };', 'rate-limit { referrals-per-second 5; };', 'rate-limit { responses-per-second 5; };', 'rate-limit { slip 5; };', 'rate-limit { window 5; };', ] result = optview_stmt_rate_limit.runTests(test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( optview_stmt_rate_limit, 'rate-limit { exempt-clients { 5.5.5.5; }; slip 5; window 6; responses-per-second 60; };', {'rate_limit': [{'addr': '5.5.5.5'}, {'slip': 5}, {'window': 6}, {'responses_per_second': 60}]} )
def test_isc_clause_stmt_masters_multielement_passing(self): """Masters clause, passing mode""" test_string = 'masters ns1 { 127.0.0.1; 192.168.1.1; 192.168.6.1; };' expected_result = { 'masters': [{ 'master_id': 'ns1', 'master_list': [{ 'addr': '127.0.0.1' }, { 'addr': '192.168.1.1' }, { 'addr': '192.168.6.1' }] }] } assertParserResultDictTrue(clause_stmt_masters_standalone, test_string, expected_result) test_string = 'masters ns1 { another_bastion_hosts1; hidden_bastion2; };' expected_result = { 'masters': [{ 'master_id': 'ns1', 'master_list': [{ 'addr': 'another_bastion_hosts1' }, { 'addr': 'hidden_bastion2' }] }] } assertParserResultDictTrue(clause_stmt_masters_standalone, test_string, expected_result)
def test_isc_zone_name_dquoted_passing(self): """ ISC Utilities; Type Zone Name; Double-Quote; passing """ test_data = ['"red_zone"'] result = zone_name_dquotable.runTests(test_data, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue(zone_name_dquotable, '"example.com."', {'zone_name': '"example.com."'})
def test_isc_optview_stmt_query_source_v6_passing(self): """ Clause options/view; Statement YYYY; passing """ test_string = [ 'query-source-v6;', # INADDR_ANY (wildcard) 'query-source-v6 address fe01::1;', 'query-source-v6 address *;', 'query-source-v6 address fe01::2 port 53;', 'query-source-v6 address fe01::3 port *;', 'query-source-v6 address * port 153;', 'query-source-v6 address * port *;', 'query-source-v6 port 253;', 'query-source-v6 port *;', ] result = optview_stmt_query_source_v6.runTests(test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( optview_stmt_query_source_v6, 'query-source-v6 address * port 353;', {'query_source_v6': {'ip6_addr': '*', 'ip_port_w': '353'}} ) assertParserResultDictTrue( optview_stmt_query_source_v6, 'query-source-v6 address fe08::08 port *;', {'query_source_v6': {'ip6_addr': 'fe08::08', 'ip_port_w': '*'}} )
def test_isc_logging_chan_file_path_size_element_passing(self): """ Clause logging; Element File path size; passing mode """ test_string = 'size 1M' expected_result = {'size_spec': [1, 'M']} assertParserResultDictTrue(logging_chan_file_path_size_element, test_string, expected_result) test_string = 'size 1024' expected_result = {'size_spec': [1024]} assertParserResultDictTrue(logging_chan_file_path_size_element, test_string, expected_result) test_string = 'size 100' expected_result = {'size_spec': [100]} assertParserResultDictTrue(logging_chan_file_path_size_element, test_string, expected_result) test_string = 'size 10G' expected_result = {'size_spec': [10, 'G']} assertParserResultDictTrue(logging_chan_file_path_size_element, test_string, expected_result) test_string = 'size 10g' expected_result = {'size_spec': [10, 'g']} assertParserResultDictTrue(logging_chan_file_path_size_element, test_string, expected_result)
def test_isc_optviewzone_stmt_alt_transfer_source_v6_passing(self): """ Clause options/view/zone; Statement alt-transfer-source-v6; passing """ test_string = [ 'alt-transfer-source-v6 *;', 'alt-transfer-source-v6 * port *;', 'alt-transfer-source-v6 * port * dscp 7;', 'alt-transfer-source-v6 * dscp 7;', 'alt-transfer-source-v6 * port 53 dscp 7;', 'alt-transfer-source-v6 * port 53;', 'alt-transfer-source-v6 fe0f::e;', 'alt-transfer-source-v6 fe0f::e port *;', 'alt-transfer-source-v6 fe0f::e port * dscp 7;', 'alt-transfer-source-v6 fe0f::e dscp 7;', 'alt-transfer-source-v6 fe0f::e port 53 dscp 7;', 'alt-transfer-source-v6 fe0f::e port 53;', ] result = optviewzone_stmt_alt_transfer_source_v6.runTests( test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue(optviewzone_stmt_alt_transfer_source_v6, 'alt-transfer-source-v6 fe0f::6 port 56;', { 'alt_transfer_source_v6': { 'ip6_addr': 'fe0f::6', 'ip_port_w': 56 } })
def test_isc_logging_chan_method_option_series_passing(self): """ Clause logging; Series Method; passing mode """ test_string = 'print-time 1; buffered 0; print-severity True;' expected_result = {'print_time': '1', 'buffered': '0', 'print_severity': 'True'} assertParserResultDictTrue(logging_chan_method_option_series, test_string, expected_result)
def test_isc_clause_logging_logging_stmt_category2_passing(self): test_string = 'category unmatched { null; };' expected_result = { 'category_group': [ { 'categories': ['null'], 'category_group_name': 'unmatched'}]} assertParserResultDictTrue(logging_stmt_category_set, test_string, expected_result)
def test_isc_logging_chan_file_method_passing(self): """ Clause logging; Element File Method; passing mode """ test_string = 'file "unquoted-key_id";' expected_result = {'path_name': '"unquoted-key_id"'} assertParserResultDictTrue(logging_chan_file_method, test_string, expected_result) test_string = 'syslog syslog;' expected_result = {'facility': 'syslog'} assertParserResultDictTrue(logging_chan_file_method, test_string, expected_result) test_string = 'syslog daemon;' expected_result = {'facility': 'daemon'} assertParserResultDictTrue(logging_chan_file_method, test_string, expected_result) test_string = 'stderr;' expected_result = {'io': 'stderr'} assertParserResultDictTrue(logging_chan_file_method, test_string, expected_result) test_string = 'null;' expected_result = {'io': 'null'} assertParserResultDictTrue(logging_chan_file_method, test_string, expected_result)
def test_isc_logging_chan_file_path_element_passing(self): """ Clause logging; Element File path; passing mode """ test_string = 'file "simple-relative-filename"' expected_result = {'path_name': '"simple-relative-filename"'} assertParserResultDictTrue(logging_chan_file_path_element, test_string, expected_result, 'did not detect missing semicolon') test_string = 'file "/tmp/unquoted-key_id"' expected_result = {'path_name': '"/tmp/unquoted-key_id"'} assertParserResultDictTrue(logging_chan_file_path_element, test_string, expected_result, 'did not detect missing semicolon') test_string = 'file "/tmp/spaced-out key_id"' expected_result = {'path_name': '"/tmp/spaced-out key_id"'} assertParserResultDictTrue(logging_chan_file_path_element, test_string, expected_result, 'did not detect missing semicolon') # test_string = 'file /tmp/"spaced dir"/spaced-outkey_id' # TODO: Either get this working or go generic-string # expected_result = {'path_name': '/tmp/spaced dir/spaced-outkey_id'} # assertParserResultDictTrue(logging_chan_file_path_element, # test_string, # expected_result, 'did not detect missing semicolon') test_string = "file '/tmp/spaced-out key_id2'" expected_result = {'path_name': "'/tmp/spaced-out key_id2'"} assertParserResultDictTrue(logging_chan_file_path_element, test_string, expected_result, 'did not detect missing semicolon') test_string = 'file \'/dev/null\'' expected_result = {'path_name': '\'/dev/null\''} assertParserResultDictTrue(logging_chan_file_path_element, test_string, expected_result, 'did not detect missing semicolon')
def test_isc_clause_zone__clause_zone_standalone_passing(self): test_data = [ """ zone "home" IN { type master; file "/var/lib/bind/internal/master/db.home"; allow-update { none; }; };""" ] test_clause_stmt_zone = clause_stmt_zone_standalone.copy() test_clause_stmt_zone = test_clause_stmt_zone.setWhitespaceChars(' \t') test_clause_stmt_zone = test_clause_stmt_zone.ignore( pythonStyleComment) test_clause_stmt_zone = test_clause_stmt_zone.ignore(cppStyleComment) # test_clause_stmt_zone.ignore(pythonStyleComment) # test_clause_stmt_zone.ignore(cppStyleComment) result = clause_stmt_zone_standalone.runTests(test_data, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( clause_stmt_zone_standalone, 'zone "home" IN { type master; file "/var/lib/bind/internal/master/db.home"; allow-update { none; }; };', { 'zone': { 'allow_update': { 'aml': [{ 'addr': 'none' }] }, 'file': '"/var/lib/bind/internal/master/db.home"', 'type': 'master', 'zone_name': '"home"' } })
def test_isc_options_stmt_disable_algorithms_passing(self): assertParserResultDictTrue(options_stmt_disable_algorithms, 'disable-algorithms example.com { sha512; cbc32; };', { 'disable_algorithms': [ { 'algorithm_list': [ 'sha512', 'cbc32' ], 'domain_name': 'example.com' }, ] } ) assertParserResultDictTrue(options_multiple_stmt_disable_algorithms, 'disable-algorithms example.com { sha512; cbc32; }; disable-algorithms yahoo.com { cbc128; };', { 'disable_algorithms': [ { 'algorithm_list': [ 'sha512', 'cbc32' ], 'domain_name': 'example.com' }, { 'algorithm_list': [ 'cbc128' ], 'domain_name': 'yahoo.com' } ] } )
def test_isc_options_stmt_blackhole_passing(self): """ Clause options; Statement blackhole; passing mode """ assertParserResultDictTrue( options_stmt_blackhole, 'blackhole { 127.0.0.1; { localhost; localnets; }; !{ any; }; { none; }; };', { 'blackhole': { 'aml': [{ 'addr': '127.0.0.1' }, { 'aml': [{ 'addr': 'localhost' }, { 'addr': 'localnets' }] }, { 'aml': [{ 'addr': 'any' }], 'not': '!' }, { 'aml': [{ 'addr': 'none' }] }] } }) assertParserResultDictTrue( options_stmt_blackhole, 'blackhole { 127.0.0.1; };', {'blackhole': { 'aml': [{ 'addr': '127.0.0.1' }] }})
def test_isc_options_stmt_listen_on3_passing(self): assertParserResultDictTrue( options_stmt_listen_on, 'listen-on { ! 10.0.1.1; any;};', {'listen_on': [{'aml': [{'addr': '10.0.1.1', 'not': '!'}, {'addr': 'any'}]}]} )
def test_isc_options_stmt_deny_answer_aliases_passing(self): assertParserResultDictTrue( options_stmt_deny_answer_aliases, 'deny-answer-aliases { 128.0.0.1; };', {'deny_answer_aliases': [{ 'name': '128.0.0.1' }]})
def test_isc_optview_stmt_dual_stack_servers_passing(self): """ Clause options/view; Statement dual-stack-servers; passing """ test_string = [ 'dual-stack-servers { 1.1.1.1; };', 'dual-stack-servers { 2.2.2.2 port 563; };', 'dual-stack-servers { fe0a::1; };', 'dual-stack-servers { fe0a::2 port 771; };', 'dual-stack-servers port 593 { 3.3.3.3; };', 'dual-stack-servers port 593 { "bastion1.example.com" port 693; };', 'dual-stack-servers port 593 { "bastion2.example.com" port 893; };', 'dual-stack-servers port 593 { "bastion3.example.com" port 893; "bastion4.example.com" port 993; };', ] result = optview_stmt_dual_stack_servers.runTests(test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( optview_stmt_dual_stack_servers, 'dual-stack-servers port 593 { "dmz.example.com" port 893; "hidden-dns.example.com" port 993; };', { 'dual_stack_servers': { 'addrs': [ { 'domain': '"dmz.example.com"', 'ip_port': '893' }, { 'domain': '"hidden-dns.example.com"', 'ip_port': '993' } ], 'ip_port': '593' } } )
def test_isc_options_stmt_listen_on_passing(self): assertParserResultDictTrue(options_stmt_listen_on, 'listen-on port 553 { 127.0.0.1;};', { 'listen_on': [ { 'aml': [{ 'addr': '127.0.0.1' }], 'ip_port': 553 }, ] }) assertParserResultDictTrue( options_multiple_stmt_listen_on, 'listen-on port 553 { 127.0.0.1;}; listen-on port 1553 { 192.168.1.1; };', { 'listen_on': [{ 'aml': [{ 'addr': '127.0.0.1' }], 'ip_port': 553 }, { 'aml': [{ 'addr': '192.168.1.1' }], 'ip_port': 1553 }] })
def test_isc_optview_stmt_query_source_passing(self): """ Clause options/view; Statement query-source; passing """ test_string = [ 'query-source;', # INADDR_ANY (wildcard) 'query-source address 4.4.4.4;', 'query-source address *;', 'query-source address 5.5.5.5 port 53;', 'query-source address 6.6.6.6 port *;', 'query-source address * port 153;', 'query-source address * port *;', 'query-source port 253;', 'query-source port *;', ] result = optview_stmt_query_source.runTests(test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( optview_stmt_query_source, 'query-source address * port 353;', {'query_source': {'ip4_addr': '*', 'ip_port_w': '353'}} ) assertParserResultDictTrue( optview_stmt_query_source, 'query-source address 7.7.7.7 port *;', {'query_source': {'ip4_addr': '7.7.7.7', 'ip_port_w': '*'}} )
def test_isc_options_stmt_prefetch_passing(self): assertParserResultDictTrue( options_stmt_prefetch, 'prefetch 55555 3600;', {'prefetch': { 'expiry_ttl': 55555, 'threshold_ttl': 3600 }})
def test_isc_clause_stmt_dlz_multiple_passing(self): """ Clause dlz; Multiple Statments group; passing mode """ assertParserResultDictTrue( clause_stmt_dlz_series, """dlz my_dlz_1 { database def; search yes; }; dlz example { database "dlopen driver.so args"; search yes; }; dlz other { database "dlopen driver.so args"; search no; }; dlz their_mysql { database mysql; search 1; };""", { 'dlz': [{ 'db_args': 'def', 'dlz_name': 'my_dlz_1', 'search': 'yes' }, { 'db_args': '"dlopen driver.so args"', 'dlz_name': 'example', 'search': 'yes' }, { 'db_args': '"dlopen driver.so args"', 'dlz_name': 'other', 'search': 'no' }, { 'db_args': 'mysql', 'dlz_name': 'their_mysql', 'search': '1' }] })
def test_isc_options_stmt_deny_answer_addresses2_passing(self): assertParserResultDictTrue( options_stmt_deny_answer_addresses, 'deny-answer-addresses { any; } except-from { "string"; };', {'deny_answer_addresses': {'aml': [{'addr': 'any'}], 'name': '"string"'}} )
def test_isc_optviewzone_stmt_alt_transfer_source_passing(self): """ Clause options/view/zone; Statement alt-transfer-source; passing """ test_string = [ 'alt-transfer-source *;', 'alt-transfer-source * port *;', 'alt-transfer-source * port * dscp 7;', 'alt-transfer-source * dscp 7;', 'alt-transfer-source * port 53 dscp 7;', 'alt-transfer-source * port 53;', 'alt-transfer-source 2.2.2.2;', 'alt-transfer-source 2.2.2.2 port *;', 'alt-transfer-source 2.2.2.2 port * dscp 7;', 'alt-transfer-source 2.2.2.2 dscp 7;', 'alt-transfer-source 2.2.2.2 port 53 dscp 7;', 'alt-transfer-source 2.2.2.2 port 53;', ] result = optviewzone_stmt_alt_transfer_source.runTests(test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( optviewzone_stmt_alt_transfer_source, 'alt-transfer-source 2.3.4.5 port * dscp 7;', {'alt_transfer_source': {'dscp_port': 7, 'ip4_addr': '2.3.4.5', 'ip_port_w': '*'}} )
def test_isc_options_stmt_deny_answer_addresses5_passing(self): assertParserResultDictTrue( options_stmt_deny_answer_addresses, 'deny-answer-addresses { 192.0.2.0/24; } except-from { "example.net"; };', {'deny_answer_addresses': {'aml': [{'addr': '192.0.2.0/24'}], 'name': '"example.net"'}} )
def test_isc_optviewzone_stmt_notify_source_v6_passing(self): """ Clause options/view/zone; Statement notify-source-v6; passing """ test_string = [ 'notify-source-v6 *;', 'notify-source-v6 * port 53;', 'notify-source-v6 * port *;', 'notify-source-v6 * port 153 dscp 1;', 'notify-source-v6 * port * dscp 1;', 'notify-source-v6 * dscp 1;', 'notify-source-v6 fe11::1;', 'notify-source-v6 fe11::1 port *;', 'notify-source-v6 fe11::1 port 253;', 'notify-source-v6 fe11::1 port * dscp 2;', 'notify-source-v6 fe11::1 port 353 dscp 2;', 'notify-source-v6 fe11::1 dscp 3;', ] result = optviewzone_stmt_notify_source_v6.runTests(test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( optviewzone_stmt_notify_source_v6, 'notify-source-v6 fe11::123 port * dscp 5;', {'notify_source_v6': {'addr': 'fe11::123', 'dscp_port': 5, 'ip_port_w': '*'}} )
def test_isc_options_stmt_deny_answer_addresses6_passing(self): assertParserResultDictTrue( options_stmt_deny_answer_addresses, """ deny-answer-addresses { 0.0.0.0; 10.0.0.0/8; 172.16.0.0/12; 192.168.0.0/16; 169.254.0.0/16; ::/80; fe80::/10; 64:ff9b::/96; } except-from { "Your.Domain"; };""", { 'deny_answer_addresses': { 'aml': [ {'addr': '0.0.0.0'}, {'addr': '10.0.0.0/8'}, {'addr': '172.16.0.0/12'}, {'addr': '192.168.0.0/16'}, {'addr': '169.254.0.0/16'}, {'addr': '::/80', 'ip6s_subnet': '80'}, {'addr': 'fe80::/10', 'ip6s_subnet': '10'}, {'addr': '64:ff9b::/96', 'ip6s_subnet': '96'}], 'name': '"Your.Domain"'}} )
def test_isc_optviewzone_stmt_transfer_source_passing(self): """ Clause options/view/zone; Statement transfer-source; passing """ test_string = [ 'transfer-source 1.1.1.1;', 'transfer-source 2.2.2.2 port 53;', 'transfer-source 3.3.3.3 port *;', 'transfer-source 4.4.4.4 port 53 dscp 1;', 'transfer-source 5.5.5.5 port * dscp 1;', 'transfer-source 6.6.6.6 dscp 2;', 'transfer-source *;', 'transfer-source * port 53;', 'transfer-source * port *;', 'transfer-source * port 53 dscp 1;', 'transfer-source * port * dscp 1;', 'transfer-source * dscp 2;', ] result = optviewzone_stmt_transfer_source.runTests(test_string, failureTests=False) self.assertTrue(result[0]) assertParserResultDictTrue( optviewzone_stmt_transfer_source, 'transfer-source 4.4.4.4 port 53 dscp 1;', {'transfer_source': {'addr': '4.4.4.4', 'dscp_port': 1, 'ip_port_w': '53'}} )
def test_isc_zone_stmt_masters_name_by_ipv4_passing(self): """ Clause zone; Name, masters; by IPv4; passing """ assertParserResultDictTrue(zone_masters_set, '4.4.4.4 key priv_dns_chan_key0;', { 'ip4': '4.4.4.4', 'key_id': 'priv_dns_chan_key0' })