Files
wehub-resource-sync bf2343b7e4
Integration Tests - MySQL + Elasticsearch / Detect Changes (push) Has been cancelled
Integration Tests - MySQL + Elasticsearch / integration-tests-mysql-elasticsearch (push) Has been cancelled
Integration Tests - PostgreSQL + Elasticsearch + Redis / Detect Changes (push) Has been cancelled
Integration Tests - PostgreSQL + Elasticsearch + Redis / integration-tests-postgres-elasticsearch-redis (push) Has been cancelled
Integration Tests - PostgreSQL + OpenSearch / Detect Changes (push) Has been cancelled
Integration Tests - PostgreSQL + OpenSearch / integration-tests-postgres-opensearch (push) Has been cancelled
Java Checkstyle / java-checkstyle (push) Has been cancelled
Maven Collate Tests / maven-collate-ci (push) Has been cancelled
OpenMetadata Service Unit Tests / openmetadata-service-unit-tests-status (push) Has been cancelled
Publish Package to Maven Central Repository / publish-maven-packages (push) Has been cancelled
OpenMetadata Service Unit Tests / Detect Changes (push) Has been cancelled
OpenMetadata Service Unit Tests / openmetadata-service-unit-tests (push) Has been cancelled
OpenMetadata Service Unit Tests / k8s_operator-unit-tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:35:45 +08:00

51 lines
1.9 KiB
Python

import pytest
from metadata.utils.credentials import normalize_pem_string
def test_normalizes_escaped_newlines_for_pem():
"""It should replace literal '\\n' with actual newlines for PEM-like strings."""
pem = "-----BEGIN PRIVATE KEY-----\\nABCDEF\\n-----END PRIVATE KEY-----"
result = normalize_pem_string(pem)
# Should contain actual newlines, not literal \n
assert "\n" in result
assert "\\n" not in result
# Should start/end correctly
assert result.startswith("-----BEGIN PRIVATE KEY-----")
assert result.endswith("-----END PRIVATE KEY-----")
def test_does_not_change_already_correct_pem():
"""It should leave PEMs with real newlines unchanged."""
pem = "-----BEGIN PRIVATE KEY-----\nABCDEF\n-----END PRIVATE KEY-----"
result = normalize_pem_string(pem)
assert result == pem
def test_ignores_non_pem_strings():
"""It should not touch non-PEM strings, even if they contain '\\n'."""
s = "password\\nwith\\nnewlines"
result = normalize_pem_string(s)
assert result == s # unchanged
def test_handles_other_pem_types():
"""It should detect and normalize other PEM headers like certificates."""
cert = "-----BEGIN CERTIFICATE-----\\nXYZ\\n-----END CERTIFICATE-----"
result = normalize_pem_string(cert)
assert "\n" in result and "\\n" not in result
def test_mixed_case_is_left_unchanged():
"""If both literal and real newlines exist, don't double-convert."""
mixed = "-----BEGIN PRIVATE KEY-----\\nABC\nDEF\\n-----END PRIVATE KEY-----"
result = normalize_pem_string(mixed)
# It should be left unchanged, since it has both kinds of newlines
assert result == mixed
@pytest.mark.parametrize("invalid", [None, 123, b"not a string"])
def test_non_string_inputs_return_untouched(invalid):
"""Non-string inputs should be returned as-is (no crash)."""
assert normalize_pem_string(invalid) == invalid