Apply Pint fixes

This commit is contained in:
Bubka 2024-09-26 23:50:01 +02:00
parent 18fe45778a
commit c00b04e192
118 changed files with 398 additions and 458 deletions

View File

@ -6,7 +6,6 @@
use App\Api\v1\Requests\SettingUpdateRequest; use App\Api\v1\Requests\SettingUpdateRequest;
use App\Facades\Settings; use App\Facades\Settings;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Validation\ValidationException;
class SettingController extends Controller class SettingController extends Controller
{ {
@ -100,7 +99,7 @@ public function destroy(string $settingName)
// When deleting a setting, it may be an original or an additional one: // When deleting a setting, it may be an original or an additional one:
// - Additional settings are created by administrators to extend 2FAuth, they are not registered in the laravel config object. // - Additional settings are created by administrators to extend 2FAuth, they are not registered in the laravel config object.
// They are not nullable so empty string is not allowed.They only exist in the Options table, so it is possible to delete them. // They are not nullable so empty string is not allowed.They only exist in the Options table, so it is possible to delete them.
// - Original settings are part of 2FAuth, they are registered in the laravel config object with their default value. // - Original settings are part of 2FAuth, they are registered in the laravel config object with their default value.
// When set by an admin, their custom value is stored in the Options table too. Deleting a custom value in the Options table from here // When set by an admin, their custom value is stored in the Options table too. Deleting a custom value in the Options table from here
// won't delete the setting at all, so we reject all requests that ask for. // won't delete the setting at all, so we reject all requests that ask for.

View File

@ -111,8 +111,9 @@ public function update(TwoFAccountUpdateRequest $request, TwoFAccount $twofaccou
if ($twofaccount->group_id != $groupId) { if ($twofaccount->group_id != $groupId) {
if ((int) $groupId === 0) { if ((int) $groupId === 0) {
TwoFAccounts::withdraw($twofaccount->id); TwoFAccounts::withdraw($twofaccount->id);
} else {
Groups::assign($twofaccount->id, $request->user(), $groupId);
} }
else Groups::assign($twofaccount->id, $request->user(), $groupId);
$twofaccount->refresh(); $twofaccount->refresh();
} }
@ -151,7 +152,7 @@ public function reorder(TwoFAccountReorderRequest $request)
$validated = $request->validated(); $validated = $request->validated();
$twofaccounts = TwoFAccount::whereIn('id', $validated['orderedIds'])->get(); $twofaccounts = TwoFAccount::whereIn('id', $validated['orderedIds'])->get();
$this->authorize('updateEach', [new TwoFAccount(), $twofaccounts]); $this->authorize('updateEach', [new TwoFAccount, $twofaccounts]);
TwoFAccount::setNewOrder($validated['orderedIds']); TwoFAccount::setNewOrder($validated['orderedIds']);
$orderedIds = $request->user()->twofaccounts->sortBy('order_column')->pluck('id'); $orderedIds = $request->user()->twofaccounts->sortBy('order_column')->pluck('id');
@ -192,7 +193,7 @@ public function export(TwoFAccountBatchRequest $request)
} }
$twofaccounts = TwoFAccounts::export($validated['ids']); $twofaccounts = TwoFAccounts::export($validated['ids']);
$this->authorize('viewEach', [new TwoFAccount(), $twofaccounts]); $this->authorize('viewEach', [new TwoFAccount, $twofaccounts]);
return new TwoFAccountExportCollection($twofaccounts); return new TwoFAccountExportCollection($twofaccounts);
} }
@ -231,7 +232,7 @@ public function otp(Request $request, $id = null)
// The request inputs should define an account // The request inputs should define an account
else { else {
$validatedData = $request->validate((new TwoFAccountStoreRequest)->rules()); $validatedData = $request->validate((new TwoFAccountStoreRequest)->rules());
$twofaccount = new TwoFAccount(); $twofaccount = new TwoFAccount;
$twofaccount->fillWithOtpParameters($validatedData, true); $twofaccount->fillWithOtpParameters($validatedData, true);
} }
@ -267,7 +268,7 @@ public function withdraw(TwoFAccountBatchRequest $request)
$ids = Helpers::commaSeparatedToArray($validated['ids']); $ids = Helpers::commaSeparatedToArray($validated['ids']);
$twofaccounts = TwoFAccount::whereIn('id', $ids)->get(); $twofaccounts = TwoFAccount::whereIn('id', $ids)->get();
$this->authorize('updateEach', [new TwoFAccount(), $twofaccounts]); $this->authorize('updateEach', [new TwoFAccount, $twofaccounts]);
TwoFAccounts::withdraw($ids); TwoFAccounts::withdraw($ids);
@ -307,7 +308,7 @@ public function batchDestroy(TwoFAccountBatchRequest $request)
$ids = Helpers::commaSeparatedToArray($validated['ids']); $ids = Helpers::commaSeparatedToArray($validated['ids']);
$twofaccounts = TwoFAccount::whereIn('id', $ids)->get(); $twofaccounts = TwoFAccount::whereIn('id', $ids)->get();
$this->authorize('deleteEach', [new TwoFAccount(), $twofaccounts]); $this->authorize('deleteEach', [new TwoFAccount, $twofaccounts]);
TwoFAccounts::delete($validated['ids']); TwoFAccounts::delete($validated['ids']);

View File

@ -34,15 +34,13 @@ public function rules()
new IsValidEmailList, new IsValidEmailList,
], ],
]; ];
} } elseif ($routeParam == 'restrictRule') {
else if ($routeParam == 'restrictRule') {
$rule = [ $rule = [
'value' => [ 'value' => [
new IsValidRegex, new IsValidRegex,
], ],
]; ];
} } else {
else {
$rule = [ $rule = [
'value' => [ 'value' => [
'required', 'required',

View File

@ -37,7 +37,7 @@ class UserAuthenticationResource extends JsonResource
*/ */
public function __construct($resource) public function __construct($resource)
{ {
$this->agent = new Agent(); $this->agent = new Agent;
$this->agent->setUserAgent($resource->user_agent); $this->agent->setUserAgent($resource->user_agent);
parent::__construct($resource); parent::__construct($resource);

View File

@ -4,12 +4,8 @@
use App\Facades\Settings; use App\Facades\Settings;
use App\Models\TwoFAccount; use App\Models\TwoFAccount;
use Exception;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Throwable;
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
@ -75,16 +71,15 @@ public function handle()
*/ */
protected function encryptServiceField() : void protected function encryptServiceField() : void
{ {
$twofaccounts = TwoFAccount::all(); $twofaccounts = TwoFAccount::all();
$fullyEncryptedTwofaccounts = $twofaccounts->whereNotIn('service', [__('errors.indecipherable')]); $fullyEncryptedTwofaccounts = $twofaccounts->whereNotIn('service', [__('errors.indecipherable')]);
$partiallyEncryptedTwofaccounts = $twofaccounts->where('service', __('errors.indecipherable')); $partiallyEncryptedTwofaccounts = $twofaccounts->where('service', __('errors.indecipherable'));
if ($fullyEncryptedTwofaccounts->count() === $twofaccounts->count()) { if ($fullyEncryptedTwofaccounts->count() === $twofaccounts->count()) {
$this->components->info('The Service field is fully encrypted'); $this->components->info('The Service field is fully encrypted');
return; return;
} } else {
else {
$this->newLine(); $this->newLine();
$this->components->warn('The Service field is not fully encrypted, although it should be.'); $this->components->warn('The Service field is not fully encrypted, although it should be.');
$this->line('ID of corresponding records in the twofaccounts table:'); $this->line('ID of corresponding records in the twofaccounts table:');
@ -95,16 +90,17 @@ protected function encryptServiceField() : void
$partiallyEncryptedTwofaccounts->each(function (TwoFAccount $twofaccount, int $key) use (&$error) { $partiallyEncryptedTwofaccounts->each(function (TwoFAccount $twofaccount, int $key) use (&$error) {
// We don't want to encrypt the Service field with a different APP_KEY // We don't want to encrypt the Service field with a different APP_KEY
// than the one used to encrypt the legacy_uri, account and secret fields, the // than the one used to encrypt the legacy_uri, account and secret fields, the
// model would be inconsistent. // model would be inconsistent.
if (str_starts_with($twofaccount->legacy_uri, 'otpauth://')) { if (str_starts_with($twofaccount->legacy_uri, 'otpauth://')) {
$rawServiceValue = $twofaccount->getRawOriginal('service'); $rawServiceValue = $twofaccount->getRawOriginal('service');
$twofaccount->service = $rawServiceValue; $twofaccount->service = $rawServiceValue;
$twofaccount->save(); $twofaccount->save();
$this->components->task(sprintf('Fixing twofaccount record with ID #%s', $twofaccount->id)); $this->components->task(sprintf('Fixing twofaccount record with ID #%s', $twofaccount->id));
} } else {
else {
$error += 1; $error += 1;
$this->components->task(sprintf('Fixing twofaccount record with ID #%s', $twofaccount->id), function() { return false; }); $this->components->task(sprintf('Fixing twofaccount record with ID #%s', $twofaccount->id), function () {
return false;
});
$this->components->error('Wrong encryption key: The current APP_KEY cannot decipher already encrypted fields, encrypting the Service field with this key would lead to inconsistent data encryption'); $this->components->error('Wrong encryption key: The current APP_KEY cannot decipher already encrypted fields, encrypting the Service field with this key would lead to inconsistent data encryption');
} }
}); });
@ -116,8 +112,7 @@ protected function encryptServiceField() : void
} }
//$this->line('Task completed'); //$this->line('Task completed');
} } else {
else {
$this->components->warn('No fix applied.'); $this->components->warn('No fix applied.');
$this->line('You can re-run this command at any time to fix inconsistent records.'); $this->line('You can re-run this command at any time to fix inconsistent records.');
} }

View File

@ -81,8 +81,8 @@ protected function flushDB() : void
protected function seedDB(string $seeder) : void protected function seedDB(string $seeder) : void
{ {
$this->callSilent('db:seed', [ $this->callSilent('db:seed', [
'--class' => $seeder, '--class' => $seeder,
'--no-interaction' => 1 '--no-interaction' => 1,
]); ]);
$this->line('Database seeded'); $this->line('Database seeded');

View File

@ -9,6 +9,4 @@
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class DbEncryptionException extends Exception class DbEncryptionException extends Exception {}
{
}

View File

@ -9,6 +9,4 @@
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class EncryptedMigrationException extends Exception class EncryptedMigrationException extends Exception {}
{
}

View File

@ -9,6 +9,4 @@
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class InvalidMigrationDataException extends Exception class InvalidMigrationDataException extends Exception {}
{
}

View File

@ -9,6 +9,4 @@
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class InvalidOtpParameterException extends Exception class InvalidOtpParameterException extends Exception {}
{
}

View File

@ -9,6 +9,4 @@
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class InvalidQrCodeException extends Exception class InvalidQrCodeException extends Exception {}
{
}

View File

@ -9,6 +9,4 @@
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class InvalidSecretException extends Exception class InvalidSecretException extends Exception {}
{
}

View File

@ -9,6 +9,4 @@
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class UndecipherableException extends Exception class UndecipherableException extends Exception {}
{
}

View File

@ -9,6 +9,4 @@
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class UnsupportedMigrationException extends Exception class UnsupportedMigrationException extends Exception {}
{
}

View File

@ -9,6 +9,4 @@
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class UnsupportedOtpTypeException extends Exception class UnsupportedOtpTypeException extends Exception {}
{
}

View File

@ -34,7 +34,7 @@ public function create(string $migrationPayload) : Migrator
} elseif ($this->isPlainText($migrationPayload)) { } elseif ($this->isPlainText($migrationPayload)) {
return App::make(PlainTextMigrator::class); return App::make(PlainTextMigrator::class);
} else { } else {
throw new UnsupportedMigrationException(); throw new UnsupportedMigrationException;
} }
} }
@ -130,7 +130,7 @@ private function isAegisJSON(string $migrationPayload) : mixed
if (Arr::has($json, 'db')) { if (Arr::has($json, 'db')) {
if (is_string($json['db']) && is_array(Arr::get($json, 'header.slots'))) { if (is_string($json['db']) && is_array(Arr::get($json, 'header.slots'))) {
throw new EncryptedMigrationException(); throw new EncryptedMigrationException;
} else { } else {
return count(Validator::validate( return count(Validator::validate(
$json, $json,
@ -180,7 +180,7 @@ private function is2FASv2(string $migrationPayload) : mixed
if (Arr::has($json, 'schemaVersion') && (Arr::has($json, 'services') || Arr::has($json, 'servicesEncrypted'))) { if (Arr::has($json, 'schemaVersion') && (Arr::has($json, 'services') || Arr::has($json, 'servicesEncrypted'))) {
if (Arr::has($json, 'servicesEncrypted')) { if (Arr::has($json, 'servicesEncrypted')) {
throw new EncryptedMigrationException(); throw new EncryptedMigrationException;
} else { } else {
return count(Validator::validate( return count(Validator::validate(
$json, $json,

View File

@ -54,7 +54,7 @@ function ($user) use ($request) {
$user->save(); $user->save();
Log::notice(sprintf('Legacy login restored for user ID #%s', $user->id)); Log::notice(sprintf('Legacy login restored for user ID #%s', $user->id));
} else { } else {
throw new AuthenticationException(); throw new AuthenticationException;
} }
} }
); );

View File

@ -16,7 +16,7 @@ class SinglePageController extends Controller
*/ */
public function index() public function index()
{ {
event(new ScanForNewReleaseCalled()); event(new ScanForNewReleaseCalled);
$settings = Settings::all()->toJson(); $settings = Settings::all()->toJson();
$proxyAuth = config('auth.defaults.guard') === 'reverse-proxy-guard' ? true : false; $proxyAuth = config('auth.defaults.guard') === 'reverse-proxy-guard' ? true : false;
@ -45,9 +45,9 @@ public function index()
], ],
'subdirectory' => $subdir, 'subdirectory' => $subdir,
])->toJson(), ])->toJson(),
'urls' => collect([ 'urls' => collect([
'installDocUrl' => $installDocUrl, 'installDocUrl' => $installDocUrl,
'ssoDocUrl' => $ssoDocUrl 'ssoDocUrl' => $ssoDocUrl,
]), ]),
'defaultPreferences' => $defaultPreferences, 'defaultPreferences' => $defaultPreferences,
'subdirectory' => $subdir, 'subdirectory' => $subdir,

View File

@ -70,7 +70,7 @@ public function latestRelease(Request $request, ReleaseRadarService $releaseRada
public function testEmail(Request $request) public function testEmail(Request $request)
{ {
try { try {
$request->user()->notify(new TestEmailSettingNotification()); $request->user()->notify(new TestEmailSettingNotification);
} catch (\Throwable $th) { } catch (\Throwable $th) {
Log::error($th->getMessage()); Log::error($th->getMessage());
} }

View File

@ -11,7 +11,7 @@ class CustomCreateFreshApiToken extends CreateFreshApiToken
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @return bool * @return bool
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
protected function requestShouldReceiveFreshToken($request) protected function requestShouldReceiveFreshToken($request)

View File

@ -11,7 +11,7 @@ class ForceJsonResponse
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @return mixed * @return mixed
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)

View File

@ -24,15 +24,16 @@ public function handle($request, Closure $next)
if (Settings::get('useSsoOnly')) { if (Settings::get('useSsoOnly')) {
if ($email = $request->input('email', null)) { if ($email = $request->input('email', null)) {
$user = User::whereEmail($email)->first(); $user = User::whereEmail($email)->first();
} else {
$user = Auth::user();
} }
else $user = Auth::user();
if ($user?->isAdministrator()) { if ($user?->isAdministrator()) {
return $next($request); return $next($request);
} }
Log::notice(sprintf('Request to %s rejected, only Admins can request it while authentication is restricted to SSO only', $request->getPathInfo())); Log::notice(sprintf('Request to %s rejected, only Admins can request it while authentication is restricted to SSO only', $request->getPathInfo()));
return response()->json(['message' => __('errors.unsupported_with_sso_only')], Response::HTTP_METHOD_NOT_ALLOWED); return response()->json(['message' => __('errors.unsupported_with_sso_only')], Response::HTTP_METHOD_NOT_ALLOWED);
} }

View File

@ -8,7 +8,7 @@ class TrustProxies extends Middleware
{ {
/** /**
* TrustProxies constructor. * TrustProxies constructor.
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()

View File

@ -59,7 +59,8 @@ public function handle(mixed $event) : void
if ($user->preferences['notifyOnFailedLogin'] == true) { if ($user->preferences['notifyOnFailedLogin'] == true) {
$user->notify(new FailedLoginNotification($log)); $user->notify(new FailedLoginNotification($log));
} }
} else {
Log::info(sprintf('%s received an event with a null $user member. Nothing has been written to the auth log', self::class));
} }
else Log::info(sprintf('%s received an event with a null $user member. Nothing has been written to the auth log', self::class));
} }
} }

View File

@ -47,12 +47,12 @@ public function handle(mixed $event) : void
$ip = config('2fauth.proxy_headers.forIp') ?? $this->request->ip(); $ip = config('2fauth.proxy_headers.forIp') ?? $this->request->ip();
$userAgent = $this->request->userAgent(); $userAgent = $this->request->userAgent();
$known = $user->authentications() $known = $user->authentications()
->whereIpAddress($ip) ->whereIpAddress($ip)
->whereUserAgent($userAgent) ->whereUserAgent($userAgent)
->whereLoginSuccessful(true) ->whereLoginSuccessful(true)
->whereGuard($event->guard) ->whereGuard($event->guard)
->first(); ->first();
$newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1; $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1;
$log = $user->authentications()->create([ $log = $user->authentications()->create([
'ip_address' => $ip, 'ip_address' => $ip,

View File

@ -46,11 +46,11 @@ public function handle(mixed $event) : void
$ip = config('2fauth.proxy_headers.forIp') ?? $this->request->ip(); $ip = config('2fauth.proxy_headers.forIp') ?? $this->request->ip();
$userAgent = $this->request->userAgent(); $userAgent = $this->request->userAgent();
$log = $user->authentications() $log = $user->authentications()
->whereIpAddress($ip) ->whereIpAddress($ip)
->whereUserAgent($userAgent) ->whereUserAgent($userAgent)
->whereGuard($event->guard) ->whereGuard($event->guard)
->orderByDesc('login_at') ->orderByDesc('login_at')
->first(); ->first();
if (! $log) { if (! $log) {
$log = new AuthLog([ $log = new AuthLog([

View File

@ -30,7 +30,7 @@
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
* *
* Excluded from test coverage as long as 2FAuth does not offer a logout Other Devices feature * Excluded from test coverage as long as 2FAuth does not offer a logout Other Devices feature
* See \Illuminate\Auth\SessionGuard::logoutOtherDevices when the time comes * See \Illuminate\Auth\SessionGuard::logoutOtherDevices when the time comes
*/ */
@ -52,10 +52,10 @@ public function handle(mixed $event) : void
$ip = config('2fauth.proxy_headers.forIp') ?? $this->request->ip(); $ip = config('2fauth.proxy_headers.forIp') ?? $this->request->ip();
$userAgent = $this->request->userAgent(); $userAgent = $this->request->userAgent();
$authLog = $user->authentications() $authLog = $user->authentications()
->whereIpAddress($ip) ->whereIpAddress($ip)
->whereUserAgent($userAgent) ->whereUserAgent($userAgent)
->first(); ->first();
$guard = $event->guard; $guard = $event->guard;
if (! $authLog) { if (! $authLog) {
$authLog = new AuthLog([ $authLog = new AuthLog([

View File

@ -28,12 +28,12 @@ public function handle(mixed $event) : void
$userAgent = $this->request->userAgent(); $userAgent = $this->request->userAgent();
$guard = config('auth.defaults.guard'); $guard = config('auth.defaults.guard');
$known = $user->authentications() $known = $user->authentications()
->whereIpAddress($ip) ->whereIpAddress($ip)
->whereUserAgent($userAgent) ->whereUserAgent($userAgent)
->whereLoginSuccessful(true) ->whereLoginSuccessful(true)
->whereGuard($guard) ->whereGuard($guard)
->first(); ->first();
$newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1; $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1;
$log = $user->authentications()->create([ $log = $user->authentications()->create([
'ip_address' => $ip, 'ip_address' => $ip,

View File

@ -10,14 +10,14 @@
* @property int $id * @property int $id
* @property string $key * @property string $key
* @property string $value * @property string $value
* *
* @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Option newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Option newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Option query() * @method static \Illuminate\Database\Eloquent\Builder|Option query()
* @method static \Illuminate\Database\Eloquent\Builder|Option whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|Option whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Option whereKey($value) * @method static \Illuminate\Database\Eloquent\Builder|Option whereKey($value)
* @method static \Illuminate\Database\Eloquent\Builder|Option whereValue($value) * @method static \Illuminate\Database\Eloquent\Builder|Option whereValue($value)
* *
* @mixin \Eloquent * @mixin \Eloquent
*/ */
class Option extends Model class Option extends Model

View File

@ -70,12 +70,13 @@
class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable
{ {
use HasApiTokens, Notifiable; use HasApiTokens, Notifiable;
use HasAuthenticationLog; use HasAuthenticationLog;
/** /**
* @use HasFactory<UserFactory> * @use HasFactory<UserFactory>
*/ */
use HasFactory; use HasFactory;
use WebAuthnAuthentication, WebAuthnManageCredentials; use WebAuthnAuthentication, WebAuthnManageCredentials;
/** /**

View File

@ -31,7 +31,7 @@ class FailedLoginNotification extends Notification implements ShouldQueue
public function __construct(AuthLog $authLog) public function __construct(AuthLog $authLog)
{ {
$this->authLog = $authLog; $this->authLog = $authLog;
$this->agent = new Agent(); $this->agent = new Agent;
$this->agent->setUserAgent($authLog->user_agent); $this->agent->setUserAgent($authLog->user_agent);
} }
@ -48,7 +48,7 @@ public function via(mixed $notifiable) : array|string
*/ */
public function toMail(mixed $notifiable) : MailMessage public function toMail(mixed $notifiable) : MailMessage
{ {
return (new MailMessage()) return (new MailMessage)
->subject(__('notifications.failed_login.subject')) ->subject(__('notifications.failed_login.subject'))
->markdown('emails.failedLogin', [ ->markdown('emails.failedLogin', [
'account' => $notifiable, 'account' => $notifiable,

View File

@ -31,7 +31,7 @@ class SignedInWithNewDeviceNotification extends Notification implements ShouldQu
public function __construct(AuthLog $authLog) public function __construct(AuthLog $authLog)
{ {
$this->authLog = $authLog; $this->authLog = $authLog;
$this->agent = new Agent(); $this->agent = new Agent;
$this->agent->setUserAgent($authLog->user_agent); $this->agent->setUserAgent($authLog->user_agent);
} }
@ -45,7 +45,7 @@ public function via(mixed $notifiable) : array|string
*/ */
public function toMail(mixed $notifiable) : MailMessage public function toMail(mixed $notifiable) : MailMessage
{ {
return (new MailMessage()) return (new MailMessage)
->subject(__('notifications.new_device.subject')) ->subject(__('notifications.new_device.subject'))
->markdown('emails.signedInWithNewDevice', [ ->markdown('emails.signedInWithNewDevice', [
'account' => $notifiable, 'account' => $notifiable,

View File

@ -26,10 +26,7 @@ class TestEmailSettingNotification extends Notification
/** /**
* TestEmailSettingNotification constructor. * TestEmailSettingNotification constructor.
*/ */
public function __construct() public function __construct() {}
{
}
/** /**
* Get the notification's delivery channels. * Get the notification's delivery channels.

View File

@ -31,7 +31,7 @@ public function before(User $user, string $ability) : ?bool
/** /**
* Determine whether the user can view the model. * Determine whether the user can view the model.
* *
* @codeCoverageIgnore * @codeCoverageIgnore
* Ignored as long as the before() method restrict the access to admins only * Ignored as long as the before() method restrict the access to admins only
*/ */
@ -48,7 +48,7 @@ public function view(User $user, User $model) : bool
/** /**
* Determine whether the user can create models. * Determine whether the user can create models.
* *
* @codeCoverageIgnore * @codeCoverageIgnore
* Ignored as long as the before() method restrict the access to admins only * Ignored as long as the before() method restrict the access to admins only
*/ */
@ -59,7 +59,7 @@ public function create(?User $user) : bool
/** /**
* Determine whether the user can update the model. * Determine whether the user can update the model.
* *
* Not ignored because the user can update itself * Not ignored because the user can update itself
*/ */
public function update(User $user, User $model) : bool public function update(User $user, User $model) : bool
@ -75,7 +75,7 @@ public function update(User $user, User $model) : bool
/** /**
* Determine whether the user can delete the model. * Determine whether the user can delete the model.
* *
* @codeCoverageIgnore * @codeCoverageIgnore
* Ignored as long as the before() method restrict the access to admins only * Ignored as long as the before() method restrict the access to admins only
*/ */
@ -92,7 +92,7 @@ public function delete(User $user, User $model) : bool
/** /**
* Determine whether the user can promote the model. * Determine whether the user can promote the model.
* *
* @codeCoverageIgnore * @codeCoverageIgnore
* Ignored as long as the before() method restrict the access to admins only * Ignored as long as the before() method restrict the access to admins only
*/ */

View File

@ -20,19 +20,19 @@ public function register() : void
$this->app->bind(MigratorFactoryInterface::class, MigratorFactory::class); $this->app->bind(MigratorFactoryInterface::class, MigratorFactory::class);
$this->app->singleton(GoogleAuthMigrator::class, function () { $this->app->singleton(GoogleAuthMigrator::class, function () {
return new GoogleAuthMigrator(); return new GoogleAuthMigrator;
}); });
$this->app->singleton(AegisMigrator::class, function () { $this->app->singleton(AegisMigrator::class, function () {
return new AegisMigrator(); return new AegisMigrator;
}); });
$this->app->singleton(TwoFASMigrator::class, function () { $this->app->singleton(TwoFASMigrator::class, function () {
return new TwoFASMigrator(); return new TwoFASMigrator;
}); });
$this->app->singleton(PlainTextMigrator::class, function () { $this->app->singleton(PlainTextMigrator::class, function () {
return new PlainTextMigrator(); return new PlainTextMigrator;
}); });
} }

View File

@ -23,7 +23,7 @@ class OpenId extends AbstractProvider implements ProviderInterface
public function __construct(Request $request, $clientId, $clientSecret, $redirectUrl, $guzzle = []) public function __construct(Request $request, $clientId, $clientSecret, $redirectUrl, $guzzle = [])
{ {
$guzzle = array_merge([ $guzzle = array_merge([
'proxy' => config('2fauth.config.outgoingProxy') 'proxy' => config('2fauth.config.outgoingProxy'),
], $guzzle); ], $guzzle);
parent::__construct($request, $clientId, $clientSecret, $redirectUrl, $guzzle); parent::__construct($request, $clientId, $clientSecret, $redirectUrl, $guzzle);
@ -72,7 +72,7 @@ protected function getUserByToken($token)
*/ */
protected function mapUserToObject(array $user) protected function mapUserToObject(array $user)
{ {
return (new User())->setRaw($user)->map([ return (new User)->setRaw($user)->map([
'email' => $user['email'] ?? null, 'email' => $user['email'] ?? null,
'email_verified' => $user['email_verified'] ?? null, 'email_verified' => $user['email_verified'] ?? null,
'name' => $user['name'] ?? null, 'name' => $user['name'] ?? null,

View File

@ -25,15 +25,15 @@ public function register()
}); });
$this->app->singleton(SettingService::class, function () { $this->app->singleton(SettingService::class, function () {
return new SettingService(); return new SettingService;
}); });
$this->app->singleton(LogoService::class, function () { $this->app->singleton(LogoService::class, function () {
return new LogoService(); return new LogoService;
}); });
$this->app->singleton(ReleaseRadarService::class, function () { $this->app->singleton(ReleaseRadarService::class, function () {
return new ReleaseRadarService(); return new ReleaseRadarService;
}); });
$this->app->bind(QrReader::class, function ($app, $parameters) { $this->app->bind(QrReader::class, function ($app, $parameters) {

View File

@ -14,12 +14,11 @@ public function validate(string $attribute, mixed $value, Closure $fail) : void
{ {
try { try {
preg_match('/' . $value . '/', ''); preg_match('/' . $value . '/', '');
if (preg_last_error() !== PREG_NO_ERROR) { if (preg_last_error() !== PREG_NO_ERROR) {
$fail('validation.IsValidRegex')->translate(); $fail('validation.IsValidRegex')->translate();
} }
} } catch (\Throwable $ex) {
catch (\Throwable $ex) {
$fail('validation.IsValidRegex')->translate(); $fail('validation.IsValidRegex')->translate();
} }
} }

View File

@ -5,11 +5,9 @@
namespace App\Services\Auth; namespace App\Services\Auth;
use App\Events\VisitedByProxyUser;
use Illuminate\Auth\GuardHelpers; use Illuminate\Auth\GuardHelpers;
use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\UserProvider; use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class ReverseProxyGuard implements Guard class ReverseProxyGuard implements Guard

View File

@ -29,7 +29,7 @@ public static function assign($ids, User $user, mixed $targetGroup = null) : voi
// TwoFAccountService::withdraw() method. // TwoFAccountService::withdraw() method.
if ($targetGroup === 0 || $targetGroup === '0') { if ($targetGroup === 0 || $targetGroup === '0') {
Log::info('Group assignment skipped, no group explicitly requested'); Log::info('Group assignment skipped, no group explicitly requested');
return; return;
} }
@ -38,11 +38,10 @@ public static function assign($ids, User $user, mixed $targetGroup = null) : voi
// - No group is passed => We try to identify a destination group through user preferences // - No group is passed => We try to identify a destination group through user preferences
$group = null; $group = null;
if(! is_null($targetGroup)) { if (! is_null($targetGroup)) {
if ($targetGroup instanceof Group && $targetGroup->exists && $targetGroup->user_id == $user->id) { if ($targetGroup instanceof Group && $targetGroup->exists && $targetGroup->user_id == $user->id) {
$group = $targetGroup; $group = $targetGroup;
} } else {
else {
$group = Group::where('id', (int) $targetGroup) $group = Group::where('id', (int) $targetGroup)
->where('user_id', $user->id) ->where('user_id', $user->id)
->first(); ->first();
@ -58,7 +57,7 @@ public static function assign($ids, User $user, mixed $targetGroup = null) : voi
$twofaccounts = TwoFAccount::find($ids); $twofaccounts = TwoFAccount::find($ids);
if ($user->cannot('updateEach', [(new TwoFAccount), $twofaccounts])) { if ($user->cannot('updateEach', [(new TwoFAccount), $twofaccounts])) {
throw new AuthorizationException(); throw new AuthorizationException;
} }
$group->twofaccounts()->saveMany($twofaccounts); $group->twofaccounts()->saveMany($twofaccounts);

View File

@ -76,7 +76,7 @@ public function migrate(mixed $migrationPayload) : Collection
break; break;
default: default:
throw new \Exception(); throw new \Exception;
} }
$parameters['iconData'] = base64_decode($otp_parameters['icon']); $parameters['iconData'] = base64_decode($otp_parameters['icon']);
} }
@ -95,7 +95,7 @@ public function migrate(mixed $migrationPayload) : Collection
Log::debug($exception->getMessage()); Log::debug($exception->getMessage());
// The token failed to generate a valid account so we create a fake account to be returned. // The token failed to generate a valid account so we create a fake account to be returned.
$fakeAccount = new TwoFAccount(); $fakeAccount = new TwoFAccount;
$fakeAccount->id = TwoFAccount::FAKE_ID; $fakeAccount->id = TwoFAccount::FAKE_ID;
$fakeAccount->otp_type = $otp_parameters['type'] ?? TwoFAccount::TOTP; $fakeAccount->otp_type = $otp_parameters['type'] ?? TwoFAccount::TOTP;
// Only basic fields are filled to limit the risk of another exception. // Only basic fields are filled to limit the risk of another exception.

View File

@ -28,7 +28,7 @@ public function migrate(mixed $migrationPayload) : Collection
{ {
try { try {
$migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', strval($migrationPayload)))); $migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', strval($migrationPayload))));
$protobuf = new Payload(); $protobuf = new Payload;
$protobuf->mergeFromString($migrationData); $protobuf->mergeFromString($migrationData);
$otpParameters = $protobuf->getOtpParameters(); $otpParameters = $protobuf->getOtpParameters();
} catch (Exception $ex) { } catch (Exception $ex) {
@ -59,7 +59,7 @@ public function migrate(mixed $migrationPayload) : Collection
Log::debug($exception->getMessage()); Log::debug($exception->getMessage());
// The token failed to generate a valid account so we create a fake account to be returned. // The token failed to generate a valid account so we create a fake account to be returned.
$fakeAccount = new TwoFAccount(); $fakeAccount = new TwoFAccount;
$fakeAccount->id = TwoFAccount::FAKE_ID; $fakeAccount->id = TwoFAccount::FAKE_ID;
$fakeAccount->otp_type = $fakeAccount::TOTP; $fakeAccount->otp_type = $fakeAccount::TOTP;
// Only basic fields are filled to limit the risk of another exception. // Only basic fields are filled to limit the risk of another exception.
@ -77,7 +77,7 @@ public function migrate(mixed $migrationPayload) : Collection
/** /**
* Encode into uppercase Base32 * Encode into uppercase Base32
* *
* @throws TypeError * @throws TypeError
*/ */
protected function toBase32(string $str) : string protected function toBase32(string $str) : string

View File

@ -37,7 +37,7 @@ public function migrate(mixed $migrationPayload) : Collection
Log::debug($exception->getMessage()); Log::debug($exception->getMessage());
// The token failed to generate a valid account so we create a fake account to be returned. // The token failed to generate a valid account so we create a fake account to be returned.
$fakeAccount = new TwoFAccount(); $fakeAccount = new TwoFAccount;
$fakeAccount->id = TwoFAccount::FAKE_ID; $fakeAccount->id = TwoFAccount::FAKE_ID;
$fakeAccount->otp_type = substr($uri, 10, 4); $fakeAccount->otp_type = substr($uri, 10, 4);
// Only basic fields are filled to limit the risk of another exception. // Only basic fields are filled to limit the risk of another exception.

View File

@ -103,7 +103,7 @@ public function migrate(mixed $migrationPayload) : Collection
Log::debug($exception->getMessage()); Log::debug($exception->getMessage());
// The token failed to generate a valid account so we create a fake account to be returned. // The token failed to generate a valid account so we create a fake account to be returned.
$fakeAccount = new TwoFAccount(); $fakeAccount = new TwoFAccount;
$fakeAccount->id = TwoFAccount::FAKE_ID; $fakeAccount->id = TwoFAccount::FAKE_ID;
$fakeAccount->otp_type = $otp_parameters['otp']['tokenType'] ?? TwoFAccount::TOTP; $fakeAccount->otp_type = $otp_parameters['otp']['tokenType'] ?? TwoFAccount::TOTP;
// Only basic fields are filled to limit the risk of another exception. // Only basic fields are filled to limit the risk of another exception.

View File

@ -93,7 +93,7 @@ public function migrate(mixed $migrationPayload) : Collection
break; break;
default: default:
throw new \Exception(); throw new \Exception;
} }
$parameters['icon_file'] = base64_decode($otp_parameters['icon_file']); $parameters['icon_file'] = base64_decode($otp_parameters['icon_file']);
} }
@ -112,7 +112,7 @@ public function migrate(mixed $migrationPayload) : Collection
Log::debug($exception->getMessage()); Log::debug($exception->getMessage());
// The token failed to generate a valid account so we create a fake account to be returned. // The token failed to generate a valid account so we create a fake account to be returned.
$fakeAccount = new TwoFAccount(); $fakeAccount = new TwoFAccount;
$fakeAccount->id = TwoFAccount::FAKE_ID; $fakeAccount->id = TwoFAccount::FAKE_ID;
$fakeAccount->otp_type = $otp_parameters['otp']['tokenType'] ?? TwoFAccount::TOTP; $fakeAccount->otp_type = $otp_parameters['otp']['tokenType'] ?? TwoFAccount::TOTP;
// Only basic fields are filled to limit the risk of another exception. // Only basic fields are filled to limit the risk of another exception.

View File

@ -40,11 +40,11 @@ public static function encode(string $data)
public static function decode(\Illuminate\Http\UploadedFile $file) public static function decode(\Illuminate\Http\UploadedFile $file)
{ {
$qrcode = app()->make(QrReader::class, [ $qrcode = app()->make(QrReader::class, [
'imgSource' => $file->get(), 'imgSource' => $file->get(),
'sourceType' => QrReader::SOURCE_TYPE_BLOB 'sourceType' => QrReader::SOURCE_TYPE_BLOB,
]); ]);
$text = $qrcode->text(); $text = $qrcode->text();
if (! $text) { if (! $text) {
$text = $qrcode->text([ $text = $qrcode->text([

View File

@ -46,8 +46,9 @@ public static function withdraw($ids) : void
if ($affectedCount) { if ($affectedCount) {
Log::info(sprintf('TwoFAccounts with IDs #%s withdrawn', implode(',', $ids))); Log::info(sprintf('TwoFAccounts with IDs #%s withdrawn', implode(',', $ids)));
} else {
Log::info(sprintf('Cannot find TwoFAccounts to withdraw using ids #%s', implode(',', $ids)));
} }
else Log::info(sprintf('Cannot find TwoFAccounts to withdraw using ids #%s', implode(',', $ids)));
} }
/** /**

View File

@ -55,7 +55,7 @@
* that can be requested max 10 times per minute by the same IP * that can be requested max 10 times per minute by the same IP
*/ */
Route::group(['middleware' => ['guest', 'throttle:10,1']], function () { Route::group(['middleware' => ['guest', 'throttle:10,1']], function () {
Route::post('user/login', [LoginController::class, 'login'])->name('user.login')->middleware('RejectIfSsoOnlyAndNotForAdmin');; Route::post('user/login', [LoginController::class, 'login'])->name('user.login')->middleware('RejectIfSsoOnlyAndNotForAdmin');
Route::post('webauthn/login', [WebAuthnLoginController::class, 'login'])->name('webauthn.login')->middleware('RejectIfSsoOnlyAndNotForAdmin'); Route::post('webauthn/login', [WebAuthnLoginController::class, 'login'])->name('webauthn.login')->middleware('RejectIfSsoOnlyAndNotForAdmin');
Route::get('/socialite/redirect/{driver}', [SocialiteController::class, 'redirect'])->name('socialite.redirect'); Route::get('/socialite/redirect/{driver}', [SocialiteController::class, 'redirect'])->name('socialite.redirect');
@ -100,10 +100,10 @@
}); });
Route::withoutMiddleware([ Route::withoutMiddleware([
SubstituteBindings::class, SubstituteBindings::class,
SetLanguage::class, SetLanguage::class,
CustomCreateFreshApiToken::class CustomCreateFreshApiToken::class,
])->get('/up', function () { ])->get('/up', function () {
//Event::dispatch(new DiagnosingHealth); //Event::dispatch(new DiagnosingHealth);
return view('health'); return view('health');
}); });

View File

@ -127,7 +127,7 @@ class TwoFAccountControllerTest extends FeatureTestCase
'algorithm', 'algorithm',
'period', 'period',
'counter', 'counter',
'otp' => self::VALID_EMBEDDED_OTP_RESOURCE_STRUCTURE_FOR_TOTP 'otp' => self::VALID_EMBEDDED_OTP_RESOURCE_STRUCTURE_FOR_TOTP,
]; ];
private const VALID_COLLECTION_RESOURCE_STRUCTURE_WITH_OTP = [ private const VALID_COLLECTION_RESOURCE_STRUCTURE_WITH_OTP = [
@ -141,7 +141,7 @@ class TwoFAccountControllerTest extends FeatureTestCase
'algorithm', 'algorithm',
'period', 'period',
'counter', 'counter',
'otp' => self::VALID_EMBEDDED_OTP_RESOURCE_STRUCTURE_FOR_TOTP 'otp' => self::VALID_EMBEDDED_OTP_RESOURCE_STRUCTURE_FOR_TOTP,
]; ];
private const VALID_EXPORT_STRUTURE = [ private const VALID_EXPORT_STRUTURE = [
@ -527,7 +527,7 @@ public function test_store_assigns_created_account_to_provided_groupid()
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('POST', '/api/v1/twofaccounts', array_merge( ->json('POST', '/api/v1/twofaccounts', array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => $this->userGroupA->id] ['group_id' => $this->userGroupA->id]
)) ))
->assertJsonFragment([ ->assertJsonFragment([
'group_id' => $this->userGroupA->id, 'group_id' => $this->userGroupA->id,
@ -540,7 +540,7 @@ public function test_store_with_assignement_to_missing_groupid_returns_validatio
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('POST', '/api/v1/twofaccounts', array_merge( ->json('POST', '/api/v1/twofaccounts', array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => 9999999] ['group_id' => 9999999]
)) ))
->assertJsonValidationErrorFor('group_id'); ->assertJsonValidationErrorFor('group_id');
} }
@ -555,7 +555,7 @@ public function test_store_with_assignement_to_null_groupid_does_not_assign_acco
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('POST', '/api/v1/twofaccounts', array_merge( ->json('POST', '/api/v1/twofaccounts', array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => null] ['group_id' => null]
)) ))
->assertJsonFragment([ ->assertJsonFragment([
'group_id' => null, 'group_id' => null,
@ -572,7 +572,7 @@ public function test_store_with_assignement_to_null_groupid_is_overriden_by_spec
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('POST', '/api/v1/twofaccounts', array_merge( ->json('POST', '/api/v1/twofaccounts', array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => null] ['group_id' => null]
)) ))
->assertJsonFragment([ ->assertJsonFragment([
'group_id' => $this->user->preferences['defaultGroup'], 'group_id' => $this->user->preferences['defaultGroup'],
@ -589,7 +589,7 @@ public function test_store_with_assignement_to_zero_groupid_overrides_specific_d
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('POST', '/api/v1/twofaccounts', array_merge( ->json('POST', '/api/v1/twofaccounts', array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => 0] ['group_id' => 0]
)) ))
->assertJsonFragment([ ->assertJsonFragment([
'group_id' => null, 'group_id' => null,
@ -606,7 +606,7 @@ public function test_store_with_assignement_to_provided_groupid_overrides_specif
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('POST', '/api/v1/twofaccounts', array_merge( ->json('POST', '/api/v1/twofaccounts', array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => $this->userGroupB->id] ['group_id' => $this->userGroupB->id]
)) ))
->assertJsonFragment([ ->assertJsonFragment([
'group_id' => $this->userGroupB->id, 'group_id' => $this->userGroupB->id,
@ -709,15 +709,15 @@ public function test_update_missing_twofaccount_returns_not_found()
public function test_update_with_assignement_to_null_group_returns_success_with_updated_resource() public function test_update_with_assignement_to_null_group_returns_success_with_updated_resource()
{ {
$this->assertNotEquals(null, $this->twofaccountA->group_id); $this->assertNotEquals(null, $this->twofaccountA->group_id);
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge( ->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => null] ['group_id' => null]
)) ))
->assertOk() ->assertOk()
->assertJsonFragment([ ->assertJsonFragment([
'group_id' => null 'group_id' => null,
]) ])
->assertJsonFragment(self::JSON_FRAGMENTS_FOR_CUSTOM_TOTP); ->assertJsonFragment(self::JSON_FRAGMENTS_FOR_CUSTOM_TOTP);
} }
@ -726,15 +726,15 @@ public function test_update_with_assignement_to_null_group_returns_success_with_
public function test_update_with_assignement_to_zero_group_returns_success_with_updated_resource() public function test_update_with_assignement_to_zero_group_returns_success_with_updated_resource()
{ {
$this->assertNotEquals(null, $this->twofaccountA->group_id); $this->assertNotEquals(null, $this->twofaccountA->group_id);
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge( ->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => 0] ['group_id' => 0]
)) ))
->assertOk() ->assertOk()
->assertJsonFragment([ ->assertJsonFragment([
'group_id' => null 'group_id' => null,
]) ])
->assertJsonFragment(self::JSON_FRAGMENTS_FOR_CUSTOM_TOTP); ->assertJsonFragment(self::JSON_FRAGMENTS_FOR_CUSTOM_TOTP);
} }
@ -743,15 +743,15 @@ public function test_update_with_assignement_to_zero_group_returns_success_with_
public function test_update_with_assignement_to_new_groupid_returns_success_with_updated_resource() public function test_update_with_assignement_to_new_groupid_returns_success_with_updated_resource()
{ {
$this->assertEquals($this->userGroupA->id, $this->twofaccountA->group_id); $this->assertEquals($this->userGroupA->id, $this->twofaccountA->group_id);
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge( ->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => $this->userGroupB->id] ['group_id' => $this->userGroupB->id]
)) ))
->assertOk() ->assertOk()
->assertJsonFragment([ ->assertJsonFragment([
'group_id' => $this->userGroupB->id 'group_id' => $this->userGroupB->id,
]) ])
->assertJsonFragment(self::JSON_FRAGMENTS_FOR_CUSTOM_TOTP); ->assertJsonFragment(self::JSON_FRAGMENTS_FOR_CUSTOM_TOTP);
} }
@ -762,7 +762,7 @@ public function test_update_with_assignement_to_missing_groupid_returns_validati
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge( ->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge(
OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP,
['group_id' => 9999999] ['group_id' => 9999999]
)) ))
->assertJsonValidationErrorFor('group_id'); ->assertJsonValidationErrorFor('group_id');
} }

View File

@ -335,10 +335,10 @@ public function test_store_another_user_returns_forbidden() : void
public function test_revokePATs_flushes_pats() public function test_revokePATs_flushes_pats()
{ {
Artisan::call('passport:install', [ Artisan::call('passport:install', [
'--verbose' => 2, '--verbose' => 2,
'--no-interaction' => 1 '--no-interaction' => 1,
]); ]);
$tokenRepository = app(TokenRepository::class); $tokenRepository = app(TokenRepository::class);
$this->actingAs($this->user, 'api-guard') $this->actingAs($this->user, 'api-guard')

View File

@ -1,13 +1,12 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
namespace Tests\Api\v1\Requests\DataProviders; namespace Tests\Api\v1\Requests\DataProviders;
final class TwoFAccountDataProvider final class TwoFAccountDataProvider
{ {
/** public static function validIdsProvider() : array
*
*/
public static function validIdsProvider(): array
{ {
return [ return [
[[ [[
@ -19,10 +18,7 @@ public static function validIdsProvider(): array
]; ];
} }
/** public static function invalidIdsProvider() : array
*
*/
public static function invalidIdsProvider(): array
{ {
return [ return [
[[ [[
@ -64,10 +60,7 @@ public static function invalidIdsProvider(): array
]; ];
} }
/** public static function validIsAdminProvider() : array
*
*/
public static function validIsAdminProvider(): array
{ {
return [ return [
[[ [[
@ -85,10 +78,7 @@ public static function validIsAdminProvider(): array
]; ];
} }
/** public static function invalidIsAdminProvider() : array
*
*/
public static function invalidIsAdminProvider(): array
{ {
return [ return [
[[ [[
@ -108,4 +98,4 @@ public static function invalidIsAdminProvider(): array
]], ]],
]; ];
} }
} }

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new GroupAssignRequest(); $request = new GroupAssignRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new GroupAssignRequest(); $request = new GroupAssignRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -59,7 +59,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new GroupAssignRequest(); $request = new GroupAssignRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -43,7 +43,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new GroupStoreRequest(); $request = new GroupStoreRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }

View File

@ -2,7 +2,6 @@
namespace Tests\Api\v1\Requests; namespace Tests\Api\v1\Requests;
use App\Api\v1\Requests\GroupAssignRequest;
use App\Api\v1\Requests\IconFetchRequest; use App\Api\v1\Requests\IconFetchRequest;
use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -27,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new IconFetchRequest(); $request = new IconFetchRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -36,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new IconFetchRequest(); $request = new IconFetchRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -64,7 +63,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new IconFetchRequest(); $request = new IconFetchRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -27,7 +27,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new QrCodeDecodeRequest(); $request = new QrCodeDecodeRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -36,7 +36,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new QrCodeDecodeRequest(); $request = new QrCodeDecodeRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -60,7 +60,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new QrCodeDecodeRequest(); $request = new QrCodeDecodeRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -29,7 +29,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new SettingStoreRequest(); $request = new SettingStoreRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -38,7 +38,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new SettingStoreRequest(); $request = new SettingStoreRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -71,7 +71,7 @@ public function test_invalid_data(array $data) : void
{ {
Settings::set(self::UNIQUE_KEY, 'uniqueValue'); Settings::set(self::UNIQUE_KEY, 'uniqueValue');
$request = new SettingStoreRequest(); $request = new SettingStoreRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new SettingUpdateRequest(); $request = new SettingUpdateRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new SettingUpdateRequest(); $request = new SettingUpdateRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -63,7 +63,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new SettingUpdateRequest(); $request = new SettingUpdateRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -27,7 +27,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new TwoFAccountBatchRequest(); $request = new TwoFAccountBatchRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -36,7 +36,7 @@ public function test_user_is_authorized()
#[DataProviderExternal(TwoFAccountDataProvider::class, 'validIdsProvider')] #[DataProviderExternal(TwoFAccountDataProvider::class, 'validIdsProvider')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new TwoFAccountBatchRequest(); $request = new TwoFAccountBatchRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -46,7 +46,7 @@ public function test_valid_data(array $data) : void
#[DataProviderExternal(TwoFAccountDataProvider::class, 'invalidIdsProvider')] #[DataProviderExternal(TwoFAccountDataProvider::class, 'invalidIdsProvider')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new TwoFAccountBatchRequest(); $request = new TwoFAccountBatchRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new TwoFAccountDynamicRequest(); $request = new TwoFAccountDynamicRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -34,8 +34,8 @@ public function test_user_is_authorized()
#[Test] #[Test]
public function test_returns_TwoFAccountUriRequest_rules_when_has_uri_input() public function test_returns_TwoFAccountUriRequest_rules_when_has_uri_input()
{ {
$twofaccountUriRequest = new TwoFAccountUriRequest(); $twofaccountUriRequest = new TwoFAccountUriRequest;
$request = new TwoFAccountDynamicRequest(); $request = new TwoFAccountDynamicRequest;
$request->merge(['uri' => 'uristring']); $request->merge(['uri' => 'uristring']);
$this->assertEquals($twofaccountUriRequest->rules(), $request->rules()); $this->assertEquals($twofaccountUriRequest->rules(), $request->rules());
@ -44,8 +44,8 @@ public function test_returns_TwoFAccountUriRequest_rules_when_has_uri_input()
#[Test] #[Test]
public function test_returns_TwoFAccountStoreRequest_rules_otherwise() public function test_returns_TwoFAccountStoreRequest_rules_otherwise()
{ {
$twofaccountStoreRequest = new TwoFAccountStoreRequest(); $twofaccountStoreRequest = new TwoFAccountStoreRequest;
$request = new TwoFAccountDynamicRequest(); $request = new TwoFAccountDynamicRequest;
$this->assertEquals($twofaccountStoreRequest->rules(), $request->rules()); $this->assertEquals($twofaccountStoreRequest->rules(), $request->rules());
} }

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new TwoFAccountImportRequest(); $request = new TwoFAccountImportRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new TwoFAccountImportRequest(); $request = new TwoFAccountImportRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -57,7 +57,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new TwoFAccountImportRequest(); $request = new TwoFAccountImportRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -27,16 +27,16 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new TwoFAccountIndexRequest(); $request = new TwoFAccountIndexRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
#[Test] #[Test]
#[DataProviderExternal(TwoFAccountDataProvider::class, 'validIdsProvider')] #[DataProviderExternal(TwoFAccountDataProvider::class, 'validIdsProvider')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new TwoFAccountIndexRequest(); $request = new TwoFAccountIndexRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -46,7 +46,7 @@ public function test_valid_data(array $data) : void
#[DataProviderExternal(TwoFAccountDataProvider::class, 'invalidIdsProvider')] #[DataProviderExternal(TwoFAccountDataProvider::class, 'invalidIdsProvider')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new TwoFAccountIndexRequest(); $request = new TwoFAccountIndexRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new TwoFAccountReorderRequest(); $request = new TwoFAccountReorderRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new TwoFAccountReorderRequest(); $request = new TwoFAccountReorderRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -60,7 +60,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new TwoFAccountReorderRequest(); $request = new TwoFAccountReorderRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -28,7 +28,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new TwoFAccountStoreRequest(); $request = new TwoFAccountStoreRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -37,7 +37,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new TwoFAccountStoreRequest(); $request = new TwoFAccountStoreRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -111,7 +111,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new TwoFAccountStoreRequest(); $request = new TwoFAccountStoreRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -28,7 +28,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new TwoFAccountUpdateRequest(); $request = new TwoFAccountUpdateRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -37,7 +37,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new TwoFAccountUpdateRequest(); $request = new TwoFAccountUpdateRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -87,7 +87,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new TwoFAccountUpdateRequest(); $request = new TwoFAccountUpdateRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new TwoFAccountUriRequest(); $request = new TwoFAccountUriRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new TwoFAccountUriRequest(); $request = new TwoFAccountUriRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -64,7 +64,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new TwoFAccountUriRequest(); $request = new TwoFAccountUriRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new UserManagerPromoteRequest(); $request = new UserManagerPromoteRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new UserManagerPromoteRequest(); $request = new UserManagerPromoteRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -66,7 +66,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new UserManagerPromoteRequest(); $request = new UserManagerPromoteRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -9,7 +9,6 @@
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\DataProviderExternal;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use Tests\FeatureTestCase; use Tests\FeatureTestCase;
@ -28,7 +27,7 @@ public function test_admin_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new UserManagerStoreRequest(); $request = new UserManagerStoreRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -41,8 +40,8 @@ public function test_valid_data(array $data) : void
'name' => 'Jane', 'name' => 'Jane',
'email' => 'jane@example.com', 'email' => 'jane@example.com',
]); ]);
$request = new UserManagerStoreRequest(); $request = new UserManagerStoreRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -80,7 +79,7 @@ public function test_invalid_data(array $data) : void
'email' => 'john@example.com', 'email' => 'john@example.com',
]); ]);
$request = new UserManagerStoreRequest(); $request = new UserManagerStoreRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -21,7 +21,7 @@ class FixServiceFieldEncryptionTest extends FeatureTestCase
* The name of the migration that changed the data this command will try to fix * The name of the migration that changed the data this command will try to fix
*/ */
protected string $relatedMigration = '2024_08_08_133136_encrypt_twofaccount_service_field'; protected string $relatedMigration = '2024_08_08_133136_encrypt_twofaccount_service_field';
/** /**
* @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable
*/ */
@ -123,10 +123,10 @@ public function test_it_encrypts_the_field_of_invalid_records_only()
Settings::set('useEncryption', true); Settings::set('useEncryption', true);
$expectedServiceName = 'myService'; $expectedServiceName = 'myService';
$twofaccounts = TwoFAccount::factory()->for($this->user)->count(3)->create([ $twofaccounts = TwoFAccount::factory()->for($this->user)->count(3)->create([
'service' => $expectedServiceName 'service' => $expectedServiceName,
]); ]);
$testedAccount = $twofaccounts[2]; $testedAccount = $twofaccounts[2];
DB::table('twofaccounts')->where('id', $testedAccount->id)->update(['service' => $expectedServiceName]); DB::table('twofaccounts')->where('id', $testedAccount->id)->update(['service' => $expectedServiceName]);
@ -141,7 +141,7 @@ public function test_it_encrypts_the_field_of_invalid_records_only()
->assertSuccessful(); ->assertSuccessful();
$testedAccount->refresh(); $testedAccount->refresh();
$this->assertEquals($expectedServiceName, $twofaccounts[0]->service); $this->assertEquals($expectedServiceName, $twofaccounts[0]->service);
$this->assertEquals($expectedServiceName, $twofaccounts[1]->service); $this->assertEquals($expectedServiceName, $twofaccounts[1]->service);
$this->assertEquals($expectedServiceName, $testedAccount->service); $this->assertEquals($expectedServiceName, $testedAccount->service);
@ -153,10 +153,10 @@ public function test_it_does_not_encrypt_the_record_if_encryption_is_not_consist
Settings::set('useEncryption', true); Settings::set('useEncryption', true);
$expectedServiceName = 'myService'; $expectedServiceName = 'myService';
$twofaccounts = TwoFAccount::factory()->for($this->user)->count(3)->create([ $twofaccounts = TwoFAccount::factory()->for($this->user)->count(3)->create([
'service' => $expectedServiceName 'service' => $expectedServiceName,
]); ]);
$testedAccount = $twofaccounts[2]; $testedAccount = $twofaccounts[2];
DB::table('twofaccounts')->where('id', $testedAccount->id)->update(['legacy_uri' => 'indecipherable_payload']); DB::table('twofaccounts')->where('id', $testedAccount->id)->update(['legacy_uri' => 'indecipherable_payload']);
@ -173,7 +173,7 @@ public function test_it_does_not_encrypt_the_record_if_encryption_is_not_consist
->expectsOutput('1 record could not be fixed, see log above for details.'); ->expectsOutput('1 record could not be fixed, see log above for details.');
$testedAccount->refresh(); $testedAccount->refresh();
$this->assertEquals($expectedServiceName, $twofaccounts[0]->service); $this->assertEquals($expectedServiceName, $twofaccounts[0]->service);
$this->assertEquals($expectedServiceName, $twofaccounts[1]->service); $this->assertEquals($expectedServiceName, $twofaccounts[1]->service);
$this->assertEquals(__('errors.indecipherable'), $testedAccount->service); $this->assertEquals(__('errors.indecipherable'), $testedAccount->service);

View File

@ -3,7 +3,6 @@
namespace Tests\Feature\Console; namespace Tests\Feature\Console;
use App\Console\Commands\Install; use App\Console\Commands\Install;
use Illuminate\Support\Facades\Artisan;
use Jackiedo\DotenvEditor\DotenvEditor; use Jackiedo\DotenvEditor\DotenvEditor;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
@ -20,7 +19,7 @@ class InstallTest extends FeatureTestCase
const PASSPORT_CREATE_CLIENTS_CONFIRMATION = 'Would you like to create the "personal access" and "password grant" clients?'; const PASSPORT_CREATE_CLIENTS_CONFIRMATION = 'Would you like to create the "personal access" and "password grant" clients?';
const TWOFAUTH_REVIEW_ENV_VAR_CONFIRMATION = 'Existing .env file found. Do you wish to review its vars?'; const TWOFAUTH_REVIEW_ENV_VAR_CONFIRMATION = 'Existing .env file found. Do you wish to review its vars?';
#[Test] #[Test]
public function test_install_completes() public function test_install_completes()
{ {
@ -101,7 +100,7 @@ public function test_install_fails_with_link_to_online_help()
{ {
$mock = $this->mock(DotenvEditor::class); $mock = $this->mock(DotenvEditor::class);
$mock->shouldReceive('load') $mock->shouldReceive('load')
->andThrow(new \Exception()); ->andThrow(new \Exception);
$this->artisan('2fauth:install') $this->artisan('2fauth:install')
->expectsOutputToContain(config('2fauth.installDocUrl')) ->expectsOutputToContain(config('2fauth.installDocUrl'))

View File

@ -21,10 +21,10 @@ public function test_reset_demo_without_demo_mode_succeeded()
public function test_reset_demo_succeeded() public function test_reset_demo_succeeded()
{ {
Artisan::call('passport:install', [ Artisan::call('passport:install', [
'--verbose' => 2, '--verbose' => 2,
'--no-interaction' => 1 '--no-interaction' => 1,
]); ]);
Config::set('2fauth.config.isDemoApp', true); Config::set('2fauth.config.isDemoApp', true);
$this->artisan('2fauth:reset-demo') $this->artisan('2fauth:reset-demo')

View File

@ -64,7 +64,7 @@ class LoginTest extends FeatureTestCase
private const PASSWORD = 'password'; private const PASSWORD = 'password';
private const WRONG_PASSWORD = 'wrong_password'; private const WRONG_PASSWORD = 'wrong_password';
private const USER_NAME = 'John'; private const USER_NAME = 'John';
private const USER_EMAIL = 'john@example.com'; private const USER_EMAIL = 'john@example.com';
@ -383,11 +383,11 @@ public function test_successful_web_logout_is_logged()
'email' => $this->user->email, 'email' => $this->user->email,
'password' => self::PASSWORD, 'password' => self::PASSWORD,
])->assertOk(); ])->assertOk();
$this->actingAs($this->user, self::WEB_GUARD) $this->actingAs($this->user, self::WEB_GUARD)
->json('GET', '/user/logout') ->json('GET', '/user/logout')
->assertOk(); ->assertOk();
$authlog = $this->user->latestAuthentication()->first(); $authlog = $this->user->latestAuthentication()->first();
$this->assertEquals($this->user->id, $authlog->authenticatable_id); $this->assertEquals($this->user->id, $authlog->authenticatable_id);
@ -426,7 +426,7 @@ public function test_reverse_proxy_access_is_logged()
$this->app['auth']->shouldUse(self::REVERSE_PROXY_GUARD); $this->app['auth']->shouldUse(self::REVERSE_PROXY_GUARD);
$this->json('GET', '/api/v1/groups', [], [ $this->json('GET', '/api/v1/groups', [], [
'HTTP_REMOTE_USER' => self::USER_NAME, 'HTTP_REMOTE_USER' => self::USER_NAME,
]); ]);
$this->assertDatabaseHas('auth_logs', [ $this->assertDatabaseHas('auth_logs', [
@ -451,11 +451,11 @@ public function test_reverse_proxy_access_is_logged_only_once_during_a_quarter()
$this->app['auth']->shouldUse(self::REVERSE_PROXY_GUARD); $this->app['auth']->shouldUse(self::REVERSE_PROXY_GUARD);
$this->json('GET', '/api/v1/groups', [], [ $this->json('GET', '/api/v1/groups', [], [
'HTTP_REMOTE_USER' => self::USER_NAME, 'HTTP_REMOTE_USER' => self::USER_NAME,
]); ]);
$this->json('GET', '/api/v1/groups', [], [ $this->json('GET', '/api/v1/groups', [], [
'HTTP_REMOTE_USER' => self::USER_NAME, 'HTTP_REMOTE_USER' => self::USER_NAME,
]); ]);
$this->assertDatabaseCount('auth_logs', 1); $this->assertDatabaseCount('auth_logs', 1);
@ -463,7 +463,7 @@ public function test_reverse_proxy_access_is_logged_only_once_during_a_quarter()
$this->travel(16)->minutes(); $this->travel(16)->minutes();
$this->json('GET', '/api/v1/groups', [], [ $this->json('GET', '/api/v1/groups', [], [
'HTTP_REMOTE_USER' => self::USER_NAME, 'HTTP_REMOTE_USER' => self::USER_NAME,
]); ]);
$this->assertDatabaseCount('auth_logs', 2); $this->assertDatabaseCount('auth_logs', 2);
@ -473,7 +473,7 @@ public function test_reverse_proxy_access_is_logged_only_once_during_a_quarter()
public function test_reverse_proxy_access_sends_new_device_notification() public function test_reverse_proxy_access_sends_new_device_notification()
{ {
Notification::fake(); Notification::fake();
Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER'); Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER');
$user = User::factory()->create([ $user = User::factory()->create([
@ -490,7 +490,7 @@ public function test_reverse_proxy_access_sends_new_device_notification()
$this->travelTo(Carbon::now()->subMinutes(2)); $this->travelTo(Carbon::now()->subMinutes(2));
$this->json('GET', '/api/v1/groups', [], [ $this->json('GET', '/api/v1/groups', [], [
'HTTP_REMOTE_USER' => self::USER_NAME, 'HTTP_REMOTE_USER' => self::USER_NAME,
]); ]);
Notification::assertSentTo($user, SignedInWithNewDeviceNotification::class); Notification::assertSentTo($user, SignedInWithNewDeviceNotification::class);
@ -500,7 +500,7 @@ public function test_reverse_proxy_access_sends_new_device_notification()
public function test_reverse_proxy_access_does_not_send_new_device_notification_if_user_disabled_it() public function test_reverse_proxy_access_does_not_send_new_device_notification_if_user_disabled_it()
{ {
Notification::fake(); Notification::fake();
Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER'); Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER');
$user = User::factory()->create([ $user = User::factory()->create([
@ -517,7 +517,7 @@ public function test_reverse_proxy_access_does_not_send_new_device_notification_
$this->travelTo(Carbon::now()->subMinutes(2)); $this->travelTo(Carbon::now()->subMinutes(2));
$this->json('GET', '/api/v1/groups', [], [ $this->json('GET', '/api/v1/groups', [], [
'HTTP_REMOTE_USER' => self::USER_NAME, 'HTTP_REMOTE_USER' => self::USER_NAME,
]); ]);
Notification::assertNothingSentTo($user); Notification::assertNothingSentTo($user);
@ -527,7 +527,7 @@ public function test_reverse_proxy_access_does_not_send_new_device_notification_
public function test_reverse_proxy_does_not_send_new_device_notification_if_user_is_considered_new() public function test_reverse_proxy_does_not_send_new_device_notification_if_user_is_considered_new()
{ {
Notification::fake(); Notification::fake();
Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER'); Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER');
$user = User::factory()->create([ $user = User::factory()->create([
@ -541,7 +541,7 @@ public function test_reverse_proxy_does_not_send_new_device_notification_if_user
$this->app['auth']->shouldUse(self::REVERSE_PROXY_GUARD); $this->app['auth']->shouldUse(self::REVERSE_PROXY_GUARD);
$this->json('GET', '/api/v1/groups', [], [ $this->json('GET', '/api/v1/groups', [], [
'HTTP_REMOTE_USER' => self::USER_NAME, 'HTTP_REMOTE_USER' => self::USER_NAME,
]); ]);
Notification::assertNothingSentTo($user); Notification::assertNothingSentTo($user);

View File

@ -23,7 +23,7 @@ class PasswordControllerTest extends FeatureTestCase
private const PASSWORD = 'password'; private const PASSWORD = 'password';
private const NEW_PASSWORD = 'newPassword'; private const NEW_PASSWORD = 'newPassword';
private const USER_NAME = 'John'; private const USER_NAME = 'John';
private const USER_EMAIL = 'john@example.com'; private const USER_EMAIL = 'john@example.com';
@ -90,14 +90,14 @@ public function test_update_pwd_of_reverse_proxy_user_return_bad_request()
]); ]);
$this->app['auth']->shouldUse(self::REVERSE_PROXY_GUARD); $this->app['auth']->shouldUse(self::REVERSE_PROXY_GUARD);
$response = $this->json('PATCH', '/user/password', [ $response = $this->json('PATCH', '/user/password', [
'currentPassword' => self::NEW_PASSWORD, 'currentPassword' => self::NEW_PASSWORD,
'password' => self::NEW_PASSWORD, 'password' => self::NEW_PASSWORD,
'password_confirmation' => self::NEW_PASSWORD, 'password_confirmation' => self::NEW_PASSWORD,
], [ ], [
'HTTP_REMOTE_USER' => self::USER_NAME, 'HTTP_REMOTE_USER' => self::USER_NAME,
]) ])
->assertStatus(405) ->assertStatus(405)
->assertJsonStructure([ ->assertJsonStructure([
'message', 'message',

View File

@ -116,13 +116,13 @@ public static function ssoConfigVarProvider()
{ {
return [ return [
'TOKEN_URL' => [ 'TOKEN_URL' => [
'token_url' 'token_url',
], ],
'AUTHORIZE_URL' => [ 'AUTHORIZE_URL' => [
'authorize_url' 'authorize_url',
], ],
'USERINFO_URL' => [ 'USERINFO_URL' => [
'userinfo_url' 'userinfo_url',
], ],
]; ];
} }
@ -286,7 +286,7 @@ public function test_callback_redirects_to_error_when_sso_provider_reject_auth()
$newSocialiteUser->email = 'jane@provider.com'; $newSocialiteUser->email = 'jane@provider.com';
Socialite::shouldReceive('driver->user') Socialite::shouldReceive('driver->user')
->andThrow(new Exception()); ->andThrow(new Exception);
$response = $this->get('/socialite/callback/github', ['driver' => 'github']); $response = $this->get('/socialite/callback/github', ['driver' => 'github']);

View File

@ -107,7 +107,7 @@ public function test_sendRecoveryEmail_does_not_send_anything_to_not_WebAuthnAut
{ {
$mock = $this->mock(\App\Extensions\WebauthnCredentialBroker::class)->makePartial(); $mock = $this->mock(\App\Extensions\WebauthnCredentialBroker::class)->makePartial();
$mock->shouldReceive('getUser') $mock->shouldReceive('getUser')
->andReturn(new \Illuminate\Foundation\Auth\User()); ->andReturn(new \Illuminate\Foundation\Auth\User);
Notification::fake(); Notification::fake();

View File

@ -132,7 +132,7 @@ public function test_webauthn_login_returns_success()
public function test_webauthn_login_of_admin_returns_success_even_with_sso_only_enabled() public function test_webauthn_login_of_admin_returns_success_even_with_sso_only_enabled()
{ {
Settings::set('useSsoOnly', true); Settings::set('useSsoOnly', true);
$this->user->promoteToAdministrator(true); $this->user->promoteToAdministrator(true);
$this->user->save(); $this->user->save();
@ -151,7 +151,7 @@ public function test_webauthn_login_of_admin_returns_success_even_with_sso_only_
->assertJsonStructure([ ->assertJsonStructure([
'preferences', 'preferences',
]); ]);
$this->user->promoteToAdministrator(false); $this->user->promoteToAdministrator(false);
$this->user->save(); $this->user->save();
} }
@ -160,7 +160,7 @@ public function test_webauthn_login_of_admin_returns_success_even_with_sso_only_
public function test_webauthn_login_sends_new_device_notification_to_existing_user() public function test_webauthn_login_sends_new_device_notification_to_existing_user()
{ {
Notification::fake(); Notification::fake();
$this->user['preferences->notifyOnNewAuthDevice'] = 1; $this->user['preferences->notifyOnNewAuthDevice'] = 1;
$this->user->save(); $this->user->save();
@ -186,7 +186,7 @@ public function test_webauthn_login_sends_new_device_notification_to_existing_us
public function test_webauthn_login_does_not_send_new_device_notification_to_new_user() public function test_webauthn_login_does_not_send_new_device_notification_to_new_user()
{ {
Notification::fake(); Notification::fake();
$this->user['preferences->notifyOnNewAuthDevice'] = 1; $this->user['preferences->notifyOnNewAuthDevice'] = 1;
$this->user->save(); $this->user->save();
@ -203,8 +203,8 @@ public function test_webauthn_login_does_not_send_new_device_notification_to_new
public function test_webauthn_login_does_not_send_new_device_notification_if_user_disabled_it() public function test_webauthn_login_does_not_send_new_device_notification_if_user_disabled_it()
{ {
Notification::fake(); Notification::fake();
$this->user['preferences->notifyOnNewAuthDevice'] =01; $this->user['preferences->notifyOnNewAuthDevice'] = 0;
$this->user->save(); $this->user->save();
$this->createWebauthnCredential(self::CREDENTIAL_ID_ALT, $this->user->id, self::USER_ID_ALT); $this->createWebauthnCredential(self::CREDENTIAL_ID_ALT, $this->user->id, self::USER_ID_ALT);

View File

@ -39,7 +39,7 @@ public function test_uses_attestation_with_fastRegistration_request() : void
$request = $this->mock(AttestationRequest::class); $request = $this->mock(AttestationRequest::class);
$request->expects('fastRegistration')->andReturnSelf(); $request->expects('fastRegistration')->andReturnSelf();
$request->expects('toCreate')->andReturn(new JsonTransport()); $request->expects('toCreate')->andReturn(new JsonTransport);
$this->actingAs($this->user, 'web-guard') $this->actingAs($this->user, 'web-guard')
->json('POST', '/webauthn/register/options') ->json('POST', '/webauthn/register/options')
@ -54,7 +54,7 @@ public function test_uses_attestation_with_secureRegistration_request() : void
$request = $this->mock(AttestationRequest::class); $request = $this->mock(AttestationRequest::class);
$request->expects('secureRegistration')->andReturnSelf(); $request->expects('secureRegistration')->andReturnSelf();
$request->expects('toCreate')->andReturn(new JsonTransport()); $request->expects('toCreate')->andReturn(new JsonTransport);
$this->actingAs($this->user, 'web-guard') $this->actingAs($this->user, 'web-guard')
->json('POST', '/webauthn/register/options') ->json('POST', '/webauthn/register/options')

View File

@ -28,8 +28,7 @@ public function test_users_are_rejected()
$request = Request::create('/admin', 'GET'); $request = Request::create('/admin', 'GET');
$middleware = new AdminOnly; $middleware = new AdminOnly;
$response = $middleware->handle($request, function () { $response = $middleware->handle($request, function () {});
});
} }
#[Test] #[Test]
@ -45,8 +44,7 @@ public function test_admins_pass()
$request = Request::create('/admin', 'GET'); $request = Request::create('/admin', 'GET');
$middleware = new AdminOnly; $middleware = new AdminOnly;
$response = $middleware->handle($request, function () { $response = $middleware->handle($request, function () {});
});
$this->assertNull($response); $this->assertNull($response);
} }

View File

@ -59,7 +59,7 @@ public function test_it_overrides_locale_when_auth_is_successful()
{ {
Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER'); Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER');
Config::set('auth.auth_proxy_headers.email', 'HTTP_REMOTE_EMAIL'); Config::set('auth.auth_proxy_headers.email', 'HTTP_REMOTE_EMAIL');
$this->app['auth']->shouldUse('reverse-proxy-guard'); $this->app['auth']->shouldUse('reverse-proxy-guard');
$lang = 'fr'; $lang = 'fr';
@ -71,7 +71,7 @@ public function test_it_overrides_locale_when_auth_is_successful()
$user->save(); $user->save();
$this->json('GET', '/api/v1/groups', [], [ $this->json('GET', '/api/v1/groups', [], [
'HTTP_REMOTE_USER' => self::USER_NAME, 'HTTP_REMOTE_USER' => self::USER_NAME,
]); ]);
$this->assertEquals($lang, App::getLocale()); $this->assertEquals($lang, App::getLocale());

View File

@ -36,7 +36,7 @@ public function setUp() : void
$this->user = User::factory()->create(); $this->user = User::factory()->create();
$this->admin = User::factory()->administrator()->create([ $this->admin = User::factory()->administrator()->create([
'password' => self::PASSWORD 'password' => self::PASSWORD,
]); ]);
Settings::set('useSsoOnly', true); Settings::set('useSsoOnly', true);

View File

@ -67,7 +67,7 @@ public function test_it_applies_fallback_locale_if_header_ask_for_several_unsupp
$this->assertEquals(self::IS_FR, App::getLocale()); $this->assertEquals(self::IS_FR, App::getLocale());
} }
#[Test] #[Test]
public function test_it_applies_fallback_locale_if_header_ask_for_wildcard() public function test_it_applies_fallback_locale_if_header_ask_for_wildcard()
{ {
@ -121,9 +121,9 @@ public function test_it_ignores_unsupported_language_from_header()
#[Test] #[Test]
public function test_user_preference_overrides_header() public function test_user_preference_overrides_header()
{ {
$this->user = new User; $this->user = new User;
$this->user['preferences->lang'] = self::IS_FR; $this->user['preferences->lang'] = self::IS_FR;
$this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => self::IS_DE]); $this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => self::IS_DE]);
$this->assertEquals(self::IS_FR, App::getLocale()); $this->assertEquals(self::IS_FR, App::getLocale());
@ -132,9 +132,9 @@ public function test_user_preference_overrides_header()
#[Test] #[Test]
public function test_user_preference_applies_header() public function test_user_preference_applies_header()
{ {
$this->user = new User; $this->user = new User;
$this->user['preferences->lang'] = 'browser'; $this->user['preferences->lang'] = 'browser';
$this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => self::IS_DE]); $this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => self::IS_DE]);
$this->assertEquals(self::IS_DE, App::getLocale()); $this->assertEquals(self::IS_DE, App::getLocale());
@ -145,9 +145,9 @@ public function test_user_preference_overrides_fallback()
{ {
Config::set('app.fallback_locale', self::IS_DE); Config::set('app.fallback_locale', self::IS_DE);
$this->user = new User; $this->user = new User;
$this->user['preferences->lang'] = self::IS_FR; $this->user['preferences->lang'] = self::IS_FR;
$this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => null]); $this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => null]);
$this->assertEquals(self::IS_FR, App::getLocale()); $this->assertEquals(self::IS_FR, App::getLocale());

View File

@ -22,7 +22,7 @@ class LoginRequestTest extends FeatureTestCase
#[Test] #[Test]
public function test_user_is_authorized() public function test_user_is_authorized()
{ {
$request = new LoginRequest(); $request = new LoginRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_valid_data(array $data) : void
'email' => 'JOHN.DOE@example.com', 'email' => 'JOHN.DOE@example.com',
]); ]);
$request = new LoginRequest(); $request = new LoginRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -66,7 +66,7 @@ public function test_invalid_data(array $data) : void
'email' => 'JOHN.DOE@example.com', 'email' => 'JOHN.DOE@example.com',
]); ]);
$request = new LoginRequest(); $request = new LoginRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new UserDeleteRequest(); $request = new UserDeleteRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new UserDeleteRequest(); $request = new UserDeleteRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -57,7 +57,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new UserDeleteRequest(); $request = new UserDeleteRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new UserPatchPwdRequest(); $request = new UserPatchPwdRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new UserPatchPwdRequest(); $request = new UserPatchPwdRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -59,7 +59,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new UserPatchPwdRequest(); $request = new UserPatchPwdRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -22,7 +22,7 @@ class UserStoreRequestTest extends FeatureTestCase
#[Test] #[Test]
public function test_user_is_authorized() public function test_user_is_authorized()
{ {
$request = new UserStoreRequest(); $request = new UserStoreRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -36,7 +36,7 @@ public function test_valid_data(array $data) : void
'email' => 'jane@example.com', 'email' => 'jane@example.com',
]); ]);
$request = new UserStoreRequest(); $request = new UserStoreRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -72,7 +72,7 @@ public function test_invalid_data(array $data) : void
'email' => 'john@example.com', 'email' => 'john@example.com',
]); ]);
$request = new UserStoreRequest(); $request = new UserStoreRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -28,7 +28,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new UserUpdateRequest(); $request = new UserUpdateRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }

View File

@ -22,7 +22,7 @@ class WebauthnAssertedRequestTest extends TestCase
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new WebauthnAssertedRequest(); $request = new WebauthnAssertedRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -53,7 +53,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new WebauthnAssertedRequest(); $request = new WebauthnAssertedRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -26,7 +26,7 @@ public function test_user_is_authorized()
->once() ->once()
->andReturn(true); ->andReturn(true);
$request = new WebauthnRenameRequest(); $request = new WebauthnRenameRequest;
$this->assertTrue($request->authorize()); $this->assertTrue($request->authorize());
} }
@ -35,7 +35,7 @@ public function test_user_is_authorized()
#[DataProvider('provideValidData')] #[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void public function test_valid_data(array $data) : void
{ {
$request = new WebauthnRenameRequest(); $request = new WebauthnRenameRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails()); $this->assertFalse($validator->fails());
@ -57,7 +57,7 @@ public static function provideValidData() : array
#[DataProvider('provideInvalidData')] #[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void public function test_invalid_data(array $data) : void
{ {
$request = new WebauthnRenameRequest(); $request = new WebauthnRenameRequest;
$validator = Validator::make($data, $request->rules()); $validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails()); $this->assertTrue($validator->fails());

View File

@ -143,7 +143,7 @@ public function test_testEmail_returns_success_even_if_sending_fails()
{ {
Notification::fake(); Notification::fake();
$this->mock(Dispatcher::class)->shouldReceive('send')->andThrow(new Exception()); $this->mock(Dispatcher::class)->shouldReceive('send')->andThrow(new Exception);
$response = $this->actingAs($this->admin, 'web-guard') $response = $this->actingAs($this->admin, 'web-guard')
->json('POST', '/system/test-email', []); ->json('POST', '/system/test-email', []);

View File

@ -17,7 +17,7 @@ class AuthLogModelTest extends FeatureTestCase
#[Test] #[Test]
public function test_equals_returns_true() public function test_equals_returns_true()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
$lastAuthLog = AuthLog::factory()->for($user, 'authenticatable')->create(); $lastAuthLog = AuthLog::factory()->for($user, 'authenticatable')->create();
$this->assertTrue($lastAuthLog->equals($lastAuthLog)); $this->assertTrue($lastAuthLog->equals($lastAuthLog));

View File

@ -108,10 +108,10 @@ public function test_resetPassword_dispatch_event()
public function test_delete_removes_user_data() public function test_delete_removes_user_data()
{ {
Artisan::call('passport:install', [ Artisan::call('passport:install', [
'--verbose' => 2, '--verbose' => 2,
'--no-interaction' => 1 '--no-interaction' => 1,
]); ]);
$user = User::factory()->create(); $user = User::factory()->create();
TwoFAccount::factory()->for($user)->create(); TwoFAccount::factory()->for($user)->create();
AuthLog::factory()->for($user, 'authenticatable')->create(); AuthLog::factory()->for($user, 'authenticatable')->create();
@ -234,10 +234,10 @@ public function test_authentications_returns_user_auth_logs_sorted_by_latest_id(
#[Test] #[Test]
public function test_authentications_returns_user_auth_logs_only() public function test_authentications_returns_user_auth_logs_only()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
$anotherUser = User::factory()->create(); $anotherUser = User::factory()->create();
$userAuthLog = AuthLog::factory()->daysAgo(10)->for($user, 'authenticatable')->create(); $userAuthLog = AuthLog::factory()->daysAgo(10)->for($user, 'authenticatable')->create();
AuthLog::factory()->daysAgo(5)->for($anotherUser, 'authenticatable')->create(); AuthLog::factory()->daysAgo(5)->for($anotherUser, 'authenticatable')->create();
$authentications = $user->authentications()->get(); $authentications = $user->authentications()->get();
@ -268,7 +268,7 @@ public function test_authenticationsByPeriod_returns_last_three_months_auth_logs
$sixMonthsAgoAuthLog = AuthLog::factory()->duringLastSixMonth()->for($user, 'authenticatable')->create(); $sixMonthsAgoAuthLog = AuthLog::factory()->duringLastSixMonth()->for($user, 'authenticatable')->create();
$threeMonthsAgoAuthLog = AuthLog::factory()->duringLastThreeMonth()->for($user, 'authenticatable')->create(); $threeMonthsAgoAuthLog = AuthLog::factory()->duringLastThreeMonth()->for($user, 'authenticatable')->create();
$duringLastMonthAuthLog = AuthLog::factory()->duringLastMonth()->for($user, 'authenticatable')->create(); $duringLastMonthAuthLog = AuthLog::factory()->duringLastMonth()->for($user, 'authenticatable')->create();
$authentications = $user->authenticationsByPeriod(3); $authentications = $user->authenticationsByPeriod(3);
$this->assertCount(2, $authentications); $this->assertCount(2, $authentications);
@ -293,7 +293,7 @@ public function test_latestAuthentication_returns_user_latest_auth_logs()
#[Test] #[Test]
public function test_latestAuthentication_returns_user_latest_auth_logs_only() public function test_latestAuthentication_returns_user_latest_auth_logs_only()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
$anotherUser = User::factory()->create(); $anotherUser = User::factory()->create();
$userAuthLog = AuthLog::factory()->duringLastThreeMonth()->for($user, 'authenticatable')->create(); $userAuthLog = AuthLog::factory()->duringLastThreeMonth()->for($user, 'authenticatable')->create();
@ -309,7 +309,7 @@ public function test_latestAuthentication_returns_user_latest_auth_logs_only()
public function test_lastLoginAt_returns_user_last_auth_date() public function test_lastLoginAt_returns_user_last_auth_date()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
$now = now(); $now = now();
$tenDaysAgoAuthLog = AuthLog::factory()->daysAgo(10)->for($user, 'authenticatable')->create(); $tenDaysAgoAuthLog = AuthLog::factory()->daysAgo(10)->for($user, 'authenticatable')->create();
$fiveDaysAgoAuthLog = AuthLog::factory()->daysAgo(5)->for($user, 'authenticatable')->create(); $fiveDaysAgoAuthLog = AuthLog::factory()->daysAgo(5)->for($user, 'authenticatable')->create();
@ -335,7 +335,7 @@ public function test_lastLoginAt_returns_null_if_user_has_no_login()
public function test_lastSuccessfulLoginAt_returns_user_last_successful_login_date() public function test_lastSuccessfulLoginAt_returns_user_last_successful_login_date()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
$now = now(); $now = now();
AuthLog::factory()->at($now)->for($user, 'authenticatable')->create(); AuthLog::factory()->at($now)->for($user, 'authenticatable')->create();
$lastSuccessfulLoginAt = $user->lastSuccessfulLoginAt(); $lastSuccessfulLoginAt = $user->lastSuccessfulLoginAt();
@ -347,7 +347,7 @@ public function test_lastSuccessfulLoginAt_returns_user_last_successful_login_da
public function test_lastSuccessfulLoginAt_returns_null_if_user_has_no_successful_login() public function test_lastSuccessfulLoginAt_returns_null_if_user_has_no_successful_login()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
$now = now(); $now = now();
AuthLog::factory()->at($now)->failedLogin()->for($user, 'authenticatable')->create(); AuthLog::factory()->at($now)->failedLogin()->for($user, 'authenticatable')->create();
$lastSuccessfulLoginAt = $user->lastSuccessfulLoginAt(); $lastSuccessfulLoginAt = $user->lastSuccessfulLoginAt();
@ -401,12 +401,12 @@ public function test_lastSuccessfulLoginIp_returns_null_if_user_has_no_successfu
#[Test] #[Test]
public function test_previousLoginAt_returns_user_last_auth_date() public function test_previousLoginAt_returns_user_last_auth_date()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
$now = now(); $now = now();
$yesterday = now()->subDay(); $yesterday = now()->subDay();
$yesterdayAuthLog = AuthLog::factory()->at($yesterday)->for($user, 'authenticatable')->create(); $yesterdayAuthLog = AuthLog::factory()->at($yesterday)->for($user, 'authenticatable')->create();
$lastAuthLog = AuthLog::factory()->at($now)->for($user, 'authenticatable')->create(); $lastAuthLog = AuthLog::factory()->at($now)->for($user, 'authenticatable')->create();
$previousLoginAt = $user->previousLoginAt(); $previousLoginAt = $user->previousLoginAt();
@ -426,7 +426,7 @@ public function test_previousLoginAt_returns_null_if_user_has_no_auth_log()
#[Test] #[Test]
public function test_previousLoginIp_returns_user_last_auth_ip() public function test_previousLoginIp_returns_user_last_auth_ip()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
$yesterday = now()->subDay(); $yesterday = now()->subDay();
AuthLog::factory()->for($user, 'authenticatable')->create(); AuthLog::factory()->for($user, 'authenticatable')->create();
@ -446,6 +446,4 @@ public function test_previousLoginIp_returns_null_if_user_has_no_auth_log()
$this->assertNull($previousLoginIp); $this->assertNull($previousLoginIp);
} }
} }

View File

@ -31,7 +31,6 @@ class FailedLoginNotificationTest extends FeatureTestCase
*/ */
protected $failedLogin; protected $failedLogin;
public function setUp() : void public function setUp() : void
{ {
parent::setUp(); parent::setUp();
@ -39,15 +38,15 @@ public function setUp() : void
$this->user = User::factory()->create(); $this->user = User::factory()->create();
AuthLog::factory()->for($this->user, 'authenticatable')->failedLogin()->create(); AuthLog::factory()->for($this->user, 'authenticatable')->failedLogin()->create();
$this->authLog = AuthLog::first(); $this->authLog = AuthLog::first();
$this->failedLogin = new FailedLoginNotification($this->authLog); $this->failedLogin = new FailedLoginNotification($this->authLog);
} }
#[Test] #[Test]
public function test_it_renders_to_email() public function test_it_renders_to_email()
{ {
$mail = $this->failedLogin->toMail($this->user); $mail = $this->failedLogin->toMail($this->user);
$this->assertInstanceOf(MailMessage::class, $mail); $this->assertInstanceOf(MailMessage::class, $mail);
@ -78,5 +77,4 @@ public function test_rendered_email_contains_expected_data()
$mail $mail
); );
} }
} }

View File

@ -31,7 +31,6 @@ class SignedInWithNewDeviceNotificationTest extends FeatureTestCase
*/ */
protected $signedInWithNewDevice; protected $signedInWithNewDevice;
public function setUp() : void public function setUp() : void
{ {
parent::setUp(); parent::setUp();
@ -39,14 +38,14 @@ public function setUp() : void
$this->user = User::factory()->create(); $this->user = User::factory()->create();
AuthLog::factory()->for($this->user, 'authenticatable')->failedLogin()->create(); AuthLog::factory()->for($this->user, 'authenticatable')->failedLogin()->create();
$this->authLog = AuthLog::first(); $this->authLog = AuthLog::first();
$this->signedInWithNewDevice = new SignedInWithNewDeviceNotification($this->authLog); $this->signedInWithNewDevice = new SignedInWithNewDeviceNotification($this->authLog);
} }
#[Test] #[Test]
public function test_it_renders_to_email() public function test_it_renders_to_email()
{ {
$mail = $this->signedInWithNewDevice->toMail($this->user); $mail = $this->signedInWithNewDevice->toMail($this->user);
$this->assertInstanceOf(MailMessage::class, $mail); $this->assertInstanceOf(MailMessage::class, $mail);
@ -77,5 +76,4 @@ public function test_rendered_email_contains_expected_data()
$mail $mail
); );
} }
} }

View File

@ -25,12 +25,11 @@ class TestEmailSettingNotificationTest extends FeatureTestCase
*/ */
protected $testEmailSettingNotification; protected $testEmailSettingNotification;
public function setUp() : void public function setUp() : void
{ {
parent::setUp(); parent::setUp();
$this->user = User::factory()->create(); $this->user = User::factory()->create();
$this->testEmailSettingNotification = new TestEmailSettingNotification('test_token'); $this->testEmailSettingNotification = new TestEmailSettingNotification('test_token');
} }

View File

@ -30,13 +30,13 @@ public function setUp() : void
{ {
parent::setUp(); parent::setUp();
$this->user = User::factory()->create(); $this->user = User::factory()->create();
$this->webauthnRecoveryNotification = new WebauthnRecoveryNotification('test_token'); $this->webauthnRecoveryNotification = new WebauthnRecoveryNotification('test_token');
} }
#[Test] #[Test]
public function test_it_renders_to_email() public function test_it_renders_to_email()
{ {
$mail = $this->webauthnRecoveryNotification->toMail($this->user); $mail = $this->webauthnRecoveryNotification->toMail($this->user);
$this->assertInstanceOf(MailMessage::class, $mail); $this->assertInstanceOf(MailMessage::class, $mail);
@ -77,5 +77,4 @@ public function test_rendered_email_contains_expected_data()
$mail $mail
); );
} }
} }

View File

@ -4,8 +4,8 @@
use App\Providers\RouteServiceProvider; use App\Providers\RouteServiceProvider;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
@ -15,6 +15,7 @@
class RouteTest extends FeatureTestCase class RouteTest extends FeatureTestCase
{ {
const API_ROUTE_PREFIX = 'api/v1'; const API_ROUTE_PREFIX = 'api/v1';
const API_MIDDLEWARE = 'api.v1'; const API_MIDDLEWARE = 'api.v1';
#[Test] #[Test]
@ -61,9 +62,7 @@ public function test_router_has_expected_global_where_patterns($pattern)
public static function wherePatternProvider() public static function wherePatternProvider()
{ {
return [ return [
'SETTING_NAME' => ['settingName'] 'SETTING_NAME' => ['settingName'],
]; ];
} }
} }

View File

@ -165,8 +165,8 @@ public function test_user_can_assign_multiple_accounts()
#[Test] #[Test]
public function test_setUser_sets_groups_user() public function test_setUser_sets_groups_user()
{ {
$this->groupOne = Group::factory()->create(); $this->groupOne = Group::factory()->create();
$this->groupTwo = Group::factory()->create(); $this->groupTwo = Group::factory()->create();
$this->assertEquals(null, $this->groupOne->user_id); $this->assertEquals(null, $this->groupOne->user_id);
$this->assertEquals(null, $this->groupTwo->user_id); $this->assertEquals(null, $this->groupTwo->user_id);

View File

@ -39,7 +39,7 @@ public function test_getIcon_returns_stored_icon_file_when_logo_exists()
Storage::fake('icons'); Storage::fake('icons');
Storage::fake('logos'); Storage::fake('logos');
$logoService = new LogoService(); $logoService = new LogoService;
$icon = $logoService->getIcon('twitter'); $icon = $logoService->getIcon('twitter');
$this->assertNotNull($icon); $this->assertNotNull($icon);
@ -56,7 +56,7 @@ public function test_getIcon_returns_null_when_github_request_fails()
Storage::fake('icons'); Storage::fake('icons');
Storage::fake('logos'); Storage::fake('logos');
$logoService = new LogoService(); $logoService = new LogoService;
$icon = $logoService->getIcon('twitter'); $icon = $logoService->getIcon('twitter');
@ -75,7 +75,7 @@ public function test_getIcon_returns_null_when_logo_fetching_fails()
Storage::fake('icons'); Storage::fake('icons');
Storage::fake('logos'); Storage::fake('logos');
$logoService = new LogoService(); $logoService = new LogoService;
$icon = $logoService->getIcon('twitter'); $icon = $logoService->getIcon('twitter');
@ -85,7 +85,7 @@ public function test_getIcon_returns_null_when_logo_fetching_fails()
#[Test] #[Test]
public function test_getIcon_returns_null_when_no_logo_exists() public function test_getIcon_returns_null_when_no_logo_exists()
{ {
$logoService = new LogoService(); $logoService = new LogoService;
$icon = $logoService->getIcon('no_logo_should_exists_with_this_name'); $icon = $logoService->getIcon('no_logo_should_exists_with_this_name');
@ -105,7 +105,7 @@ public function test_logoService_loads_empty_collection_when_tfajson_fetching_fa
Storage::fake('icons'); Storage::fake('icons');
Storage::fake('logos'); Storage::fake('logos');
$logoService = new LogoService(); $logoService = new LogoService;
$icon = $logoService->getIcon('twitter'); $icon = $logoService->getIcon('twitter');
$this->assertNull($icon); $this->assertNull($icon);

View File

@ -66,27 +66,24 @@ public function test_decodee_throws_an_exception($exception)
// QrReader is a final class, so we need to mock it here with a new object instance // QrReader is a final class, so we need to mock it here with a new object instance
// to then bind it to the container // to then bind it to the container
$fileContent = LocalFile::fake()->validQrcode()->get(); $fileContent = LocalFile::fake()->validQrcode()->get();
$qrReader = \Mockery::mock(new QrReader($fileContent, QrReader::SOURCE_TYPE_BLOB))->makePartial(); $qrReader = \Mockery::mock(new QrReader($fileContent, QrReader::SOURCE_TYPE_BLOB))->makePartial();
$qrReader->shouldReceive('text')->andReturn(''); $qrReader->shouldReceive('text')->andReturn('');
$qrReader->shouldReceive('getError')->andReturn($exception); $qrReader->shouldReceive('getError')->andReturn($exception);
$this->app->bind(QrReader::class, function() use($qrReader) { $this->app->bind(QrReader::class, function () use ($qrReader) {
return $qrReader; return $qrReader;
}); });
QrCode::decode(LocalFile::fake()->validQrcode()); QrCode::decode(LocalFile::fake()->validQrcode());
} }
/**
*
*/
public static function QrReaderExceptionProvider() public static function QrReaderExceptionProvider()
{ {
return [ return [
'NotFoundException' => [new NotFoundException()], 'NotFoundException' => [new NotFoundException],
'FormatException' => [new FormatException()], 'FormatException' => [new FormatException],
'ChecksumException' => [new ChecksumException()], 'ChecksumException' => [new ChecksumException],
'default' => [new Exception()], 'default' => [new Exception],
]; ];
} }
} }

View File

@ -337,7 +337,7 @@ public function test_cache_is_requested_at_instanciation()
Cache::shouldReceive('remember') Cache::shouldReceive('remember')
->andReturn(collect([])); ->andReturn(collect([]));
$settingService = new SettingService(); $settingService = new SettingService;
Cache::shouldHaveReceived('remember'); Cache::shouldHaveReceived('remember');
} }
@ -348,7 +348,7 @@ public function test_cache_is_updated_when_setting_is_set()
Cache::shouldReceive('remember', 'put') Cache::shouldReceive('remember', 'put')
->andReturn(collect([]), true); ->andReturn(collect([]), true);
$settingService = new SettingService(); $settingService = new SettingService;
$settingService->set(self::SETTING_NAME, self::SETTING_VALUE_STRING); $settingService->set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
Cache::shouldHaveReceived('put'); Cache::shouldHaveReceived('put');
@ -360,7 +360,7 @@ public function test_cache_is_updated_when_setting_is_deleted()
Cache::shouldReceive('remember', 'put') Cache::shouldReceive('remember', 'put')
->andReturn(collect([]), true); ->andReturn(collect([]), true);
$settingService = new SettingService(); $settingService = new SettingService;
$settingService->delete(self::SETTING_NAME); $settingService->delete(self::SETTING_NAME);
Cache::shouldHaveReceived('put'); Cache::shouldHaveReceived('put');

View File

@ -325,8 +325,8 @@ public function test_delete_single_id()
#[Test] #[Test]
public function test_setUser_sets_twofaccounts_user() public function test_setUser_sets_twofaccounts_user()
{ {
$twofaccountA = TwoFAccount::factory()->create(); $twofaccountA = TwoFAccount::factory()->create();
$twofaccountB = TwoFAccount::factory()->create(); $twofaccountB = TwoFAccount::factory()->create();
$this->assertEquals(null, $twofaccountA->user_id); $this->assertEquals(null, $twofaccountA->user_id);
$this->assertEquals(null, $twofaccountB->user_id); $this->assertEquals(null, $twofaccountB->user_id);

Some files were not shown because too many files have changed in this diff Show More