示例#1
0
    def test_client_cert_missing_one(self, request, tmp_path):
        """Test cert or key supplied, but not the other."""
        ax_url = get_url(request)
        test_path = tmp_path / TEST_CLIENT_CERT_NAME
        test_path.write_text(TEST_CLIENT_CERT)

        with pytest.raises(HttpError):
            Http(url=ax_url, cert_client_cert=test_path, certwarn=False)

        with pytest.raises(HttpError):
            Http(url=ax_url, cert_client_key=test_path, certwarn=False)
示例#2
0
    def test_certwarn_true(self, request, httpbin_secure):
        """Test quiet_urllib=False shows warning from urllib3."""
        url = httpbin_secure.url
        http = Http(url=url, certwarn=True, save_history=True)

        with pytest.warns(InsecureRequestWarning):
            http()
示例#3
0
 def test_verify_ca_bundle(self, request, httpbin_secure,
                           httpbin_ca_bundle):
     """Test quiet_urllib=False no warning from urllib3 when using ca bundle."""
     url = httpbin_secure.url
     http = Http(url=url, certwarn=False)
     response = http()
     assert response.status_code == 200
示例#4
0
def get_auth(request):
    """Pass."""
    http = Http(url=get_url(request), certwarn=False)

    obj = auth.ApiKey(http=http, **get_key_creds(request))
    obj.login()
    return obj
示例#5
0
    def test_str_repr(self, request):
        """Test str/repr has URL."""
        ax_url = get_url(request)

        http = Http(url=ax_url)

        assert ax_url in format(http)
        assert ax_url in repr(http)
示例#6
0
    def test_old_version(self, request, monkeypatch):
        """Test exc thrown when login() and login() already called."""
        monkeypatch.setattr(ApiKey, "_validate_path", "api/badwolf")

        http = Http(url=get_url(request), certwarn=False)
        auth = ApiKey(http=http, **get_key_creds(request))
        with pytest.raises(AuthError):
            auth.login()
示例#7
0
    def test_logout_not_logged_in(self, request):
        """Test exc thrown when logout() but login() not called."""
        http = Http(url=get_url(request), certwarn=False)

        auth = ApiKey(http=http, **get_key_creds(request))

        with pytest.raises(NotLoggedIn):
            auth.logout()
示例#8
0
    def test_save_last_true(self, request):
        """Test last req/resp with save_last=True."""
        ax_url = get_url(request)

        http = Http(url=ax_url, save_last=True, certwarn=False)
        response = http()
        assert response == http.LAST_RESPONSE
        assert response.request == http.LAST_REQUEST
示例#9
0
    def test_save_history(self, request):
        """Test last resp added to history with save_history=True."""
        ax_url = get_url(request)

        http = Http(url=ax_url, save_history=True, certwarn=False)

        response = http()

        assert response in http.HISTORY
示例#10
0
    def test_login_already_logged_in(self, request):
        """Test exc thrown when login() and login() already called."""
        http = Http(url=get_url(request), certwarn=False)

        auth = ApiKey(http=http, **get_key_creds(request))

        auth.login()

        with pytest.raises(AlreadyLoggedIn):
            auth.login()
示例#11
0
    def test_invalid_creds(self, request):
        """Test str/repr has URL."""
        http = Http(url=get_url(request), certwarn=False)

        bad = "badwolf"

        auth = ApiKey(http=http, key=bad, secret=bad)

        with pytest.raises(InvalidCredentials):
            auth.login()
示例#12
0
    def test_client_cert_both(self, request, tmp_path):
        """Test cert or key supplied, but not the other."""
        ax_url = get_url(request)
        both_path = tmp_path / TEST_CLIENT_CERT_NAME
        both_cert = "{}\n{}\n".format(TEST_CLIENT_CERT, TEST_CLIENT_KEY)
        both_path.write_text(both_cert)

        http = Http(url=ax_url, cert_client_both=both_path, certwarn=False)

        http()
示例#13
0
    def test_http_lock_fail(self, request):
        """Test using an http client from another authmethod throws exc."""
        http = Http(url=get_url(request), certwarn=False)

        auth = ApiKey(http=http, **get_key_creds(request))

        assert auth.http._auth_lock

        with pytest.raises(AuthError):
            auth = ApiKey(http=http, **get_key_creds(request))
示例#14
0
    def test_parsed_url(self, request):
        """Test url=UrlParser() works."""
        ax_url = get_url(request)

        parsed_url = UrlParser(url=ax_url, default_scheme="https")

        http = Http(url=parsed_url)

        assert ax_url in format(http)
        assert ax_url in repr(http)
示例#15
0
    def test_save_last_false(self, request):
        """Test last req/resp with save_last=False."""
        ax_url = get_url(request)

        http = Http(url=ax_url, save_last=False, certwarn=False)

        http()

        assert not http.LAST_RESPONSE
        assert not http.LAST_REQUEST
示例#16
0
    def test_valid_creds(self, request):
        """Test str/repr has URL."""
        http = Http(url=get_url(request), certwarn=False)

        auth = ApiKey(http=http, **get_key_creds(request))

        auth.login()

        assert auth.is_logged_in
        assert "url" in format(auth)
        assert "url" in repr(auth)
示例#17
0
    def test_logout(self, request):
        """Test no exc when logout() after login()."""
        http = Http(url=get_url(request), certwarn=False)

        auth = ApiKey(http=http, **get_key_creds(request))

        auth.login()

        assert auth.is_logged_in

        auth.logout()

        assert not auth.is_logged_in
示例#18
0
    def test_log_req_body_false(self, request, caplog):
        """Test no logging of request body when log_request_body=False."""
        caplog.set_level(logging.DEBUG)

        ax_url = get_url(request)

        http = Http(url=ax_url,
                    log_request_body=False,
                    certwarn=False,
                    log_level="debug")

        http()

        assert not caplog.records
示例#19
0
    def test_log_response_attrs_none(self, request, caplog):
        """Test no logging of response attrs when log_response_attrs=None."""
        caplog.set_level(logging.DEBUG)

        ax_url = get_url(request)

        http = Http(url=ax_url,
                    log_response_attrs=None,
                    certwarn=False,
                    log_level="debug")

        http()

        assert not caplog.records
示例#20
0
    def test_client_cert_seperate(self, request, tmp_path):
        """Test cert or key supplied, but not the other."""
        ax_url = get_url(request)
        cert_path = tmp_path / TEST_CLIENT_CERT_NAME
        cert_path.write_text(TEST_CLIENT_CERT)
        key_path = tmp_path / TEST_CLIENT_KEY_NAME
        key_path.write_text(TEST_CLIENT_KEY)

        http = Http(
            url=ax_url,
            cert_client_cert=cert_path,
            cert_client_key=key_path,
            certwarn=False,
        )

        http()
示例#21
0
    def test_log_req_body_true(self, request, caplog):
        """Test logging of request body when log_request_body=True."""
        caplog.set_level(logging.DEBUG)

        ax_url = get_url(request)

        http = Http(url=ax_url,
                    log_request_body=True,
                    certwarn=False,
                    log_level="debug")

        http()

        assert len(caplog.records) == 1

        entries = ["REQUEST BODY:.*"]
        log_check(caplog, entries)
示例#22
0
    def test_log_resp_attrs_true(self, request, caplog):
        """Test verbose logging of response attrs when log_response_attrs=True."""
        caplog.set_level(logging.DEBUG)

        ax_url = get_url(request)

        http = Http(
            url=ax_url,
            log_response_attrs=["url", "headers"],
            certwarn=False,
            log_level="debug",
        )

        http()

        assert len(caplog.records) == 1

        entries = ["RESPONSE ATTRS:.*{}.*headers".format(http.url)]
        log_check(caplog, entries)
示例#23
0
    def test_certwarn_false(self, request, httpbin_secure):
        """Test quiet_urllib=False shows warning from urllib3."""
        url = httpbin_secure.url
        http = Http(url=url, certwarn=False)

        http()
示例#24
0
    def test_user_agent(self, request):
        """Test user_agent has version in it."""
        ax_url = get_url(request)

        http = Http(url=ax_url)
        assert __version__ in http.user_agent