Mod LoginTest
This commit is contained in:
parent
d9e336dc16
commit
2519d63929
tests/Feature
|
@ -4,34 +4,67 @@ namespace Tests\Feature;
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
use Tests\TestCase;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
class LoginTest extends TestCase
|
class LoginTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function test_it_stores_login_cookie()
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItCanLoginWithANamiAccount()
|
||||||
{
|
{
|
||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
$this->fakeNamiMembers([
|
app('nami.backend')->fakeLogin(123, [], 'cookie-123');
|
||||||
[ 'gruppierungId' => 11222, 'vorname' => 'Max', 'nachname' => 'Muster', 'id' => 123 ]
|
|
||||||
]);
|
|
||||||
$this->fakeNamiPassword(123, 'secret', [11222]);
|
|
||||||
|
|
||||||
$this->post('/login', [
|
$this->post('/login', [
|
||||||
'mglnr' => 123,
|
'mglnr' => 123,
|
||||||
'password' => 'secret'
|
'password' => 'secret'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$cache = Cache::get('namicookie-123');
|
|
||||||
|
|
||||||
$key = session()->get('auth_key');
|
$key = session()->get('auth_key');
|
||||||
$cache = Cache::get("namiauth-{$key}");
|
$cache = Cache::get("namiauth-{$key}");
|
||||||
$this->assertEquals('secret', data_get($cache, 'credentials.password'));
|
$this->assertEquals('secret', data_get($cache, 'credentials.password'));
|
||||||
$this->assertEquals(123, auth()->user()->getMglnr());
|
$this->assertEquals(123, data_get($cache, 'credentials.mglnr'));
|
||||||
$this->assertEquals('Max', auth()->user()->getFirstname());
|
$this->assertTrue(auth()->check());
|
||||||
$this->assertEquals('Muster', auth()->user()->getLastname());
|
}
|
||||||
|
|
||||||
|
public function testItDoesntLoginTwoTimes()
|
||||||
|
{
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
app('nami.backend')->fakeLogin(123, [], 'cookie-123');
|
||||||
|
|
||||||
|
$this->post('/login', [
|
||||||
|
'mglnr' => 123,
|
||||||
|
'password' => 'secret'
|
||||||
|
]);
|
||||||
|
auth()->logout();
|
||||||
|
$this->post('/login', [
|
||||||
|
'mglnr' => 123,
|
||||||
|
'password' => 'secret'
|
||||||
|
]);
|
||||||
|
|
||||||
$this->assertTrue(auth()->check());
|
$this->assertTrue(auth()->check());
|
||||||
|
|
||||||
|
Http::assertSentCount(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItThrowsExceptionWhenLoginFailed()
|
||||||
|
{
|
||||||
|
app('nami.backend')->fakeFailedLogin(123);
|
||||||
|
|
||||||
|
$this->post('/login', [
|
||||||
|
'mglnr' => 123,
|
||||||
|
'password' => 'secret'
|
||||||
|
])->assertRedirect('/');
|
||||||
|
|
||||||
|
$this->assertFalse(auth()->check());
|
||||||
|
|
||||||
|
Http::assertSentCount(2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue