Exemplo n.º 1
0
    def test_create_host_info(self):
        serializer = Serializer()

        foreground_color = Color(value=Color.CYAN)
        background_color = Color(value=Color.RED)
        cursor_position = Coordinates(x=1, y=2)
        window_position = Coordinates(x=3, y=4)
        cursor_size = 10
        buffer_size = Size(height=10, width=20)
        window_size = Size(height=30, width=40)
        max_window_size = Size(height=50, width=60)
        max_physical_window_size = Size(height=70, width=80)
        window_title = "Random Window Title"

        ps_raw_ui = PSHostRawUserInterface(
            window_title, cursor_size, foreground_color, background_color,
            cursor_position, window_position, buffer_size,
            max_physical_window_size, max_window_size, window_size
        )
        ps_ui = PSHostUserInterface(raw_ui=ps_raw_ui)
        ps_host = PSHost(None, None, False, None, None, ps_ui, None)

        host_info = HostInfo(host=ps_host)
        expected_xml = normalise_xml(self.HOST_XML)

        actual = serializer.serialize(host_info)
        actual_xml = normalise_xml(ET.tostring(actual))
        assert_xml_diff(actual_xml, expected_xml)
Exemplo n.º 2
0
    def test_pshost_methods(self):
        wsman = WSMan("server")
        runspace = RunspacePool(wsman)
        host = PSHost(CultureInfo(), CultureInfo(), True, "name", None, None,
                      "1.0")

        assert host.GetName(None, None) == "name"
        actual_version = host.GetVersion(runspace, None)
        assert actual_version.text == "1.0"
        assert actual_version.tag == "Version"
        assert isinstance(host.GetInstanceId(None, None), uuid.UUID)
        assert isinstance(host.GetCurrentCulture(None, None), CultureInfo)
        assert isinstance(host.GetCurrentUICulture(None, None), CultureInfo)
        host.NotifyBeginApplication(None, None)
        host.NotifyEndApplication(None, None)
Exemplo n.º 3
0
    def test_psrp_pshost_methods(self, wsman_conn):
        host = PSHost(None, None, False, "host name", None, None, "1.0")

        with RunspacePool(wsman_conn, host=host) as pool:
            ps = PowerShell(pool)
            # SetShouldExit is really the only one that seems to work so
            # we will just test that
            ps.add_script('$host.CurrentCulture; $host.SetShouldExit(1)')
            actual = ps.invoke()
            assert len(actual) == 1
            assert str(actual[0]) == "en-US"
            assert isinstance(actual[0], CultureInfo)
            assert host.rc == 1
Exemplo n.º 4
0
    def _connect(self):
        if not HAS_PYPSRP:
            raise AnsibleError("pypsrp or dependencies are not installed: %s"
                               % to_native(PYPSRP_IMP_ERR))
        super(Connection, self)._connect()
        self._build_kwargs()
        display.vvv("ESTABLISH PSRP CONNECTION FOR USER: %s ON PORT %s TO %s" %
                    (self._psrp_user, self._psrp_port, self._psrp_host),
                    host=self._psrp_host)

        if not self.runspace:
            connection = WSMan(**self._psrp_conn_kwargs)

            # create our pseudo host to capture the exit code and host output
            host_ui = PSHostUserInterface()
            self.host = PSHost(None, None, False, "Ansible PSRP Host", None,
                               host_ui, None)

            self.runspace = RunspacePool(
                connection, host=self.host,
                configuration_name=self._psrp_configuration_name
            )
            display.vvvvv(
                "PSRP OPEN RUNSPACE: auth=%s configuration=%s endpoint=%s" %
                (self._psrp_auth, self._psrp_configuration_name,
                 connection.transport.endpoint), host=self._psrp_host
            )
            try:
                self.runspace.open()
            except AuthenticationError as e:
                raise AnsibleConnectionFailure("failed to authenticate with "
                                               "the server: %s" % to_native(e))
            except WinRMError as e:
                raise AnsibleConnectionFailure(
                    "psrp connection failure during runspace open: %s"
                    % to_native(e)
                )
            except (ConnectionError, ConnectTimeout) as e:
                raise AnsibleConnectionFailure(
                    "Failed to connect to the host via PSRP: %s"
                    % to_native(e)
                )

            self._connected = True
            self._last_pipeline = None
        return self
Exemplo n.º 5
0
 def __init__(
     self,
     psrp_conn_id: str,
     logging_level: int = DEBUG,
     operation_timeout: Optional[int] = None,
     runspace_options: Optional[Dict[str, Any]] = None,
     wsman_options: Optional[Dict[str, Any]] = None,
     on_output_callback: Optional[OutputCallback] = None,
     exchange_keys: bool = True,
     host: Optional[PSHost] = None,
 ):
     self.conn_id = psrp_conn_id
     self._logging_level = logging_level
     self._operation_timeout = operation_timeout
     self._runspace_options = runspace_options or {}
     self._wsman_options = wsman_options or {}
     self._on_output_callback = on_output_callback
     self._exchange_keys = exchange_keys
     self._host = host or PSHost(None, None, False,
                                 type(self).__name__, None, None, "1.0")
Exemplo n.º 6
0
    def test_psrp_pshost_ui_mocked_methods(self, wsman_conn, monkeypatch):
        # This tests that the args from an actual host call match up with our
        # definitions
        monkeypatch.setattr('cryptography.hazmat.primitives.asymmetric.rsa.'
                            'generate_private_key', gen_rsa_keypair)

        mock_read_line = MagicMock(return_value="ReadLine response")
        mock_read_line_as_ss = MagicMock()
        mock_write1 = MagicMock(return_value=None)
        mock_write2 = MagicMock(return_value=None)
        mock_write_line1 = MagicMock(return_value=None)
        mock_write_line2 = MagicMock(return_value=None)
        mock_write_line3 = MagicMock(return_value=None)
        mock_write_error = MagicMock(return_value=None)
        mock_write_debug = MagicMock(return_value=None)
        mock_write_progress = MagicMock(return_value=None)
        mock_write_verbose = MagicMock(return_value=None)
        mock_write_warning = MagicMock(return_value=None)
        mock_prompt = MagicMock(return_value={
            "prompt field": "prompt response",
        })
        mock_prompt_credential = MagicMock()
        mock_prompt_choice = MagicMock(return_value=1)

        host_ui = PSHostUserInterface()
        host_ui.ReadLine = mock_read_line
        host_ui.ReadLineAsSecureString = mock_read_line_as_ss
        host_ui.Write1 = mock_write1
        host_ui.Write2 = mock_write2
        host_ui.WriteLine1 = mock_write_line1
        host_ui.WriteLine2 = mock_write_line2
        host_ui.WriteLine3 = mock_write_line3
        host_ui.WriteErrorLine = mock_write_error
        host_ui.WriteDebugLine = mock_write_debug
        host_ui.WriteProgress = mock_write_progress
        host_ui.WriteVerboseLine = mock_write_verbose
        host_ui.WriteWarningLine = mock_write_warning
        host_ui.Prompt = mock_prompt
        # seems like PS never calls PromptForCredential1 so we will skip that
        host_ui.PromptForCredential2 = mock_prompt_credential
        host_ui.PromptForChoice = mock_prompt_choice

        host = PSHost(None, None, False, None, None, host_ui, None)

        with RunspacePool(wsman_conn, host=host) as pool:
            pool.exchange_keys()
            mock_read_line_as_ss.return_value = pool.serialize(
                u"ReadLineAsSecureString response", ObjectMeta("SS")
            )
            mock_ps_credential = PSCredential(username="******",
                                              password=u"password")
            mock_prompt_credential.return_value = mock_ps_credential

            ps = PowerShell(pool)
            ps.add_script('''$host.UI.ReadLine()
$host.UI.ReadLineAsSecureString()
$host.UI.Write("Write1")
$host.UI.Write([System.ConsoleColor]::Blue, [System.ConsoleColor]::White, "Write2")
$host.UI.WriteLine()
$host.UI.WriteLine("WriteLine2")
$host.UI.WriteLine([System.ConsoleColor]::Gray, [System.ConsoleColor]::Green, "WriteLine3")
$host.UI.WriteErrorLine("WriteErrorLine")
$host.UI.WriteDebugLine("WriteDebugLine")
$host.UI.WriteProgress(1, (New-Object -TypeName System.Management.Automation.ProgressRecord -ArgumentList 2, "activity", "description"))
$host.UI.WriteVerboseLine("WriteVerboseLine")
$host.UI.WriteWarningLine("WriteWarningLine")

$prompt_field = New-Object -TypeName System.Management.Automation.Host.FieldDescription -ArgumentList @("prompt field")
$prompt_field.Label = "PromptLabel"
$host.UI.Prompt("Prompt caption", "Prompt message", $prompt_field)

$host.UI.PromptForCredential("PromptForCredential caption", "PromptForCredential message", "PromptForCredential user", "PromptForCredential target")

$choice_field1 = New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList "Prompt1 label", "Prompt1 help"
$choice_field2 = New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList "Prompt2 label", "Prompt2 help"
$host.UI.PromptForChoice("PromptForChoice caption", "PromptForChoice message", @($choice_field1, $choice_field2), 0)''')
            actual = ps.invoke()

        assert len(actual) == 5

        assert actual[0] == "ReadLine response"
        assert mock_read_line.call_count == 1
        assert isinstance(mock_read_line.call_args[0][0], RunspacePool)
        assert isinstance(mock_read_line.call_args[0][1], PowerShell)

        assert actual[1] == "ReadLineAsSecureString response"
        assert mock_read_line_as_ss.call_count == 1
        assert isinstance(mock_read_line_as_ss.call_args[0][0],
                          RunspacePool)
        assert isinstance(mock_read_line_as_ss.call_args[0][1], PowerShell)

        assert mock_write1.call_count == 1
        assert isinstance(mock_write1.call_args[0][0], RunspacePool)
        assert isinstance(mock_write1.call_args[0][1], PowerShell)
        assert mock_write1.call_args[0][2] == "Write1"

        assert mock_write2.call_count == 1
        assert isinstance(mock_write2.call_args[0][0], RunspacePool)
        assert isinstance(mock_write2.call_args[0][1], PowerShell)
        assert mock_write2.call_args[0][2] == Color.BLUE
        assert mock_write2.call_args[0][3] == Color.WHITE
        assert mock_write2.call_args[0][4] == "Write2"

        assert mock_write_line1.call_count == 1
        assert isinstance(mock_write_line1.call_args[0][0], RunspacePool)
        assert isinstance(mock_write_line1.call_args[0][1], PowerShell)

        assert mock_write_line2.call_count == 1
        assert isinstance(mock_write_line2.call_args[0][0], RunspacePool)
        assert isinstance(mock_write_line2.call_args[0][1], PowerShell)
        assert mock_write_line2.call_args[0][2] == "WriteLine2"

        assert mock_write_line3.call_count == 1
        assert isinstance(mock_write_line3.call_args[0][0], RunspacePool)
        assert isinstance(mock_write_line3.call_args[0][1], PowerShell)
        assert mock_write_line3.call_args[0][2] == Color.GRAY
        assert mock_write_line3.call_args[0][3] == Color.GREEN
        assert mock_write_line3.call_args[0][4] == "WriteLine3"

        assert mock_write_error.call_count == 1
        assert isinstance(mock_write_error.call_args[0][0], RunspacePool)
        assert isinstance(mock_write_error.call_args[0][1], PowerShell)
        assert mock_write_error.call_args[0][2] == "WriteErrorLine"

        assert mock_write_debug.call_count == 1
        assert isinstance(mock_write_debug.call_args[0][0], RunspacePool)
        assert isinstance(mock_write_debug.call_args[0][1], PowerShell)
        assert mock_write_debug.call_args[0][2] == "WriteDebugLine"

        # On PSv5 a progress record is always sent, we still sent one
        # ourselves to ensure it works so we verify we received at least
        # one and assert the last
        assert mock_write_progress.call_count > 0
        progress_args = mock_write_progress.call_args_list[-1]
        assert isinstance(progress_args[0][0], RunspacePool)
        assert isinstance(progress_args[0][1], PowerShell)
        assert progress_args[0][2] == 1
        progress_record = pool._serializer.deserialize(
            progress_args[0][3], ObjectMeta("Obj", object=ProgressRecord)
        )
        assert progress_record.activity == "activity"
        assert progress_record.activity_id == 2
        assert progress_record.description == "description"

        assert mock_write_verbose.call_count == 1
        assert isinstance(mock_write_verbose.call_args[0][0], RunspacePool)
        assert isinstance(mock_write_verbose.call_args[0][1], PowerShell)
        assert mock_write_verbose.call_args[0][2] == "WriteVerboseLine"

        assert mock_write_warning.call_count == 1
        assert isinstance(mock_write_warning.call_args[0][0], RunspacePool)
        assert isinstance(mock_write_warning.call_args[0][1], PowerShell)
        assert mock_write_warning.call_args[0][2] == "WriteWarningLine"

        assert actual[2] == {"prompt field": "prompt response"}
        assert mock_prompt.call_count == 1
        assert isinstance(mock_prompt.call_args[0][0], RunspacePool)
        assert isinstance(mock_prompt.call_args[0][1], PowerShell)
        assert mock_prompt.call_args[0][2] == "Prompt caption"
        assert mock_prompt.call_args[0][3] == "Prompt message"
        assert isinstance(mock_prompt.call_args[0][4], list)
        assert len(mock_prompt.call_args[0][4]) == 1
        assert mock_prompt.call_args[0][4][0].extended_properties['name'] == \
            'prompt field'
        assert mock_prompt.call_args[0][4][0].extended_properties['label'] == \
            'PromptLabel'

        assert isinstance(actual[3], PSCredential)
        assert actual[3].username == "username"
        assert actual[3].password == "password"
        assert mock_prompt_credential.call_count == 1
        assert isinstance(mock_prompt_credential.call_args[0][0],
                          RunspacePool)
        assert isinstance(mock_prompt_credential.call_args[0][1],
                          PowerShell)
        assert mock_prompt_credential.call_args[0][2] == \
            "PromptForCredential caption"
        assert mock_prompt_credential.call_args[0][3] == \
            "PromptForCredential message"
        assert mock_prompt_credential.call_args[0][4] == \
            "PromptForCredential user"
        assert mock_prompt_credential.call_args[0][5] == \
            "PromptForCredential target"
        assert mock_prompt_credential.call_args[0][6] == 3
        assert mock_prompt_credential.call_args[0][7] == 1

        assert actual[4] == 1
        assert mock_prompt_choice.call_count == 1
        assert isinstance(mock_prompt_choice.call_args[0][0], RunspacePool)
        assert isinstance(mock_prompt_choice.call_args[0][1], PowerShell)
        assert mock_prompt_choice.call_args[0][2] == "PromptForChoice caption"
        assert mock_prompt_choice.call_args[0][3] == "PromptForChoice message"
        assert isinstance(mock_prompt_choice.call_args[0][4], list)
        assert len(mock_prompt_choice.call_args[0][4]) == 2
        assert mock_prompt_choice.call_args[0][4][0].extended_properties[
            'label'] == "Prompt1 label"
        assert mock_prompt_choice.call_args[0][4][0].extended_properties[
            'helpMessage'] == "Prompt1 help"
        assert mock_prompt_choice.call_args[0][4][1].extended_properties[
            'label'] == "Prompt2 label"
        assert mock_prompt_choice.call_args[0][4][1].extended_properties[
            'helpMessage'] == "Prompt2 help"
Exemplo n.º 7
0
 def test_pshost_run_method_not_implemented(self):
     host = PSHost(None, None, False, None, None, None, None)
     actual = host.run_method(HostMethodIdentifier(value=53), [], None)
     assert actual is None
Exemplo n.º 8
0
 def test_pshost_not_implemented_methods(self):
     host = PSHost(None, None, False, None, None, None, None)
     with pytest.raises(NotImplementedError):
         host.EnterNestedPrompt(None, None)
     with pytest.raises(NotImplementedError):
         host.ExitNestedPrompt(None, None)
Exemplo n.º 9
0
    def test_psrp_pshost_raw_ui_mocked_methods(self, wsman_conn,
                                               monkeypatch):
        # in a mocked context the calculated size differs on a few variables
        # we will mock out that call and return the ones used in our existing
        # responses
        mock_calc = MagicMock()
        mock_calc.side_effect = [113955, 382750]

        key_info = KeyInfo(code=65, character="a",
                           state=ControlKeyState.CapsLockOn, key_down=True)

        set_foreground_color = MagicMock(return_value=None)
        set_background_color = MagicMock(return_value=None)
        set_cursor_position = MagicMock(return_value=None)
        set_window_position = MagicMock(return_value=None)
        set_cursor_size = MagicMock(return_value=None)
        set_buffer_size = MagicMock(return_value=None)
        set_window_size = MagicMock(return_value=None)
        set_window_title = MagicMock(return_value=None)
        read_key = MagicMock(return_value=key_info)
        flush_input = MagicMock(return_value=None)
        set_buffer1 = MagicMock(return_value=None)
        set_buffer2 = MagicMock(return_value=None)
        scroll_buffer = MagicMock(return_value=None)

        window_title = "pypsrp window"
        cursor_size = 50
        foreground_color = Color(value=Color.WHITE)
        background_color = Color(value=Color.BLUE)
        cursor_position = Coordinates(x=1, y=2)
        window_position = Coordinates(x=3, y=4)
        buffer_size = Size(width=80, height=80)
        max_physical_window_size = Size(width=80, height=80)
        max_window_size = Size(width=80, height=80)
        window_size = Size(width=80, height=80)

        host_raw_ui = PSHostRawUserInterface(window_title, cursor_size,
                                             foreground_color,
                                             background_color, cursor_position,
                                             window_position, buffer_size,
                                             max_physical_window_size,
                                             max_window_size, window_size)
        host_raw_ui.SetForegroundColor = set_foreground_color
        host_raw_ui.SetBackgroundColor = set_background_color
        host_raw_ui.SetCursorPosition = set_cursor_position
        host_raw_ui.SetWindowPosition = set_window_position
        host_raw_ui.SetCursorSize = set_cursor_size
        host_raw_ui.SetBufferSize = set_buffer_size
        host_raw_ui.SetWindowSize = set_window_size
        host_raw_ui.SetWindowTitle = set_window_title
        host_raw_ui.ReadKey = read_key
        host_raw_ui.FlushInputBuffer = flush_input
        host_raw_ui.SetBufferContents1 = set_buffer1
        host_raw_ui.SetBufferContents2 = set_buffer2
        host_raw_ui.ScrollBufferContents = scroll_buffer

        host_ui = PSHostUserInterface(host_raw_ui)
        host = PSHost(None, None, False, None, None, host_ui, None)

        with RunspacePool(wsman_conn, host=host) as pool:
            ps = PowerShell(pool)
            ps.add_script('''$host.UI.RawUI.ForegroundColor
$host.UI.RawUI.ForegroundColor = [System.ConsoleColor]::Green
$host.UI.RawUI.ForegroundColor

$host.UI.RawUI.BackgroundColor
$host.UI.RawUI.BackgroundColor = [System.ConsoleColor]::Red
$host.UI.RawUI.BackgroundColor

$host.UI.RawUI.CursorPosition
$host.UI.RawUI.CursorPosition = (New-Object -TypeName System.Management.Automation.Host.Coordinates -ArgumentList 11, 12)
$host.UI.RawUI.CursorPosition

$host.UI.RawUI.WindowPosition
$host.UI.RawUI.WindowPosition = (New-Object -TypeName System.Management.Automation.Host.Coordinates -ArgumentList 13, 14)
$host.UI.RawUI.WindowPosition

$host.UI.RawUI.CursorSize
$host.UI.RawUI.CursorSize = 25
$host.UI.RawUI.CursorSize

$host.UI.RawUI.BufferSize
$host.UI.RawUI.BufferSize = (New-Object -TypeName System.Management.Automation.Host.Size -ArgumentList 8, 9)
$host.UI.RawUI.BufferSize

$host.UI.RawUI.WindowSize
$host.UI.RawUI.WindowSize = (New-Object -TypeName System.Management.Automation.Host.Size -ArgumentList 8, 9)
$host.UI.RawUI.WindowSize

$host.UI.RawUI.WindowTitle
$host.UI.RawUI.WindowTitle = "New Window Title"
$host.UI.RawUI.WindowTitle

$host.UI.RawUI.ReadKey()

$host.UI.RawUI.FlushInputBuffer()

$buffer_cell = New-Object -TypeName System.Management.Automation.Host.BufferCell -ArgumentList "Z", ([System.ConsoleColor]::Red), ([System.ConsoleColor]::Green), ([System.Management.Automation.Host.BufferCellType]::Complete)
$rectangle = New-Object -TypeName System.Management.Automation.Host.Rectangle -ArgumentList 1, 2, 3, 4
$host.UI.RawUI.SetBufferContents($rectangle, $buffer_cell)

$coordinates = New-Object -TypeName System.Management.Automation.Host.Coordinates -ArgumentList 15, 15

$buffer_cell1_1 = New-Object -TypeName System.Management.Automation.Host.BufferCell -ArgumentList "A", ([System.ConsoleColor]::Black), ([System.ConsoleColor]::White), ([System.Management.Automation.Host.BufferCellType]::Leading)
$buffer_cell1_2 = New-Object -TypeName System.Management.Automation.Host.BufferCell -ArgumentList "B", ([System.ConsoleColor]::Black), ([System.ConsoleColor]::White), ([System.Management.Automation.Host.BufferCellType]::Trailing)
$buffer_cell2_1 = New-Object -TypeName System.Management.Automation.Host.BufferCell -ArgumentList "C", ([System.ConsoleColor]::Black), ([System.ConsoleColor]::White), ([System.Management.Automation.Host.BufferCellType]::Leading)
$buffer_cell2_2 = New-Object -TypeName System.Management.Automation.Host.BufferCell -ArgumentList "D", ([System.ConsoleColor]::Black), ([System.ConsoleColor]::White), ([System.Management.Automation.Host.BufferCellType]::Trailing)

$cells = New-Object -TypeName "System.Management.Automation.Host.BufferCell[,]" -ArgumentList 2,2
$cells[0,0] = $buffer_cell1_1
$cells[0,1] = $buffer_cell1_2
$cells[1,1] = $buffer_cell2_2
$cells[1,0] = $buffer_cell2_1
$host.UI.RawUI.SetBufferContents($coordinates, $cells)

$host.UI.RawUI.ScrollBufferContents($rectangle, $coordinates, $rectangle, $buffer_cell)''')
            actual = ps.invoke()

        assert len(actual) == 17

        assert str(actual[0]) == "White"
        assert str(actual[1]) == "Green"
        assert set_foreground_color.call_count == 1
        assert isinstance(set_foreground_color.call_args[0][0], RunspacePool)
        assert isinstance(set_foreground_color.call_args[0][1], PowerShell)
        assert set_foreground_color.call_args[0][2] == Color.GREEN

        assert str(actual[2]) == "Blue"
        assert str(actual[3]) == "Red"
        assert set_background_color.call_count == 1
        assert isinstance(set_background_color.call_args[0][0], RunspacePool)
        assert isinstance(set_background_color.call_args[0][1], PowerShell)
        assert set_background_color.call_args[0][2] == Color.RED

        assert str(actual[4]) == "1,2"
        assert str(actual[5]) == "11,12"
        assert set_cursor_position.call_count == 1
        assert isinstance(set_cursor_position.call_args[0][0], RunspacePool)
        assert isinstance(set_cursor_position.call_args[0][1], PowerShell)
        assert set_cursor_position.call_args[0][2].extended_properties['x'] \
            == 11
        assert set_cursor_position.call_args[0][2].extended_properties['y'] \
            == 12

        assert str(actual[6]) == "3,4"
        assert str(actual[7]) == "13,14"
        assert set_window_position.call_count == 1
        assert isinstance(set_window_position.call_args[0][0], RunspacePool)
        assert isinstance(set_window_position.call_args[0][1], PowerShell)
        assert set_window_position.call_args[0][2].extended_properties['x'] \
            == 13
        assert set_window_position.call_args[0][2].extended_properties['y'] \
            == 14

        assert actual[8] == 50
        assert actual[9] == 25
        assert set_cursor_size.call_count == 1
        assert isinstance(set_cursor_size.call_args[0][0], RunspacePool)
        assert isinstance(set_cursor_size.call_args[0][1], PowerShell)
        assert set_cursor_size.call_args[0][2] == 25

        assert str(actual[10]) == "80,80"
        assert str(actual[11]) == "8,9"
        assert set_buffer_size.call_count == 1
        assert isinstance(set_buffer_size.call_args[0][0], RunspacePool)
        assert isinstance(set_buffer_size.call_args[0][1], PowerShell)
        assert isinstance(set_buffer_size.call_args[0][2],
                          GenericComplexObject)
        assert set_buffer_size.call_args[0][2].extended_properties['width'] \
            == 8
        assert set_buffer_size.call_args[0][2].extended_properties['height'] \
            == 9

        assert str(actual[12]) == "80,80"
        assert str(actual[13]) == "8,9"
        assert set_window_size.call_count == 1
        assert isinstance(set_window_size.call_args[0][0], RunspacePool)
        assert isinstance(set_window_size.call_args[0][1], PowerShell)
        assert isinstance(set_window_size.call_args[0][2],
                          GenericComplexObject)
        assert set_window_size.call_args[0][2].extended_properties['width'] \
            == 8
        assert set_window_size.call_args[0][2].extended_properties['height'] \
            == 9

        assert actual[14] == "pypsrp window"
        assert actual[15] == "New Window Title"
        assert set_window_title.call_count == 1
        assert isinstance(set_window_title.call_args[0][0], RunspacePool)
        assert isinstance(set_window_title.call_args[0][1], PowerShell)
        assert set_window_title.call_args[0][2] == "New Window Title"

        assert str(actual[16]) == "65,a,CapsLockOn,True"
        assert isinstance(actual[16], KeyInfoDotNet)
        assert read_key.call_count == 1
        assert isinstance(read_key.call_args[0][0], RunspacePool)
        assert isinstance(read_key.call_args[0][1], PowerShell)
        assert read_key.call_args[0][2] == 4

        assert flush_input.call_count == 1
        assert isinstance(flush_input.call_args[0][0], RunspacePool)
        assert isinstance(flush_input.call_args[0][1], PowerShell)

        assert set_buffer1.call_count == 1
        assert isinstance(set_buffer1.call_args[0][0], RunspacePool)
        assert isinstance(set_buffer1.call_args[0][1], PowerShell)
        assert isinstance(set_buffer1.call_args[0][2], GenericComplexObject)
        assert set_buffer1.call_args[0][2].extended_properties['left'] == 1
        assert set_buffer1.call_args[0][2].extended_properties['top'] == 2
        assert set_buffer1.call_args[0][2].extended_properties['right'] == 3
        assert set_buffer1.call_args[0][2].extended_properties['bottom'] == 4
        fill = set_buffer1.call_args[0][3]
        assert isinstance(fill, GenericComplexObject)
        assert fill.extended_properties['character'] == "Z"
        assert fill.extended_properties['foregroundColor'] == 12
        assert fill.extended_properties['backgroundColor'] == 10
        assert fill.extended_properties['bufferCellType'] == 0

        assert set_buffer2.call_count == 1
        assert isinstance(set_buffer2.call_args[0][0], RunspacePool)
        assert isinstance(set_buffer2.call_args[0][1], PowerShell)
        assert isinstance(set_buffer2.call_args[0][2], GenericComplexObject)
        assert set_buffer2.call_args[0][2].extended_properties['x'] == 15
        assert set_buffer2.call_args[0][2].extended_properties['y'] == 15
        assert isinstance(set_buffer2.call_args[0][3], GenericComplexObject)
        assert set_buffer2.call_args[0][3].extended_properties['mal'] == [2, 2]
        set_contents = set_buffer2.call_args[0][3].extended_properties['mae']
        assert len(set_contents) == 4
        assert set_contents[0].extended_properties['character'] == "A"
        assert set_contents[0].extended_properties['foregroundColor'] == 0
        assert set_contents[0].extended_properties['backgroundColor'] == 15
        assert set_contents[0].extended_properties['bufferCellType'] == 1
        assert set_contents[1].extended_properties['character'] == "B"
        assert set_contents[1].extended_properties['foregroundColor'] == 0
        assert set_contents[1].extended_properties['backgroundColor'] == 15
        assert set_contents[1].extended_properties['bufferCellType'] == 2
        assert set_contents[2].extended_properties['character'] == "C"
        assert set_contents[2].extended_properties['foregroundColor'] == 0
        assert set_contents[2].extended_properties['backgroundColor'] == 15
        assert set_contents[2].extended_properties['bufferCellType'] == 1
        assert set_contents[3].extended_properties['character'] == "D"
        assert set_contents[3].extended_properties['foregroundColor'] == 0
        assert set_contents[3].extended_properties['backgroundColor'] == 15
        assert set_contents[3].extended_properties['bufferCellType'] == 2

        assert scroll_buffer.call_count == 1
        assert isinstance(scroll_buffer.call_args[0][0], RunspacePool)
        assert isinstance(scroll_buffer.call_args[0][1], PowerShell)
        source = scroll_buffer.call_args[0][2]
        assert isinstance(source, GenericComplexObject)
        assert source.extended_properties['left'] == 1
        assert source.extended_properties['top'] == 2
        assert source.extended_properties['right'] == 3
        assert source.extended_properties['bottom'] == 4
        destination = scroll_buffer.call_args[0][3]
        assert isinstance(destination, GenericComplexObject)
        assert destination.extended_properties['x'] == 15
        assert destination.extended_properties['y'] == 15
        clip = scroll_buffer.call_args[0][4]
        assert isinstance(clip, GenericComplexObject)
        assert clip.extended_properties['left'] == 1
        assert clip.extended_properties['top'] == 2
        assert clip.extended_properties['right'] == 3
        assert clip.extended_properties['bottom'] == 4
        fill = scroll_buffer.call_args[0][5]
        assert isinstance(fill, GenericComplexObject)
        assert fill.extended_properties['character'] == "Z"
        assert fill.extended_properties['foregroundColor'] == 12
        assert fill.extended_properties['backgroundColor'] == 10
        assert fill.extended_properties['bufferCellType'] == 0