-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2383 from DataDog/cbeauchesne/better_schema_checks
Better schema test logic API
- Loading branch information
Showing
12 changed files
with
156 additions
and
170 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
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 |
---|---|---|
|
@@ -52,45 +52,6 @@ def test_agent_provide_config_endpoint(self): | |
class RemoteConfigurationFieldsBasicTests: | ||
"""Misc tests on fields and values on remote configuration requests""" | ||
|
||
@bug(context.library < "[email protected]") | ||
@bug(context.library < "[email protected]") | ||
@bug(context.library >= "[email protected]") | ||
def test_schemas(self): | ||
"""Test all library schemas""" | ||
interfaces.library.assert_schemas() | ||
|
||
def test_non_regression(self): | ||
"""Non-regression test on shemas""" | ||
|
||
# Never skip this test. As a full respect of shemas may be hard, this test ensure that | ||
# at least the part that was ok stays ok. | ||
|
||
allowed_errors = None | ||
if context.library == "golang": | ||
allowed_errors = ( | ||
r"'actor' is a required property on instance \['events'\]\[\d+\]\['context'\]", | ||
r"'protocol_version' is a required property on instance ", | ||
) | ||
elif context.library == "java": | ||
# pylint: disable=line-too-long | ||
allowed_errors = ( | ||
r"'appsec' was expected on instance \['events'\]\[\d+\]\['event_type'\]", | ||
r"'headers' is a required property on instance \['events'\]\[\d+\]\['context'\]\['http'\]\['response'\]", | ||
r"'idempotency_key' is a required property on instance ", | ||
) | ||
elif context.library == "dotnet": | ||
allowed_errors = ( | ||
# value is missing in configuration object in telemetry payloads | ||
r"'value' is a required property on instance \['payload'\]\['configuration'\]\[\d+\]", | ||
) | ||
elif context.library == "nodejs": | ||
allowed_errors = ( | ||
# value is missing in configuration object in telemetry payloads | ||
r"'value' is a required property on instance \['payload'\]\['configuration'\]\[\d+\]", | ||
) | ||
|
||
interfaces.library.assert_schemas(allowed_errors=allowed_errors) | ||
|
||
def test_client_state_errors(self): | ||
"""Ensure that the Client State error is consistent""" | ||
|
||
|
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 |
---|---|---|
|
@@ -4,106 +4,56 @@ | |
|
||
"""Test format specifications""" | ||
|
||
from utils import weblog, interfaces, bug, context | ||
from utils import weblog, interfaces, bug, irrelevant, context, scenarios | ||
|
||
|
||
class Test_Library: | ||
@scenarios.all_endtoend_scenarios | ||
class Test_library: | ||
"""Libraries's payload are valid regarding schemas""" | ||
|
||
def setup_full(self): | ||
def setup_library_schema_full(self): | ||
# send some requests to be sure to trigger events | ||
weblog.get("/waf", params={"key": "\n :"}) # rules.http_protocol_violation.crs_921_160 | ||
weblog.get("/waf", params={"key": "\n :"}) | ||
|
||
@bug(context.library < "[email protected]") | ||
@bug(context.library < "[email protected]") | ||
@bug(context.library >= "[email protected]") | ||
@bug(context.library >= "[email protected]") | ||
@bug( | ||
context.library >= "[email protected]" | ||
and context.agent_version >= "7.47.0rc2" | ||
and context.appsec_rules_file is not None, | ||
reason="on /v0.7/config, client.products is an empty array", | ||
) | ||
def test_full(self): | ||
interfaces.library.assert_schemas() | ||
def test_library_schema_full(self): | ||
interfaces.library.assert_schema_points( | ||
excluded_points=[ | ||
("/telemetry/proxy/api/v2/apmtelemetry", "$.payload.configuration[]"), | ||
("/telemetry/proxy/api/v2/apmtelemetry", "$.payload"), # APPSEC-52845 | ||
] | ||
) | ||
|
||
def test_non_regression(self): | ||
""" Non-regression test on shemas """ | ||
@bug(context.library >= "[email protected]", reason="APPSEC-52805") | ||
def test_library_schema_telemetry_conf_value(self): | ||
interfaces.library.assert_schema_point("/telemetry/proxy/api/v2/apmtelemetry", "$.payload.configuration[]") | ||
|
||
# Never skip this test. As a full respect of shemas may be hard, this test ensure that | ||
# at least the part that was ok stays ok. | ||
|
||
allowed_errors = None | ||
if context.library == "golang": | ||
allowed_errors = ( | ||
r"'actor' is a required property on instance \['events'\]\[\d+\]\['context'\]", | ||
r"'protocol_version' is a required property on instance ", | ||
) | ||
elif context.library == "java": | ||
# pylint: disable=line-too-long | ||
allowed_errors = ( | ||
r"'appsec' was expected on instance \['events'\]\[\d+\]\['event_type'\]", | ||
r"'headers' is a required property on instance \['events'\]\[\d+\]\['context'\]\['http'\]\['response'\]", | ||
r"'idempotency_key' is a required property on instance ", | ||
) | ||
elif context.library == "dotnet": | ||
allowed_errors = ( | ||
# value is missing in configuration object in telemetry payloads | ||
r"'value' is a required property on instance \['payload'\]\['configuration'\]\[\d+\]", | ||
) | ||
elif context.library == "nodejs": | ||
allowed_errors = ( | ||
# value is missing in configuration object in telemetry payloads | ||
r"'value' is a required property on instance \['payload'\]\['configuration'\]\[\d+\]", | ||
) | ||
elif context.library == "python": | ||
allowed_errors = (r"\[\] is too short on instance \['client'\]\['products'\]",) | ||
|
||
interfaces.library.assert_schemas(allowed_errors=allowed_errors) | ||
@bug(library="python", reason="APPSEC-52845") | ||
def test_library_schema_telemetry_job_object(self): | ||
interfaces.library.assert_schema_point("/telemetry/proxy/api/v2/apmtelemetry", "$.payload") | ||
|
||
|
||
@scenarios.all_endtoend_scenarios | ||
class Test_Agent: | ||
"""Agents's payload are valid regarding schemas""" | ||
|
||
def setup_full(self): | ||
def setup_agent_schema_full(self): | ||
# send some requests to be sure to trigger events | ||
weblog.get("/waf", params={"key": "\n :"}) # rules.http_protocol_violation.crs_921_160 | ||
|
||
@bug(context.library < "[email protected]") | ||
@bug(context.library < "[email protected]") | ||
@bug(context.library >= "[email protected]") | ||
@bug(context.library >= "[email protected]") | ||
def test_full(self): | ||
interfaces.agent.assert_schemas() | ||
|
||
def test_non_regression(self): | ||
""" Non-regression test on shemas """ | ||
|
||
# Never skip this test. As a full respect of shemas may be hard, this test ensure that | ||
# at least the part that was ok stays ok. | ||
|
||
allowed_errors = None | ||
if context.library == "golang": | ||
allowed_errors = ( | ||
r"'actor' is a required property on instance \['events'\]\[\d+\]\['context'\]", | ||
r"'protocol_version' is a required property on instance ", | ||
) | ||
elif context.library == "java": | ||
# pylint: disable=line-too-long | ||
allowed_errors = ( | ||
r"'appsec' was expected on instance \['events'\]\[\d+\]\['event_type'\]", | ||
r"'headers' is a required property on instance \['events'\]\[\d+\]\['context'\]\['http'\]\['response'\]", | ||
r"'idempotency_key' is a required property on instance ", | ||
) | ||
elif context.library == "dotnet": | ||
allowed_errors = ( | ||
# value is missing in configuration object in telemetry payloads | ||
r"'value' is a required property on instance \['payload'\]\['configuration'\]\[\d+\]", | ||
) | ||
elif context.library == "nodejs": | ||
allowed_errors = ( | ||
# value is missing in configuration object in telemetry payloads | ||
r"'value' is a required property on instance \['payload'\]\['configuration'\]\[\d+\]", | ||
) | ||
|
||
interfaces.agent.assert_schemas(allowed_errors=allowed_errors) | ||
weblog.get("/waf", params={"key": "\n :"}) | ||
|
||
def test_agent_schema_full(self): | ||
interfaces.agent.assert_schema_points( | ||
excluded_points=[ | ||
("/api/v2/apmtelemetry", "$.payload.configuration[]"), | ||
("/api/v2/apmtelemetry", "$.payload"), # APPSEC-52845 | ||
] | ||
) | ||
|
||
@bug(context.library >= "[email protected]", reason="APPSEC-52805") | ||
@irrelevant(context.scenario is scenarios.crossed_tracing_libraries, reason="APPSEC-52805") | ||
@irrelevant(context.scenario is scenarios.graphql_appsec, reason="APPSEC-52805") | ||
def test_agent_schema_telemetry_conf_value(self): | ||
interfaces.agent.assert_schema_point("/api/v2/apmtelemetry", "$.payload.configuration[]") | ||
|
||
@bug(library="python", reason="APPSEC-52845") | ||
def test_library_schema_telemetry_job_object(self): | ||
interfaces.agent.assert_schema_point("/api/v2/apmtelemetry", "$.payload") |
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
Oops, something went wrong.