Skip to content

Commit

Permalink
feat(Integrations: Laravel): update appsec function calls
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Rulleau <[email protected]>
  • Loading branch information
Leiyks committed Dec 9, 2024
1 parent 0e26602 commit 9de7062
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ Array
[appsec.events.users.login.success.metadata] => some other metadata
[appsec.events.users.login.success.email] => [email protected]
[appsec.events.users.login.success.track] => true
[appsec.events.users.login.success] => null
)
35 changes: 16 additions & 19 deletions src/DDTrace/Integrations/Laravel/LaravelIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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, []);
}
);

Expand All @@ -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)
Expand All @@ -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
);
}
);
Expand All @@ -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)
Expand All @@ -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
);
}
);
Expand All @@ -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, []);
}
);

Expand All @@ -453,19 +451,18 @@ 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)
) {
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() : '',
[]
);
}
);
Expand Down
3 changes: 0 additions & 3 deletions tests/Integrations/Laravel/AutomatedLoginEventsTestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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']);
}
Expand Down

0 comments on commit 9de7062

Please sign in to comment.