|
3 | 3 | # Copyright 2021 Datadog, Inc.
|
4 | 4 |
|
5 | 5 | 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 |
6 | 16 |
|
7 | 17 |
|
8 | 18 | @features.not_reported
|
9 | 19 | class Test_NoExceptions:
|
10 |
| - """There is not exception in dotnet-tracer-managed log files""" |
| 20 | + """No unexpected exceptions or errors.""" |
11 | 21 |
|
12 | 22 | @irrelevant(context.library != "dotnet", reason="only for .NET")
|
13 | 23 | def test_dotnet(self):
|
| 24 | + """There is not exception in dotnet-tracer-managed log files""" |
14 | 25 | interfaces.library_dotnet_managed.assert_absence(
|
15 | 26 | pattern=r"[A-Za-z]+\.[A-Za-z]*Exception",
|
16 | 27 | allowed_patterns=[
|
17 | 28 | r"System.DllNotFoundException: Unable to load shared library 'Datadog.AutoInstrumentation.Profiler.Native.x64'", # pylint: disable=line-too-long
|
18 | 29 | r"Logger retrieved for: Datadog.Trace.Debugger.ExceptionAutoInstrumentation.ExceptionDebugging", # pylint: disable=line-too-long
|
19 | 30 | ],
|
20 | 31 | )
|
| 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