py:dcerpc/raw_testcase: pass auth_context and stub_len to parse_auth() in order to...
authorStefan Metzmacher <metze@samba.org>
Tue, 20 Nov 2018 14:48:08 +0000 (15:48 +0100)
committerJeremy Allison <jra@samba.org>
Sun, 23 Dec 2018 17:15:20 +0000 (18:15 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
python/samba/tests/dcerpc/raw_testcase.py

index 61538ce..035d3ac 100644 (file)
@@ -18,7 +18,7 @@
 
 import sys
 import socket
-import samba.dcerpc.dcerpc
+import samba.dcerpc.dcerpc as dcerpc
 import samba.dcerpc.base
 import samba.dcerpc.epmapper
 import samba.tests
@@ -207,7 +207,7 @@ class RawDCERPCTest(TestCase):
         self.assertGreater(len(rep.u.auth_info), samba.dcerpc.dcerpc.DCERPC_AUTH_TRAILER_LENGTH)
         self.assertEquals(rep.auth_length, len(rep.u.auth_info) - samba.dcerpc.dcerpc.DCERPC_AUTH_TRAILER_LENGTH)
 
-        a = self.parse_auth(rep.u.auth_info)
+        a = self.parse_auth(rep.u.auth_info, auth_context=auth_context)
 
         from_server = a.credentials
         (finished, to_server) = auth_context["gensec"].update(from_server)
@@ -253,7 +253,7 @@ class RawDCERPCTest(TestCase):
         self.assertGreater(len(rep.u.auth_info), samba.dcerpc.dcerpc.DCERPC_AUTH_TRAILER_LENGTH)
         self.assertEquals(rep.auth_length, len(rep.u.auth_info) - samba.dcerpc.dcerpc.DCERPC_AUTH_TRAILER_LENGTH)
 
-        a = self.parse_auth(rep.u.auth_info)
+        a = self.parse_auth(rep.u.auth_info, auth_context=auth_context)
 
         from_server = a.credentials
         (finished, to_server) = auth_context["gensec"].update(from_server)
@@ -411,12 +411,9 @@ class RawDCERPCTest(TestCase):
                 rep_sig = rep_blob[ofs_sig:]
                 rep_auth_info_blob = rep_blob[ofs_trailer:]
 
-                rep_auth_info = self.parse_auth(rep_auth_info_blob)
-                self.assertEquals(rep_auth_info.auth_type, auth_context["auth_type"])
-                self.assertEquals(rep_auth_info.auth_level, auth_context["auth_level"])
-                self.assertLessEqual(rep_auth_info.auth_pad_length, len(rep_data))
-                self.assertEquals(rep_auth_info.auth_reserved, 0)
-                self.assertEquals(rep_auth_info.auth_context_id, auth_context["auth_context_id"])
+                rep_auth_info = self.parse_auth(rep_auth_info_blob,
+                                                auth_context=auth_context,
+                                                stub_len=len(rep_data))
                 self.assertEquals(rep_auth_info.credentials, rep_sig)
 
                 if auth_context["auth_level"] >= samba.dcerpc.dcerpc.DCERPC_AUTH_LEVEL_PACKET:
@@ -622,7 +619,8 @@ class RawDCERPCTest(TestCase):
 
         return ai
 
-    def parse_auth(self, auth_info, ndr_print=None, hexdump=None):
+    def parse_auth(self, auth_info, ndr_print=None, hexdump=None,
+                   auth_context=None, stub_len=0):
         if ndr_print is None:
             ndr_print = self.do_ndr_print
         if hexdump is None:
@@ -637,6 +635,15 @@ class RawDCERPCTest(TestCase):
         if ndr_print:
             sys.stderr.write("parse_auth: %s" % samba.ndr.ndr_print(a))
 
+        if auth_context is not None:
+            self.assertEquals(a.auth_type, auth_context["auth_type"])
+            self.assertEquals(a.auth_level, auth_context["auth_level"])
+            self.assertEquals(a.auth_reserved, 0)
+            self.assertEquals(a.auth_context_id, auth_context["auth_context_id"])
+
+            self.assertLessEqual(a.auth_pad_length, dcerpc.DCERPC_AUTH_PAD_ALIGNMENT)
+            self.assertLessEqual(a.auth_pad_length, stub_len)
+
         return a
 
     def generate_pdu(self, ptype, call_id, payload,