def test_pack_multiple_raw_context(self):
        alloc_size = SMB2CreateAllocationSize()
        alloc_size['allocation_size'] = 1024

        expected = b"\x00\x00\x00\x00" \
                   b"\x10\x00" \
                   b"\x04\x00" \
                   b"\x00\x00" \
                   b"\x18\x00" \
                   b"\x08\x00\x00\x00" \
                   b"\x41\x6c\x53\x69" \
                   b"\x00\x00\x00\x00" \
                   b"\x00\x04\x00\x00\x00\x00\x00\x00"
        actual = SMB2CreateContextRequest.pack_multiple([alloc_size])
        assert actual == expected
    def test_create_message(self):
        ea_buffer1 = SMB2CreateEABuffer()
        ea_buffer1['ea_name'] = "Authors\x00".encode('ascii')
        ea_buffer1['ea_value'] = "Jordan Borean".encode("utf-8")

        ea_buffer2 = SMB2CreateEABuffer()
        ea_buffer2['ea_name'] = "Title\x00".encode('ascii')
        ea_buffer2['ea_value'] = "Jordan Borean Title".encode('utf-8')

        ea_buffers = SMB2CreateContextRequest()
        ea_buffers['buffer_name'] = CreateContextName.SMB2_CREATE_EA_BUFFER
        ea_buffers['buffer_data'] = SMB2CreateEABuffer.pack_multiple(
            [ea_buffer1, ea_buffer2])

        alloc_size = SMB2CreateAllocationSize()
        alloc_size['allocation_size'] = 1024

        alloc_size_context = SMB2CreateContextRequest()
        alloc_size_context['buffer_name'] = \
            CreateContextName.SMB2_CREATE_ALLOCATION_SIZE
        alloc_size_context['buffer_data'] = alloc_size

        query_disk = SMB2CreateContextRequest()
        query_disk['buffer_name'] = \
            CreateContextName.SMB2_CREATE_QUERY_ON_DISK_ID

        expected = b"\x60\x00\x00\x00" \
                   b"\x10\x00" \
                   b"\x04\x00" \
                   b"\x00\x00" \
                   b"\x18\x00" \
                   b"\x41\x00\x00\x00" \
                   b"\x45\x78\x74\x41" \
                   b"\x00\x00\x00\x00" \
                   b"\x20\x00\x00\x00" \
                   b"\x00" \
                   b"\x07" \
                   b"\x0d\x00" \
                   b"\x41\x75\x74\x68\x6f\x72\x73\x00" \
                   b"\x4a\x6f\x72\x64\x61\x6e\x20\x42" \
                   b"\x6f\x72\x65\x61\x6e" \
                   b"\x00\x00\x00" \
                   b"\x00\x00\x00\x00" \
                   b"\x00" \
                   b"\x05" \
                   b"\x13\x00" \
                   b"\x54\x69\x74\x6c\x65\x00" \
                   b"\x4a\x6f\x72\x64\x61\x6e\x20\x42" \
                   b"\x6f\x72\x65\x61\x6e\x20\x54\x69" \
                   b"\x74\x6c\x65" \
                   b"\x00\x00\x00\x00\x00\x00\x00" \
                   b"\x20\x00\x00\x00" \
                   b"\x10\x00" \
                   b"\x04\x00" \
                   b"\x00\x00" \
                   b"\x18\x00" \
                   b"\x08\x00\x00\x00" \
                   b"\x41\x6c\x53\x69" \
                   b"\x00\x00\x00\x00" \
                   b"\x00\x04\x00\x00\x00\x00\x00\x00" \
                   b"\x00\x00\x00\x00" \
                   b"\x10\x00" \
                   b"\x04\x00" \
                   b"\x00\x00" \
                   b"\x00\x00" \
                   b"\x00\x00\x00\x00" \
                   b"\x51\x46\x69\x64" \
                   b"\x00\x00\x00\x00"

        actual = SMB2CreateContextRequest.pack_multiple(
            [ea_buffers, alloc_size_context, query_disk])

        # now has padding on the end
        assert len(ea_buffers) == 96
        assert len(alloc_size_context) == 32
        assert len(query_disk) == 24
        assert actual == expected
 def test_pack_multiple_bad_message(self):
     expected = "Invalid context message, must be either a SMB2CreateContextRequest or a predefined structure " \
                "object with NAME defined."
     with pytest.raises(ValueError, match=re.escape(expected)):
         SMB2CreateContextRequest.pack_multiple([b"\x00"])