-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(asm): new smoke + patch + e2e package tests (#9529)
## Description Adds a lot more end to end test to the IAST package tests basically covering almost all of the top 100 modules except the ones that require some remote service (S3, Azure, etc) that we will need to mock or some that are not working also unpatched (we will need to investigate these). Also (needed for this PR): - Allow to configure a custom port in the `flask_server` appsec fixture to avoid port conflicts with other appsec tests running in parallel. - Add the package tests directory to CodeQL ignore file. ## 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] Risks are described (performance impact, potential for breakage, maintainability) - [X] Change is maintainable (easy to change, telemetry, documentation) - [X] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [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)) - [X] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. ## Reviewer Checklist - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has 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) --------- Signed-off-by: Juanjo Alvarez <[email protected]> Co-authored-by: Federico Mon <[email protected]>
- Loading branch information
Showing
56 changed files
with
2,338 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: "CodeQL config" | ||
paths-ignore: | ||
- 'tests/appsec/iast_packages/packages/**' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
aiohttp==3.9.5 | ||
https://pypi.org/project/aiohttp/ | ||
""" | ||
from flask import Blueprint | ||
from flask import jsonify | ||
from flask import request | ||
|
||
from .utils import ResultResponse | ||
|
||
|
||
pkg_aiohttp = Blueprint("package_aiohttp", __name__) | ||
|
||
|
||
@pkg_aiohttp.route("/aiohttp") | ||
def pkg_aiohttp_view(): | ||
import asyncio | ||
|
||
response = ResultResponse(request.args.get("package_param")) | ||
|
||
async def fetch(url): | ||
import aiohttp | ||
|
||
async with aiohttp.ClientSession() as session: | ||
async with session.get(url) as resp: | ||
return await resp.text() | ||
|
||
try: | ||
url = request.args.get("package_param", "https://example.com") | ||
|
||
try: | ||
# Use asyncio to run the async function | ||
result_output = asyncio.run(fetch(url)) | ||
except Exception as e: | ||
result_output = f"Error: {str(e)}" | ||
|
||
response.result1 = result_output | ||
except Exception as e: | ||
response.result1 = f"Error: {str(e)}" | ||
|
||
return jsonify(response.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
aiosignal==1.2.0 | ||
https://pypi.org/project/aiosignal/ | ||
""" | ||
import asyncio | ||
|
||
from flask import Blueprint | ||
from flask import jsonify | ||
from flask import request | ||
|
||
from .utils import ResultResponse | ||
|
||
|
||
pkg_aiosignal = Blueprint("package_aiosignal", __name__) | ||
|
||
|
||
@pkg_aiosignal.route("/aiosignal") | ||
def pkg_aiosignal_view(): | ||
from aiosignal import Signal | ||
|
||
response = ResultResponse(request.args.get("package_param")) | ||
|
||
async def handler_1(sender, **kwargs): | ||
return "Handler 1 called" | ||
|
||
async def handler_2(sender, **kwargs): | ||
return "Handler 2 called" | ||
|
||
try: | ||
param_value = request.args.get("package_param", "default_value") | ||
|
||
try: | ||
signal = Signal(owner=None) | ||
signal.append(handler_1) | ||
signal.append(handler_2) | ||
signal.freeze() # Freeze the signal to allow sending | ||
|
||
async def emit_signal(): | ||
results = await signal.send(param_value) | ||
return results | ||
|
||
# Use asyncio to run the async function and gather results | ||
results = asyncio.run(emit_signal()) | ||
result_output = f"Signal handlers results: {results}" | ||
except Exception as e: | ||
result_output = f"Error: {str(e)}" | ||
|
||
response.result1 = result_output | ||
except Exception as e: | ||
response.result1 = f"Error: {str(e)}" | ||
|
||
return jsonify(response.json()) |
42 changes: 42 additions & 0 deletions
42
tests/appsec/iast_packages/packages/pkg_annotated_types.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
annotated-types==0.7.0 | ||
https://pypi.org/project/annotated-types/ | ||
""" | ||
|
||
from flask import Blueprint | ||
from flask import jsonify | ||
from flask import request | ||
|
||
from .utils import ResultResponse | ||
|
||
|
||
pkg_annotated_types = Blueprint("package_annotated_types", __name__) | ||
|
||
|
||
@pkg_annotated_types.route("/annotated-types") | ||
def pkg_annotated_types_view(): | ||
from typing import Annotated | ||
|
||
from annotated_types import Gt | ||
|
||
response = ResultResponse(request.args.get("package_param")) | ||
|
||
def process_value(value: Annotated[int, Gt(10)]): | ||
return f"Processed value: {value}" | ||
|
||
try: | ||
param_value = int(request.args.get("package_param", "15")) | ||
|
||
try: | ||
result_output = process_value(param_value) | ||
except ValueError as e: | ||
result_output = f"Error: Value must be greater than 10. {str(e)}" | ||
except Exception as e: | ||
result_output = f"Error: {str(e)}" | ||
|
||
response.result1 = result_output.replace("\n", "\\n").replace('"', '\\"').replace("'", "\\'") | ||
except Exception as e: | ||
response.result1 = f"Error: {str(e)}" | ||
|
||
return jsonify(response.json()) |
Oops, something went wrong.