tests/krb5: Use Python bindings for LZ77+Huffman compression
[Samba.git] / python / samba / tests / dns_invalid.py
blob0234798091d3a9ddc7c1e7137c9e6b9a1eb14a01
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Kai Blin <kai@samba.org> 2018
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import sys
19 from samba import credentials
20 from samba.dcerpc import dns
21 from samba.tests.subunitrun import SubunitOptions, TestProgram
22 from samba.tests.dns_base import DNSTest
23 import samba.getopt as options
24 import optparse
26 parser = optparse.OptionParser("dns_invalid.py <server ip> [options]")
27 sambaopts = options.SambaOptions(parser)
28 parser.add_option_group(sambaopts)
30 # This timeout only has relevance when testing against Windows
31 # Format errors tend to return patchy responses, so a timeout is needed.
32 parser.add_option("--timeout", type="int", dest="timeout",
33 help="Specify timeout for DNS requests")
35 # use command line creds if available
36 credopts = options.CredentialsOptions(parser)
37 parser.add_option_group(credopts)
38 subunitopts = SubunitOptions(parser)
39 parser.add_option_group(subunitopts)
41 opts, args = parser.parse_args()
43 lp = sambaopts.get_loadparm()
44 creds = credopts.get_credentials(lp)
46 timeout = opts.timeout
48 if len(args) < 1:
49 parser.print_usage()
50 sys.exit(1)
52 server_ip = args[0]
53 creds.set_krb_forwardable(credentials.NO_KRB_FORWARDABLE)
56 class TestBrokenQueries(DNSTest):
57 def setUp(self):
58 super(TestBrokenQueries, self).setUp()
59 global server, server_ip, lp, creds, timeout
60 self.server_ip = server_ip
61 self.lp = lp
62 self.creds = creds
63 self.timeout = timeout
65 def test_invalid_chars_in_name(self):
66 """Check the server refuses invalid characters in the query name"""
67 p = self.make_name_packet(dns.DNS_OPCODE_QUERY)
68 questions = []
70 name = "\x10\x11\x05\xa8.%s" % self.get_dns_domain()
71 q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN)
72 print("asking for %s" % (q.name))
73 questions.append(q)
75 self.finish_name_packet(p, questions)
76 (response, response_packet) = self.dns_transaction_udp(p, host=server_ip)
77 self.assert_dns_rcode_equals(response, dns.DNS_RCODE_NXDOMAIN)
80 TestProgram(module=__name__, opts=subunitopts)