-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2d9d2f
commit 22b29fe
Showing
6 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
use DDTrace\Tests\Frameworks\Util\Request\GetSpec; | ||
use datadog\appsec\AppsecStatus; | ||
|
||
class AutomatedLoginEventsTest extends WebFrameworkTestCase | ||
class LoginEventsTest extends WebFrameworkTestCase | ||
{ | ||
protected static function getAppIndexScript() | ||
{ | ||
|
@@ -39,18 +39,24 @@ public static function ddTearDownAfterClass() | |
|
||
protected function login($email) | ||
{ | ||
$this->call( | ||
GetSpec::create('Login success event', '/login/auth?email='.$email) | ||
); | ||
return $this->tracesFromWebRequest(function () use ($email) { | ||
$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')"); | ||
} | ||
|
||
public function testUserLoginSuccessEvent() | ||
{ | ||
$id = 1234; | ||
$name = 'someName'; | ||
$email = '[email protected]'; | ||
//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')"); | ||
$this->createUser($id, $name, $email); | ||
|
||
$this->login($email); | ||
|
||
|
@@ -63,6 +69,42 @@ public function testUserLoginSuccessEvent() | |
$this->assertEquals('track_user_login_success_event', $events[0]['eventName']); | ||
} | ||
|
||
public function testLoggedInCalls() | ||
{ | ||
$id = 1234; | ||
$name = 'someName'; | ||
$email = '[email protected]'; | ||
$this->createUser($id, $name, $email); | ||
|
||
//First log in | ||
$traces = $this->login($email); | ||
|
||
$meta = $traces[0][0]['meta']; | ||
$this->assertEquals($id, $meta['usr.id']); | ||
$this->assertEquals($name, $meta['usr.name']); | ||
$this->assertEquals($email, $meta['usr.email']); | ||
|
||
$events = AppsecStatus::getInstance()->getEvents(); | ||
$this->assertEquals(1, count($events)); | ||
$this->assertEquals($id, $events[0]['userId']); | ||
$this->assertEquals($name, $events[0]['metadata']['name']); | ||
$this->assertEquals($email, $events[0]['metadata']['email']); | ||
$this->assertTrue($events[0]['automated']); | ||
$this->assertEquals('track_user_login_success_event', $events[0]['eventName']); | ||
|
||
//Now we are logged in lets do another call | ||
AppsecStatus::getInstance()->setDefaults(); //Remove all events | ||
$traces = $this->tracesFromWebRequest(function () { | ||
$this->call(GetSpec::create('Behind auth', '/behind_auth')); | ||
}); | ||
|
||
$meta = $traces[0][0]['meta']; | ||
$this->assertEquals(0, count($events)); //Auth does not generate appsec events | ||
$this->assertEquals($id, $meta['usr.id']); | ||
$this->assertEquals($name, $meta['usr.name']); | ||
$this->assertEquals($email, $meta['usr.email']); | ||
} | ||
|
||
public function testUserLoginFailureEvent() | ||
{ | ||
$email = '[email protected]'; | ||
|