Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasShabi committed Oct 14, 2024
1 parent 7fddeae commit f1b24ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions tests/appsec/api_security/test_apisec_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def setup_sampling_rate(self):
for _ in range(self.N ** 2)
]

@irrelevant(
context.library in ("nodejs", "python"), reason="New sampling algorithm tests have been implemented"
)
@irrelevant(context.library in ("nodejs", "python"), reason="New sampling algorithm tests have been implemented")
def test_sampling_rate(self):
"""can provide request header schema"""
N = self.N
Expand All @@ -58,6 +56,7 @@ def test_sampling_rate(self):
logger.info(f"API SECURITY SAMPLING RESULT: diff is {diff:.2f} standard deviations")
assert diff <= 4.0, "sampling rate is not 0.1"


@rfc("https://docs.google.com/document/d/1PYoHms9PPXR8V_5_T5-KXAhoFDKQYA8mTnmS12xkGOE")
@scenarios.appsec_api_security_with_sampling
@features.api_security_configuration
Expand All @@ -84,6 +83,7 @@ def test_sampling_delay(self):
assert all(r.status_code == 200 for r in self.all_requests)
assert all(get_schema(r, "req.headers") is None for r in self.all_requests)


@rfc("https://docs.google.com/document/d/1PYoHms9PPXR8V_5_T5-KXAhoFDKQYA8mTnmS12xkGOE")
@scenarios.appsec_api_security_with_sampling
@features.api_security_configuration
Expand All @@ -94,12 +94,7 @@ def setup_sampling_delay(self):
# Wait for 10s to avoid other tests calling same endpoints
time.sleep(10)
self.request1 = weblog.get("/sample_rate_route/21")
self.all_requests = [
weblog.get(
f"/sample_rate_route/{i}"
)
for i in range(20)
]
self.all_requests = [weblog.get(f"/sample_rate_route/{i}") for i in range(20)]

def test_sampling_delay(self):

Expand All @@ -110,6 +105,7 @@ def test_sampling_delay(self):
assert all(r.status_code == 200 for r in self.all_requests)
assert all(get_schema(r, "req.headers") is None for r in self.all_requests)


@rfc("https://docs.google.com/document/d/1PYoHms9PPXR8V_5_T5-KXAhoFDKQYA8mTnmS12xkGOE")
@scenarios.appsec_api_security_with_sampling
@features.api_security_configuration
Expand All @@ -121,7 +117,7 @@ def setup_sampling_delay(self):
time.sleep(10)
self.request1 = weblog.get("/tag_value/api_match_AS002/200")
self.request2 = weblog.get("/tag_value/api_match_AS002/201")
self.all_requests = [weblog.get("/tag_value/api_match_AS003/201") for _ in range(20) ]
self.all_requests = [weblog.get("/tag_value/api_match_AS003/201") for _ in range(20)]

def test_sampling_delay(self):
"""can provide request header schema"""
Expand All @@ -137,6 +133,7 @@ def test_sampling_delay(self):
assert all(r.status_code == 201 for r in self.all_requests)
assert all(get_schema(r, "req.headers") is None for r in self.all_requests)


@rfc("https://docs.google.com/document/d/1PYoHms9PPXR8V_5_T5-KXAhoFDKQYA8mTnmS12xkGOE")
@scenarios.appsec_api_security_with_sampling
@features.api_security_configuration
Expand All @@ -148,7 +145,7 @@ def setup_sampling_delay(self):
time.sleep(13)
self.request1 = weblog.get("/headers")
self.request2 = weblog.get("/headers")
time.sleep(4) # Delay is set to 3s via the env var DD_API_SECURITY_SAMPLE_DELAY
time.sleep(4) # Delay is set to 3s via the env var DD_API_SECURITY_SAMPLE_DELAY
self.request3 = weblog.get("/headers")

def test_sampling_delay(self):
Expand Down
2 changes: 1 addition & 1 deletion utils/_context/_scenarios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def all_endtoend_scenarios(test_object):
weblog_env={
"DD_EXPERIMENTAL_API_SECURITY_ENABLED": "true",
"DD_API_SECURITY_ENABLED": "true",
"DD_API_SECURITY_SAMPLE_DELAY": "3"
"DD_API_SECURITY_SAMPLE_DELAY": "3",
},
doc="""
Scenario for API Security feature, testing api security sampling rate.
Expand Down

0 comments on commit f1b24ab

Please sign in to comment.