Skip to content

Commit

Permalink
Add testing loging
Browse files Browse the repository at this point in the history
  • Loading branch information
estringana committed Feb 12, 2024
1 parent 6d77a47 commit 2353c8b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/Integrations/Integrations/Laravel/LaravelIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ function ($exceptionHandler, $scope, $args) use ($integration) {
'attempt',
null,
function ($This, $scope, $args, $loginSuccess) use ($integration) {
var_dump('LaravelIntegration: At track_user_login_failure_event');
if ($loginSuccess || !function_exists('\datadog\appsec\track_user_login_failure_event')) {
return;
}
Expand All @@ -371,6 +372,7 @@ function ($This, $scope, $args, $loginSuccess) use ($integration) {
'Illuminate\Auth\SessionGuard',
'setUser',
function ($This, $scope, $args) use ($integration) {
var_dump('LaravelIntegration: At track_user_login_success_event');
$authClass = 'Illuminate\Contracts\Auth\Authenticatable';
if (
!function_exists('\datadog\appsec\track_user_login_success_event') ||
Expand Down Expand Up @@ -496,6 +498,7 @@ function ($This, $scope, $args) use ($integration) {
'__construct',
null,
function ($This, $scope, $args) use ($integration) {
var_dump('LaravelIntegration: At set_user');
$authClass = 'Illuminate\Contracts\Auth\Authenticatable';
if (
!isset($args[1]) ||
Expand Down
4 changes: 2 additions & 2 deletions tests/Appsec/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function getDbPdo()

public function init()
{
$this->getDbPdo()->exec("CREATE TABLE IF NOT EXISTS appsec_events (event varchar(1000))");
var_dump('Mock: create events table', $this->getDbPdo()->exec("CREATE TABLE IF NOT EXISTS appsec_events (event varchar(1000))"));
}

public function destroy()
Expand All @@ -43,7 +43,7 @@ public function setDefaults()
public function addEvent(array $event, $eventName)
{
$event['eventName'] = $eventName;
$this->getDbPdo()->exec(sprintf("INSERT INTO appsec_events VALUES ('%s')", json_encode($event)));
var_dump('Mock: inserting events', $this->getDbPdo()->exec(sprintf("INSERT INTO appsec_events VALUES ('%s')", json_encode($event))));
}

public function getEvents()
Expand Down
10 changes: 5 additions & 5 deletions tests/Integrations/Laravel/V9_x/LoginEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public static function ddTearDownAfterClass()
protected function login($email)
{
return $this->tracesFromWebRequest(function () use ($email) {
$this->call(
var_dump("login call", $this->call(
GetSpec::create('Login success event', '/login/auth?email='.$email)
);
));
});
}

protected function createUser($id, $name, $email) {
//Password is password
$this->connection()->exec("insert into users (id, name, email, password) VALUES (".$id.", '".$name."', '".$email."', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi')");
var_dump('LaravelTests: user creation', $this->connection()->exec("insert into users (id, name, email, password) VALUES (".$id.", '".$name."', '".$email."', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi')"));
}

public function testUserLoginSuccessEvent()
Expand Down Expand Up @@ -126,9 +126,9 @@ public function testUserSignUp()
$name = 'somename';
$password = 'somepassword';

$this->call(
var_dump('LaravelTests: sign up call', $this->call(
GetSpec::create('Signup', sprintf('/login/signup?email=%s&name=%s&password=%s',$email, $email, $password))
);
));

$users = $this->connection()->query("SELECT * FROM users where email='".$email."'")->fetchAll();

Expand Down

0 comments on commit 2353c8b

Please sign in to comment.