File size: 988 Bytes
30ea0e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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