withRoles([Role::query()->where('slug', Role::ADMINISTRATION)->firstOrFail()])->create(['password' => 'geheim123']); } public function test_only_linked_admins_can_switch_off_and_everything_follows(): void { $provider = $this->entraProvider(); $admin = $this->admin(); // Nicht verknüpft: würde sich aussperren Livewire::actingAs($admin)->test(ListIdentityProviders::class)->callAction('passwordOff'); $this->assertTrue(app(PasswordLogin::class)->enabled()); DB::table('user_identities')->insert(['user_id' => $admin->id, 'identity_provider_id' => $provider->id, 'subject' => 'oid-1', 'created_at' => now(), 'updated_at' => now()]); Livewire::actingAs($admin)->test(ListIdentityProviders::class)->callAction('passwordOff'); $this->assertFalse(app(PasswordLogin::class)->enabled()); auth()->logout(); $this->get('/login')->assertInertia(fn (Assert $p) => $p->where('passwordLogin', false)->where('canResetPassword', false)->has('providers', 1)); $this->post('/login', ['email' => $admin->email, 'password' => 'geheim123'])->assertSessionHasErrors('email'); $this->assertGuest(); $this->get('/forgot-password')->assertRedirect('/login'); $this->post('/forgot-password', ['email' => $admin->email])->assertRedirect('/login'); $this->getJson('/api/v1/config')->assertJsonPath('login.password', false); $this->postJson('/api/v1/token', ['email' => $admin->email, 'password' => 'geheim123', 'device_name' => 'iPhone'])->assertUnprocessable(); // Notausgang in der .env config(['inhaus.password_login_override' => 'true']); $this->post('/login', ['email' => $admin->email, 'password' => 'geheim123'])->assertRedirect(); $this->assertAuthenticatedAs($admin); } public function test_password_login_returns_when_no_provider_is_usable(): void { $provider = $this->entraProvider(); app(PasswordLogin::class)->set(false); $this->assertFalse(app(PasswordLogin::class)->enabled()); $provider->update(['enabled' => false]); $this->assertTrue(app(PasswordLogin::class)->enabled(), 'Sonst käme niemand mehr hinein'); $this->get('/login')->assertInertia(fn (Assert $p) => $p->where('passwordLogin', true)); } }