How to use the pypsrp.transport.TransportHTTP 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_transport.py View on Github external
def test_build_certificate_no_pem(self):
        transport = TransportHTTP("", certificate_key_pem="path")
        with pytest.raises(ValueError) as err:
            transport._build_auth_certificate(None)
        assert str(err.value) == \
            "For certificate auth, the path to the certificate pem file " \
            "must be specified with certificate_pem"
github jborean93 / pypsrp / tests / test_transport.py View on Github external
def test_build_negotiate_with_kwargs(self):
        transport = TransportHTTP("", auth="negotiate", username="user",
                                  ssl=False, password="pass",
                                  negotiate_delegate=True,
                                  negotiate_hostname_override="host",
                                  negotiate_send_cbt=False,
                                  negotiate_service="HTTP")
        session = transport._build_session()
        assert isinstance(transport.encryption, WinRMEncryption)
        assert transport.encryption.protocol == WinRMEncryption.SPNEGO
        assert isinstance(session.auth, HTTPNegotiateAuth)
        assert session.auth.auth_provider == "auto"
        assert session.auth.delegate is True
        assert session.auth.hostname_override == "host"
        assert session.auth.password == "pass"
        assert session.auth.send_cbt is False
        assert session.auth.service == 'HTTP'
        assert session.auth.username == "user"
github jborean93 / pypsrp / tests / test_transport.py View on Github external
def test_invalid_encryption_value(self):
        with pytest.raises(ValueError) as err:
            TransportHTTP("", "", encryption="fake")
        assert str(err.value) == \
            "The encryption value 'fake' must be auto, always, or never"
github jborean93 / pypsrp / tests / test_transport.py View on Github external
def test_build_session_proxies_default(self):
        transport = TransportHTTP("")
        session = transport._build_session()
        assert session.proxies == {}
github jborean93 / pypsrp / tests / test_transport.py View on Github external
def test_send_winrm_error_blank(self, monkeypatch):
        response = requests.Response()
        response.status_code = 500
        response._content = b""

        send_mock = MagicMock()
        send_mock.return_value = response

        monkeypatch.setattr(requests.Session, "send", send_mock)

        transport = TransportHTTP("server", ssl=True)
        session = transport._build_session()
        transport.session = session
        request = requests.Request('POST', transport.endpoint, data=b"data")
        prep_request = session.prepare_request(request)

        with pytest.raises(WinRMTransportError) as err:
            transport._send_request(prep_request, "server")
        assert str(err.value) == "Bad HTTP response returned from the " \
                                 "server. Code: 500, Content: ''"
        assert err.value.code == 500
        assert err.value.protocol == 'http'
        assert err.value.response_text == ''
github jborean93 / pypsrp / tests / runner.py View on Github external
allow_real = test_params[0]
    test_name = test_params[1]

    # these need to be set to run against a proper server
    username = os.environ.get('PYPSRP_USERNAME', None)
    password = os.environ.get('PYPSRP_PASSWORD', None)
    server = os.environ.get('PYPSRP_SERVER', None)

    # these are optional vars that can further control the transport setup
    auth = os.environ.get('PYPSRP_AUTH', 'basic')
    port = int(os.environ.get('PYPSRP_PORT', '5985'))
    ssl = port != 5985

    if allow_real and username is not None and password is not None and \
            server is not None:
        transport = TransportHTTP(server, port, username, password, ssl,
                                  auth=auth)
    else:
        # Mock out UUID's so they are not a problem when comparing messages
        def mockuuid():
            return uuid.UUID("00000000-0000-0000-0000-000000000000")
        monkeypatch.setattr(uuid, 'uuid4', mockuuid)
        transport = TransportFake(test_name, "fakehost", port, "username",
                                  "password", ssl, "wsman", auth)
    return transport
github jborean93 / pypsrp / tests / test_transport.py View on Github external
def test_build_kerberos_with_kwargs(self):
        transport = TransportHTTP("", auth="kerberos", username="user",
                                  ssl=False, password="pass",
                                  negotiate_delegate=True,
                                  negotiate_hostname_override="host",
                                  negotiate_send_cbt=False,
                                  negotiate_service="HTTP")
        session = transport._build_session()
        assert isinstance(transport.encryption, WinRMEncryption)
        assert transport.encryption.protocol == WinRMEncryption.SPNEGO
        assert isinstance(session.auth, HTTPNegotiateAuth)
        assert session.auth.auth_provider == "kerberos"
        assert session.auth.delegate is True
        assert session.auth.hostname_override == "host"
        assert session.auth.password == "pass"
        assert session.auth.send_cbt is False
        assert session.auth.service == 'HTTP'
        assert session.auth.username == "user"
github jborean93 / pypsrp / tests / test_transport.py View on Github external
def test_build_credssp_not_imported(self, reset_imports):
        pypsrp_transport.HAS_CREDSSP = False
        pypsrp_transport.CREDSSP_IMP_ERR = "import failed"
        transport = TransportHTTP("")
        with pytest.raises(ImportError) as err:
            transport._build_auth_credssp(None)
        assert str(err.value) == \
            "Cannot use CredSSP auth as requests-credssp is not " \
            "installed: import failed"
github jborean93 / pypsrp / tests / test_transport.py View on Github external
def test_build_certificate_not_ssl(self):
        transport = TransportHTTP("", certificate_key_pem="path",
                                  certificate_pem="path", ssl=False)
        with pytest.raises(ValueError) as err:
            transport._build_auth_certificate(None)
        assert str(err.value) == "For certificate auth, SSL must be used"
github jborean93 / pypsrp / tests / test_transport.py View on Github external
def test_build_session_proxies_kwarg(self):
        transport = TransportHTTP("", proxy="https://kwargproxy")
        session = transport._build_session()
        assert session.proxies == {"https": "https://kwargproxy"}