mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 08:13:11 +01:00
Fix phpstan & pint issues
This commit is contained in:
parent
e7f542816d
commit
f823f69dd2
@ -311,7 +311,7 @@ public function batchDestroy(TwoFAccountBatchRequest $request)
|
||||
/**
|
||||
* Checks ids length
|
||||
*
|
||||
* @param string $ids comma-separated ids
|
||||
* @param string $ids comma-separated ids
|
||||
* @return bool whether or not the number of ids is acceptable
|
||||
*/
|
||||
private function tooManyIds(string $ids) : bool
|
||||
|
@ -130,9 +130,9 @@ public function revokePATs(Request $request, User $user, TokenRepository $tokenR
|
||||
$tokens = $tokenRepository->forUser($user->getAuthIdentifier());
|
||||
|
||||
$tokens->load('client')->filter(function ($token) {
|
||||
return $token->client->personal_access_client && ! $token->revoked;
|
||||
return $token->client->personal_access_client && ! $token->revoked; /** @phpstan-ignore-line */
|
||||
})->each(function ($token) {
|
||||
$token->revoke();
|
||||
$token->revoke(); /** @phpstan-ignore-line */
|
||||
});
|
||||
|
||||
Log::info(sprintf('All personal access tokens for User ID #%s have been revoked', $user->id));
|
||||
@ -188,7 +188,7 @@ public function destroy(Request $request, User $user)
|
||||
/**
|
||||
* Promote (or demote) a user
|
||||
*
|
||||
* @return \App\Api\v1\Resources\UserManagerResource
|
||||
* @return \App\Api\v1\Resources\UserManagerResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function promote(UserManagerPromoteRequest $request, User $user)
|
||||
{
|
||||
@ -209,7 +209,7 @@ public function promote(UserManagerPromoteRequest $request, User $user)
|
||||
/**
|
||||
* Get the user's authentication logs
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
||||
*/
|
||||
public function authentications(Request $request, User $user)
|
||||
{
|
||||
@ -217,7 +217,7 @@ public function authentications(Request $request, User $user)
|
||||
|
||||
$validated = $this->validate($request, [
|
||||
'period' => 'sometimes|numeric',
|
||||
'limit' => 'sometimes|numeric',
|
||||
'limit' => 'sometimes|numeric',
|
||||
]);
|
||||
|
||||
$authentications = $request->has('period') ? $user->authenticationsByPeriod($validated['period']) : $user->authentications;
|
||||
|
@ -9,11 +9,15 @@
|
||||
|
||||
/**
|
||||
* @property mixed $id
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property string $oauth_provider
|
||||
* @property \Illuminate\Support\Collection<array-key, mixed> $preferences
|
||||
* @property string $is_admin
|
||||
* @property string $ip_address
|
||||
* @property string $user_agent
|
||||
* @property string $browser
|
||||
* @property string $platform
|
||||
* @property string $device
|
||||
* @property Carbon|null $login_at
|
||||
* @property Carbon|null $logout_at
|
||||
* @property bool $login_successful
|
||||
* @property string|null $duration
|
||||
*/
|
||||
class UserAuthentication extends JsonResource
|
||||
{
|
||||
@ -47,16 +51,16 @@ public function __construct($resource)
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'ip_address' => $this->ip_address,
|
||||
'user_agent' => $this->user_agent,
|
||||
'browser' => $this->agent->browser(),
|
||||
'platform' => $this->agent->platform(),
|
||||
'device' => $this->agent->deviceType(),
|
||||
'login_at' => $this->login_at
|
||||
'id' => $this->id,
|
||||
'ip_address' => $this->ip_address,
|
||||
'user_agent' => $this->user_agent,
|
||||
'browser' => $this->agent->browser(),
|
||||
'platform' => $this->agent->platform(),
|
||||
'device' => $this->agent->deviceType(),
|
||||
'login_at' => $this->login_at
|
||||
? Carbon::parse($this->login_at)->toDayDateTimeString()
|
||||
: null,
|
||||
'logout_at' => $this->logout_at
|
||||
'logout_at' => $this->logout_at
|
||||
? Carbon::parse($this->logout_at)->toDayDateTimeString()
|
||||
: null,
|
||||
'login_successful' => $this->login_successful,
|
||||
|
@ -55,7 +55,7 @@ public function __construct($resource)
|
||||
$tokens = $tokenRepository->forUser($this->resource->getAuthIdentifier());
|
||||
|
||||
$PATs_count = $tokens->load('client')->filter(function ($token) {
|
||||
return $token->client->personal_access_client && ! $token->revoked;
|
||||
return $token->client->personal_access_client && ! $token->revoked; /** @phpstan-ignore-line */
|
||||
})->count();
|
||||
|
||||
$this->with = [
|
||||
|
@ -80,7 +80,7 @@ public function retrieveById($identifier)
|
||||
/**
|
||||
* Set a fake email address
|
||||
*
|
||||
* @param $id mixed
|
||||
* @param $id mixed
|
||||
* @return string
|
||||
*/
|
||||
protected function fakeRemoteEmail(mixed $id)
|
||||
|
@ -19,7 +19,7 @@ class MigratorFactory implements MigratorFactoryInterface
|
||||
/**
|
||||
* Infer the type of migrator needed from a payload and create the migrator
|
||||
*
|
||||
* @param string $migrationPayload The migration payload used to infer the migrator type
|
||||
* @param string $migrationPayload The migration payload used to infer the migrator type
|
||||
*/
|
||||
public function create(string $migrationPayload) : Migrator
|
||||
{
|
||||
@ -41,7 +41,7 @@ public function create(string $migrationPayload) : Migrator
|
||||
/**
|
||||
* Determine if a payload comes from Google Authenticator
|
||||
*
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
*/
|
||||
private function isGoogleAuth(string $migrationPayload) : bool
|
||||
{
|
||||
@ -59,7 +59,7 @@ private function isGoogleAuth(string $migrationPayload) : bool
|
||||
/**
|
||||
* Determine if a payload is a plain text content
|
||||
*
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
*/
|
||||
private function isPlainText(string $migrationPayload) : bool
|
||||
{
|
||||
@ -77,7 +77,7 @@ private function isPlainText(string $migrationPayload) : bool
|
||||
/**
|
||||
* Determine if a payload comes from 2FAuth in JSON format
|
||||
*
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
*/
|
||||
private function isTwoFAuthJSON(string $migrationPayload) : bool
|
||||
{
|
||||
@ -105,7 +105,7 @@ private function isTwoFAuthJSON(string $migrationPayload) : bool
|
||||
/**
|
||||
* Determine if a payload comes from Aegis Authenticator in JSON format
|
||||
*
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @return bool
|
||||
*/
|
||||
private function isAegisJSON(string $migrationPayload) : mixed
|
||||
@ -150,7 +150,7 @@ private function isAegisJSON(string $migrationPayload) : mixed
|
||||
/**
|
||||
* Determine if a payload comes from 2FAS Authenticator
|
||||
*
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @return bool
|
||||
*/
|
||||
private function is2FASv2(string $migrationPayload) : mixed
|
||||
|
@ -9,7 +9,7 @@ interface MigratorFactoryInterface
|
||||
/**
|
||||
* Infer the type of migrator needed from a payload and create the migrator
|
||||
*
|
||||
* @param string $migrationPayload The migration payload used to infer the migrator type
|
||||
* @param string $migrationPayload The migration payload used to infer the migrator type
|
||||
*/
|
||||
public function create(string $migrationPayload) : Migrator;
|
||||
}
|
||||
|
@ -27,14 +27,14 @@ class Group extends Model
|
||||
/**
|
||||
* model's array form.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = ['name'];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $appends = [];
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Option extends Model
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'key',
|
||||
|
@ -95,7 +95,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
/**
|
||||
* model's array form.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
// 'service',
|
||||
@ -119,7 +119,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public $appends = [];
|
||||
|
||||
@ -611,7 +611,7 @@ private function initGenerator() : void
|
||||
* Store and set the provided icon
|
||||
*
|
||||
* @param \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource $data
|
||||
* @param string|null $extension The resource extension, without the dot
|
||||
* @param string|null $extension The resource extension, without the dot
|
||||
*/
|
||||
public function setIcon($data, $extension = null) : void
|
||||
{
|
||||
@ -633,7 +633,7 @@ public function setIcon($data, $extension = null) : void
|
||||
* Store img data as an icon file.
|
||||
*
|
||||
* @param \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource $content
|
||||
* @param string $extension The file extension, without the dot
|
||||
* @param string $extension The file extension, without the dot
|
||||
* @return string|null The filename of the stored icon or null if the operation fails
|
||||
*/
|
||||
private function storeFileDataAsIcon($content, $extension) : ?string
|
||||
|
@ -46,15 +46,9 @@
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog> $authentications
|
||||
* @property-read int|null $authentications_count
|
||||
* @property-read \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog|null $latestAuthentication
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User admins()
|
||||
* @method \Illuminate\Support\Carbon|null latestAuthentication()
|
||||
* @method \Illuminate\Support\Carbon|null lastLoginAt()
|
||||
* @method \Illuminate\Support\Carbon|null lastSuccessfulLoginAt()
|
||||
* @method \Illuminate\Support\Carbon|null lastLoginIp()
|
||||
* @method \Illuminate\Support\Carbon|null lastSuccessfulLoginIp()
|
||||
* @method \Illuminate\Support\Carbon|null previousLoginAt()
|
||||
* @method \Illuminate\Support\Carbon|null previousLoginIp()
|
||||
* @method \Illuminate\Support\Collection<int, \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog> authenticationsByPeriod()
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable
|
||||
@ -66,7 +60,7 @@ class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthe
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int,string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'oauth_id', 'oauth_provider',
|
||||
@ -148,15 +142,13 @@ public function promoteToAdministrator(bool $promote = true) : bool
|
||||
/**
|
||||
* Say if the user is the only registered administrator
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function isLastAdministrator()
|
||||
{
|
||||
$admins = User::admins()->get();
|
||||
|
||||
$toto = $admins->contains($this->id) && $admins->count() === 1;
|
||||
|
||||
return $toto;
|
||||
return $admins->contains($this->id) && $admins->count() === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Bubka\LaravelAuthenticationLog\Models\AuthenticationLog;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Jenssegers\Agent\Agent;
|
||||
use Bubka\LaravelAuthenticationLog\Models\AuthenticationLog;
|
||||
|
||||
class SignedInWithNewDevice extends Notification implements ShouldQueue
|
||||
{
|
||||
@ -32,10 +32,7 @@ public function __construct(AuthenticationLog $authenticationLog)
|
||||
$this->agent->setUserAgent($authenticationLog->user_agent);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function via($notifiable)
|
||||
public function via(mixed $notifiable) : array|string
|
||||
{
|
||||
return $notifiable->notifyAuthenticationLogVia();
|
||||
}
|
||||
@ -43,7 +40,7 @@ public function via($notifiable)
|
||||
/**
|
||||
* Wrap the notification to a mail envelop
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
public function toMail(mixed $notifiable) : MailMessage
|
||||
{
|
||||
return (new MailMessage())
|
||||
->subject(__('notifications.new_device.subject'))
|
||||
|
@ -58,7 +58,7 @@ protected function getUserByToken($token)
|
||||
*/
|
||||
public function refreshToken($refreshToken)
|
||||
{
|
||||
return $this->getHttpClient()->post($this->getTokenUrl(), [
|
||||
return $this->getHttpClient()->post($this->getTokenUrl(), [/** @phpstan-ignore-line */
|
||||
RequestOptions::FORM_PARAMS => [
|
||||
'client_id' => $this->clientId,
|
||||
'client_secret' => $this->clientSecret,
|
||||
|
@ -14,8 +14,8 @@ class GroupService
|
||||
/**
|
||||
* Assign one or more accounts to a group
|
||||
*
|
||||
* @param array|int $ids accounts ids to assign
|
||||
* @param \App\Models\Group|null $group The group the accounts will be assigned to
|
||||
* @param array|int $ids accounts ids to assign
|
||||
* @param \App\Models\Group|null $group The group the accounts will be assigned to
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
|
@ -33,7 +33,7 @@ public function __construct()
|
||||
/**
|
||||
* Fetch a logo for the given service and save it as an icon
|
||||
*
|
||||
* @param string $serviceName Name of the service to fetch a logo for
|
||||
* @param string $serviceName Name of the service to fetch a logo for
|
||||
* @return string|null The icon filename or null if no logo has been found
|
||||
*/
|
||||
public function getIcon($serviceName)
|
||||
@ -52,7 +52,7 @@ public function getIcon($serviceName)
|
||||
/**
|
||||
* Return the logo's filename for a given service
|
||||
*
|
||||
* @param string $serviceName Name of the service to fetch a logo for
|
||||
* @param string $serviceName Name of the service to fetch a logo for
|
||||
* @return string|null The logo filename or null if no logo has been found
|
||||
*/
|
||||
protected function getLogo($serviceName)
|
||||
@ -114,7 +114,7 @@ protected function cacheTfaDirectorySource() : void
|
||||
/**
|
||||
* Fetch and cache a logo from 2fa.Directory repository
|
||||
*
|
||||
* @param string $logoFile Logo filename to fetch
|
||||
* @param string $logoFile Logo filename to fetch
|
||||
*/
|
||||
protected function fetchLogo(string $logoFile) : void
|
||||
{
|
||||
|
@ -20,13 +20,13 @@ class GoogleAuthMigrator extends Migrator
|
||||
/**
|
||||
* Convert Google Authenticator migration URI to a set of TwoFAccount objects.
|
||||
*
|
||||
* @param mixed $migrationPayload migration uri provided by Google Authenticator export feature
|
||||
* @param mixed $migrationPayload migration uri provided by Google Authenticator export feature
|
||||
* @return \Illuminate\Support\Collection<int|string, \App\Models\TwoFAccount> The converted accounts
|
||||
*/
|
||||
public function migrate(mixed $migrationPayload) : Collection
|
||||
{
|
||||
try {
|
||||
$migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', $migrationPayload)));
|
||||
$migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', strval($migrationPayload))));
|
||||
$protobuf = new Payload();
|
||||
$protobuf->mergeFromString($migrationData);
|
||||
$otpParameters = $protobuf->getOtpParameters();
|
||||
|
@ -15,7 +15,7 @@ class QrCodeService
|
||||
/**
|
||||
* Encode a string into a QR code image
|
||||
*
|
||||
* @param string $data The string to encode
|
||||
* @param string $data The string to encode
|
||||
* @return mixed
|
||||
*/
|
||||
public static function encode(string $data)
|
||||
@ -55,19 +55,12 @@ public static function decode(\Illuminate\Http\UploadedFile $file)
|
||||
switch (get_class($qrcode->getError())) {
|
||||
case NotFoundException::class:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_detect_qrcode_in_image'));
|
||||
break;
|
||||
|
||||
case FormatException::class:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_decode_detected_qrcode'));
|
||||
break;
|
||||
|
||||
case ChecksumException::class:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.qrcode_has_invalid_checksum'));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.no_readable_qrcode'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public function __construct()
|
||||
/**
|
||||
* Get a setting
|
||||
*
|
||||
* @param string $setting A single setting name
|
||||
* @param string $setting A single setting name
|
||||
* @return mixed string|int|boolean|null
|
||||
*/
|
||||
public function get($setting)
|
||||
@ -67,8 +67,8 @@ public function all() : Collection
|
||||
/**
|
||||
* Set a setting
|
||||
*
|
||||
* @param string|array $setting A single setting name or an associative array of name:value settings
|
||||
* @param string|int|bool|null $value The value for single setting
|
||||
* @param string|array $setting A single setting name or an associative array of name:value settings
|
||||
* @param string|int|bool|null $value The value for single setting
|
||||
*/
|
||||
public function set($setting, $value = null) : void
|
||||
{
|
||||
@ -93,7 +93,7 @@ public function set($setting, $value = null) : void
|
||||
/**
|
||||
* Delete a setting
|
||||
*
|
||||
* @param string $name The setting name
|
||||
* @param string $name The setting name
|
||||
*/
|
||||
public function delete(string $name) : void
|
||||
{
|
||||
@ -200,7 +200,7 @@ private function setEncryptionTo(bool $state) : void
|
||||
/**
|
||||
* Encrypt/Decrypt accounts in database
|
||||
*
|
||||
* @param bool $encrypted Whether the record should be encrypted or not
|
||||
* @param bool $encrypted Whether the record should be encrypted or not
|
||||
* @return bool Whether the operation completed successfully
|
||||
*/
|
||||
private function updateRecords(bool $encrypted) : bool
|
||||
|
@ -28,7 +28,7 @@ public function __construct(MigratorFactoryInterface $migratorFactory)
|
||||
/**
|
||||
* Withdraw one or more twofaccounts from their group
|
||||
*
|
||||
* @param int|array|string $ids twofaccount ids to free
|
||||
* @param int|array|string $ids twofaccount ids to free
|
||||
*/
|
||||
public static function withdraw($ids) : void
|
||||
{
|
||||
@ -50,7 +50,7 @@ public static function withdraw($ids) : void
|
||||
/**
|
||||
* Convert a migration payload to a set of TwoFAccount objects
|
||||
*
|
||||
* @param string $migrationPayload Migration payload from 2FA apps export feature
|
||||
* @param string $migrationPayload Migration payload from 2FA apps export feature
|
||||
* @return \Illuminate\Support\Collection<int|string, TwoFAccount> The converted accounts
|
||||
*/
|
||||
public function migrate(string $migrationPayload) : Collection
|
||||
@ -64,7 +64,7 @@ public function migrate(string $migrationPayload) : Collection
|
||||
/**
|
||||
* Export one or more twofaccounts
|
||||
*
|
||||
* @param int|array|string $ids twofaccount ids to delete
|
||||
* @param int|array|string $ids twofaccount ids to delete
|
||||
* @return \Illuminate\Support\Collection<int, TwoFAccount> The converted accounts
|
||||
*/
|
||||
public static function export($ids) : Collection
|
||||
@ -80,7 +80,7 @@ public static function export($ids) : Collection
|
||||
/**
|
||||
* Delete one or more twofaccounts
|
||||
*
|
||||
* @param int|array|string $ids twofaccount ids to delete
|
||||
* @param int|array|string $ids twofaccount ids to delete
|
||||
* @return int The number of deleted
|
||||
*/
|
||||
public static function delete($ids) : int
|
||||
|
@ -561,7 +561,7 @@ protected function feedAuthenticationLog() : int
|
||||
public function test_authentications_returns_all_entries() : void
|
||||
{
|
||||
$created = $this->feedAuthenticationLog();
|
||||
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications')
|
||||
->assertOk()
|
||||
@ -574,7 +574,7 @@ public function test_authentications_returns_all_entries() : void
|
||||
public function test_authentications_returns_expected_resource() : void
|
||||
{
|
||||
$this->user->authentications()->create(AuthenticationLogData::duringLastMonth());
|
||||
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications')
|
||||
->assertJsonStructure([
|
||||
@ -589,7 +589,7 @@ public function test_authentications_returns_expected_resource() : void
|
||||
'logout_at',
|
||||
'login_successful',
|
||||
'duration',
|
||||
]
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
@ -599,12 +599,12 @@ public function test_authentications_returns_expected_resource() : void
|
||||
public function test_authentications_returns_no_login_entry() : void
|
||||
{
|
||||
$this->user->authentications()->create(AuthenticationLogData::noLogin());
|
||||
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
|
||||
->assertJsonCount(1)
|
||||
->assertJsonFragment([
|
||||
'login_at' => null
|
||||
'login_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -614,12 +614,12 @@ public function test_authentications_returns_no_login_entry() : void
|
||||
public function test_authentications_returns_no_logout_entry() : void
|
||||
{
|
||||
$this->user->authentications()->create(AuthenticationLogData::noLogout());
|
||||
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
|
||||
->assertJsonCount(1)
|
||||
->assertJsonFragment([
|
||||
'logout_at' => null
|
||||
'logout_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -630,12 +630,12 @@ public function test_authentications_returns_failed_entry() : void
|
||||
{
|
||||
$this->user->authentications()->create(AuthenticationLogData::failedLogin());
|
||||
$expected = Carbon::parse(AuthenticationLogData::failedLogin()['login_at'])->toDayDateTimeString();
|
||||
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
|
||||
->assertJsonCount(1)
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expected,
|
||||
'login_at' => $expected,
|
||||
'login_successful' => false,
|
||||
]);
|
||||
}
|
||||
@ -647,12 +647,12 @@ public function test_authentications_returns_last_month_entries() : void
|
||||
{
|
||||
$this->feedAuthenticationLog();
|
||||
$expected = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
|
||||
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
|
||||
->assertJsonCount(3)
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expected
|
||||
'login_at' => $expected,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -662,17 +662,17 @@ public function test_authentications_returns_last_month_entries() : void
|
||||
public function test_authentications_returns_last_three_months_entries() : void
|
||||
{
|
||||
$this->feedAuthenticationLog();
|
||||
$expectedOneMonth = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedOneMonth = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedThreeMonth = Carbon::parse(AuthenticationLogData::duringLastThreeMonth()['login_at'])->toDayDateTimeString();
|
||||
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=3')
|
||||
->assertJsonCount(4)
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedOneMonth
|
||||
'login_at' => $expectedOneMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedThreeMonth
|
||||
'login_at' => $expectedThreeMonth,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -682,21 +682,21 @@ public function test_authentications_returns_last_three_months_entries() : void
|
||||
public function test_authentications_returns_last_six_months_entries() : void
|
||||
{
|
||||
$this->feedAuthenticationLog();
|
||||
$expectedOneMonth = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedOneMonth = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedThreeMonth = Carbon::parse(AuthenticationLogData::duringLastThreeMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedSixMonth = Carbon::parse(AuthenticationLogData::duringLastSixMonth()['login_at'])->toDayDateTimeString();
|
||||
|
||||
$expectedSixMonth = Carbon::parse(AuthenticationLogData::duringLastSixMonth()['login_at'])->toDayDateTimeString();
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=6')
|
||||
->assertJsonCount(5)
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedOneMonth
|
||||
'login_at' => $expectedOneMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedThreeMonth
|
||||
'login_at' => $expectedThreeMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedSixMonth
|
||||
'login_at' => $expectedSixMonth,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -706,25 +706,25 @@ public function test_authentications_returns_last_six_months_entries() : void
|
||||
public function test_authentications_returns_last_year_entries() : void
|
||||
{
|
||||
$this->feedAuthenticationLog();
|
||||
$expectedOneMonth = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedOneMonth = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedThreeMonth = Carbon::parse(AuthenticationLogData::duringLastThreeMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedSixMonth = Carbon::parse(AuthenticationLogData::duringLastSixMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedYear = Carbon::parse(AuthenticationLogData::duringLastYear()['login_at'])->toDayDateTimeString();
|
||||
|
||||
$expectedSixMonth = Carbon::parse(AuthenticationLogData::duringLastSixMonth()['login_at'])->toDayDateTimeString();
|
||||
$expectedYear = Carbon::parse(AuthenticationLogData::duringLastYear()['login_at'])->toDayDateTimeString();
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=12')
|
||||
->assertJsonCount(6)
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedOneMonth
|
||||
'login_at' => $expectedOneMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedThreeMonth
|
||||
'login_at' => $expectedThreeMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedSixMonth
|
||||
'login_at' => $expectedSixMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedYear
|
||||
'login_at' => $expectedYear,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -735,7 +735,7 @@ public function test_authentications_returns_last_year_entries() : void
|
||||
public function test_authentications_returns_limited_entries($limit) : void
|
||||
{
|
||||
$this->feedAuthenticationLog();
|
||||
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?limit=' . $limit)
|
||||
->assertOk()
|
||||
@ -760,21 +760,21 @@ public static function LimitProvider()
|
||||
public function test_authentications_returns_expected_ip_and_useragent_chunks() : void
|
||||
{
|
||||
$this->user->authentications()->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',
|
||||
'login_at' => now(),
|
||||
'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',
|
||||
'login_at' => now(),
|
||||
'login_successful' => true,
|
||||
'logout_at' => null,
|
||||
'location' => null,
|
||||
'logout_at' => null,
|
||||
'location' => null,
|
||||
]);
|
||||
|
||||
|
||||
$this->actingAs($this->admin, 'api-guard')
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
|
||||
->assertJsonFragment([
|
||||
'ip_address' => '127.0.0.1',
|
||||
'browser' => 'Firefox',
|
||||
'platform' => 'Windows',
|
||||
'device' => 'desktop',
|
||||
'browser' => 'Firefox',
|
||||
'platform' => 'Windows',
|
||||
'device' => 'desktop',
|
||||
]);
|
||||
}
|
||||
|
||||
@ -806,12 +806,11 @@ public function test_authentications_with_invalid_period_returns_validation_erro
|
||||
public static function invalidQueryParameterProvider()
|
||||
{
|
||||
return [
|
||||
'empty' => [''],
|
||||
'null' => ['null'],
|
||||
'empty' => [''],
|
||||
'null' => ['null'],
|
||||
'boolean' => ['true'],
|
||||
'string' => ['string'],
|
||||
'array' => ['[]'],
|
||||
'string' => ['string'],
|
||||
'array' => ['[]'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ class AuthenticationLogData
|
||||
public static function failedLogin()
|
||||
{
|
||||
$loginDate = now()->subDays(15);
|
||||
|
||||
|
||||
return [
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'login_successful' => false,
|
||||
'logout_at' => null,
|
||||
'location' => null,
|
||||
'logout_at' => null,
|
||||
'location' => null,
|
||||
];
|
||||
}
|
||||
|
||||
@ -31,12 +31,12 @@ public static function failedLogin()
|
||||
public static function noLogin()
|
||||
{
|
||||
return [
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => null,
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => null,
|
||||
'login_successful' => false,
|
||||
'logout_at' => now(),
|
||||
'location' => null,
|
||||
'logout_at' => now(),
|
||||
'location' => null,
|
||||
];
|
||||
}
|
||||
|
||||
@ -48,12 +48,12 @@ public static function noLogin()
|
||||
public static function noLogout()
|
||||
{
|
||||
return [
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => now(),
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => now(),
|
||||
'login_successful' => true,
|
||||
'logout_at' => null,
|
||||
'location' => null,
|
||||
'logout_at' => null,
|
||||
'location' => null,
|
||||
];
|
||||
}
|
||||
|
||||
@ -64,16 +64,16 @@ public static function noLogout()
|
||||
*/
|
||||
public static function duringLastMonth()
|
||||
{
|
||||
$loginDate = now()->subDays(15);
|
||||
$loginDate = now()->subDays(15);
|
||||
$logoutDate = $loginDate->addHours(1);
|
||||
|
||||
|
||||
return [
|
||||
'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',
|
||||
'login_at' => $loginDate,
|
||||
'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',
|
||||
'login_at' => $loginDate,
|
||||
'login_successful' => true,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
];
|
||||
}
|
||||
|
||||
@ -84,16 +84,16 @@ public static function duringLastMonth()
|
||||
*/
|
||||
public static function duringLastThreeMonth()
|
||||
{
|
||||
$loginDate = now()->subMonths(2);
|
||||
$loginDate = now()->subMonths(2);
|
||||
$logoutDate = $loginDate->addHours(1);
|
||||
|
||||
|
||||
return [
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'login_successful' => true,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
];
|
||||
}
|
||||
|
||||
@ -104,16 +104,16 @@ public static function duringLastThreeMonth()
|
||||
*/
|
||||
public static function duringLastSixMonth()
|
||||
{
|
||||
$loginDate = now()->subMonths(4);
|
||||
$loginDate = now()->subMonths(4);
|
||||
$logoutDate = $loginDate->addHours(1);
|
||||
|
||||
|
||||
return [
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'login_successful' => true,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
];
|
||||
}
|
||||
|
||||
@ -124,16 +124,16 @@ public static function duringLastSixMonth()
|
||||
*/
|
||||
public static function duringLastYear()
|
||||
{
|
||||
$loginDate = now()->subMonths(10);
|
||||
$loginDate = now()->subMonths(10);
|
||||
$logoutDate = $loginDate->addHours(1);
|
||||
|
||||
|
||||
return [
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'login_successful' => true,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
];
|
||||
}
|
||||
|
||||
@ -144,16 +144,16 @@ public static function duringLastYear()
|
||||
*/
|
||||
public static function beforeLastYear()
|
||||
{
|
||||
$loginDate = now()->subYears(2);
|
||||
$loginDate = now()->subYears(2);
|
||||
$logoutDate = $loginDate->addHours(1);
|
||||
|
||||
|
||||
return [
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
'login_at' => $loginDate,
|
||||
'login_successful' => true,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
'logout_at' => $logoutDate,
|
||||
'location' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user