How to use the pypsrp.serializer.Serializer function in pypsrp

To help you get started, we’ve selected a few pypsrp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_create_buffer_cell(self):
        serializer = Serializer()

        buffer_cell = BufferCell(
            character="A", foreground_color=Color(value=Color.CYAN),
            background_color=Color(value=Color.GREEN),
            cell_type=BufferCellType.COMPLETE
        )

        expected_xml = normalise_xml(self.BUFFER_CELL)
        actual = serializer.serialize(buffer_cell)
        actual_xml = normalise_xml(ET.tostring(actual))

        assert_xml_diff(actual_xml, expected_xml)
github jborean93 / pypsrp / tests / test_messages.py View on Github external
def test_parse_public_key_request(self):
        data = b"\x02\x00\x00\x00" \
               b"\x07\x00\x01\x00" \
               b"\x00\x00\x00\x00\x00\x00\x00\x00" \
               b"\x00\x00\x00\x00\x00\x00\x00\x00" \
               b"\x00\x00\x00\x00\x00\x00\x00\x00" \
               b"\x00\x00\x00\x00\x00\x00\x00\x00" \
               b"<s>"
        actual = Message.unpack(data, Serializer())
        assert actual.message_type == MessageType.PUBLIC_KEY_REQUEST
        assert isinstance(actual.data, PublicKeyRequest)
</s>
github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_parse_three_dimensional_array(self):
        serializer = Serializer()
        actual = serializer.deserialize(self.THREE_ARRAY,
                                        ObjectMeta("Obj", object=Array))
        array = actual.array
        assert array == [
            [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],
            [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]
        ]
        assert actual.mae == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
                              13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
        assert actual.mal == [2, 3, 4]
github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_create_array(self):
        serializer = Serializer()

        array = Array(array=[1, 2, 3])

        expected_xml = normalise_xml(self.SINGLE_ARRAY)
        actual = serializer.serialize(array)
        actual_xml = normalise_xml(ET.tostring(actual))

        assert_xml_diff(actual_xml, expected_xml)

        array.array = [4, 5, 6]
        expected_xml = normalise_xml(self.SINGLE_ARRAY2)
        actual = serializer.serialize(array)
        actual_xml = normalise_xml(ET.tostring(actual))

        assert_xml_diff(actual_xml, expected_xml)
github jborean93 / pypsrp / tests / test_serializer.py View on Github external
def test_deserialize_circular_reference(self):
        serializer = Serializer()
        xml = '''
    
        Microsoft.Exchange.Data.Directory.ADObjectId
        Microsoft.Exchange.Data.ObjectId
        System.Object
    
    com
    
        
        <b>false</b>
        
        0
        <s>DC=com</s>
        <b>false</b>
        
        <s>com</s>
github jborean93 / pypsrp / tests / test_serializer.py View on Github external
def test_deserialize_obj_missing_prop(self):
        class SerialObject(ComplexObject):
            def __init__(self, **kwargs):
                super(SerialObject, self).__init__()
                self._types = [
                    "System.Test",
                    "System.Object"
                ]
                self._extended_properties = (
                    ('man_prop', ObjectMeta("S", optional=False)),
                )
                self.man_prop = kwargs.get('man_prop')

        serializer = Serializer()
        xml = 'System.Test' \
              'System.Object'
        with pytest.raises(SerializationError) as err:
            serializer.deserialize(xml, ObjectMeta("Obj", object=SerialObject))
        assert str(err.value) == \
            "Mandatory return value for 'Unknown' was not found on object " \
            "Unknown"
github jborean93 / pypsrp / tests / test_serializer.py View on Github external
def test_deserialize_empty_string(self):
        serializer = Serializer()
        actual = serializer.deserialize('')
        assert actual == ''
github jborean93 / pypsrp / tests / test_powershell.py View on Github external
def test_defragment_two_fragments_one_message(self):
        serial = Serializer()
        fragmenter = Fragmenter(70, serial)
        fragments = [
            b"\x00\x00\x00\x00\x00\x00\x00\x01"
            b"\x00\x00\x00\x00\x00\x00\x00\x00"
            b"\x01"
            b"\x00\x00\x00\x31"
            b"\x02\x00\x00\x00"
            b"\x02\x10\x04\x00"
            b"\x00\x00\x00\x00\x00\x00\x00\x00"
            b"\x00\x00\x00\x00\x00\x00\x00\x00"
            b"\x00\x00\x00\x00\x00\x00\x00\x00"
            b"\x00\x00\x00\x00\x00\x00\x00\x00"
            b"<s>1234</s>
github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_parse_pipeline_single(self):
        serializer = Serializer()
        actual = serializer.deserialize(normalise_xml(self.PIPE_SINGLE),
                                        ObjectMeta("Obj", object=Pipeline))
        assert actual.history is None
        assert actual.is_nested is False
        assert actual.redirect_err_to_out is False
        assert len(actual.commands) == 1
        assert len(actual.commands[0].args) == 2
        assert actual.commands[0].args[0].name == "Name"
        assert actual.commands[0].args[0].value == "var"
        assert actual.commands[0].args[1].name == "Value"
        assert actual.commands[0].args[1].value == "abc"
        assert actual.commands[0].cmd == "Set-Variable"
        assert actual.commands[0].end_of_statement is False
        assert actual.commands[0].is_script is False
        assert str(actual.commands[0].merge_debug) == "None"
        assert str(actual.commands[0].merge_error) == "None"
github jborean93 / pypsrp / pypsrp / client.py View on Github external
:param clixml: The clixml to parse
        :return: A unicode code string of the decoded output
        """
        output = to_unicode(clixml)
        if output.startswith("#&lt; CLIXML"):
            # Strip off the '#&lt; CLIXML\r\n' by finding the 2nd index of '&lt;'
            output = output[clixml.index('&lt;', 2):]
            element = ET.fromstring(output)
            namespace = element.tag.replace("Objs", "")[1:-1]

            errors = []
            for error in element.findall("{%s}S[@S='Error']" % namespace):
                errors.append(error.text)

            output = Serializer()._deserialize_string("".join(errors))

        return output