From 9de7062668462123642f08c7b23b3c67b62b9421 Mon Sep 17 00:00:00 2001 From: Alexandre Rulleau Date: Mon, 9 Dec 2024 10:57:06 +0100 Subject: [PATCH] feat(Integrations: Laravel): update appsec function calls Signed-off-by: Alexandre Rulleau --- ...racking_do_nothing_from_login_success.phpt | 1 + .../Laravel/LaravelIntegration.php | 35 +++++++++---------- .../Laravel/AutomatedLoginEventsTestSuite.php | 3 -- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/appsec/tests/extension/user_tracking_do_nothing_from_login_success.phpt b/appsec/tests/extension/user_tracking_do_nothing_from_login_success.phpt index 02524c88bc..c02d2e1742 100644 --- a/appsec/tests/extension/user_tracking_do_nothing_from_login_success.phpt +++ b/appsec/tests/extension/user_tracking_do_nothing_from_login_success.phpt @@ -52,4 +52,5 @@ Array [appsec.events.users.login.success.metadata] => some other metadata [appsec.events.users.login.success.email] => noneofyour@business.com [appsec.events.users.login.success.track] => true + [appsec.events.users.login.success] => null ) diff --git a/src/DDTrace/Integrations/Laravel/LaravelIntegration.php b/src/DDTrace/Integrations/Laravel/LaravelIntegration.php index ab47451ecb..4d6de74e4d 100644 --- a/src/DDTrace/Integrations/Laravel/LaravelIntegration.php +++ b/src/DDTrace/Integrations/Laravel/LaravelIntegration.php @@ -201,7 +201,7 @@ function ($This, $scope, $args) use ($integration) { if ($span->resource == 'eloquent.created: User') { $authClass = 'User'; if ( - !function_exists('\datadog\appsec\track_user_signup_event') || + !function_exists('\datadog\appsec\track_user_signup_event_automated') || !isset($args[1]) || !$args[1] || !($args[1] instanceof $authClass) @@ -214,7 +214,7 @@ function ($This, $scope, $args) use ($integration) { $id = $args[1]['id']; } - \datadog\appsec\track_user_signup_event($id, $this->getLoginFromArgs($args[1]), [], true); + \datadog\appsec\track_user_signup_event_automated($this->getLoginFromArgs($args[1]), $id, []); } }, 'recurse' => true, @@ -356,11 +356,11 @@ function ($exceptionHandler, $scope, $args) use ($integration) { 'attempt', null, function ($This, $scope, $args, $loginSuccess) use ($integration) { - if ($loginSuccess || !function_exists('\datadog\appsec\track_user_login_failure_event')) { + if ($loginSuccess || !function_exists('\datadog\appsec\track_user_login_failure_event_automated')) { return; } - \datadog\appsec\track_user_login_failure_event(null, $this->getLoginFromArgs($args[0]), false, [], true); + \datadog\appsec\track_user_login_failure_event_automated($this->getLoginFromArgs($args[0]), null, false, []); } ); @@ -371,7 +371,7 @@ function ($This, $scope, $args, $loginSuccess) use ($integration) { function ($This, $scope, $args) use ($integration) { $authClass = 'Illuminate\Contracts\Auth\Authenticatable'; if ( - !function_exists('\datadog\appsec\track_user_login_success_event') || + !function_exists('\datadog\appsec\track_user_login_success_event_automated') || !isset($args[1]) || !$args[1] || !($args[1] instanceof $authClass) @@ -389,11 +389,10 @@ function ($This, $scope, $args) use ($integration) { $metadata['email'] = $args[1]['email']; } - \datadog\appsec\track_user_login_success_event( - \method_exists($args[1], 'getAuthIdentifier') ? $args[1]->getAuthIdentifier() : '', + \datadog\appsec\track_user_login_success_event_automated( $this->getLoginFromArgs($args[1]), + \method_exists($args[1], 'getAuthIdentifier') ? $args[1]->getAuthIdentifier() : '', $metadata, - true ); } ); @@ -405,7 +404,7 @@ function ($This, $scope, $args) use ($integration) { function ($This, $scope, $args) use ($integration) { $authClass = 'Illuminate\Auth\UserInterface'; if ( - !function_exists('\datadog\appsec\track_user_login_success_event') || + !function_exists('\datadog\appsec\track_user_login_success_event_automated') || !isset($args[0]) || !$args[0] || !($args[0] instanceof $authClass) @@ -423,11 +422,10 @@ function ($This, $scope, $args) use ($integration) { $metadata['email'] = $args[0]['email']; } - \datadog\appsec\track_user_login_success_event( - \method_exists($args[0], 'getAuthIdentifier') ? $args[0]->getAuthIdentifier() : '', + \datadog\appsec\track_user_login_success_event_automated( $this->getLoginFromArgs($args[0]), + \method_exists($args[0], 'getAuthIdentifier') ? $args[0]->getAuthIdentifier() : '', $metadata, - true ); } ); @@ -438,11 +436,11 @@ function ($This, $scope, $args) use ($integration) { 'attempt', null, function ($This, $scope, $args, $loginSuccess) use ($integration) { - if ($loginSuccess || !function_exists('\datadog\appsec\track_user_login_failure_event')) { + if ($loginSuccess || !function_exists('\datadog\appsec\track_user_login_failure_event_automated')) { return; } - \datadog\appsec\track_user_login_failure_event(null, $this->getLoginFromArgs($args[0]), false, [], true); + \datadog\appsec\track_user_login_failure_event_automated($this->getLoginFromArgs($args[0]), null, false, []); } ); @@ -453,7 +451,7 @@ function ($This, $scope, $args, $loginSuccess) use ($integration) { function ($This, $scope, $args) use ($integration) { $authClass = 'Illuminate\Contracts\Auth\Authenticatable'; if ( - !function_exists('\datadog\appsec\track_user_signup_event') || + !function_exists('\datadog\appsec\track_user_signup_event_automated') || !isset($args[0]) || !$args[0] || !($args[0] instanceof $authClass) @@ -461,11 +459,10 @@ function ($This, $scope, $args) use ($integration) { return; } - \datadog\appsec\track_user_signup_event( - \method_exists($args[0], 'getAuthIdentifier') ? $args[0]->getAuthIdentifier() : '', + \datadog\appsec\track_user_signup_event_automated( $this->getLoginFromArgs($args[0]), - [], - true + \method_exists($args[0], 'getAuthIdentifier') ? $args[0]->getAuthIdentifier() : '', + [] ); } ); diff --git a/tests/Integrations/Laravel/AutomatedLoginEventsTestSuite.php b/tests/Integrations/Laravel/AutomatedLoginEventsTestSuite.php index ecb34c7d60..6ad1f80c41 100644 --- a/tests/Integrations/Laravel/AutomatedLoginEventsTestSuite.php +++ b/tests/Integrations/Laravel/AutomatedLoginEventsTestSuite.php @@ -50,7 +50,6 @@ public function testUserLoginSuccessEvent() $this->assertEquals($email, $events[0]['userLogin']); $this->assertEquals($name, $events[0]['metadata']['name']); $this->assertEquals($email, $events[0]['metadata']['email']); - $this->assertTrue($events[0]['automated']); } public function testUserLoginFailureEvent() @@ -62,7 +61,6 @@ public function testUserLoginFailureEvent() $events = AppsecStatus::getInstance()->getEvents(['track_user_login_failure_event']); $this->assertEquals(1, count($events)); $this->assertEquals($email, $events[0]['userLogin']); - $this->assertTrue($events[0]['automated']); } public function testUserSignUp() @@ -81,7 +79,6 @@ public function testUserSignUp() $signUpEvent = AppsecStatus::getInstance()->getEvents(['track_user_signup_event']); - $this->assertTrue($signUpEvent[0]['automated']); $this->assertEquals($users[0]['id'], $signUpEvent[0]['userId']); $this->assertEquals($users[0]['email'], $signUpEvent[0]['userLogin']); }