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 @@ public function toArray($request)
'platform' => $this->agent->platform(),
'device' => $this->agent->deviceType(),
'login_at' => $this->login_at
? Carbon::parse($this->login_at,)->tz($tz)->toDayDateTimeString()
? Carbon::parse($this->login_at)->tz($tz)->toDayDateTimeString()
: null,
'logout_at' => $this->logout_at
? Carbon::parse($this->logout_at)->tz($tz)->toDayDateTimeString()
@ -70,7 +70,7 @@ public function toArray($request)
'duration' => $this->logout_at
? Carbon::parse($this->logout_at)->diffForHumans(Carbon::parse($this->login_at), ['syntax' => CarbonInterface::DIFF_ABSOLUTE])
: null,
'login_method' => $this->login_method,
'login_method' => $this->login_method,
];
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,6 @@
use App\Events\VisitedByProxyUser;
use App\Extensions\RemoteUserProvider;
use App\Listeners\Authentication\AbstractAccessListener;
use App\Notifications\SignedInWithNewDevice;
use Illuminate\Support\Carbon;
@ -12,10 +11,8 @@ class VisitedByProxyUserListener extends AbstractAccessListener
{
/**
* Handle the event.
*
* @return void
*/
public function handle(mixed $event): void
public function handle(mixed $event) : void
{
if (! $event instanceof VisitedByProxyUser) {
return;

View File

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

View File

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

View File

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

View File

@ -94,9 +94,9 @@ public function test_allPreferences_returns_preferences_with_user_values()
foreach (config('2fauth.preferences') as $pref => $value) {
if (is_numeric($value)) {
$userPrefs[$pref] = $value + 1;
} else if (is_string($value)) {
} elseif (is_string($value)) {
$userPrefs[$pref] = $value . '_';
} else if (is_bool($value)) {
} elseif (is_bool($value)) {
$userPrefs[$pref] = ! $value;
}

View File

@ -96,36 +96,36 @@ public function test_index_returns_all_users_with_expected_UserManagerResources(
->assertJsonCount(3)
->assertJsonStructure([
'*' => [
"last_seen_at",
"created_at",
]
'last_seen_at',
'created_at',
],
])
->assertJsonFragment([
"id" => $this->user->id,
"name" => $this->user->name,
"email" => $this->user->email,
"oauth_provider" => null,
"preferences" => $this->defaultPreferences,
"is_admin" => false,
"twofaccounts_count" => 0,
'id' => $this->user->id,
'name' => $this->user->name,
'email' => $this->user->email,
'oauth_provider' => null,
'preferences' => $this->defaultPreferences,
'is_admin' => false,
'twofaccounts_count' => 0,
])
->assertJsonFragment([
"id" => $this->admin->id,
"name" => $this->admin->name,
"email" => $this->admin->email,
"oauth_provider" => null,
"preferences" => $this->defaultPreferences,
"is_admin" => true,
"twofaccounts_count" => 0,
'id' => $this->admin->id,
'name' => $this->admin->name,
'email' => $this->admin->email,
'oauth_provider' => null,
'preferences' => $this->defaultPreferences,
'is_admin' => true,
'twofaccounts_count' => 0,
])
->assertJsonFragment([
"id" => $this->anotherUser->id,
"name" => $this->anotherUser->name,
"email" => $this->anotherUser->email,
"oauth_provider" => null,
"preferences" => $this->defaultPreferences,
"is_admin" => false,
"twofaccounts_count" => 1,
'id' => $this->anotherUser->id,
'name' => $this->anotherUser->name,
'email' => $this->anotherUser->email,
'oauth_provider' => null,
'preferences' => $this->defaultPreferences,
'is_admin' => false,
'twofaccounts_count' => 1,
]);
}
@ -137,20 +137,20 @@ public function test_show_returns_the_expected_UserManagerResource() : void
$this->actingAs($this->admin, 'api-guard')
->json('GET', '/api/v1/users/' . $this->user->id)
->assertJson([
"info" => [
"id" => $this->user->id,
"name" => $this->user->name,
"email" => $this->user->email,
"oauth_provider" => null,
"preferences" => $this->defaultPreferences,
"is_admin" => false,
"twofaccounts_count" => 0,
"last_seen_at" => "1 second ago",
"created_at" => "1 second ago"
'info' => [
'id' => $this->user->id,
'name' => $this->user->name,
'email' => $this->user->email,
'oauth_provider' => null,
'preferences' => $this->defaultPreferences,
'is_admin' => false,
'twofaccounts_count' => 0,
'last_seen_at' => '1 second ago',
'created_at' => '1 second ago',
],
"password_reset" => null,
"valid_personal_access_tokens" => 0,
"webauthn_credentials" => 0
'password_reset' => null,
'valid_personal_access_tokens' => 0,
'webauthn_credentials' => 0,
]);
}
@ -607,11 +607,11 @@ public function test_authentications_returns_expected_resource() : void
*/
public function test_authentications_returns_resource_with_timezoned_dates() : void
{
$timezone = 'Europe/Paris';
$timezone = 'Europe/Paris';
$this->admin['preferences->timezone'] = $timezone;
$this->admin->save();
$now = now();
$now = now();
$timezonedNow = now($timezone);
AuthLog::factory()->for($this->user, 'authenticatable')->create([
@ -789,8 +789,8 @@ public static function LimitProvider()
public function test_authentications_returns_expected_ip_and_useragent_chunks() : void
{
AuthLog::factory()->for($this->user, 'authenticatable')->create([
'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',
'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',
]);
$this->actingAs($this->admin, 'api-guard')
@ -856,7 +856,7 @@ protected function logUserIn() : void
protected function logUserOut() : void
{
$this->actingAs($this->user, 'web-guard')
->json('GET', '/user/logout');
->json('GET', '/user/logout');
}
/**

View File

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

View File

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