selftest: Add expected-output tests for the ndrdump struct mode
authorAndrew Bartlett <abartlet@samba.org>
Mon, 11 Nov 2019 03:39:13 +0000 (16:39 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Wed, 13 Nov 2019 00:32:36 +0000 (00:32 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14191

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/tests/blackbox/ndrdump.py
selftest/knownfail.d/ndrdump [new file with mode: 0644]
source4/librpc/tests/dns-decode_dns_name_packet-hex.txt [new file with mode: 0644]
source4/librpc/tests/krb5pac-PAC_DATA.dat [new file with mode: 0644]

index fd1bc832d9beb732294c6f065b5ed027c864f7c3..b8f467f8e82b77cb7c0b31d5650ca37c86bfc3c7 100644 (file)
@@ -62,9 +62,35 @@ class NdrDumpTests(BlackboxTestCase):
                 self.data_path("dns-decode_dns_name_packet-hex.dat")))
 
     def test_ndrdump_with_hex_struct_name(self):
+        expected = open(self.data_path("dns-decode_dns_name_packet-hex.txt")).read()
         try:
-            self.check_run(
+            actual = self.check_output(
                 "ndrdump dns dns_name_packet struct --hex-input %s" %
                 self.data_path("dns-decode_dns_name_packet-hex.dat"))
         except BlackboxProcessError as e:
             self.fail(e)
+
+        # check_output will return bytes
+        # convert expected to bytes for python 3
+        self.assertEqual(actual, expected.encode('utf-8'))
+
+    def test_ndrdump_with_binary_struct_name(self):
+        # Prefix of the expected unparsed PAC data (without times, as
+        # these vary by host)
+        expected = '''pull returned NT_STATUS_OK
+    PAC_DATA: struct PAC_DATA
+        num_buffers              : 0x00000005 (5)
+        version                  : 0x00000000 (0)
+        buffers: ARRAY(5)'''
+        try:
+            actual = self.check_output(
+                "ndrdump krb5pac PAC_DATA struct %s" %
+                self.data_path("krb5pac-PAC_DATA.dat"))
+        except BlackboxProcessError as e:
+            self.fail(e)
+
+        # check_output will return bytes
+        # convert expected to bytes for python 3
+        self.assertEqual(actual[:len(expected)],
+                         expected.encode('utf-8'))
+        self.assertTrue(actual.endswith(b"dump OK\n"))
diff --git a/selftest/knownfail.d/ndrdump b/selftest/knownfail.d/ndrdump
new file mode 100644 (file)
index 0000000..6ad82d7
--- /dev/null
@@ -0,0 +1,2 @@
+^samba.tests.blackbox.ndrdump.samba.tests.blackbox.ndrdump.NdrDumpTests.test_ndrdump_with_binary_struct_name
+^samba.tests.blackbox.ndrdump.samba.tests.blackbox.ndrdump.NdrDumpTests.test_ndrdump_with_hex_struct_name
diff --git a/source4/librpc/tests/dns-decode_dns_name_packet-hex.txt b/source4/librpc/tests/dns-decode_dns_name_packet-hex.txt
new file mode 100644 (file)
index 0000000..a973c28
--- /dev/null
@@ -0,0 +1,35 @@
+pull returned NT_STATUS_OK
+    dns_name_packet: struct dns_name_packet
+        id                       : 0xecef (60655)
+        operation                : 0x2800 (10240)
+            0x00: DNS_RCODE                 (0)
+               0: DNS_FLAG_RECURSION_AVAIL 
+               0: DNS_FLAG_RECURSION_DESIRED
+               0: DNS_FLAG_TRUNCATION      
+               0: DNS_FLAG_AUTHORITATIVE   
+            0x05: DNS_OPCODE                (5)
+               0: DNS_FLAG_REPLY           
+        qdcount                  : 0x0001 (1)
+        ancount                  : 0x0000 (0)
+        nscount                  : 0x0001 (1)
+        arcount                  : 0x0000 (0)
+        questions: ARRAY(1)
+            questions: struct dns_name_question
+                name                     : 'samba2003.example.com'
+                question_type            : DNS_QTYPE_SOA (0x6)
+                question_class           : DNS_QCLASS_IN (0x1)
+        answers: ARRAY(0)
+        nsrecs: ARRAY(1)
+            nsrecs: struct dns_res_rec
+                name                     : 'cnamedotprefix0.samba2003.example.com'
+                rr_type                  : DNS_QTYPE_CNAME (0x5)
+                rr_class                 : DNS_QCLASS_IN (0x1)
+                ttl                      : 0x00000384 (900)
+                length                   : 0x0013 (19)
+                rdata                    : union dns_rdata(case 0x5)
+                cname_record             : ''
+                unexpected               : DATA_BLOB length=18
+[0000] 0F 62 6E 61 6D 65 64 6F   74 70 72 65 66 69 78 32   .bnamedo tprefix2
+[0010] C0 0C                                              .. 
+        additional: ARRAY(0)
+dump OK
diff --git a/source4/librpc/tests/krb5pac-PAC_DATA.dat b/source4/librpc/tests/krb5pac-PAC_DATA.dat
new file mode 100644 (file)
index 0000000..71b48d9
Binary files /dev/null and b/source4/librpc/tests/krb5pac-PAC_DATA.dat differ