forked from kenzuya/unshackle
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -46,37 +46,6 @@ def test_brief_keeps_the_host_and_reason_and_drops_the_url() -> None:
|
||||
assert leak not in text
|
||||
|
||||
|
||||
def test_brief_names_a_timeout() -> None:
|
||||
error = requests.ReadTimeout(
|
||||
"HTTPConnectionPool(host='vault.example', port=8080): Read timed out. (read timeout=10)", request=request()
|
||||
)
|
||||
text = brief(error)
|
||||
assert "timed out" in text
|
||||
assert "SECRETPW" not in text
|
||||
|
||||
|
||||
def test_brief_gives_the_status_of_an_http_error() -> None:
|
||||
response = html(503)
|
||||
error = requests.HTTPError(f"503 Server Error: Service Unavailable for url: {URL}", response=response)
|
||||
assert brief(error) == "HTTP 503 from vault.example:8080"
|
||||
|
||||
|
||||
def test_brief_keeps_one_short_line_of_any_other_error() -> None:
|
||||
assert brief(ValueError("line1\nline2")) == "line1"
|
||||
assert len(brief(ValueError("x" * 5000))) <= 200
|
||||
assert brief(ValueError()) == "ValueError"
|
||||
|
||||
|
||||
def test_brief_keeps_the_reason_of_a_tls_failure() -> None:
|
||||
error = requests.exceptions.SSLError(
|
||||
"HTTPSConnectionPool(host='vault.example', port=8080): Max retries exceeded with url: /vault.php?password=SECRETPW "
|
||||
"(Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: "
|
||||
"self-signed certificate (_ssl.c:1010)')))",
|
||||
request=request(),
|
||||
)
|
||||
assert brief(error) == "SSLError to vault.example:8080 (certificate verify failed: self-signed certificate)"
|
||||
|
||||
|
||||
def test_brief_keeps_the_text_of_a_requests_error_with_no_request() -> None:
|
||||
assert brief(requests.JSONDecodeError("Expecting value", "<html>", 0)).startswith("Expecting value")
|
||||
text = brief(requests.exceptions.InvalidSchema(f"No connection adapters were found for 'htp{URL[4:]}'"))
|
||||
@@ -120,35 +89,6 @@ def test_a_query_mode_vault_that_is_down_never_logs_its_password(
|
||||
assert vault in vaults.unreachable
|
||||
|
||||
|
||||
def test_an_api_vault_that_answers_html_is_skipped_after_one_warning(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
calls: list[str] = []
|
||||
|
||||
def parked(url: str, **kw: object) -> requests.Response:
|
||||
calls.append(url)
|
||||
return html()
|
||||
|
||||
vault = API("api", "https://api.example/", "tok")
|
||||
monkeypatch.setattr(vault.session, "get", parked)
|
||||
monkeypatch.setattr(vault.session, "post", parked)
|
||||
vaults = Vaults("SVC")
|
||||
vaults.vaults = [vault]
|
||||
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
assert vaults.get_key(KID) == (None, None)
|
||||
assert vaults.get_key(SIBLING) == (None, None)
|
||||
|
||||
assert len(calls) == 1
|
||||
assert vault in vaults.unreachable
|
||||
warnings = [m for m in records(caplog, logging.WARNING) if m.startswith("Failed to get key")]
|
||||
assert warnings == ["Failed to get key from Vault 'api': HTTP 200 text/html response is not a JSON object"]
|
||||
assert not [r for r in caplog.records if "<html" in r.getMessage()]
|
||||
with pytest.raises(ConnectionError):
|
||||
vault.add_keys("EXAMPLE", {KID: "bb" * 16})
|
||||
assert len(calls) == 2
|
||||
|
||||
|
||||
def test_a_broken_sqlite_file_warns_once_and_is_still_used(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user