Skip to content

Commit

Permalink
test(appsec: extension): add special cases tests for automated functions
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Rulleau <[email protected]>
  • Loading branch information
Leiyks committed Dec 10, 2024
1 parent 5ba401a commit dfb19df
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 4 deletions.
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
)
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/
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
)
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
--TEST--
Track a user login failure event without user id provided and verify the tags in the root span
Track a 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;
use function datadog\appsec\track_user_login_failure_event;
include __DIR__ . '/inc/ddtrace_version.php';

ddtrace_version_at_least('0.79.0');

track_user_login_failure_event_automated("", "", false, []);
track_user_login_failure_event("", false, []);

echo "root_span_get_meta():\n";
print_r(root_span_get_meta());
Expand All @@ -22,8 +22,8 @@ root_span_get_meta():
Array
(
[runtime-id] => %s
[_dd.appsec.events.users.login.failure.auto.mode] => identification
[appsec.events.users.login.failure.track] => true
[_dd.appsec.events.users.login.failure.sdk] => true
[appsec.events.users.login.failure.usr.exists] => false
[appsec.events.users.login.failure] => null
)
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
)
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
)
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/
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
)

0 comments on commit dfb19df

Please sign in to comment.