Skip to content

Commit 966f717

Browse files
committed
[java] Check Java logs
1 parent 4e32064 commit 966f717

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

Diff for: tests/test_library_logs.py

+52-1
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,69 @@
33
# Copyright 2021 Datadog, Inc.
44

55
from utils import context, interfaces, irrelevant, features
6+
import itertools
7+
import re
8+
from typing import Pattern
9+
10+
11+
def matches_any(patterns: list[Pattern], string: str):
12+
for pattern in patterns:
13+
if re.fullmatch(pattern, string):
14+
return True
15+
return False
616

717

818
@features.not_reported
919
class Test_NoExceptions:
10-
"""There is not exception in dotnet-tracer-managed log files"""
20+
"""No unexpected exceptions or errors."""
1121

1222
@irrelevant(context.library != "dotnet", reason="only for .NET")
1323
def test_dotnet(self):
24+
"""There is not exception in dotnet-tracer-managed log files"""
1425
interfaces.library_dotnet_managed.assert_absence(
1526
pattern=r"[A-Za-z]+\.[A-Za-z]*Exception",
1627
allowed_patterns=[
1728
r"System.DllNotFoundException: Unable to load shared library 'Datadog.AutoInstrumentation.Profiler.Native.x64'", # pylint: disable=line-too-long
1829
r"Logger retrieved for: Datadog.Trace.Debugger.ExceptionAutoInstrumentation.ExceptionDebugging", # pylint: disable=line-too-long
1930
],
2031
)
32+
33+
@irrelevant(context.library != "java", reason="only for Java")
34+
def test_java_logs(self):
35+
"""Test Java logs for unexpected errors."""
36+
java_allowed_patterns: list[Pattern] | list[str] = [
37+
r".*"
38+
+ re.escape(
39+
"Skipped authentication, auth=org.springframework.security.authentication.AnonymousAuthenticationToken"
40+
),
41+
# APPSEC-56726:
42+
r".*" + re.escape("Attempt to replace context value for Address{key='usr.login'}"),
43+
# APPSEC-56727:
44+
r".*org.hsqldb.HsqlException.*",
45+
# APPSEC-56728:
46+
r".*getWriter.* has already been called for this response.*",
47+
# APPSEC-56729:
48+
r".*java.lang.NullPointerException: null.*at com.datadoghq.system_tests.iast.utils.SqlExamples.fetchUsers.*",
49+
]
50+
java_allowed_patterns = [re.compile(p, re.MULTILINE | re.DOTALL) for p in java_allowed_patterns]
51+
logs = list(interfaces.library_stdout.get_data())
52+
logs = list({l["raw"] for l in logs})
53+
logs = [l for l in logs if "ERROR" in l]
54+
logs = [l for l in logs if not matches_any(java_allowed_patterns, l)]
55+
assert not logs
56+
57+
@irrelevant(context.library != "java", reason="only for Java")
58+
def test_java_telemetry_logs(self):
59+
"""Test Java telemetry logs for unexpected errors."""
60+
java_allowed_patterns: list[Pattern] | list[str] = [
61+
re.escape("Skipped authentication, auth={}"),
62+
# APPSEC-56726
63+
re.escape("Attempt to replace context value for {}"),
64+
]
65+
java_allowed_patterns = [re.compile(p, re.MULTILINE | re.DOTALL) for p in java_allowed_patterns]
66+
data = interfaces.library.get_telemetry_data()
67+
data = [d["request"]["content"] for d in data]
68+
data = [d["payload"]["logs"] for d in data if d.get("request_type") == "logs"]
69+
data = list(itertools.chain(*data))
70+
data = [d for d in data if not matches_any(java_allowed_patterns, d["message"])]
71+
assert not data

0 commit comments

Comments
 (0)