Add filter for member id
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2021-11-23 01:02:18 +01:00
parent 9d8c48817d
commit 1fb212b553
12 changed files with 68 additions and 31 deletions

View File

@ -2,9 +2,12 @@
namespace App\Providers;
use App\Setting\GeneralSettings;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Zoomyboy\LaravelNami\Authentication\NamiGuard;
class AppServiceProvider extends ServiceProvider
{
@ -24,7 +27,6 @@ class AppServiceProvider extends ServiceProvider
return $this;
});
}
/**
@ -34,6 +36,10 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
//
NamiGuard::beforeLogin(function(array $credentials) {
return in_array($credentials['mglnr'], app(GeneralSettings::class)->allowed_nami_accounts)
? null
: false;
});
}
}

View File

@ -12,6 +12,9 @@ class GeneralSettings extends Settings
public bool $single_view;
/** @var array<int, int> */
public array $allowed_nami_accounts;
/**
* @return array<int, string>
*/

View File

@ -0,0 +1,11 @@
<?php
use Spatie\LaravelSettings\Migrations\SettingsMigration;
class CreateAllowedNamiLoginSetting extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('general.allowed_nami_accounts', []);
}
}

@ -1 +1 @@
Subproject commit d96457dd338857306b6ffb14da5444b8cf08417a
Subproject commit 6d6aa60363554c7f049ff91691302c7ef5c92d79

View File

@ -23,9 +23,8 @@ class DeleteTest extends TestCase
app(CourseFake::class)->deleteSuccessful(123, 999);
$member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne();
$response = $this->delete("/member/{$member->id}/course/{$member->courses->first()->id}");
$this->delete("/member/{$member->id}/course/{$member->courses->first()->id}");
$response->assertRedirect("/member");
$this->assertDatabaseCount('course_members', 0);
app(CourseFake::class)->assertDeleted(123, 999);
}

View File

@ -77,14 +77,13 @@ class StoreTest extends TestCase
$course = Course::factory()->inNami(456)->createOne();
app(CourseFake::class)->createsSuccessful(123, 999);
$response = $this->post("/member/{$member->id}/course", [
$this->post("/member/{$member->id}/course", [
'course_id' => $course->id,
'completed_at' => '2021-01-02',
'event_name' => '::event::',
'organizer' => '::org::',
]);
$response->assertRedirect("/member");
$this->assertDatabaseHas('course_members', [
'member_id' => $member->id,
'course_id' => $course->id,

View File

@ -78,14 +78,13 @@ class UpdateTest extends TestCase
$member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne();
$newCourse = Course::factory()->inNami(789)->create();
$response = $this->patch("/member/{$member->id}/course/{$member->courses->first()->id}", array_merge([
$this->patch("/member/{$member->id}/course/{$member->courses->first()->id}", array_merge([
'course_id' => $newCourse->id,
'completed_at' => '1999-02-03',
'event_name' => '::newevent::',
'organizer' => '::neworg::',
]));
$response->assertRedirect("/member");
$this->assertDatabaseHas('course_members', [
'member_id' => $member->id,
'course_id' => $newCourse->id,
@ -115,7 +114,7 @@ class UpdateTest extends TestCase
'event_name' => '::event::',
'organizer' => '::org::',
]);
$response->assertSessionHasErrors(['id' => 'Unbekannter Fehler']);
}

View File

@ -65,10 +65,7 @@ class InitializeTest extends TestCase
{
$this->withoutExceptionHandling();
$this->initializeProvider();
$this->post('/login', [
'mglnr' => 123,
'password' => 'secret',
]);
$this->login();
$this->post('/initialize');
@ -129,10 +126,7 @@ class InitializeTest extends TestCase
$this->member(['courses' => [ ['bausteinId' => 506, 'id' => 788, 'veranstalter' => 'KJA', 'vstgName' => 'eventname', 'vstgTag' => '2021-11-12 00:00:00'] ]])
]);
});
$this->post('/login', [
'mglnr' => 123,
'password' => 'secret',
]);
$this->login();
$this->post('/initialize');
@ -152,10 +146,7 @@ class InitializeTest extends TestCase
$this->initializeProvider(function($backend) {
$backend->fakeMembers([$this->member(['eintrittsdatum' => null])]);
});
$this->post('/login', [
'mglnr' => 123,
'password' => 'secret',
]);
$this->login();
$this->post('/initialize');
@ -192,11 +183,7 @@ class InitializeTest extends TestCase
$backend->fakeMembers($members->toArray());
});
$this->post('/login', [
'mglnr' => 123,
'password' => 'secret',
]);
$this->login();
$this->post('/initialize');

View File

@ -2,6 +2,7 @@
namespace Tests\Feature;
use App\Setting\GeneralSettings;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Cache;
@ -13,6 +14,8 @@ use Zoomyboy\LaravelNami\Backend\FakeBackend;
class LoginTest extends TestCase
{
use RefreshDatabase;
public function setUp(): void
{
parent::setUp();
@ -21,6 +24,7 @@ class LoginTest extends TestCase
public function testItCanLoginWithANamiAccount(): void
{
$this->withoutExceptionHandling();
$this->setLoginId(123);
app(FakeBackend::class)
->fakeLogin('123')
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]);
@ -43,6 +47,7 @@ class LoginTest extends TestCase
public function testItDoesntLoginTwoTimes(): void
{
$this->withoutExceptionHandling();
$this->setLoginId(123);
app(FakeBackend::class)
->fakeLogin('123')
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]);
@ -65,6 +70,7 @@ class LoginTest extends TestCase
public function testItResolvesTheLoginFromTheCache(): void
{
$this->withoutExceptionHandling();
$this->setLoginId(123);
app(FakeBackend::class)
->fakeLogin('123')
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]);
@ -86,6 +92,7 @@ class LoginTest extends TestCase
public function testItThrowsExceptionWhenLoginFailed(): void
{
$this->setLoginId(123);
app(FakeBackend::class)->fakeFailedLogin();
$this->post('/login', [
@ -98,4 +105,29 @@ class LoginTest extends TestCase
Http::assertSentCount(2);
}
public function testItCannotLoginWithAWrongNamiId(): void
{
app(FakeBackend::class)
->fakeLogin('123')
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]);
$this->post('/login', [
'mglnr' => 123,
'password' => 'secret'
])->assertRedirect('/');
$this->assertTrue(auth()->guest());
Http::assertSentCount(0);
}
private function setLoginId(int $mglNr): self
{
GeneralSettings::fake([
'allowed_nami_accounts' => [$mglNr]
]);
return $this;
}
}

View File

@ -151,7 +151,7 @@ class GenerateTest extends TestCase
?array $output = null
): void {
$this->withoutExceptionHandling();
$this->login();
$this->login()->init();
$members = $this->setupMembers($members);
$urlId = call_user_func($urlCallable, $members);
@ -180,7 +180,7 @@ class GenerateTest extends TestCase
?array $output = null
): void {
$this->withoutExceptionHandling();
$this->login();
$this->login()->init();
$members = $this->setupMembers($members);
$urlId = call_user_func($urlCallable, $members);

View File

@ -15,7 +15,7 @@ class GlobalSettingTest extends TestCase
public function testItLoadsGeneralSettings(): void
{
GeneralSettings::fake([
'modules' => ['bill']
'modules' => ['bill'],
]);
$this->withoutExceptionHandling();
$this->login()->init();

View File

@ -3,6 +3,7 @@
namespace Tests;
use App\Member\Member;
use App\Setting\GeneralSettings;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Testing\TestResponse;
use Tests\Lib\InertiaMixin;
@ -25,7 +26,7 @@ abstract class TestCase extends BaseTestCase
app(FakeBackend::class)
->fakeLogin('123')
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]);
$this->post('/login', [
auth()->login([
'mglnr' => 123,
'password' => 'secret',
]);