mirror of https://github.com/Bubka/2FAuth.git
Fix pint issues
This commit is contained in:
parent
c6f8317d81
commit
7e1fdf67bb
|
@ -61,7 +61,7 @@ class UserAuthentication extends JsonResource
|
|||
'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 @@ class UserAuthentication extends JsonResource
|
|||
'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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use Illuminate\Validation\ValidationException;
|
|||
class RemoteUserProvider implements UserProvider
|
||||
{
|
||||
const FAKE_REMOTE_DOMAIN = '@remote';
|
||||
|
||||
|
||||
/**
|
||||
* The currently authenticated user.
|
||||
*
|
||||
|
|
|
@ -30,7 +30,7 @@ abstract class AbstractAccessListener
|
|||
|
||||
/**
|
||||
* Get the login method based on the request input parameters
|
||||
*/
|
||||
*/
|
||||
public function loginMethod() : ?string
|
||||
{
|
||||
if ($this->request->has('response.authenticatorData')) {
|
||||
|
|
|
@ -31,8 +31,6 @@ class FailedLoginListener extends AbstractAccessListener
|
|||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(mixed $event) : void
|
||||
{
|
||||
|
|
|
@ -32,8 +32,6 @@ class LoginListener extends AbstractAccessListener
|
|||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(mixed $event) : void
|
||||
{
|
||||
|
|
|
@ -31,8 +31,6 @@ class LogoutListener extends AbstractAccessListener
|
|||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(mixed $event) : void
|
||||
{
|
||||
|
|
|
@ -31,8 +31,6 @@ class OtherDeviceLogoutListener extends AbstractAccessListener
|
|||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(mixed $event) : void
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace App\Listeners\Authentication;
|
|||
|
||||
use App\Events\VisitedByProxyUser;
|
||||
use App\Extensions\RemoteUserProvider;
|
||||
use App\Listeners\Authentication\AbstractAccessListener;
|
||||
use App\Notifications\SignedInWithNewDevice;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
|
@ -12,15 +11,13 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var \App\Models\User
|
||||
*/
|
||||
|
@ -43,4 +40,4 @@ class VisitedByProxyUserListener extends AbstractAccessListener
|
|||
$user->notify(new SignedInWithNewDevice($log));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|||
class AuthLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*/
|
||||
|
|
|
@ -55,7 +55,7 @@ trait HasAuthenticationLog
|
|||
|
||||
/**
|
||||
* Get the user's latest authentication
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphOne<AuthLog>
|
||||
*/
|
||||
public function latestAuthentication()
|
||||
|
|
|
@ -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 @@ use Laravel\Passport\HasApiTokens;
|
|||
*/
|
||||
class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable
|
||||
{
|
||||
use HasAuthenticationLog;
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
use HasAuthenticationLog;
|
||||
use WebAuthnAuthentication, WebAuthnManageCredentials;
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,7 @@ use Jenssegers\Agent\Agent;
|
|||
class SignedInWithNewDevice extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
|
||||
/**
|
||||
* The AuthLog model instance
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -58,14 +58,17 @@ class OpenId extends AbstractProvider
|
|||
*/
|
||||
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,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -94,17 +94,17 @@ class UserControllerTest extends FeatureTestCase
|
|||
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;
|
||||
}
|
||||
|
||||
$this->user['preferences->' . $pref] = $userPrefs[$pref];
|
||||
}
|
||||
|
||||
|
||||
$this->user->save();
|
||||
|
||||
|
||||
$response = $this->actingAs($this->user, 'api-guard')
|
||||
->json('GET', '/api/v1/user/preferences')
|
||||
->assertJsonCount(count(config('2fauth.preferences')), $key = null);
|
||||
|
|
|
@ -96,36 +96,36 @@ class UserManagerControllerTest extends FeatureTestCase
|
|||
->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 @@ class UserManagerControllerTest extends FeatureTestCase
|
|||
$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 @@ class UserManagerControllerTest extends FeatureTestCase
|
|||
*/
|
||||
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 @@ class UserManagerControllerTest extends FeatureTestCase
|
|||
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 @@ class UserManagerControllerTest extends FeatureTestCase
|
|||
protected function logUserOut() : void
|
||||
{
|
||||
$this->actingAs($this->user, 'web-guard')
|
||||
->json('GET', '/user/logout');
|
||||
->json('GET', '/user/logout');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -90,7 +90,7 @@ class LoginTest extends FeatureTestCase
|
|||
])->assertOk();
|
||||
|
||||
$this->actingAs($this->user, 'web-guard')
|
||||
->json('GET', '/user/logout');
|
||||
->json('GET', '/user/logout');
|
||||
|
||||
$this->travel(1)->minute();
|
||||
|
||||
|
@ -98,7 +98,7 @@ class LoginTest extends FeatureTestCase
|
|||
'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 @@ class LoginTest extends FeatureTestCase
|
|||
])->assertOk();
|
||||
|
||||
$this->actingAs($this->user, 'web-guard')
|
||||
->json('GET', '/user/logout');
|
||||
->json('GET', '/user/logout');
|
||||
|
||||
$this->travel(1)->minute();
|
||||
|
||||
|
@ -128,7 +128,7 @@ class LoginTest extends FeatureTestCase
|
|||
'email' => $this->user->email,
|
||||
'password' => self::PASSWORD,
|
||||
], [
|
||||
'HTTP_USER_AGENT' => 'NotSymfony'
|
||||
'HTTP_USER_AGENT' => 'NotSymfony',
|
||||
])->assertOk();
|
||||
|
||||
Notification::assertNothingSentTo($this->user);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue