Skip to content

Commit

Permalink
Add test to find "None" as http.ip
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufede committed Oct 2, 2024
1 parent 64ba71c commit 3d3c3c2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/appsec/appsec/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ddtrace.appsec._processor import _transform_headers
from ddtrace.constants import USER_KEEP
from ddtrace.contrib.trace_utils import set_http_meta
from ddtrace.ext import http
from ddtrace.ext import SpanTypes
from ddtrace.internal import core
from tests.utils import flaky
Expand Down Expand Up @@ -681,3 +682,36 @@ def test_asm_context_registration(tracer_appsec):
span.span_type = SpanTypes.HTTP
assert core.get_item("asm_env") is not None
assert core.get_item("asm_env") is None


@pytest.mark.parametrize(
"received_ip",
[
None,
"",
],
)
@pytest.mark.parametrize(
"request_headers",
[
None,
"",
{},
{"x-forwarded-for": ""},
{"x-forwarded-for": None},
{"x-forwarded-for": "127.0.0.1"},
{"x-client-ip": ""},
{"x-client-ip": None},
{"x-client-ip": "127.0.0.1"},
],
)
def test_set_http_meta_client_ip(tracer_appsec, received_ip, request_headers):
tracer = tracer_appsec
integration_config = Config()
integration_config.is_header_tracing_configured = True
integration_config._header_tag_name = lambda header_name: "http.client_ip"

with _asm_request_context.asm_request_context_manager(), tracer.trace("test", span_type=SpanTypes.WEB) as span:
set_http_meta(span, integration_config, peer_ip=received_ip, request_headers=request_headers)

assert span.get_metric(http.CLIENT_IP) is None

0 comments on commit 3d3c3c2

Please sign in to comment.