dev-bucket-sync / tests /test_audit.py
cmpatino's picture
cmpatino HF Staff
Upload folder using huggingface_hub
30ea0e9 verified
Raw History Blame Contribute Delete
988 Bytes
import json
import pytest
from app.audit import AuditLogger
from app.config import Settings
from fakes import FakeHub
@pytest.mark.parametrize(
"audit_bucket, in_org",
[("test-org/test-audit", True), ("test-org-admin/test-audit", False)],
)
def test_caller_ip_omitted_when_audit_bucket_is_in_challenge_org(audit_bucket, in_org):
settings = Settings(ORG="test-org", COLLAB_SLUG="test", AUDIT_BUCKET=audit_bucket)
assert settings.audit_bucket_in_org is in_org
hub = FakeHub(settings)
AuditLogger(hub, record_client=not settings.audit_bucket_in_org).write(
agent_id="agent-1", route="/v1/sync", via=None, source=None,
target_path=None, bytes_count=0, status_code=200,
caller_ip="203.0.113.7", user_agent="curl/8",
)
(log,) = hub.buckets[audit_bucket].values()
record = json.loads(log)
assert record["agent_id"] == "agent-1"
assert ("caller_ip" in record) is not in_org
assert ("user_agent" in record) is not in_org