Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions tests/appsec/test_event_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2021 Datadog, Inc.
from utils import weblog, interfaces, features
from utils.dd_types import DataDogLibrarySpan
from tests.appsec.utils import find_series
from tests.appsec.utils import find_series, is_same_boolean

HEADERS = {
"Accept": "text/html",
Expand Down Expand Up @@ -61,7 +61,7 @@ def validate_user_login_success_tags(span: DataDogLibrarySpan):
for tag, expected_value in expected_tags.items():
assert tag in span["meta"], f"Can't find {tag} in span's meta"
value = span["meta"][tag]
if value != expected_value:
if not is_same_boolean(actual=value, expected=expected_value):
raise Exception(f"{tag} value is '{value}', should be '{expected_value}'")

return True
Expand Down Expand Up @@ -127,11 +127,10 @@ def validate_user_login_failure_tags(span: DataDogLibrarySpan):
"appsec.events.users.login.failure.metadata0": "value0",
"appsec.events.users.login.failure.metadata1": "value1",
}

for tag, expected_value in expected_tags.items():
assert tag in span["meta"], f"Can't find {tag} in span's meta"
value = span["meta"][tag]
if value != expected_value:
if not is_same_boolean(actual=value, expected=expected_value):
raise Exception(f"{tag} value is '{value}', should be '{expected_value}'")

return True
Expand Down Expand Up @@ -194,11 +193,11 @@ def validate_custom_event_tags(span: DataDogLibrarySpan):
"appsec.events.system_tests_event.metadata0": "value0",
"appsec.events.system_tests_event.metadata1": "value1",
}

for tag, expected_value in expected_tags.items():
assert tag in span["meta"], f"Can't find {tag} in span's meta"
value = span["meta"][tag]
if value != expected_value:

if not is_same_boolean(actual=value, expected=expected_value):
raise Exception(f"{tag} value is '{value}', should be '{expected_value}'")

return True
Expand Down
4 changes: 2 additions & 2 deletions tests/appsec/test_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from utils.tools import nested_lookup
from utils.dd_constants import SamplingPriority
from utils.dd_types import DataDogLibrarySpan
from tests.appsec.utils import is_same_boolean


RUNTIME_FAMILIES = ["nodejs", "ruby", "jvm", "dotnet", "go", "php", "python", "cpp"]
Expand Down Expand Up @@ -45,8 +46,7 @@ def validate_appsec_event_span_tags(span: DataDogLibrarySpan):

if "appsec.event" not in span["meta"]:
raise Exception("Can't find appsec.event in span's meta")

if span["meta"]["appsec.event"] != "true":
if not is_same_boolean(actual=span["meta"]["appsec.event"], expected="true"):
raise Exception(f'appsec.event in span\'s meta should be "true", not {span["meta"]["appsec.event"]}')

if "_sampling_priority_v1" not in span["metrics"]:
Expand Down
10 changes: 10 additions & 0 deletions tests/appsec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def find_configuration() -> Generator:
yield payload.get("configuration")


# Protocol v1.0 may return booleans as True,
# while older protocols may return them as the string "true".
def _normalize_for_compare(*, value: bool | str) -> str:
return "true" if value is True else ("false" if value is False else value)


def is_same_boolean(*, actual: bool | str, expected: bool | str) -> bool:
return _normalize_for_compare(value=actual) == _normalize_for_compare(value=expected)


class BaseFullDenyListTest:
states: remote_config.RemoteConfigStateResults | None = None

Expand Down
Loading