forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurityLoggerTest.php
More file actions
68 lines (58 loc) · 2.08 KB
/
SecurityLoggerTest.php
File metadata and controls
68 lines (58 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Tests\Feature;
use Database\Seeders\PermissionSeeder;
use Faker\Factory as Faker;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use ProcessMaker\Models\SecurityLog;
use ProcessMaker\Models\User;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;
class SecurityLoggerTest extends TestCase
{
/**
* Test to ensure security events are logged
*/
public function testLogSecurityEvents()
{
// Set the config to log security events
config(['auth.log_auth_events' => true]);
// Build a user with a specified password
$user = User::factory()->create([
'username' =>'newuser',
'password' => Hash::make('password'),
]);
$this->assertDatabaseMissing('security_logs', ['user_id' => $user->id]);
// Attempt to login with incorrect credentials
$this->assertFalse(Auth::attempt([
'username' => $user->username,
'password' => 'invalidpassword',
]));
$this->assertDatabaseHas('security_logs', ['event' => 'attempt', 'user_id' => $user->id]);
// Attempt to login with correct password
$this->assertTrue(Auth::attempt([
'username' => $user->username,
'password' => 'password',
]));
$this->assertDatabaseHas('security_logs', ['event' => 'login', 'user_id' => $user->id]);
// Attempt to logout
if (in_array(Auth::getDefaultDriver(), config('samlidp.guards'))) {
return redirect('saml/logout');
} else {
Auth::logout();
}
$this->assertDatabaseHas('security_logs', ['event' => 'logout', 'user_id' => $user->id]);
// Disable security logging
config(['auth.log_auth_events' => false]);
// We need to do our own teardown here since were not using
// transactions for this test
User::where('username', '!=', '_pm4_anon_user')->forceDelete();
}
/**
* Do not use transactions for this test
*/
protected function connectionsToTransact()
{
return [];
}
}