forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthTest.php
More file actions
77 lines (68 loc) · 2.19 KB
/
AuthTest.php
File metadata and controls
77 lines (68 loc) · 2.19 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
69
70
71
72
73
74
75
76
77
<?php
namespace Tests\Feature;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use ProcessMaker\Models\Permission;
use ProcessMaker\Models\User;
use Tests\TestCase;
class AuthTest extends TestCase
{
/**
* Tests to determine if we can manually log someone in by setting them in the Auth framework immediately
*
* @return void
*/
public function testAuthLoginAndLogout()
{
$user = User::factory()->create();
Auth::login($user);
$this->assertEquals($user->id, Auth::id());
Auth::logoutCurrentDevice();
$this->assertNull(Auth::user());
}
/**
* Tests the manual login functionality to support logging in with credentials passed from some external
* source.
*/
public function testAuthManualLogin()
{
// Build a user with a specified password
$user = User::factory()->create([
'username' =>'newuser',
'password' => Hash::make('password'),
]);
// Make sure we have a failed attempt with a bad password
$this->assertFalse(Auth::attempt([
'username' => $user->username,
'password' => 'invalidpassword',
]));
// Test to see if we can provide a successful auth attempt
$this->assertTrue(Auth::attempt([
'username' => 'newuser',
'password' => 'password',
]));
$this->assertEquals($user->id, Auth::id());
}
public function testLoginWithUnknownUser()
{
$response = $this->post('login', [
'username' => 'foobar',
'password' => 'abc123',
]);
$response->assertRedirect('/');
$response->assertSessionHasErrors();
User::factory()->create([
'username' => 'foobar',
'password' => Hash::make('abc123'),
'status' => 'ACTIVE',
]);
$response = $this->post('login', [
'username' => 'foobar',
'password' => 'abc123',
]);
// See https://github.com/ProcessMaker/processmaker/pull/4375
$response->assertRedirect('/');
$response->assertSessionHasNoErrors();
}
}