-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(appsec: extension): add special cases tests for automated functions
Signed-off-by: Alexandre Rulleau <[email protected]>
- Loading branch information
Showing
9 changed files
with
233 additions
and
4 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
appsec/tests/extension/track_user_login_failure_event_automated_no_login.phpt
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,31 @@ | ||
--TEST-- | ||
Track an automated user login failure event without login provided and verify the tags in the root span | ||
--INI-- | ||
extension=ddtrace.so | ||
--ENV-- | ||
DD_APPSEC_ENABLED=1 | ||
--FILE-- | ||
<?php | ||
use function datadog\appsec\testing\root_span_get_meta; | ||
use function datadog\appsec\track_user_login_failure_event_automated; | ||
include __DIR__ . '/inc/ddtrace_version.php'; | ||
|
||
ddtrace_version_at_least('0.79.0'); | ||
|
||
track_user_login_failure_event_automated("", "automatedID", false, []); | ||
|
||
echo "root_span_get_meta():\n"; | ||
print_r(root_span_get_meta()); | ||
?> | ||
--EXPECTF-- | ||
root_span_get_meta(): | ||
Array | ||
( | ||
[runtime-id] => %s | ||
[appsec.events.users.login.failure.usr.id] => automatedID | ||
[_dd.appsec.usr.id] => automatedID | ||
[_dd.appsec.events.users.login.failure.auto.mode] => identification | ||
[appsec.events.users.login.failure.track] => true | ||
[appsec.events.users.login.failure.usr.exists] => false | ||
[appsec.events.users.login.failure] => null | ||
) |
29 changes: 29 additions & 0 deletions
29
appsec/tests/extension/track_user_login_failure_event_automated_no_root_span.phpt
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,29 @@ | ||
--TEST-- | ||
Track an automated user login failure event when no root span is available and verify the logs | ||
--INI-- | ||
extension=ddtrace.so | ||
datadog.appsec.log_file=/tmp/php_appsec_test.log | ||
datadog.appsec.log_level=debug | ||
--ENV-- | ||
DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
DD_APPSEC_ENABLED=1 | ||
--FILE-- | ||
<?php | ||
use function datadog\appsec\track_user_login_failure_event_automated; | ||
include __DIR__ . '/inc/ddtrace_version.php'; | ||
|
||
ddtrace_version_at_least('0.79.0'); | ||
|
||
track_user_login_failure_event_automated("login", "automatedID", false, | ||
[ | ||
"value" => "something", | ||
"metadata" => "some other metadata", | ||
"email" => "[email protected]" | ||
]); | ||
|
||
|
||
require __DIR__ . '/inc/logging.php'; | ||
match_log("/No root span available on request init/"); | ||
?> | ||
--EXPECTF-- | ||
found message in log matching /No root span available on request init/ |
31 changes: 31 additions & 0 deletions
31
appsec/tests/extension/track_user_login_failure_event_automated_no_user.phpt
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,31 @@ | ||
--TEST-- | ||
Track an automated user login failure event without user provided and verify the tags in the root span | ||
--INI-- | ||
extension=ddtrace.so | ||
--ENV-- | ||
DD_APPSEC_ENABLED=1 | ||
--FILE-- | ||
<?php | ||
use function datadog\appsec\testing\root_span_get_meta; | ||
use function datadog\appsec\track_user_login_failure_event_automated; | ||
include __DIR__ . '/inc/ddtrace_version.php'; | ||
|
||
ddtrace_version_at_least('0.79.0'); | ||
|
||
track_user_login_failure_event_automated("login", "", false, []); | ||
|
||
echo "root_span_get_meta():\n"; | ||
print_r(root_span_get_meta()); | ||
?> | ||
--EXPECTF-- | ||
root_span_get_meta(): | ||
Array | ||
( | ||
[runtime-id] => %s | ||
[_dd.appsec.events.users.login.failure.auto.mode] => identification | ||
[appsec.events.users.login.failure.usr.login] => login | ||
[_dd.appsec.usr.login] => login | ||
[appsec.events.users.login.failure.track] => true | ||
[appsec.events.users.login.failure.usr.exists] => false | ||
[appsec.events.users.login.failure] => null | ||
) |
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
32 changes: 32 additions & 0 deletions
32
appsec/tests/extension/track_user_login_success_event_automated_empty_login.phpt
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,32 @@ | ||
--TEST-- | ||
Track an automated user login success event with an empty user login and verify the logs | ||
--INI-- | ||
extension=ddtrace.so | ||
datadog.appsec.log_file=/tmp/php_appsec_test.log | ||
datadog.appsec.log_level=debug | ||
--ENV-- | ||
DD_APPSEC_ENABLED=1 | ||
--FILE-- | ||
<?php | ||
use function datadog\appsec\testing\root_span_get_meta; | ||
use function datadog\appsec\track_user_login_success_event_automated; | ||
include __DIR__ . '/inc/ddtrace_version.php'; | ||
|
||
ddtrace_version_at_least('0.79.0'); | ||
|
||
track_user_login_success_event_automated("", "automatedID", | ||
[ | ||
"value" => "something", | ||
"metadata" => "some other metadata", | ||
"email" => "[email protected]" | ||
]); | ||
|
||
echo "root_span_get_meta():\n"; | ||
print_r(root_span_get_meta()); | ||
?> | ||
--EXPECTF-- | ||
root_span_get_meta(): | ||
Array | ||
( | ||
[runtime-id] => %s | ||
) |
37 changes: 37 additions & 0 deletions
37
appsec/tests/extension/track_user_login_success_event_automated_empty_user.phpt
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,37 @@ | ||
--TEST-- | ||
Track an automated user login success event with an empty user and verify the tags | ||
--INI-- | ||
extension=ddtrace.so | ||
datadog.appsec.log_file=/tmp/php_appsec_test.log | ||
datadog.appsec.log_level=debug | ||
--ENV-- | ||
DD_APPSEC_ENABLED=1 | ||
--FILE-- | ||
<?php | ||
use function datadog\appsec\testing\root_span_get_meta; | ||
use function datadog\appsec\track_user_login_success_event_automated; | ||
include __DIR__ . '/inc/ddtrace_version.php'; | ||
|
||
ddtrace_version_at_least('0.79.0'); | ||
|
||
track_user_login_success_event_automated("login", "", | ||
[ | ||
"value" => "something", | ||
"metadata" => "some other metadata", | ||
"email" => "[email protected]" | ||
]); | ||
|
||
echo "root_span_get_meta():\n"; | ||
print_r(root_span_get_meta()); | ||
?> | ||
--EXPECTF-- | ||
root_span_get_meta(): | ||
Array | ||
( | ||
[runtime-id] => %s | ||
[_dd.appsec.events.users.login.success.auto.mode] => identification | ||
[appsec.events.users.login.success.usr.login] => login | ||
[_dd.appsec.usr.login] => login | ||
[appsec.events.users.login.success.track] => true | ||
[appsec.events.users.login.success] => null | ||
) |
32 changes: 32 additions & 0 deletions
32
appsec/tests/extension/track_user_login_success_event_automated_no_root_span.phpt
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,32 @@ | ||
--TEST-- | ||
Track an automated user login success event when no root span is available and verify the logs | ||
--INI-- | ||
extension=ddtrace.so | ||
datadog.appsec.log_file=/tmp/php_appsec_test.log | ||
datadog.appsec.log_level=debug | ||
--ENV-- | ||
DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
DD_APPSEC_ENABLED=1 | ||
--FILE-- | ||
<?php | ||
|
||
use function datadog\appsec\track_user_login_success_event_automated; | ||
|
||
include __DIR__ . '/inc/ddtrace_version.php'; | ||
|
||
ddtrace_version_at_least('0.79.0'); | ||
|
||
track_user_login_success_event_automated("login", "automatedID", | ||
[ | ||
"value" => "something", | ||
"metadata" => "some other metadata", | ||
"email" => "[email protected]" | ||
] | ||
); | ||
|
||
|
||
require __DIR__ . '/inc/logging.php'; | ||
match_log("/No root span available on request init/"); | ||
?> | ||
--EXPECTF-- | ||
found message in log matching /No root span available on request init/ |
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
appsec/tests/extension/track_user_signup_event_automated_empty_user.phpt
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,37 @@ | ||
--TEST-- | ||
Track an automated user login success event with an empty user and verify the logs | ||
--INI-- | ||
extension=ddtrace.so | ||
datadog.appsec.log_file=/tmp/php_appsec_test.log | ||
datadog.appsec.log_level=debug | ||
--ENV-- | ||
DD_APPSEC_ENABLED=1 | ||
--FILE-- | ||
<?php | ||
use function datadog\appsec\testing\root_span_get_meta; | ||
use function datadog\appsec\track_user_signup_event_automated; | ||
include __DIR__ . '/inc/ddtrace_version.php'; | ||
|
||
ddtrace_version_at_least('0.79.0'); | ||
|
||
track_user_signup_event_automated("login", "", | ||
[ | ||
"value" => "something", | ||
"metadata" => "some other metadata", | ||
"email" => "[email protected]" | ||
]); | ||
|
||
echo "root_span_get_meta():\n"; | ||
print_r(root_span_get_meta()); | ||
?> | ||
--EXPECTF-- | ||
root_span_get_meta(): | ||
Array | ||
( | ||
[runtime-id] => %s | ||
[_dd.appsec.events.users.signup.auto.mode] => identification | ||
[appsec.events.users.signup.usr.login] => login | ||
[_dd.appsec.usr.login] => login | ||
[appsec.events.users.signup.track] => true | ||
[appsec.events.users.signup] => null | ||
) |