selftest: Test repushing an ntlmssp AUTHENTICATE_MESSAGE
[Samba.git] / python / samba / tests / blackbox / ndrdump.py
blobca637b3ac7b604030bfb62fbd33be0eb4789ee45
1 # Blackbox tests for ndrdump
2 # Copyright (C) 2008 Andrew Tridgell <tridge@samba.org>
3 # Copyright (C) 2008 Andrew Bartlett <abartlet@samba.org>
4 # Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
5 # based on test_smbclient.sh
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from __future__ import print_function
22 """Blackbox tests for ndrdump."""
24 import os
25 from samba.tests import BlackboxTestCase, BlackboxProcessError
27 for p in ["../../../../../source4/librpc/tests",
28 "../../../../../librpc/tests"]:
29 data_path_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), p))
30 print(data_path_dir)
31 if os.path.exists(data_path_dir):
32 break
35 class NdrDumpTests(BlackboxTestCase):
36 """Blackbox tests for ndrdump."""
38 def data_path(self, name):
39 return os.path.join(data_path_dir, name)
41 def test_ndrdump_with_in(self):
42 self.check_run(("ndrdump samr samr_CreateUser in %s" %
43 (self.data_path("samr-CreateUser-in.dat"))))
45 def test_ndrdump_with_out(self):
46 self.check_run(("ndrdump samr samr_CreateUser out %s" %
47 (self.data_path("samr-CreateUser-out.dat"))))
49 def test_ndrdump_context_file(self):
50 self.check_run(
51 ("ndrdump --context-file %s samr samr_CreateUser out %s" %
52 (self.data_path("samr-CreateUser-in.dat"),
53 self.data_path("samr-CreateUser-out.dat"))))
55 def test_ndrdump_with_validate(self):
56 self.check_run(("ndrdump --validate samr samr_CreateUser in %s" %
57 (self.data_path("samr-CreateUser-in.dat"))))
59 def test_ndrdump_with_hex_decode_function(self):
60 self.check_run(
61 ("ndrdump dns decode_dns_name_packet in --hex-input %s" %
62 self.data_path("dns-decode_dns_name_packet-hex.dat")))
64 def test_ndrdump_with_hex_struct_name(self):
65 expected = open(self.data_path("dns-decode_dns_name_packet-hex.txt")).read()
66 try:
67 actual = self.check_output(
68 "ndrdump dns dns_name_packet struct --hex-input %s" %
69 self.data_path("dns-decode_dns_name_packet-hex.dat"))
70 except BlackboxProcessError as e:
71 self.fail(e)
73 # check_output will return bytes
74 # convert expected to bytes for python 3
75 self.assertEqual(actual, expected.encode('utf-8'))
77 def test_ndrdump_with_binary_struct_name(self):
78 # Prefix of the expected unparsed PAC data (without times, as
79 # these vary by host)
80 expected = '''pull returned Success
81 PAC_DATA: struct PAC_DATA
82 num_buffers : 0x00000005 (5)
83 version : 0x00000000 (0)
84 buffers: ARRAY(5)'''
85 try:
86 actual = self.check_output(
87 "ndrdump krb5pac PAC_DATA struct %s" %
88 self.data_path("krb5pac-PAC_DATA.dat"))
89 except BlackboxProcessError as e:
90 self.fail(e)
92 # check_output will return bytes
93 # convert expected to bytes for python 3
94 self.assertEqual(actual[:len(expected)],
95 expected.encode('utf-8'))
96 self.assertTrue(actual.endswith(b"dump OK\n"))
98 def test_ndrdump_with_binary_struct_number(self):
99 expected = '''pull returned Success
100 0 : 33323130-3534-3736-3839-616263646566
101 dump OK
103 try:
104 actual = self.check_output(
105 "ndrdump misc 0 struct %s" %
106 self.data_path("misc-GUID.dat"))
107 except BlackboxProcessError as e:
108 self.fail(e)
110 # check_output will return bytes
111 # convert expected to bytes for python 3
112 self.assertEqual(actual, expected.encode('utf-8'))
114 def test_ndrdump_fuzzed_clusapi_QueryAllValues(self):
115 expected = b'''pull returned Success
116 WARNING! 53 unread bytes
117 [0000] 00 FF 00 00 FF 00 00 00 00 09 00 00 00 08 00 33 ........ .......3
118 [0010] 33 32 37 36 32 36 39 33 32 37 36 38 34 01 00 00 32762693 27684...
119 [0020] 80 32 0D FF 00 00 FF 00 00 00 00 08 00 00 00 1C .2...... ........
120 [0030] F1 29 08 00 00 .)... ''' \
121 b'''
122 clusapi_QueryAllValues: struct clusapi_QueryAllValues
123 out: struct clusapi_QueryAllValues
124 pcbData : *
125 pcbData : 0x01000000 (16777216)
126 ppData : *
127 ppData: ARRAY(1)
128 ppData : NULL
129 rpc_status : *
130 rpc_status : WERR_OK
131 result : WERR_NOT_ENOUGH_MEMORY
132 dump OK
134 try:
135 actual = self.check_output(
136 'ndrdump clusapi clusapi_QueryAllValues out ' +\
137 '--base64-input --input=' +\
138 'AAAAAQEAAAAAAAAAAAAAAAgAAAAA/wAA/wAAAAAJAAAACAAzMzI3NjI2OTMyNzY4NAEAAIAyDf8AAP8AAAAACAAAABzxKQgAAA==')
139 except BlackboxProcessError as e:
140 self.fail(e)
141 self.assertEqual(actual, expected)
143 def test_ndrdump_fuzzed_IOXIDResolver_ResolveOxid(self):
144 expected = '''pull returned Character Conversion Error
146 try:
147 actual = self.check_exit_code(
148 'ndrdump IOXIDResolver ResolveOxid out ' +\
149 '--base64-input --input=' +\
150 'c87PMf7CBAUAAAAADgQMBASjfPqKw0KPld6DY87PMfQ=',
152 except BlackboxProcessError as e:
153 self.fail(e)
154 self.assertRegex(actual.decode('utf8'), expected + "$")
156 def test_ndrdump_fuzzed_IOXIDResolver_ResolveOxid2(self):
157 expected = '''pull returned Buffer Size Error
159 try:
160 actual = self.check_exit_code(
161 'ndrdump IOXIDResolver ResolveOxid2 out ' +\
162 '--base64-input --input=' +\
163 'AAAAAQ0K9Q0AAAAAAAAAA6ampqampqampqampqampqampqampqamNAAAAAAtNDQ=',
165 except BlackboxProcessError as e:
166 self.fail(e)
167 self.assertRegex(actual.decode('utf8'), expected + "$")
169 def test_ndrdump_fuzzed_IOXIDResolver_ServerAlive2(self):
170 expected = b'''pull returned Success
171 WARNING! 46 unread bytes
172 [0000] 0D 36 0A 0A 0A 0A 0A 00 00 00 00 00 00 00 03 00 .6...... ........
173 [0010] 00 00 01 00 00 33 39 36 31 36 31 37 37 36 38 34 .....396 16177684
174 [0020] 32 34 FC 85 AC 49 0B 61 87 0A 0A 0A F5 00 24...I.a ......
175 ServerAlive: struct ServerAlive
176 out: struct ServerAlive
177 result : DOS code 0x01000000
178 dump OK
180 try:
181 actual = self.check_output(
182 'ndrdump IOXIDResolver ServerAlive out ' +\
183 '--base64-input --input=' +\
184 'AAAAAQ02CgoKCgoAAAAAAAAAAwAAAAEAADM5NjE2MTc3Njg0MjT8haxJC2GHCgoK9QA=')
185 except BlackboxProcessError as e:
186 self.fail(e)
187 self.assertEqual(actual, expected)
189 def test_ndrdump_fuzzed_IRemoteActivation_RemoteActivation(self):
190 expected = '''pull returned Buffer Size Error
192 try:
193 actual = self.check_exit_code(
194 'ndrdump IRemoteActivation RemoteActivation out ' +\
195 '--base64-input --input=' +\
196 'AAAAAQAAAAAAAABKAAD/AAAAAP4AAAAAAAAASgAAAAAAAAABIiIjIiIiIiIiIiIiIiMiAAAAAAD/AAAAAAAA',
198 except BlackboxProcessError as e:
199 self.fail(e)
200 self.assertRegex(actual.decode('utf8'), expected + "$")
202 def test_ndrdump_fuzzed_ntlmsssp_AUTHENTICATE_MESSAGE(self):
203 expected = open(self.data_path("fuzzed_ntlmssp-AUTHENTICATE_MESSAGE.txt")).read()
204 try:
205 actual = self.check_output(
206 "ndrdump ntlmssp AUTHENTICATE_MESSAGE struct --base64-input %s --validate" %
207 self.data_path("fuzzed_ntlmssp-AUTHENTICATE_MESSAGE.b64.txt"))
208 except BlackboxProcessError as e:
209 self.fail(e)
210 # check_output will return bytes
211 # convert expected to bytes for python 3
212 self.assertEqual(actual, expected.encode('utf-8'))