Skip to content

Commit

Permalink
latest black linter
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelchcki committed Jun 24, 2024
1 parent 4430ce0 commit a3e92ae
Show file tree
Hide file tree
Showing 131 changed files with 2,211 additions and 919 deletions.
20 changes: 16 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ def pytest_addoption(parser):

# report data to feature parity dashboard
parser.addoption(
"--report-run-url", type=str, action="store", default=None, help="URI of the run who produced the report",
"--report-run-url",
type=str,
action="store",
default=None,
help="URI of the run who produced the report",
)
parser.addoption(
"--report-environment", type=str, action="store", default=None, help="The environment the test is run under",
"--report-environment",
type=str,
action="store",
default=None,
help="The environment the test is run under",
)


Expand Down Expand Up @@ -353,13 +361,17 @@ def pytest_sessionfinish(session, exitstatus):
if not hasattr(session.config, "workerinput"):
with open(f"{context.scenario.host_log_folder}/known_versions.json", "w", encoding="utf-8") as f:
json.dump(
{library: sorted(versions) for library, versions in LibraryVersion.known_versions.items()}, f, indent=2,
{library: sorted(versions) for library, versions in LibraryVersion.known_versions.items()},
f,
indent=2,
)

data = session.config._json_report.report # pylint: disable=protected-access

junit_modifyreport(
data, session.config.option.xmlpath, junit_properties=context.scenario.get_junit_properties(),
data,
session.config.option.xmlpath,
junit_properties=context.scenario.get_junit_properties(),
)

export_feature_parity_dashboard(session, data)
Expand Down
1 change: 1 addition & 0 deletions docs/architecture/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# - Skip for every library except one
# @irrelevant(context.library = "dotnet", reason="only for .NET")


# To run an individual test: ./run.sh tests/test_traces.py::Test_Misc::test_main
class Test_Misc:
"""*ATTENTION*: This is where you summarize the test"""
Expand Down
17 changes: 0 additions & 17 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
nix2containerPkg.url = "github:nlewo/nix2container";

nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin";
nixpkgs-black-pinned.url = "github:NixOS/nixpkgs/6625284c397b44bc9518a5a1567c1b5aae455c08";

nix-github-actions.url = "github:nix-community/nix-github-actions";
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
Expand All @@ -20,22 +19,11 @@
flake-utils,
treefmt-nix,
nix2containerPkg,
nixpkgs-black-pinned,
nix-github-actions,
}:
(flake-utils.lib.eachDefaultSystem (system: let
pkgs-black = import nixpkgs-black-pinned {inherit system;};
pinned-black = pkgs-black.black;

black-overlay = final: prev: {
black = pinned-black;
};

pkgs = import nixpkgs {
inherit system;
overlays = [
black-overlay
];
};

black = pkgs.black;
Expand Down
6 changes: 3 additions & 3 deletions tests/apm_tracing_e2e/test_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
@features.otel_api
@scenarios.apm_tracing_e2e_otel
class Test_Otel_Span:
"""This is a test that that exercises the full flow of APM Tracing with the use of Datadog OTel API.
"""
"""This is a test that that exercises the full flow of APM Tracing with the use of Datadog OTel API."""

def setup_datadog_otel_span(self):
self.req = weblog.get(
Expand Down Expand Up @@ -49,7 +48,8 @@ def test_datadog_otel_span(self):

def setup_distributed_otel_trace(self):
self.req = weblog.get(
"/e2e_otel_span/mixed_contrib", {"shouldIndex": 1, "parentName": "root-otel-name.dd-resource"},
"/e2e_otel_span/mixed_contrib",
{"shouldIndex": 1, "parentName": "root-otel-name.dd-resource"},
)

@irrelevant(condition=context.library != "golang", reason="Golang specific test with OTel Go contrib package")
Expand Down
2 changes: 1 addition & 1 deletion tests/appsec/api_security/test_apisec_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setup_sampling_rate(self):
weblog.get(
f"/tag_value/api_match_AS001/200?{''.join(random.choices(string.ascii_letters, k=16))}={random.randint(1<<31, (1<<32)-1)}"
)
for _ in range(self.N ** 2)
for _ in range(self.N**2)
]

@irrelevant(
Expand Down
47 changes: 38 additions & 9 deletions tests/appsec/api_security/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class Test_Schema_Request_Cookies:

def setup_request_method(self):
self.request = weblog.get(
"/tag_value/api_match_AS001/200", cookies={"secret": "any_value", "cache": "any_other_value"},
"/tag_value/api_match_AS001/200",
cookies={"secret": "any_value", "cache": "any_other_value"},
)

@missing_feature(context.library < "[email protected]")
Expand Down Expand Up @@ -151,7 +152,10 @@ def test_request_method(self):
"""can provide request request body schema"""
schema = get_schema(self.request, "req.body")
assert self.request.status_code == 200
assert contains(schema, [{"main": [[[{"key": [8], "value": [16]}]], {"len": 2}], "nullable": [1]}],)
assert contains(
schema,
[{"main": [[[{"key": [8], "value": [16]}]], {"len": 2}], "nullable": [1]}],
)


@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
Expand All @@ -177,8 +181,14 @@ def test_request_method(self):
schema = get_schema(self.request, "req.body")
assert self.request.status_code == 200
assert (
contains(schema, [{"main": [[[{"key": [8], "value": [8]}]], {"len": 2}], "nullable": [8]}],)
or contains(schema, [{"main": [[[{"key": [8], "value": [16]}]], {"len": 2}], "nullable": [1]}],)
contains(
schema,
[{"main": [[[{"key": [8], "value": [8]}]], {"len": 2}], "nullable": [8]}],
)
or contains(
schema,
[{"main": [[[{"key": [8], "value": [16]}]], {"len": 2}], "nullable": [1]}],
)
or contains(
schema,
[
Expand Down Expand Up @@ -222,7 +232,12 @@ class Test_Schema_Response_Body:
def setup_request_method(self):
self.request = weblog.post(
"/tag_value/payload_in_response_body_001/200",
data={"test_int": 1, "test_str": "anything", "test_bool": True, "test_float": 1.5234,},
data={
"test_int": 1,
"test_str": "anything",
"test_bool": True,
"test_float": 1.5234,
},
)

def test_request_method(self):
Expand Down Expand Up @@ -251,7 +266,12 @@ class Test_Schema_Response_Body_env_var:
def setup_request_method(self):
self.request = weblog.post(
"/tag_value/payload_in_response_body_001/200?X-option=test_value",
data={"test_int": 1, "test_str": "anything", "test_bool": True, "test_float": 1.5234,},
data={
"test_int": 1,
"test_str": "anything",
"test_bool": True,
"test_float": 1.5234,
},
)

def test_request_method(self):
Expand All @@ -277,8 +297,14 @@ class Test_Scanners:
def setup_request_method(self):
self.request = weblog.get(
"/tag_value/api_match_AS001/200",
cookies={"mastercard": "5123456789123456", "authorization": "digest_a0b1c2", "SSN": "123-45-6789",},
headers={"authorization": "digest a0b1c2",},
cookies={
"mastercard": "5123456789123456",
"authorization": "digest_a0b1c2",
"SSN": "123-45-6789",
},
headers={
"authorization": "digest a0b1c2",
},
)

@missing_feature(context.library < "[email protected]")
Expand All @@ -295,7 +321,10 @@ def test_request_method(self):
{
"SSN": [8, {"category": "pii", "type": "us_ssn"}],
"authorization": [8],
"mastercard": [8, {"card_type": "mastercard", "type": "card", "category": "payment"},],
"mastercard": [
8,
{"card_type": "mastercard", "type": "card", "category": "payment"},
],
},
{
"SSN": [[[8, {"category": "pii", "type": "us_ssn"}]], {"len": 1}],
Expand Down
4 changes: 2 additions & 2 deletions tests/appsec/iast/source/test_parameter_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class TestParameterName(BaseSourceTest):
@bug(library="python", reason="Python frameworks need a header, if not, 415 status code")
@missing_feature(library="dotnet", reason="Tainted as request body")
def test_source_post_reported(self):
""" for use case where only one is reported, we want to keep a test on the one reported """
"""for use case where only one is reported, we want to keep a test on the one reported"""
self.validate_request_reported(self.requests["POST"])

setup_source_get_reported = BaseSourceTest.setup_source_reported

@bug(weblog_variant="jersey-grizzly2", reason="Not reported")
@bug(weblog_variant="resteasy-netty3", reason="Not reported")
def test_source_get_reported(self):
""" for use case where only one is reported, we want to keep a test on the one reported """
"""for use case where only one is reported, we want to keep a test on the one reported"""
self.validate_request_reported(self.requests["GET"])

@missing_feature(weblog_variant="express4", reason="Tainted as request body")
Expand Down
8 changes: 4 additions & 4 deletions tests/appsec/rasp/test_lfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@features.rasp_local_file_inclusion
@scenarios.appsec_rasp
class Test_Lfi_UrlQuery:
""" Local file inclusion through query parameters """
"""Local file inclusion through query parameters"""

def setup_lfi_get(self):
self.r = weblog.get("/rasp/lfi", params={"file": "../etc/passwd"})
Expand All @@ -31,7 +31,7 @@ def test_lfi_get(self):
@features.rasp_local_file_inclusion
@scenarios.appsec_rasp
class Test_Lfi_BodyUrlEncoded:
""" Local file inclusion through a url-encoded body parameter """
"""Local file inclusion through a url-encoded body parameter"""

def setup_lfi_post_urlencoded(self):
self.r = weblog.post("/rasp/lfi", data={"file": "../etc/passwd"})
Expand All @@ -53,7 +53,7 @@ def test_lfi_post_urlencoded(self):
@features.rasp_local_file_inclusion
@scenarios.appsec_rasp
class Test_Lfi_BodyXml:
""" Local file inclusion through an xml body parameter """
"""Local file inclusion through an xml body parameter"""

def setup_lfi_post_xml(self):
data = "<?xml version='1.0' encoding='utf-8'?><file>../etc/passwd</file>"
Expand All @@ -76,7 +76,7 @@ def test_lfi_post_xml(self):
@features.rasp_local_file_inclusion
@scenarios.appsec_rasp
class Test_Lfi_BodyJson:
""" Local file inclusion through a json body parameter """
"""Local file inclusion through a json body parameter"""

def setup_lfi_post_json(self):
"""AppSec detects attacks in JSON body values"""
Expand Down
4 changes: 2 additions & 2 deletions tests/appsec/rasp/test_span_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def validate_span_tags(request, expected_meta=[], expected_metrics=[]):
@features.rasp_span_tags
@scenarios.appsec_rasp
class Test_Mandatory_SpanTags:
""" Validate span tag generation on exploit attempts """
"""Validate span tag generation on exploit attempts"""

def setup_lfi_span_tags(self):
self.r = weblog.get("/rasp/lfi", params={"file": "../etc/passwd"})
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_sqli_span_tags(self):
@features.rasp_span_tags
@scenarios.appsec_rasp
class Test_Optional_SpanTags:
""" Validate span tag generation on exploit attempts """
"""Validate span tag generation on exploit attempts"""

def setup_lfi_span_tags(self):
self.r = weblog.get("/rasp/lfi", params={"file": "../etc/passwd"})
Expand Down
8 changes: 4 additions & 4 deletions tests/appsec/rasp/test_sqli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@features.rasp_sql_injection
@scenarios.appsec_rasp
class Test_Sqli_UrlQuery:
""" SQL Injection through query parameters """
"""SQL Injection through query parameters"""

def setup_sqli_get(self):
self.r = weblog.get("/rasp/sqli", params={"user_id": "' OR 1 = 1 --"})
Expand All @@ -32,7 +32,7 @@ def test_sqli_get(self):
@features.rasp_sql_injection
@scenarios.appsec_rasp
class Test_Sqli_BodyUrlEncoded:
""" SQL Injection through a url-encoded body parameter """
"""SQL Injection through a url-encoded body parameter"""

def setup_sqli_post_urlencoded(self):
self.r = weblog.post("/rasp/sqli", data={"user_id": "' OR 1 = 1 --"})
Expand All @@ -55,7 +55,7 @@ def test_sqli_post_urlencoded(self):
@features.rasp_sql_injection
@scenarios.appsec_rasp
class Test_Sqli_BodyXml:
""" SQL Injection through an xml body parameter """
"""SQL Injection through an xml body parameter"""

def setup_sqli_post_xml(self):
data = "<?xml version='1.0' encoding='utf-8'?><user_id>' OR 1 = 1 --</user_id>"
Expand All @@ -79,7 +79,7 @@ def test_sqli_post_xml(self):
@features.rasp_sql_injection
@scenarios.appsec_rasp
class Test_Sqli_BodyJson:
""" SQL Injection through a json body parameter """
"""SQL Injection through a json body parameter"""

def setup_sqli_post_json(self):
"""AppSec detects attacks in JSON body values"""
Expand Down
8 changes: 4 additions & 4 deletions tests/appsec/rasp/test_ssrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@features.rasp_server_side_request_forgery
@scenarios.appsec_rasp
class Test_Ssrf_UrlQuery:
""" Server-side request forgery through query parameters """
"""Server-side request forgery through query parameters"""

def setup_ssrf_get(self):
self.r = weblog.get("/rasp/ssrf", params={"domain": "169.254.169.254"})
Expand All @@ -31,7 +31,7 @@ def test_ssrf_get(self):
@features.rasp_server_side_request_forgery
@scenarios.appsec_rasp
class Test_Ssrf_BodyUrlEncoded:
""" Server-side request forgery through a url-encoded body parameter """
"""Server-side request forgery through a url-encoded body parameter"""

def setup_ssrf_post_urlencoded(self):
self.r = weblog.post("/rasp/ssrf", data={"domain": "169.254.169.254"})
Expand All @@ -53,7 +53,7 @@ def test_ssrf_post_urlencoded(self):
@features.rasp_server_side_request_forgery
@scenarios.appsec_rasp
class Test_Ssrf_BodyXml:
""" Server-side request forgery through an xml body parameter """
"""Server-side request forgery through an xml body parameter"""

def setup_ssrf_post_xml(self):
data = f"<?xml version='1.0' encoding='utf-8'?><domain>169.254.169.254</domain>"
Expand All @@ -76,7 +76,7 @@ def test_ssrf_post_xml(self):
@features.rasp_server_side_request_forgery
@scenarios.appsec_rasp
class Test_Ssrf_BodyJson:
""" Server-side request forgery through a json body parameter """
"""Server-side request forgery through a json body parameter"""

def setup_ssrf_post_json(self):
"""AppSec detects attacks in JSON body values"""
Expand Down
2 changes: 1 addition & 1 deletion tests/appsec/rasp/test_stack_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def validate_stack_traces(request):
@features.rasp_stack_trace
@scenarios.appsec_rasp
class Test_StackTrace:
""" Validate stack trace generation on exploit attempts """
"""Validate stack trace generation on exploit attempts"""

def setup_lfi_stack_trace(self):
self.r = weblog.get("/rasp/lfi", params={"file": "../etc/passwd"})
Expand Down
Loading

0 comments on commit a3e92ae

Please sign in to comment.