Mod LoginTest

This commit is contained in:
philipp lang 2021-11-17 00:20:13 +01:00
parent d9e336dc16
commit 2519d63929
1 changed files with 44 additions and 11 deletions
tests/Feature

View File

@ -4,34 +4,67 @@ namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class LoginTest extends TestCase
{
public function test_it_stores_login_cookie()
public function setUp(): void
{
parent::setUp();
}
public function testItCanLoginWithANamiAccount()
{
$this->withoutExceptionHandling();
$this->fakeNamiMembers([
[ 'gruppierungId' => 11222, 'vorname' => 'Max', 'nachname' => 'Muster', 'id' => 123 ]
]);
$this->fakeNamiPassword(123, 'secret', [11222]);
app('nami.backend')->fakeLogin(123, [], 'cookie-123');
$this->post('/login', [
'mglnr' => 123,
'password' => 'secret'
]);
$cache = Cache::get('namicookie-123');
$key = session()->get('auth_key');
$cache = Cache::get("namiauth-{$key}");
$this->assertEquals('secret', data_get($cache, 'credentials.password'));
$this->assertEquals(123, auth()->user()->getMglnr());
$this->assertEquals('Max', auth()->user()->getFirstname());
$this->assertEquals('Muster', auth()->user()->getLastname());
$this->assertEquals(123, data_get($cache, 'credentials.mglnr'));
$this->assertTrue(auth()->check());
}
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());
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);
}
}