Fix pint issues

This commit is contained in:
Bubka 2024-04-26 08:01:20 +02:00
parent c6f8317d81
commit 7e1fdf67bb
18 changed files with 75 additions and 86 deletions

View File

@ -61,7 +61,7 @@ class UserAuthentication extends JsonResource
'platform' => $this->agent->platform(), 'platform' => $this->agent->platform(),
'device' => $this->agent->deviceType(), 'device' => $this->agent->deviceType(),
'login_at' => $this->login_at 'login_at' => $this->login_at
? Carbon::parse($this->login_at,)->tz($tz)->toDayDateTimeString() ? Carbon::parse($this->login_at)->tz($tz)->toDayDateTimeString()
: null, : null,
'logout_at' => $this->logout_at 'logout_at' => $this->logout_at
? Carbon::parse($this->logout_at)->tz($tz)->toDayDateTimeString() ? Carbon::parse($this->logout_at)->tz($tz)->toDayDateTimeString()
@ -70,7 +70,7 @@ class UserAuthentication extends JsonResource
'duration' => $this->logout_at 'duration' => $this->logout_at
? Carbon::parse($this->logout_at)->diffForHumans(Carbon::parse($this->login_at), ['syntax' => CarbonInterface::DIFF_ABSOLUTE]) ? Carbon::parse($this->logout_at)->diffForHumans(Carbon::parse($this->login_at), ['syntax' => CarbonInterface::DIFF_ABSOLUTE])
: null, : null,
'login_method' => $this->login_method, 'login_method' => $this->login_method,
]; ];
} }
} }

View File

@ -17,7 +17,7 @@ use Illuminate\Validation\ValidationException;
class RemoteUserProvider implements UserProvider class RemoteUserProvider implements UserProvider
{ {
const FAKE_REMOTE_DOMAIN = '@remote'; const FAKE_REMOTE_DOMAIN = '@remote';
/** /**
* The currently authenticated user. * The currently authenticated user.
* *

View File

@ -30,7 +30,7 @@ abstract class AbstractAccessListener
/** /**
* Get the login method based on the request input parameters * Get the login method based on the request input parameters
*/ */
public function loginMethod() : ?string public function loginMethod() : ?string
{ {
if ($this->request->has('response.authenticatorData')) { if ($this->request->has('response.authenticatorData')) {

View File

@ -31,8 +31,6 @@ class FailedLoginListener extends AbstractAccessListener
{ {
/** /**
* Handle the event. * Handle the event.
*
* @return void
*/ */
public function handle(mixed $event) : void public function handle(mixed $event) : void
{ {

View File

@ -32,8 +32,6 @@ class LoginListener extends AbstractAccessListener
{ {
/** /**
* Handle the event. * Handle the event.
*
* @return void
*/ */
public function handle(mixed $event) : void public function handle(mixed $event) : void
{ {

View File

@ -31,8 +31,6 @@ class LogoutListener extends AbstractAccessListener
{ {
/** /**
* Handle the event. * Handle the event.
*
* @return void
*/ */
public function handle(mixed $event) : void public function handle(mixed $event) : void
{ {

View File

@ -31,8 +31,6 @@ class OtherDeviceLogoutListener extends AbstractAccessListener
{ {
/** /**
* Handle the event. * Handle the event.
*
* @return void
*/ */
public function handle(mixed $event) : void public function handle(mixed $event) : void
{ {

View File

@ -4,7 +4,6 @@ namespace App\Listeners\Authentication;
use App\Events\VisitedByProxyUser; use App\Events\VisitedByProxyUser;
use App\Extensions\RemoteUserProvider; use App\Extensions\RemoteUserProvider;
use App\Listeners\Authentication\AbstractAccessListener;
use App\Notifications\SignedInWithNewDevice; use App\Notifications\SignedInWithNewDevice;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
@ -12,15 +11,13 @@ class VisitedByProxyUserListener extends AbstractAccessListener
{ {
/** /**
* Handle the event. * Handle the event.
*
* @return void
*/ */
public function handle(mixed $event): void public function handle(mixed $event) : void
{ {
if (! $event instanceof VisitedByProxyUser) { if (! $event instanceof VisitedByProxyUser) {
return; return;
} }
/** /**
* @var \App\Models\User * @var \App\Models\User
*/ */
@ -43,4 +40,4 @@ class VisitedByProxyUserListener extends AbstractAccessListener
$user->notify(new SignedInWithNewDevice($log)); $user->notify(new SignedInWithNewDevice($log));
} }
} }
} }

View File

@ -44,7 +44,7 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
class AuthLog extends Model class AuthLog extends Model
{ {
use HasFactory; use HasFactory;
/** /**
* Indicates if the model should be timestamped. * Indicates if the model should be timestamped.
*/ */

View File

@ -55,7 +55,7 @@ trait HasAuthenticationLog
/** /**
* Get the user's latest authentication * Get the user's latest authentication
* *
* @return \Illuminate\Database\Eloquent\Relations\MorphOne<AuthLog> * @return \Illuminate\Database\Eloquent\Relations\MorphOne<AuthLog>
*/ */
public function latestAuthentication() public function latestAuthentication()

View File

@ -2,8 +2,8 @@
namespace App\Models; namespace App\Models;
use App\Models\Traits\WebAuthnManageCredentials;
use App\Models\Traits\HasAuthenticationLog; use App\Models\Traits\HasAuthenticationLog;
use App\Models\Traits\WebAuthnManageCredentials;
use Illuminate\Auth\Events\PasswordReset; use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Contracts\Translation\HasLocalePreference; use Illuminate\Contracts\Translation\HasLocalePreference;
@ -53,8 +53,8 @@ use Laravel\Passport\HasApiTokens;
*/ */
class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable
{ {
use HasAuthenticationLog;
use HasApiTokens, HasFactory, Notifiable; use HasApiTokens, HasFactory, Notifiable;
use HasAuthenticationLog;
use WebAuthnAuthentication, WebAuthnManageCredentials; use WebAuthnAuthentication, WebAuthnManageCredentials;
/** /**

View File

@ -12,7 +12,7 @@ use Jenssegers\Agent\Agent;
class SignedInWithNewDevice extends Notification implements ShouldQueue class SignedInWithNewDevice extends Notification implements ShouldQueue
{ {
use Queueable; use Queueable;
/** /**
* The AuthLog model instance * The AuthLog model instance
*/ */

View File

@ -2,15 +2,15 @@
namespace App\Providers; namespace App\Providers;
use App\Listeners\Authentication\VisitedByProxyUserListener;
use App\Events\GroupDeleted; use App\Events\GroupDeleted;
use App\Events\GroupDeleting; use App\Events\GroupDeleting;
use App\Events\VisitedByProxyUser;
use App\Events\ScanForNewReleaseCalled; use App\Events\ScanForNewReleaseCalled;
use App\Events\TwoFAccountDeleted; use App\Events\TwoFAccountDeleted;
use App\Events\VisitedByProxyUser;
use App\Listeners\Authentication\FailedLoginListener; use App\Listeners\Authentication\FailedLoginListener;
use App\Listeners\Authentication\LoginListener; use App\Listeners\Authentication\LoginListener;
use App\Listeners\Authentication\LogoutListener; use App\Listeners\Authentication\LogoutListener;
use App\Listeners\Authentication\VisitedByProxyUserListener;
use App\Listeners\CleanIconStorage; use App\Listeners\CleanIconStorage;
use App\Listeners\DissociateTwofaccountFromGroup; use App\Listeners\DissociateTwofaccountFromGroup;
use App\Listeners\LogNotification; use App\Listeners\LogNotification;

View File

@ -58,14 +58,17 @@ class OpenId extends AbstractProvider
*/ */
public function refreshToken($refreshToken) public function refreshToken($refreshToken)
{ {
return $this->getHttpClient()->post($this->getTokenUrl(), [/** @phpstan-ignore-line */ return $this->getHttpClient()->post( /** @phpstan-ignore-line */
RequestOptions::FORM_PARAMS => [ $this->getTokenUrl(),
'client_id' => $this->clientId, [
'client_secret' => $this->clientSecret, RequestOptions::FORM_PARAMS => [
'grant_type' => 'refresh_token', 'client_id' => $this->clientId,
'refresh_token' => $refreshToken, 'client_secret' => $this->clientSecret,
], 'grant_type' => 'refresh_token',
]); 'refresh_token' => $refreshToken,
],
]
);
} }
/** /**

View File

@ -94,17 +94,17 @@ class UserControllerTest extends FeatureTestCase
foreach (config('2fauth.preferences') as $pref => $value) { foreach (config('2fauth.preferences') as $pref => $value) {
if (is_numeric($value)) { if (is_numeric($value)) {
$userPrefs[$pref] = $value + 1; $userPrefs[$pref] = $value + 1;
} else if (is_string($value)) { } elseif (is_string($value)) {
$userPrefs[$pref] = $value . '_'; $userPrefs[$pref] = $value . '_';
} else if (is_bool($value)) { } elseif (is_bool($value)) {
$userPrefs[$pref] = ! $value; $userPrefs[$pref] = ! $value;
} }
$this->user['preferences->' . $pref] = $userPrefs[$pref]; $this->user['preferences->' . $pref] = $userPrefs[$pref];
} }
$this->user->save(); $this->user->save();
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('GET', '/api/v1/user/preferences') ->json('GET', '/api/v1/user/preferences')
->assertJsonCount(count(config('2fauth.preferences')), $key = null); ->assertJsonCount(count(config('2fauth.preferences')), $key = null);

View File

@ -96,36 +96,36 @@ class UserManagerControllerTest extends FeatureTestCase
->assertJsonCount(3) ->assertJsonCount(3)
->assertJsonStructure([ ->assertJsonStructure([
'*' => [ '*' => [
"last_seen_at", 'last_seen_at',
"created_at", 'created_at',
] ],
]) ])
->assertJsonFragment([ ->assertJsonFragment([
"id" => $this->user->id, 'id' => $this->user->id,
"name" => $this->user->name, 'name' => $this->user->name,
"email" => $this->user->email, 'email' => $this->user->email,
"oauth_provider" => null, 'oauth_provider' => null,
"preferences" => $this->defaultPreferences, 'preferences' => $this->defaultPreferences,
"is_admin" => false, 'is_admin' => false,
"twofaccounts_count" => 0, 'twofaccounts_count' => 0,
]) ])
->assertJsonFragment([ ->assertJsonFragment([
"id" => $this->admin->id, 'id' => $this->admin->id,
"name" => $this->admin->name, 'name' => $this->admin->name,
"email" => $this->admin->email, 'email' => $this->admin->email,
"oauth_provider" => null, 'oauth_provider' => null,
"preferences" => $this->defaultPreferences, 'preferences' => $this->defaultPreferences,
"is_admin" => true, 'is_admin' => true,
"twofaccounts_count" => 0, 'twofaccounts_count' => 0,
]) ])
->assertJsonFragment([ ->assertJsonFragment([
"id" => $this->anotherUser->id, 'id' => $this->anotherUser->id,
"name" => $this->anotherUser->name, 'name' => $this->anotherUser->name,
"email" => $this->anotherUser->email, 'email' => $this->anotherUser->email,
"oauth_provider" => null, 'oauth_provider' => null,
"preferences" => $this->defaultPreferences, 'preferences' => $this->defaultPreferences,
"is_admin" => false, 'is_admin' => false,
"twofaccounts_count" => 1, 'twofaccounts_count' => 1,
]); ]);
} }
@ -137,20 +137,20 @@ class UserManagerControllerTest extends FeatureTestCase
$this->actingAs($this->admin, 'api-guard') $this->actingAs($this->admin, 'api-guard')
->json('GET', '/api/v1/users/' . $this->user->id) ->json('GET', '/api/v1/users/' . $this->user->id)
->assertJson([ ->assertJson([
"info" => [ 'info' => [
"id" => $this->user->id, 'id' => $this->user->id,
"name" => $this->user->name, 'name' => $this->user->name,
"email" => $this->user->email, 'email' => $this->user->email,
"oauth_provider" => null, 'oauth_provider' => null,
"preferences" => $this->defaultPreferences, 'preferences' => $this->defaultPreferences,
"is_admin" => false, 'is_admin' => false,
"twofaccounts_count" => 0, 'twofaccounts_count' => 0,
"last_seen_at" => "1 second ago", 'last_seen_at' => '1 second ago',
"created_at" => "1 second ago" 'created_at' => '1 second ago',
], ],
"password_reset" => null, 'password_reset' => null,
"valid_personal_access_tokens" => 0, 'valid_personal_access_tokens' => 0,
"webauthn_credentials" => 0 'webauthn_credentials' => 0,
]); ]);
} }
@ -607,11 +607,11 @@ class UserManagerControllerTest extends FeatureTestCase
*/ */
public function test_authentications_returns_resource_with_timezoned_dates() : void public function test_authentications_returns_resource_with_timezoned_dates() : void
{ {
$timezone = 'Europe/Paris'; $timezone = 'Europe/Paris';
$this->admin['preferences->timezone'] = $timezone; $this->admin['preferences->timezone'] = $timezone;
$this->admin->save(); $this->admin->save();
$now = now(); $now = now();
$timezonedNow = now($timezone); $timezonedNow = now($timezone);
AuthLog::factory()->for($this->user, 'authenticatable')->create([ AuthLog::factory()->for($this->user, 'authenticatable')->create([
@ -789,8 +789,8 @@ class UserManagerControllerTest extends FeatureTestCase
public function test_authentications_returns_expected_ip_and_useragent_chunks() : void public function test_authentications_returns_expected_ip_and_useragent_chunks() : void
{ {
AuthLog::factory()->for($this->user, 'authenticatable')->create([ AuthLog::factory()->for($this->user, 'authenticatable')->create([
'ip_address' => '127.0.0.1', 'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
]); ]);
$this->actingAs($this->admin, 'api-guard') $this->actingAs($this->admin, 'api-guard')
@ -856,7 +856,7 @@ class UserManagerControllerTest extends FeatureTestCase
protected function logUserOut() : void protected function logUserOut() : void
{ {
$this->actingAs($this->user, 'web-guard') $this->actingAs($this->user, 'web-guard')
->json('GET', '/user/logout'); ->json('GET', '/user/logout');
} }
/** /**

View File

@ -90,7 +90,7 @@ class LoginTest extends FeatureTestCase
])->assertOk(); ])->assertOk();
$this->actingAs($this->user, 'web-guard') $this->actingAs($this->user, 'web-guard')
->json('GET', '/user/logout'); ->json('GET', '/user/logout');
$this->travel(1)->minute(); $this->travel(1)->minute();
@ -98,7 +98,7 @@ class LoginTest extends FeatureTestCase
'email' => $this->user->email, 'email' => $this->user->email,
'password' => self::PASSWORD, 'password' => self::PASSWORD,
], [ ], [
'HTTP_USER_AGENT' => 'NotSymfony' 'HTTP_USER_AGENT' => 'NotSymfony',
])->assertOk(); ])->assertOk();
Notification::assertSentTo($this->user, SignedInWithNewDevice::class); Notification::assertSentTo($this->user, SignedInWithNewDevice::class);
@ -120,7 +120,7 @@ class LoginTest extends FeatureTestCase
])->assertOk(); ])->assertOk();
$this->actingAs($this->user, 'web-guard') $this->actingAs($this->user, 'web-guard')
->json('GET', '/user/logout'); ->json('GET', '/user/logout');
$this->travel(1)->minute(); $this->travel(1)->minute();
@ -128,7 +128,7 @@ class LoginTest extends FeatureTestCase
'email' => $this->user->email, 'email' => $this->user->email,
'password' => self::PASSWORD, 'password' => self::PASSWORD,
], [ ], [
'HTTP_USER_AGENT' => 'NotSymfony' 'HTTP_USER_AGENT' => 'NotSymfony',
])->assertOk(); ])->assertOk();
Notification::assertNothingSentTo($this->user); Notification::assertNothingSentTo($this->user);

View File

@ -3,11 +3,8 @@
namespace Tests\Unit\Listeners\Authentication; namespace Tests\Unit\Listeners\Authentication;
use App\Listeners\Authentication\LoginListener; use App\Listeners\Authentication\LoginListener;
use App\Models\User;
use Illuminate\Auth\Events\Login; use Illuminate\Auth\Events\Login;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Mockery;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use Tests\TestCase; use Tests\TestCase;