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: 2 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ ignore = [
"T201", # 15 occurences [*] print
"FBT001", # 12 occurences [ ] boolean-type-hint-positional-argument
"SLF001", # 12 occurences [ ] private-member-access
"SIM118", # 12 occurences [*] in-dict-keys
"UP035", # 12 occurences [ ] deprecated-import
"S105", # 10 occurences [ ] hardcoded-password-string
"B015", # 10 occurences [ ] useless-comparison
Expand All @@ -226,32 +225,26 @@ ignore = [
"PT015", # 7 occurences [ ] pytest-assert-always-false
"N815", # 7 occurences [ ] mixed-case-variable-in-class-scope
"PT006", # 6 occurences [*] pytest-parametrize-names-wrong-type
"RET504", # 6 occurences [*] unnecessary-assign
"N803", # 6 occurences [ ] invalid-argument-name
"E712", # 6 occurences [*] true-false-comparison
"E741", # 6 occurences [ ] ambiguous-variable-name
"S113", # 5 occurences [ ] request-without-timeout
"PT011", # 5 occurences [ ] pytest-raises-too-broad
"E731", # 5 occurences [*] lambda-assignment
"RUF005", # 5 occurences [ ] collection-literal-concatenation
"B006", # 4 occurences [*] mutable-argument-default
"PIE794", # 4 occurences [*] duplicate-class-field-definition
"PTH103", # 4 occurences [ ] os-makedirs
"PLW2901", # 4 occurences [ ] redefined-loop-name
"PTH112", # 3 occurences [ ] os-path-isdir
"RUF017", # 3 occurences [*] quadratic-list-summation
"ANN002", # 2 occurences [ ] missing-type-args
"ASYNC230", # 2 occurences [ ] blocking-open-call-in-async-function
"S605", # 2 occurences [ ] start-process-with-a-shell
"C408", # 2 occurences [*] unnecessary-collection-call
"C416", # 2 occurences [*] unnecessary-comprehension
"PIE810", # 2 occurences [*] multiple-starts-ends-with
"PTH100", # 2 occurences [ ] os-path-abspath
"PTH109", # 2 occurences [ ] os-getcwd

# keep those exceptions
"C400", # unnecessary-generator-list: explicit list is more readable for non-python users
"C401", # unnecessary-generator-set: explicit set is more readable for non-python users
"C408", # unnecessary-collection-call: explicit tuple is more readable for non-python users
"C416", # unnecessary-comprehension: may make the code less readable for non-python users
"FIX003", # line-contains-xxx: freedom of speech!
"FIX004", # line-contains-xxx: freedom of speech!
"PLR1730", # if-stmt-min-max: not clear that it makes the code easier to read
Expand Down
2 changes: 1 addition & 1 deletion tests/apm_tracing_e2e/test_single_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_child_span_is_single_span(self):

def _assert_single_span_event(event, name, is_root):
assert event["operation_name"] == name
assert event["single_span"] == True
assert event["single_span"] is True
assert event["ingestion_reason"] == "single_span"
parent_id = event["parent_id"]
if is_root:
Expand Down
8 changes: 6 additions & 2 deletions tests/appsec/iast/sink/test_hardcoded_passwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ def get_hardcoded_password_vulnerabilities(self):
assert spans_meta, "No spans meta found"
iast_events = [meta.get("_dd.iast.json") for meta in spans_meta if meta.get("_dd.iast.json")]
assert iast_events, "No iast events found"
vulnerabilities = [event.get("vulnerabilities") for event in iast_events if event.get("vulnerabilities")]

vulnerabilities: list = []
for event in iast_events:
vulnerabilities.extend(event.get("vulnerabilities", []))

assert vulnerabilities, "No vulnerabilities found"
vulnerabilities = sum(vulnerabilities, []) # set all the vulnerabilities in a single list

hardcoded_passwords = [vuln for vuln in vulnerabilities if vuln.get("type") == "HARDCODED_PASSWORD"]
assert hardcoded_passwords, "No hardcoded passwords found"
return hardcoded_passwords
Expand Down
8 changes: 6 additions & 2 deletions tests/appsec/iast/sink/test_hardcoded_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ def get_hardcoded_secret_vulnerabilities():
assert spans_meta, "No spans meta found"
iast_events = [meta.get("_dd.iast.json") for meta in spans_meta if meta.get("_dd.iast.json")]
assert iast_events, "No iast events found"
vulnerabilities = [event.get("vulnerabilities") for event in iast_events if event.get("vulnerabilities")]

vulnerabilities: list = []
for event in iast_events:
vulnerabilities.extend(event.get("vulnerabilities", []))

assert vulnerabilities, "No vulnerabilities found"
vulnerabilities = sum(vulnerabilities, []) # set all the vulnerabilities in a single list

hardcoded_secrets = [vuln for vuln in vulnerabilities if vuln.get("type") == "HARDCODED_SECRET"]
assert hardcoded_secrets, "No hardcoded secrets found"
return hardcoded_secrets
Expand Down
11 changes: 7 additions & 4 deletions tests/appsec/iast/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ def get_all_iast_events():


def get_iast_sources(iast_events):
sources = [event.get("sources") for event in iast_events if event.get("sources")]
sources: list = []

for event in iast_events:
sources.extend(event.get("sources", []))

assert sources, "No sources found"
sources = sum(sources, []) # set all the sources in a single list

return sources


Expand Down Expand Up @@ -365,8 +369,7 @@ def check_test_telemetry_should_execute(self):

def get_sources(self, request):
iast = get_iast_event(request=request)
sources = iast["sources"]
return sources
return iast["sources"]

def validate_request_reported(self, request, source_type=None):
if source_type is None: # allow to overwrite source_type for parameter value node's use case
Expand Down
2 changes: 1 addition & 1 deletion tests/appsec/rasp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from utils import interfaces


def validate_span_tags(request, expected_meta=[], expected_metrics=[]):
def validate_span_tags(request, expected_meta=(), expected_metrics=()):
"""Validate RASP span tags are added when an event is generated"""
spans = [s for _, s in interfaces.library.get_root_spans(request=request)]
assert spans, "No spans to validate"
Expand Down
2 changes: 1 addition & 1 deletion tests/auto_inject/test_blocklist_auto_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ def test_builtIn_instrument_args(self, virtual_machine):
for command in self.buildIn_args_commands_injected[language]:
local_log_file = self._execute_remote_command(ssh_client, command)
assert (
command_injection_skipped(command, local_log_file) == False
command_injection_skipped(command, local_log_file) is False
), f"The command {command} was not instrumented, but it should be instrumented!"
2 changes: 1 addition & 1 deletion tests/debugger/test_debugger_expression_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def _method_and_language_to_line_number(self, method, language):
"Nulls": {"java": [130], "dotnet": [127], "python": [136]},
}.get(method, {}).get(language, [])

def _create_expression_probes(self, methodName, expressions, lines=[]):
def _create_expression_probes(self, methodName, expressions, lines=()):
probes = []
expected_message_map = {}
prob_types = ["method"]
Expand Down
5 changes: 2 additions & 3 deletions tests/debugger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ def extract_probe_ids(probes):
return []


def _get_path(test_name, suffix):
def _get_path(test_name, suffix) -> str:
filename = test_name + "_" + _Base_Debugger_Test.tracer["language"] + "_" + suffix + ".json"
path = os.path.join(_CUR_DIR, "approvals", filename)
return path
return os.path.join(_CUR_DIR, "approvals", filename)


def write_approval(data, test_name, suffix):
Expand Down
2 changes: 1 addition & 1 deletion tests/docker_ssi/test_docker_ssi.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_telemetry_abort(self):
assert inject_result is not None, "No telemetry data found for inject.success, inject.skip or inject.error"

# The injector detected by itself that the version is not supported
if inject_result == False:
if inject_result is False:
return

# There is telemetry data about the library entrypoint. We only validate there is data
Expand Down
2 changes: 1 addition & 1 deletion tests/fuzzer/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _load_dir(base_dirname):
_load_dir(os.path.join(base_dirname, dirname))

for filename in filenames:
if filename.endswith(".json") or filename.endswith(".dump"):
if filename.endswith((".json", ".dump")):
_load_file(os.path.join(base_dirname, filename))

if Path(source).is_file():
Expand Down
7 changes: 1 addition & 6 deletions tests/integrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ def _setup(self):
setup_db_system = _setup
setup_runtime_id = _setup
setup_span_kind = _setup
setup_sql_traces = _setup
setup_resource = _setup
setup_db_type = _setup
setup_db_name = _setup
setup_error_type_and_stack = _setup
setup_error_message = _setup
setup_obfuscate_query = _setup
Expand Down Expand Up @@ -295,8 +291,7 @@ def get_bytes(s):
def sha_hash(checkpoint_string):
if isinstance(checkpoint_string, str):
checkpoint_string = checkpoint_string.encode("utf-8")
hash_obj = hashlib.md5(checkpoint_string).digest()[:8]
return hash_obj
return hashlib.md5(checkpoint_string).digest()[:8]


def compute_dsm_hash_nodejs(parent_hash, edge_tags):
Expand Down
3 changes: 2 additions & 1 deletion tests/parametric/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
from collections.abc import Iterable
import contextlib
import dataclasses
import os
Expand Down Expand Up @@ -438,7 +439,7 @@ def wait_for_rc_apply_state(
time.sleep(0.01)
raise AssertionError("No RemoteConfig apply status found, got requests %r" % rc_reqs)

def wait_for_rc_capabilities(self, capabilities: list[int] = [], wait_loops: int = 100):
def wait_for_rc_capabilities(self, capabilities: Iterable[int] = (), wait_loops: int = 100):
"""Wait for the given RemoteConfig apply state to be received by the test agent."""
rc_reqs = []
capabilities_seen = set()
Expand Down
2 changes: 1 addition & 1 deletion tests/parametric/test_config_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def test_setting_trace_rate_limit(self, library_env, test_agent, test_library):
@scenarios.parametric
@features.tracing_configuration_consistency
class Test_Config_Tags:
@parametrize("library_env", [{"DD_TAGS": key} for key in tag_scenarios.keys()])
@parametrize("library_env", [{"DD_TAGS": key} for key in tag_scenarios])
def test_comma_space_tag_separation(self, library_env, test_agent, test_library):
expected_local_tags = []
if "DD_TAGS" in library_env:
Expand Down
18 changes: 9 additions & 9 deletions tests/parametric/test_headers_baggage.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_headers_baggage_default_D001(self, test_agent, test_library):
span = find_only_span(test_agent.wait_for_num_traces(1))
assert span.get("trace_id") == 123456789
assert span.get("parent_id") == 987654321
assert "baggage" in headers.keys()
assert "baggage" in headers
assert headers["baggage"] == "foo=bar"

@only_baggage_enabled()
Expand All @@ -44,9 +44,9 @@ def test_headers_baggage_only_D002(self, test_library):
[["x-datadog-trace-id", "123456789"], ["baggage", "foo=bar"]]
)

assert "x-datadog-trace-id" not in headers.keys()
assert "x-datadog-parent-id" not in headers.keys()
assert "baggage" in headers.keys()
assert "x-datadog-trace-id" not in headers
assert "x-datadog-parent-id" not in headers
assert "baggage" in headers
assert headers["baggage"] == "foo=bar"

@disable_baggage()
Expand All @@ -60,7 +60,7 @@ def test_baggage_disable_settings_D003(self, test_agent, test_library):
span = find_only_span(test_agent.wait_for_num_traces(1))
assert span.get("trace_id") == 123456789
assert span.get("parent_id") == 987654321
assert "baggage" not in headers.keys()
assert "baggage" not in headers

def test_baggage_inject_header_D004(self, test_library):
"""Testing baggage header injection, proper concatenation of key value pairs, and encoding"""
Expand Down Expand Up @@ -178,28 +178,28 @@ def test_baggage_malformed_headers_D012(self, test_library, test_agent):
[["baggage", "no-equal-sign,foo=gets-dropped-because-previous-pair-is-malformed"]],
)

assert "baggage" not in headers.keys()
assert "baggage" not in headers

def test_baggage_malformed_headers_D013(self, test_library):
"""Ensure that malformed baggage headers are handled properly. Unable to use get_baggage functions because it does not return anything"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([["baggage", "=no-key"]])

assert "baggage" not in headers.keys()
assert "baggage" not in headers

def test_baggage_malformed_headers_D014(self, test_library):
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([["baggage", "no-value="]])

assert "baggage" not in headers.keys()
assert "baggage" not in headers

def test_baggage_malformed_headers_D015(self, test_library):
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[["baggage", "foo=gets-dropped-because-subsequent-pair-is-malformed,="]],
)

assert "baggage" not in headers.keys()
assert "baggage" not in headers

def test_baggageheader_maxitems_inject_D016(self, test_library):
"""Ensure that baggage headers are not injected when the number of baggage items exceeds the maximum number of items."""
Expand Down
6 changes: 3 additions & 3 deletions tests/parametric/test_span_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def test_root_span_selected_and_child_dropped_by_sss_when_dropping_policy_is_act
We're essentially testing to make sure that the child unsampled span is dropped on the tracer side because of
the activate dropping policy.
"""
assert test_agent.info()["client_drop_p0s"] == True, "Client drop p0s expected to be enabled"
assert test_agent.info()["client_drop_p0s"] is True, "Client drop p0s expected to be enabled"

with test_library:
with test_library.dd_start_span(name="parent", service="webserver"):
Expand Down Expand Up @@ -672,7 +672,7 @@ def test_child_span_selected_and_root_dropped_by_sss_when_dropping_policy_is_act
We're essentially testing to make sure that the root unsampled span is dropped on the tracer side because of
the activate dropping policy.
"""
assert test_agent.info()["client_drop_p0s"] == True, "Client drop p0s expected to be enabled"
assert test_agent.info()["client_drop_p0s"] is True, "Client drop p0s expected to be enabled"

with test_library:
with test_library.dd_start_span(name="parent", service="webserver") as ps1:
Expand Down Expand Up @@ -726,7 +726,7 @@ def test_entire_trace_dropped_when_dropping_policy_is_active018(self, test_agent
We're essentially testing to make sure that the entire unsampled trace is dropped on the tracer side because of
the activate dropping policy.
"""
assert test_agent.info()["client_drop_p0s"] == True, "Client drop p0s expected to be enabled"
assert test_agent.info()["client_drop_p0s"] is True, "Client drop p0s expected to be enabled"

with test_library:
with test_library.dd_start_span(name="parent", service="webserver"):
Expand Down
5 changes: 2 additions & 3 deletions tests/parametric/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,7 @@ def get_app_started_configuration_by_name(test_agent, test_library):

configuration = body["payload"]["configuration"]

configuration_by_name = {item["name"]: item for item in configuration}
return configuration_by_name
return {item["name"]: item for item in configuration}

return None

Expand Down Expand Up @@ -628,4 +627,4 @@ def test_telemetry_sca_enabled_not_propagated(self, library_env, test_agent, tes
assert cfg_appsec_enabled is not None, f"Missing telemetry config item for '{DD_APPSEC_SCA_ENABLED}'"
assert cfg_appsec_enabled.get("value") is None
else:
assert DD_APPSEC_SCA_ENABLED not in configuration_by_name.keys()
assert DD_APPSEC_SCA_ENABLED not in configuration_by_name
3 changes: 1 addition & 2 deletions tests/test_config_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,5 +639,4 @@ def parse_log_injection_message(log_message):
except json.JSONDecodeError:
continue
if message.get("dd") and message.get(log_injection_fields[context.library.library]["message"]) == log_message:
dd = message.get("dd")
return dd
return message.get("dd")
2 changes: 1 addition & 1 deletion tests/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def save_data(data, container):
)

if len(self.library_requests) != 0:
for s, r in self.library_requests.keys():
for s, r in self.library_requests:
logger.error(f"seq_id: {s}, runtime_id: {r}")

raise Exception("The following telemetry messages were not forwarded by the agent")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_the_test/test_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def test_utils():
# verify that all files in test folder are either a test file, a utils.py file or a conftest.py file
for folder, _, files in os.walk("tests"):
if folder.startswith("tests/fuzzer") or folder.startswith("tests/perfs"):
if folder.startswith(("tests/fuzzer", "tests/perfs")):
# do not check these folders, they are particular use cases
continue

Expand Down