Skip to content

Commit 1116c8d

Browse files
avara1986P403n1x87
andauthored
chore(iast): update test to find leaks (#7629)
Update IAST test with memray to find possible leaksm. Add regression tests for #7630 Those tests implement memray and pytest-memray, those are inspired in this PR #7112 thanks @pablogsal More Info: https://github.com/bloomberg/memray https://github.com/bloomberg/pytest-memray ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. --------- Co-authored-by: Gabriele N. Tornetta <[email protected]>
1 parent 7a9a79c commit 1116c8d

File tree

14 files changed

+509
-85
lines changed

14 files changed

+509
-85
lines changed

.circleci/config.templ.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,14 @@ jobs:
432432
<<: *machine_executor
433433
steps:
434434
- run_test:
435-
pattern: 'appsec_iast'
435+
pattern: 'appsec_iast$'
436+
snapshot: true
437+
438+
appsec_iast_memcheck:
439+
<<: *machine_executor
440+
steps:
441+
- run_test:
442+
pattern: 'appsec_iast_memcheck'
436443
snapshot: true
437444

438445
appsec_integrations:

.riot/requirements/1b5d605.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# This file is autogenerated by pip-compile with python 3.9
3+
# To update, run:
4+
#
5+
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/1b5d605.in
6+
#
7+
attrs==23.1.0
8+
certifi==2023.7.22
9+
cffi==1.16.0
10+
charset-normalizer==3.3.2
11+
coverage[toml]==7.3.2
12+
cryptography==41.0.5
13+
exceptiongroup==1.1.3
14+
hypothesis==6.45.0
15+
idna==3.4
16+
iniconfig==2.0.0
17+
jinja2==3.1.2
18+
markdown-it-py==3.0.0
19+
markupsafe==2.1.3
20+
mdurl==0.1.2
21+
memray==1.10.0
22+
mock==5.1.0
23+
opentracing==2.4.0
24+
packaging==23.2
25+
pluggy==1.3.0
26+
pycparser==2.21
27+
pycryptodome==3.19.0
28+
pygments==2.16.1
29+
pytest==7.4.3
30+
pytest-cov==4.1.0
31+
pytest-memray==1.5.0
32+
pytest-mock==3.12.0
33+
requests==2.31.0
34+
rich==13.7.0
35+
sortedcontainers==2.4.0
36+
tomli==2.0.1
37+
urllib3==2.1.0

.riot/requirements/7121e51.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/7121e51.in
6+
#
7+
attrs==23.1.0
8+
certifi==2023.7.22
9+
cffi==1.16.0
10+
charset-normalizer==3.3.2
11+
coverage[toml]==7.3.2
12+
cryptography==41.0.5
13+
hypothesis==6.45.0
14+
idna==3.4
15+
iniconfig==2.0.0
16+
jinja2==3.1.2
17+
markdown-it-py==3.0.0
18+
markupsafe==2.1.3
19+
mdurl==0.1.2
20+
memray==1.10.0
21+
mock==5.1.0
22+
opentracing==2.4.0
23+
packaging==23.2
24+
pluggy==1.3.0
25+
pycparser==2.21
26+
pycryptodome==3.19.0
27+
pygments==2.16.1
28+
pytest==7.4.3
29+
pytest-cov==4.1.0
30+
pytest-memray==1.5.0
31+
pytest-mock==3.12.0
32+
requests==2.31.0
33+
rich==13.7.0
34+
sortedcontainers==2.4.0
35+
urllib3==2.1.0

.riot/requirements/861bff5.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/861bff5.in
6+
#
7+
attrs==23.1.0
8+
certifi==2023.7.22
9+
cffi==1.16.0
10+
charset-normalizer==3.3.2
11+
coverage[toml]==7.3.2
12+
cryptography==41.0.5
13+
exceptiongroup==1.1.3
14+
hypothesis==6.45.0
15+
idna==3.4
16+
iniconfig==2.0.0
17+
jinja2==3.1.2
18+
markdown-it-py==3.0.0
19+
markupsafe==2.1.3
20+
mdurl==0.1.2
21+
memray==1.10.0
22+
mock==5.1.0
23+
opentracing==2.4.0
24+
packaging==23.2
25+
pluggy==1.3.0
26+
pycparser==2.21
27+
pycryptodome==3.19.0
28+
pygments==2.16.1
29+
pytest==7.4.3
30+
pytest-cov==4.1.0
31+
pytest-memray==1.5.0
32+
pytest-mock==3.12.0
33+
requests==2.31.0
34+
rich==13.7.0
35+
sortedcontainers==2.4.0
36+
tomli==2.0.1
37+
urllib3==2.1.0

.riot/requirements/f43b103.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/f43b103.in
6+
#
7+
attrs==23.1.0
8+
certifi==2023.7.22
9+
cffi==1.16.0
10+
charset-normalizer==3.3.2
11+
coverage[toml]==7.3.2
12+
cryptography==41.0.5
13+
exceptiongroup==1.1.3
14+
hypothesis==6.45.0
15+
idna==3.4
16+
iniconfig==2.0.0
17+
jinja2==3.1.2
18+
markdown-it-py==3.0.0
19+
markupsafe==2.1.3
20+
mdurl==0.1.2
21+
memray==1.10.0
22+
mock==5.1.0
23+
opentracing==2.4.0
24+
packaging==23.2
25+
pluggy==1.3.0
26+
pycparser==2.21
27+
pycryptodome==3.19.0
28+
pygments==2.16.1
29+
pytest==7.4.3
30+
pytest-cov==4.1.0
31+
pytest-memray==1.5.0
32+
pytest-mock==3.12.0
33+
requests==2.31.0
34+
rich==13.7.0
35+
sortedcontainers==2.4.0
36+
tomli==2.0.1
37+
typing-extensions==4.8.0
38+
urllib3==2.1.0

riotfile.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION):
150150
"_DD_APPSEC_DEDUPLICATION_ENABLED": "false",
151151
},
152152
),
153+
Venv(
154+
name="appsec_iast_memcheck",
155+
pys=select_pys(min_version="3.8", max_version="3.11"),
156+
command="pytest {cmdargs} --memray --stacks=35 tests/appsec/iast_memcheck/",
157+
pkgs={
158+
"requests": latest,
159+
"pycryptodome": latest,
160+
"cryptography": latest,
161+
"pytest-memray": latest,
162+
},
163+
env={
164+
"DD_IAST_REQUEST_SAMPLING": "100", # Override default 30% to analyze all IAST requests
165+
"_DD_APPSEC_DEDUPLICATION_ENABLED": "false",
166+
},
167+
),
153168
Venv(
154169
name="appsec_integrations",
155170
command="pytest {cmdargs} tests/appsec/integrations/",

tests/.suitespec.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,15 @@
407407
"@appsec_iast",
408408
"tests/appsec/iast/*"
409409
],
410+
"appsec_iast_memcheck": [
411+
"@bootstrap",
412+
"@core",
413+
"@tracing",
414+
"@appsec",
415+
"@appsec_iast",
416+
"tests/appsec/iast/*",
417+
"tests/appsec/iast_memcheck/*"
418+
],
410419
"appsec_integrations": [
411420
"@bootstrap",
412421
"@core",

tests/appsec/iast/test_iast_mem_check.py

Lines changed: 0 additions & 84 deletions
This file was deleted.

tests/appsec/iast_memcheck/__init__.py

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import inspect
2+
import os
3+
from typing import TYPE_CHECKING
4+
5+
6+
if TYPE_CHECKING: # pragma: no cover
7+
from typing import Optional
8+
from typing import Text
9+
from typing import Tuple
10+
11+
12+
FIRST_FRAME_NO_DDTRACE = 1
13+
14+
DD_TRACE_INSTALLED_PREFIX = os.sep + "ddtrace" + os.sep
15+
SITE_PACKAGES_PREFIX = os.sep + "site-packages" + os.sep
16+
TESTS_PREFIX = os.sep + "tests" + os.sep
17+
18+
19+
def get_info_frame(cwd):
20+
# type: (Text) -> Optional[Tuple[Text, int]]
21+
"""Get the filename (path + filename) and line number of the original wrapped function to report it.
22+
23+
CAVEAT: We should migrate this function to native code to improve the performance.
24+
"""
25+
stack = inspect.stack()
26+
for frame in stack[FIRST_FRAME_NO_DDTRACE:]:
27+
filename = frame.filename
28+
lineno = frame.lineno
29+
if (
30+
(DD_TRACE_INSTALLED_PREFIX in filename and TESTS_PREFIX not in filename)
31+
or (cwd not in filename)
32+
or (SITE_PACKAGES_PREFIX in filename)
33+
):
34+
continue
35+
36+
return filename, lineno
37+
38+
return None

0 commit comments

Comments
 (0)