From c00b04e19219f20083e0a967a80a1126c9646be7 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Thu, 26 Sep 2024 23:50:01 +0200 Subject: [PATCH] Apply Pint fixes --- app/Api/v1/Controllers/SettingController.php | 3 +- .../v1/Controllers/TwoFAccountController.php | 13 ++-- app/Api/v1/Requests/SettingUpdateRequest.php | 6 +- .../Resources/UserAuthenticationResource.php | 2 +- .../Maintenance/FixServiceFieldEncryption.php | 25 +++----- app/Console/Commands/Utils/ResetTrait.php | 4 +- app/Exceptions/DbEncryptionException.php | 4 +- .../EncryptedMigrationException.php | 4 +- .../InvalidMigrationDataException.php | 4 +- .../InvalidOtpParameterException.php | 4 +- app/Exceptions/InvalidQrCodeException.php | 4 +- app/Exceptions/InvalidSecretException.php | 4 +- app/Exceptions/UndecipherableException.php | 4 +- .../UnsupportedMigrationException.php | 4 +- .../UnsupportedOtpTypeException.php | 4 +- app/Factories/MigratorFactory.php | 6 +- .../Auth/WebAuthnRecoveryController.php | 2 +- app/Http/Controllers/SinglePageController.php | 6 +- app/Http/Controllers/SystemController.php | 2 +- .../Middleware/CustomCreateFreshApiToken.php | 2 +- app/Http/Middleware/ForceJsonResponse.php | 2 +- .../RejectIfSsoOnlyAndNotForAdmin.php | 9 +-- app/Http/Middleware/TrustProxies.php | 2 +- .../Authentication/FailedLoginListener.php | 3 +- .../Authentication/LoginListener.php | 12 ++-- .../Authentication/LogoutListener.php | 10 +-- .../OtherDeviceLogoutListener.php | 10 +-- .../VisitedByProxyUserListener.php | 12 ++-- app/Models/Option.php | 4 +- app/Models/User.php | 3 +- app/Notifications/FailedLoginNotification.php | 4 +- .../SignedInWithNewDeviceNotification.php | 4 +- .../TestEmailSettingNotification.php | 5 +- app/Policies/UserPolicy.php | 10 +-- app/Providers/MigrationServiceProvider.php | 8 +-- app/Providers/Socialite/OpenId.php | 4 +- app/Providers/TwoFAuthServiceProvider.php | 6 +- app/Rules/IsValidRegex.php | 5 +- app/Services/Auth/ReverseProxyGuard.php | 2 - app/Services/GroupService.php | 9 ++- app/Services/Migrators/AegisMigrator.php | 4 +- app/Services/Migrators/GoogleAuthMigrator.php | 6 +- app/Services/Migrators/PlainTextMigrator.php | 2 +- app/Services/Migrators/TwoFASMigrator.php | 2 +- app/Services/Migrators/TwoFAuthMigrator.php | 4 +- app/Services/QrCodeService.php | 6 +- app/Services/TwoFAccountService.php | 3 +- routes/web.php | 10 +-- .../Controllers/TwoFAccountControllerTest.php | 36 +++++------ .../Controllers/UserManagerControllerTest.php | 6 +- .../DataProviders/TwoFAccountDataProvider.php | 26 +++----- .../v1/Requests/GroupAssignRequestTest.php | 6 +- .../Api/v1/Requests/GroupStoreRequestTest.php | 2 +- .../Api/v1/Requests/IconFetchRequestTest.php | 7 +-- .../v1/Requests/QrCodeDecodeRequestTest.php | 6 +- .../v1/Requests/SettingStoreRequestTest.php | 6 +- .../v1/Requests/SettingUpdateRequestTest.php | 6 +- .../Requests/TwoFAccountBatchRequestTest.php | 6 +- .../TwoFAccountDynamicRequestTest.php | 10 +-- .../Requests/TwoFAccountImportRequestTest.php | 6 +- .../Requests/TwoFAccountIndexRequestTest.php | 8 +-- .../TwoFAccountReorderRequestTest.php | 6 +- .../Requests/TwoFAccountStoreRequestTest.php | 6 +- .../Requests/TwoFAccountUpdateRequestTest.php | 6 +- .../v1/Requests/TwoFAccountUriRequestTest.php | 6 +- .../UserManagerPromoteRequestTest.php | 6 +- .../Requests/UserManagerStoreRequestTest.php | 9 ++- .../Console/FixServiceFieldEncryptionTest.php | 18 +++--- tests/Feature/Console/InstallTest.php | 5 +- tests/Feature/Console/ResetDemoTest.php | 6 +- tests/Feature/Http/Auth/LoginTest.php | 26 ++++---- .../Http/Auth/PasswordControllerTest.php | 16 ++--- .../Http/Auth/SocialiteControllerTest.php | 8 +-- .../Auth/WebAuthnDeviceLostControllerTest.php | 2 +- .../Http/Auth/WebAuthnLoginControllerTest.php | 12 ++-- .../Auth/WebAuthnRegisterControllerTest.php | 4 +- .../Middlewares/AdminOnlyMiddlewareTest.php | 6 +- .../AuthenticateMiddlewareTest.php | 4 +- ...tIfSsoOnlyAndNotForAdminMiddlewareTest.php | 2 +- .../Middlewares/SetLanguageMiddlewareTest.php | 14 ++--- .../Http/Requests/LoginRequestTest.php | 6 +- .../Http/Requests/UserDeleteRequestTest.php | 6 +- .../Http/Requests/UserPatchPwdRequestTest.php | 6 +- .../Http/Requests/UserStoreRequestTest.php | 6 +- .../Http/Requests/UserUpdateRequestTest.php | 2 +- .../Requests/WebauthnAssertedRequestTest.php | 4 +- .../Requests/WebauthnRenameRequestTest.php | 6 +- tests/Feature/Http/SystemControllerTest.php | 2 +- tests/Feature/Models/AuthLogModelTest.php | 2 +- tests/Feature/Models/UserModelTest.php | 32 +++++----- .../FailedLoginNotificationTest.php | 8 +-- .../SignedInWithNewDeviceNotificationTest.php | 8 +-- .../TestEmailSettingNotificationTest.php | 3 +- .../WebauthnRecoveryNotificationTest.php | 5 +- tests/Feature/RouteTest.php | 7 +-- tests/Feature/Services/GroupServiceTest.php | 4 +- tests/Feature/Services/LogoServiceTest.php | 10 +-- tests/Feature/Services/QrCodeServiceTest.php | 17 +++-- tests/Feature/Services/SettingServiceTest.php | 6 +- .../Services/TwoFAccountServiceTest.php | 4 +- tests/Feature/ViewTest.php | 4 +- tests/FeatureTestCase.php | 3 +- .../v1/Controllers/GroupControllerTest.php | 6 +- tests/Unit/Events/VisitedByProxyUserTest.php | 2 +- tests/Unit/Exceptions/HandlerTest.php | 10 +-- tests/Unit/GroupModelTest.php | 6 +- .../FailedLoginListenerTest.php | 9 ++- .../Authentication/LoginListenerTest.php | 3 +- .../Authentication/LogoutListenerTest.php | 2 +- .../VisitedByProxyUserListenerTest.php | 2 +- tests/Unit/Listeners/CleanIconStorageTest.php | 2 +- tests/Unit/Listeners/LogNotificationTest.php | 4 +- tests/Unit/Listeners/ReleaseRadarTest.php | 4 +- tests/Unit/MigratorTest.php | 62 +++++++++---------- .../Socialite/OpenIdProviderStub.php | 2 +- .../Socialite/OpenIdProviderTest.php | 16 ++--- tests/Unit/TwoFAccountModelTest.php | 4 +- tests/Unit/UserModelTest.php | 10 +-- 118 files changed, 398 insertions(+), 458 deletions(-) diff --git a/app/Api/v1/Controllers/SettingController.php b/app/Api/v1/Controllers/SettingController.php index a0c8b9dc..7577bdeb 100644 --- a/app/Api/v1/Controllers/SettingController.php +++ b/app/Api/v1/Controllers/SettingController.php @@ -6,7 +6,6 @@ use App\Api\v1\Requests\SettingUpdateRequest; use App\Facades\Settings; use App\Http\Controllers\Controller; -use Illuminate\Validation\ValidationException; 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: // - 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. // 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. diff --git a/app/Api/v1/Controllers/TwoFAccountController.php b/app/Api/v1/Controllers/TwoFAccountController.php index b6bc812f..557779d7 100644 --- a/app/Api/v1/Controllers/TwoFAccountController.php +++ b/app/Api/v1/Controllers/TwoFAccountController.php @@ -111,8 +111,9 @@ public function update(TwoFAccountUpdateRequest $request, TwoFAccount $twofaccou if ($twofaccount->group_id != $groupId) { if ((int) $groupId === 0) { TwoFAccounts::withdraw($twofaccount->id); + } else { + Groups::assign($twofaccount->id, $request->user(), $groupId); } - else Groups::assign($twofaccount->id, $request->user(), $groupId); $twofaccount->refresh(); } @@ -151,7 +152,7 @@ public function reorder(TwoFAccountReorderRequest $request) $validated = $request->validated(); $twofaccounts = TwoFAccount::whereIn('id', $validated['orderedIds'])->get(); - $this->authorize('updateEach', [new TwoFAccount(), $twofaccounts]); + $this->authorize('updateEach', [new TwoFAccount, $twofaccounts]); TwoFAccount::setNewOrder($validated['orderedIds']); $orderedIds = $request->user()->twofaccounts->sortBy('order_column')->pluck('id'); @@ -192,7 +193,7 @@ public function export(TwoFAccountBatchRequest $request) } $twofaccounts = TwoFAccounts::export($validated['ids']); - $this->authorize('viewEach', [new TwoFAccount(), $twofaccounts]); + $this->authorize('viewEach', [new TwoFAccount, $twofaccounts]); return new TwoFAccountExportCollection($twofaccounts); } @@ -231,7 +232,7 @@ public function otp(Request $request, $id = null) // The request inputs should define an account else { $validatedData = $request->validate((new TwoFAccountStoreRequest)->rules()); - $twofaccount = new TwoFAccount(); + $twofaccount = new TwoFAccount; $twofaccount->fillWithOtpParameters($validatedData, true); } @@ -267,7 +268,7 @@ public function withdraw(TwoFAccountBatchRequest $request) $ids = Helpers::commaSeparatedToArray($validated['ids']); $twofaccounts = TwoFAccount::whereIn('id', $ids)->get(); - $this->authorize('updateEach', [new TwoFAccount(), $twofaccounts]); + $this->authorize('updateEach', [new TwoFAccount, $twofaccounts]); TwoFAccounts::withdraw($ids); @@ -307,7 +308,7 @@ public function batchDestroy(TwoFAccountBatchRequest $request) $ids = Helpers::commaSeparatedToArray($validated['ids']); $twofaccounts = TwoFAccount::whereIn('id', $ids)->get(); - $this->authorize('deleteEach', [new TwoFAccount(), $twofaccounts]); + $this->authorize('deleteEach', [new TwoFAccount, $twofaccounts]); TwoFAccounts::delete($validated['ids']); diff --git a/app/Api/v1/Requests/SettingUpdateRequest.php b/app/Api/v1/Requests/SettingUpdateRequest.php index b5e11d58..7fd69204 100644 --- a/app/Api/v1/Requests/SettingUpdateRequest.php +++ b/app/Api/v1/Requests/SettingUpdateRequest.php @@ -34,15 +34,13 @@ public function rules() new IsValidEmailList, ], ]; - } - else if ($routeParam == 'restrictRule') { + } elseif ($routeParam == 'restrictRule') { $rule = [ 'value' => [ new IsValidRegex, ], ]; - } - else { + } else { $rule = [ 'value' => [ 'required', diff --git a/app/Api/v1/Resources/UserAuthenticationResource.php b/app/Api/v1/Resources/UserAuthenticationResource.php index 1cea4187..3a3f86e1 100644 --- a/app/Api/v1/Resources/UserAuthenticationResource.php +++ b/app/Api/v1/Resources/UserAuthenticationResource.php @@ -37,7 +37,7 @@ class UserAuthenticationResource extends JsonResource */ public function __construct($resource) { - $this->agent = new Agent(); + $this->agent = new Agent; $this->agent->setUserAgent($resource->user_agent); parent::__construct($resource); diff --git a/app/Console/Commands/Maintenance/FixServiceFieldEncryption.php b/app/Console/Commands/Maintenance/FixServiceFieldEncryption.php index b67cce59..ad07e426 100644 --- a/app/Console/Commands/Maintenance/FixServiceFieldEncryption.php +++ b/app/Console/Commands/Maintenance/FixServiceFieldEncryption.php @@ -4,12 +4,8 @@ use App\Facades\Settings; use App\Models\TwoFAccount; -use Exception; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Log; -use Throwable; /** * @codeCoverageIgnore @@ -75,16 +71,15 @@ public function handle() */ protected function encryptServiceField() : void { - $twofaccounts = TwoFAccount::all(); - $fullyEncryptedTwofaccounts = $twofaccounts->whereNotIn('service', [__('errors.indecipherable')]); + $twofaccounts = TwoFAccount::all(); + $fullyEncryptedTwofaccounts = $twofaccounts->whereNotIn('service', [__('errors.indecipherable')]); $partiallyEncryptedTwofaccounts = $twofaccounts->where('service', __('errors.indecipherable')); if ($fullyEncryptedTwofaccounts->count() === $twofaccounts->count()) { $this->components->info('The Service field is fully encrypted'); return; - } - else { + } else { $this->newLine(); $this->components->warn('The Service field is not fully encrypted, although it should be.'); $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) { // 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 - // model would be inconsistent. + // model would be inconsistent. if (str_starts_with($twofaccount->legacy_uri, 'otpauth://')) { - $rawServiceValue = $twofaccount->getRawOriginal('service'); + $rawServiceValue = $twofaccount->getRawOriginal('service'); $twofaccount->service = $rawServiceValue; $twofaccount->save(); $this->components->task(sprintf('Fixing twofaccount record with ID #%s', $twofaccount->id)); - } - else { + } else { $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'); } }); @@ -116,8 +112,7 @@ protected function encryptServiceField() : void } //$this->line('Task completed'); - } - else { + } else { $this->components->warn('No fix applied.'); $this->line('You can re-run this command at any time to fix inconsistent records.'); } diff --git a/app/Console/Commands/Utils/ResetTrait.php b/app/Console/Commands/Utils/ResetTrait.php index 37dd4c50..15ee8e0d 100644 --- a/app/Console/Commands/Utils/ResetTrait.php +++ b/app/Console/Commands/Utils/ResetTrait.php @@ -81,8 +81,8 @@ protected function flushDB() : void protected function seedDB(string $seeder) : void { $this->callSilent('db:seed', [ - '--class' => $seeder, - '--no-interaction' => 1 + '--class' => $seeder, + '--no-interaction' => 1, ]); $this->line('Database seeded'); diff --git a/app/Exceptions/DbEncryptionException.php b/app/Exceptions/DbEncryptionException.php index a392d62d..9ba0698b 100644 --- a/app/Exceptions/DbEncryptionException.php +++ b/app/Exceptions/DbEncryptionException.php @@ -9,6 +9,4 @@ * * @codeCoverageIgnore */ -class DbEncryptionException extends Exception -{ -} +class DbEncryptionException extends Exception {} diff --git a/app/Exceptions/EncryptedMigrationException.php b/app/Exceptions/EncryptedMigrationException.php index da9725a7..73b44394 100644 --- a/app/Exceptions/EncryptedMigrationException.php +++ b/app/Exceptions/EncryptedMigrationException.php @@ -9,6 +9,4 @@ * * @codeCoverageIgnore */ -class EncryptedMigrationException extends Exception -{ -} +class EncryptedMigrationException extends Exception {} diff --git a/app/Exceptions/InvalidMigrationDataException.php b/app/Exceptions/InvalidMigrationDataException.php index 0c310ef4..158e403b 100644 --- a/app/Exceptions/InvalidMigrationDataException.php +++ b/app/Exceptions/InvalidMigrationDataException.php @@ -9,6 +9,4 @@ * * @codeCoverageIgnore */ -class InvalidMigrationDataException extends Exception -{ -} +class InvalidMigrationDataException extends Exception {} diff --git a/app/Exceptions/InvalidOtpParameterException.php b/app/Exceptions/InvalidOtpParameterException.php index cf3ed3e9..49698ffd 100644 --- a/app/Exceptions/InvalidOtpParameterException.php +++ b/app/Exceptions/InvalidOtpParameterException.php @@ -9,6 +9,4 @@ * * @codeCoverageIgnore */ -class InvalidOtpParameterException extends Exception -{ -} +class InvalidOtpParameterException extends Exception {} diff --git a/app/Exceptions/InvalidQrCodeException.php b/app/Exceptions/InvalidQrCodeException.php index 9002538b..c77fb4f3 100644 --- a/app/Exceptions/InvalidQrCodeException.php +++ b/app/Exceptions/InvalidQrCodeException.php @@ -9,6 +9,4 @@ * * @codeCoverageIgnore */ -class InvalidQrCodeException extends Exception -{ -} +class InvalidQrCodeException extends Exception {} diff --git a/app/Exceptions/InvalidSecretException.php b/app/Exceptions/InvalidSecretException.php index 45c23f26..db6c330a 100644 --- a/app/Exceptions/InvalidSecretException.php +++ b/app/Exceptions/InvalidSecretException.php @@ -9,6 +9,4 @@ * * @codeCoverageIgnore */ -class InvalidSecretException extends Exception -{ -} +class InvalidSecretException extends Exception {} diff --git a/app/Exceptions/UndecipherableException.php b/app/Exceptions/UndecipherableException.php index 7922d6b7..0b7f423a 100644 --- a/app/Exceptions/UndecipherableException.php +++ b/app/Exceptions/UndecipherableException.php @@ -9,6 +9,4 @@ * * @codeCoverageIgnore */ -class UndecipherableException extends Exception -{ -} +class UndecipherableException extends Exception {} diff --git a/app/Exceptions/UnsupportedMigrationException.php b/app/Exceptions/UnsupportedMigrationException.php index 399a1f5b..ea81321d 100644 --- a/app/Exceptions/UnsupportedMigrationException.php +++ b/app/Exceptions/UnsupportedMigrationException.php @@ -9,6 +9,4 @@ * * @codeCoverageIgnore */ -class UnsupportedMigrationException extends Exception -{ -} +class UnsupportedMigrationException extends Exception {} diff --git a/app/Exceptions/UnsupportedOtpTypeException.php b/app/Exceptions/UnsupportedOtpTypeException.php index 4633510b..7513a534 100644 --- a/app/Exceptions/UnsupportedOtpTypeException.php +++ b/app/Exceptions/UnsupportedOtpTypeException.php @@ -9,6 +9,4 @@ * * @codeCoverageIgnore */ -class UnsupportedOtpTypeException extends Exception -{ -} +class UnsupportedOtpTypeException extends Exception {} diff --git a/app/Factories/MigratorFactory.php b/app/Factories/MigratorFactory.php index 0f104515..ffd57f94 100644 --- a/app/Factories/MigratorFactory.php +++ b/app/Factories/MigratorFactory.php @@ -34,7 +34,7 @@ public function create(string $migrationPayload) : Migrator } elseif ($this->isPlainText($migrationPayload)) { return App::make(PlainTextMigrator::class); } else { - throw new UnsupportedMigrationException(); + throw new UnsupportedMigrationException; } } @@ -130,7 +130,7 @@ private function isAegisJSON(string $migrationPayload) : mixed if (Arr::has($json, 'db')) { if (is_string($json['db']) && is_array(Arr::get($json, 'header.slots'))) { - throw new EncryptedMigrationException(); + throw new EncryptedMigrationException; } else { return count(Validator::validate( $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, 'servicesEncrypted')) { - throw new EncryptedMigrationException(); + throw new EncryptedMigrationException; } else { return count(Validator::validate( $json, diff --git a/app/Http/Controllers/Auth/WebAuthnRecoveryController.php b/app/Http/Controllers/Auth/WebAuthnRecoveryController.php index c2f5e4bc..49d9a995 100644 --- a/app/Http/Controllers/Auth/WebAuthnRecoveryController.php +++ b/app/Http/Controllers/Auth/WebAuthnRecoveryController.php @@ -54,7 +54,7 @@ function ($user) use ($request) { $user->save(); Log::notice(sprintf('Legacy login restored for user ID #%s', $user->id)); } else { - throw new AuthenticationException(); + throw new AuthenticationException; } } ); diff --git a/app/Http/Controllers/SinglePageController.php b/app/Http/Controllers/SinglePageController.php index e80c00e1..86108ca6 100644 --- a/app/Http/Controllers/SinglePageController.php +++ b/app/Http/Controllers/SinglePageController.php @@ -16,7 +16,7 @@ class SinglePageController extends Controller */ public function index() { - event(new ScanForNewReleaseCalled()); + event(new ScanForNewReleaseCalled); $settings = Settings::all()->toJson(); $proxyAuth = config('auth.defaults.guard') === 'reverse-proxy-guard' ? true : false; @@ -45,9 +45,9 @@ public function index() ], 'subdirectory' => $subdir, ])->toJson(), - 'urls' => collect([ + 'urls' => collect([ 'installDocUrl' => $installDocUrl, - 'ssoDocUrl' => $ssoDocUrl + 'ssoDocUrl' => $ssoDocUrl, ]), 'defaultPreferences' => $defaultPreferences, 'subdirectory' => $subdir, diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 3349b12d..182b1f11 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -70,7 +70,7 @@ public function latestRelease(Request $request, ReleaseRadarService $releaseRada public function testEmail(Request $request) { try { - $request->user()->notify(new TestEmailSettingNotification()); + $request->user()->notify(new TestEmailSettingNotification); } catch (\Throwable $th) { Log::error($th->getMessage()); } diff --git a/app/Http/Middleware/CustomCreateFreshApiToken.php b/app/Http/Middleware/CustomCreateFreshApiToken.php index 5b141da9..95b98cc6 100644 --- a/app/Http/Middleware/CustomCreateFreshApiToken.php +++ b/app/Http/Middleware/CustomCreateFreshApiToken.php @@ -11,7 +11,7 @@ class CustomCreateFreshApiToken extends CreateFreshApiToken * * @param \Illuminate\Http\Request $request * @return bool - * + * * @codeCoverageIgnore */ protected function requestShouldReceiveFreshToken($request) diff --git a/app/Http/Middleware/ForceJsonResponse.php b/app/Http/Middleware/ForceJsonResponse.php index 79f217b9..4cd5e28e 100644 --- a/app/Http/Middleware/ForceJsonResponse.php +++ b/app/Http/Middleware/ForceJsonResponse.php @@ -11,7 +11,7 @@ class ForceJsonResponse * * @param \Illuminate\Http\Request $request * @return mixed - * + * * @codeCoverageIgnore */ public function handle($request, Closure $next) diff --git a/app/Http/Middleware/RejectIfSsoOnlyAndNotForAdmin.php b/app/Http/Middleware/RejectIfSsoOnlyAndNotForAdmin.php index 41bb98b6..64362925 100644 --- a/app/Http/Middleware/RejectIfSsoOnlyAndNotForAdmin.php +++ b/app/Http/Middleware/RejectIfSsoOnlyAndNotForAdmin.php @@ -24,15 +24,16 @@ public function handle($request, Closure $next) if (Settings::get('useSsoOnly')) { if ($email = $request->input('email', null)) { $user = User::whereEmail($email)->first(); + } else { + $user = Auth::user(); } - else $user = Auth::user(); - + if ($user?->isAdministrator()) { return $next($request); } - + 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); } diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index e5a47242..788da121 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -8,7 +8,7 @@ class TrustProxies extends Middleware { /** * TrustProxies constructor. - * + * * @codeCoverageIgnore */ public function __construct() diff --git a/app/Listeners/Authentication/FailedLoginListener.php b/app/Listeners/Authentication/FailedLoginListener.php index d9ff0afc..d77a01fc 100644 --- a/app/Listeners/Authentication/FailedLoginListener.php +++ b/app/Listeners/Authentication/FailedLoginListener.php @@ -59,7 +59,8 @@ public function handle(mixed $event) : void if ($user->preferences['notifyOnFailedLogin'] == true) { $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)); } } diff --git a/app/Listeners/Authentication/LoginListener.php b/app/Listeners/Authentication/LoginListener.php index bbcdda60..fde59925 100644 --- a/app/Listeners/Authentication/LoginListener.php +++ b/app/Listeners/Authentication/LoginListener.php @@ -47,12 +47,12 @@ public function handle(mixed $event) : void $ip = config('2fauth.proxy_headers.forIp') ?? $this->request->ip(); $userAgent = $this->request->userAgent(); $known = $user->authentications() - ->whereIpAddress($ip) - ->whereUserAgent($userAgent) - ->whereLoginSuccessful(true) - ->whereGuard($event->guard) - ->first(); - $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1; + ->whereIpAddress($ip) + ->whereUserAgent($userAgent) + ->whereLoginSuccessful(true) + ->whereGuard($event->guard) + ->first(); + $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1; $log = $user->authentications()->create([ 'ip_address' => $ip, diff --git a/app/Listeners/Authentication/LogoutListener.php b/app/Listeners/Authentication/LogoutListener.php index 1c5a462b..5f30b7f2 100644 --- a/app/Listeners/Authentication/LogoutListener.php +++ b/app/Listeners/Authentication/LogoutListener.php @@ -46,11 +46,11 @@ public function handle(mixed $event) : void $ip = config('2fauth.proxy_headers.forIp') ?? $this->request->ip(); $userAgent = $this->request->userAgent(); $log = $user->authentications() - ->whereIpAddress($ip) - ->whereUserAgent($userAgent) - ->whereGuard($event->guard) - ->orderByDesc('login_at') - ->first(); + ->whereIpAddress($ip) + ->whereUserAgent($userAgent) + ->whereGuard($event->guard) + ->orderByDesc('login_at') + ->first(); if (! $log) { $log = new AuthLog([ diff --git a/app/Listeners/Authentication/OtherDeviceLogoutListener.php b/app/Listeners/Authentication/OtherDeviceLogoutListener.php index cd2a1b92..1309d526 100644 --- a/app/Listeners/Authentication/OtherDeviceLogoutListener.php +++ b/app/Listeners/Authentication/OtherDeviceLogoutListener.php @@ -30,7 +30,7 @@ /** * @codeCoverageIgnore - * + * * 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 */ @@ -52,10 +52,10 @@ public function handle(mixed $event) : void $ip = config('2fauth.proxy_headers.forIp') ?? $this->request->ip(); $userAgent = $this->request->userAgent(); $authLog = $user->authentications() - ->whereIpAddress($ip) - ->whereUserAgent($userAgent) - ->first(); - $guard = $event->guard; + ->whereIpAddress($ip) + ->whereUserAgent($userAgent) + ->first(); + $guard = $event->guard; if (! $authLog) { $authLog = new AuthLog([ diff --git a/app/Listeners/Authentication/VisitedByProxyUserListener.php b/app/Listeners/Authentication/VisitedByProxyUserListener.php index daaef6a7..a0f80073 100644 --- a/app/Listeners/Authentication/VisitedByProxyUserListener.php +++ b/app/Listeners/Authentication/VisitedByProxyUserListener.php @@ -28,12 +28,12 @@ public function handle(mixed $event) : void $userAgent = $this->request->userAgent(); $guard = config('auth.defaults.guard'); $known = $user->authentications() - ->whereIpAddress($ip) - ->whereUserAgent($userAgent) - ->whereLoginSuccessful(true) - ->whereGuard($guard) - ->first(); - $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1; + ->whereIpAddress($ip) + ->whereUserAgent($userAgent) + ->whereLoginSuccessful(true) + ->whereGuard($guard) + ->first(); + $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1; $log = $user->authentications()->create([ 'ip_address' => $ip, diff --git a/app/Models/Option.php b/app/Models/Option.php index 9d6064e6..c47ddf67 100644 --- a/app/Models/Option.php +++ b/app/Models/Option.php @@ -10,14 +10,14 @@ * @property int $id * @property string $key * @property string $value - * + * * @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Option newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Option query() * @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 whereValue($value) - * + * * @mixin \Eloquent */ class Option extends Model diff --git a/app/Models/User.php b/app/Models/User.php index f55ebd11..50643aeb 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -70,12 +70,13 @@ class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable { use HasApiTokens, Notifiable; - use HasAuthenticationLog; + /** * @use HasFactory */ use HasFactory; + use WebAuthnAuthentication, WebAuthnManageCredentials; /** diff --git a/app/Notifications/FailedLoginNotification.php b/app/Notifications/FailedLoginNotification.php index 4564f77c..e9d4c96c 100644 --- a/app/Notifications/FailedLoginNotification.php +++ b/app/Notifications/FailedLoginNotification.php @@ -31,7 +31,7 @@ class FailedLoginNotification extends Notification implements ShouldQueue public function __construct(AuthLog $authLog) { $this->authLog = $authLog; - $this->agent = new Agent(); + $this->agent = new Agent; $this->agent->setUserAgent($authLog->user_agent); } @@ -48,7 +48,7 @@ public function via(mixed $notifiable) : array|string */ public function toMail(mixed $notifiable) : MailMessage { - return (new MailMessage()) + return (new MailMessage) ->subject(__('notifications.failed_login.subject')) ->markdown('emails.failedLogin', [ 'account' => $notifiable, diff --git a/app/Notifications/SignedInWithNewDeviceNotification.php b/app/Notifications/SignedInWithNewDeviceNotification.php index 758ef845..41567458 100644 --- a/app/Notifications/SignedInWithNewDeviceNotification.php +++ b/app/Notifications/SignedInWithNewDeviceNotification.php @@ -31,7 +31,7 @@ class SignedInWithNewDeviceNotification extends Notification implements ShouldQu public function __construct(AuthLog $authLog) { $this->authLog = $authLog; - $this->agent = new Agent(); + $this->agent = new Agent; $this->agent->setUserAgent($authLog->user_agent); } @@ -45,7 +45,7 @@ public function via(mixed $notifiable) : array|string */ public function toMail(mixed $notifiable) : MailMessage { - return (new MailMessage()) + return (new MailMessage) ->subject(__('notifications.new_device.subject')) ->markdown('emails.signedInWithNewDevice', [ 'account' => $notifiable, diff --git a/app/Notifications/TestEmailSettingNotification.php b/app/Notifications/TestEmailSettingNotification.php index a1e1dcc2..74668914 100644 --- a/app/Notifications/TestEmailSettingNotification.php +++ b/app/Notifications/TestEmailSettingNotification.php @@ -26,10 +26,7 @@ class TestEmailSettingNotification extends Notification /** * TestEmailSettingNotification constructor. */ - public function __construct() - { - - } + public function __construct() {} /** * Get the notification's delivery channels. diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php index e98f9294..31f71482 100644 --- a/app/Policies/UserPolicy.php +++ b/app/Policies/UserPolicy.php @@ -31,7 +31,7 @@ public function before(User $user, string $ability) : ?bool /** * Determine whether the user can view the model. - * + * * @codeCoverageIgnore * 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. - * + * * @codeCoverageIgnore * 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. - * + * * Not ignored because the user can update itself */ 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. - * + * * @codeCoverageIgnore * 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. - * + * * @codeCoverageIgnore * Ignored as long as the before() method restrict the access to admins only */ diff --git a/app/Providers/MigrationServiceProvider.php b/app/Providers/MigrationServiceProvider.php index 426795e8..19efd9c4 100644 --- a/app/Providers/MigrationServiceProvider.php +++ b/app/Providers/MigrationServiceProvider.php @@ -20,19 +20,19 @@ public function register() : void $this->app->bind(MigratorFactoryInterface::class, MigratorFactory::class); $this->app->singleton(GoogleAuthMigrator::class, function () { - return new GoogleAuthMigrator(); + return new GoogleAuthMigrator; }); $this->app->singleton(AegisMigrator::class, function () { - return new AegisMigrator(); + return new AegisMigrator; }); $this->app->singleton(TwoFASMigrator::class, function () { - return new TwoFASMigrator(); + return new TwoFASMigrator; }); $this->app->singleton(PlainTextMigrator::class, function () { - return new PlainTextMigrator(); + return new PlainTextMigrator; }); } diff --git a/app/Providers/Socialite/OpenId.php b/app/Providers/Socialite/OpenId.php index 33d30289..49328af0 100644 --- a/app/Providers/Socialite/OpenId.php +++ b/app/Providers/Socialite/OpenId.php @@ -23,7 +23,7 @@ class OpenId extends AbstractProvider implements ProviderInterface public function __construct(Request $request, $clientId, $clientSecret, $redirectUrl, $guzzle = []) { $guzzle = array_merge([ - 'proxy' => config('2fauth.config.outgoingProxy') + 'proxy' => config('2fauth.config.outgoingProxy'), ], $guzzle); parent::__construct($request, $clientId, $clientSecret, $redirectUrl, $guzzle); @@ -72,7 +72,7 @@ protected function getUserByToken($token) */ protected function mapUserToObject(array $user) { - return (new User())->setRaw($user)->map([ + return (new User)->setRaw($user)->map([ 'email' => $user['email'] ?? null, 'email_verified' => $user['email_verified'] ?? null, 'name' => $user['name'] ?? null, diff --git a/app/Providers/TwoFAuthServiceProvider.php b/app/Providers/TwoFAuthServiceProvider.php index 1259db41..219fbad7 100644 --- a/app/Providers/TwoFAuthServiceProvider.php +++ b/app/Providers/TwoFAuthServiceProvider.php @@ -25,15 +25,15 @@ public function register() }); $this->app->singleton(SettingService::class, function () { - return new SettingService(); + return new SettingService; }); $this->app->singleton(LogoService::class, function () { - return new LogoService(); + return new LogoService; }); $this->app->singleton(ReleaseRadarService::class, function () { - return new ReleaseRadarService(); + return new ReleaseRadarService; }); $this->app->bind(QrReader::class, function ($app, $parameters) { diff --git a/app/Rules/IsValidRegex.php b/app/Rules/IsValidRegex.php index 03112192..a20c21fa 100644 --- a/app/Rules/IsValidRegex.php +++ b/app/Rules/IsValidRegex.php @@ -14,12 +14,11 @@ public function validate(string $attribute, mixed $value, Closure $fail) : void { try { preg_match('/' . $value . '/', ''); - + if (preg_last_error() !== PREG_NO_ERROR) { $fail('validation.IsValidRegex')->translate(); } - } - catch (\Throwable $ex) { + } catch (\Throwable $ex) { $fail('validation.IsValidRegex')->translate(); } } diff --git a/app/Services/Auth/ReverseProxyGuard.php b/app/Services/Auth/ReverseProxyGuard.php index abc4072c..75ace2f2 100644 --- a/app/Services/Auth/ReverseProxyGuard.php +++ b/app/Services/Auth/ReverseProxyGuard.php @@ -5,11 +5,9 @@ namespace App\Services\Auth; -use App\Events\VisitedByProxyUser; use Illuminate\Auth\GuardHelpers; use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\UserProvider; -use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Log; class ReverseProxyGuard implements Guard diff --git a/app/Services/GroupService.php b/app/Services/GroupService.php index 38c7aafa..a7898b4d 100644 --- a/app/Services/GroupService.php +++ b/app/Services/GroupService.php @@ -29,7 +29,7 @@ public static function assign($ids, User $user, mixed $targetGroup = null) : voi // TwoFAccountService::withdraw() method. if ($targetGroup === 0 || $targetGroup === '0') { Log::info('Group assignment skipped, no group explicitly requested'); - + 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 $group = null; - if(! is_null($targetGroup)) { + if (! is_null($targetGroup)) { if ($targetGroup instanceof Group && $targetGroup->exists && $targetGroup->user_id == $user->id) { $group = $targetGroup; - } - else { + } else { $group = Group::where('id', (int) $targetGroup) ->where('user_id', $user->id) ->first(); @@ -58,7 +57,7 @@ public static function assign($ids, User $user, mixed $targetGroup = null) : voi $twofaccounts = TwoFAccount::find($ids); if ($user->cannot('updateEach', [(new TwoFAccount), $twofaccounts])) { - throw new AuthorizationException(); + throw new AuthorizationException; } $group->twofaccounts()->saveMany($twofaccounts); diff --git a/app/Services/Migrators/AegisMigrator.php b/app/Services/Migrators/AegisMigrator.php index fd970248..a2a58504 100644 --- a/app/Services/Migrators/AegisMigrator.php +++ b/app/Services/Migrators/AegisMigrator.php @@ -76,7 +76,7 @@ public function migrate(mixed $migrationPayload) : Collection break; default: - throw new \Exception(); + throw new \Exception; } $parameters['iconData'] = base64_decode($otp_parameters['icon']); } @@ -95,7 +95,7 @@ public function migrate(mixed $migrationPayload) : Collection Log::debug($exception->getMessage()); // 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->otp_type = $otp_parameters['type'] ?? TwoFAccount::TOTP; // Only basic fields are filled to limit the risk of another exception. diff --git a/app/Services/Migrators/GoogleAuthMigrator.php b/app/Services/Migrators/GoogleAuthMigrator.php index 5825039b..d97e24e4 100644 --- a/app/Services/Migrators/GoogleAuthMigrator.php +++ b/app/Services/Migrators/GoogleAuthMigrator.php @@ -28,7 +28,7 @@ public function migrate(mixed $migrationPayload) : Collection { try { $migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', strval($migrationPayload)))); - $protobuf = new Payload(); + $protobuf = new Payload; $protobuf->mergeFromString($migrationData); $otpParameters = $protobuf->getOtpParameters(); } catch (Exception $ex) { @@ -59,7 +59,7 @@ public function migrate(mixed $migrationPayload) : Collection Log::debug($exception->getMessage()); // 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->otp_type = $fakeAccount::TOTP; // 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 - * + * * @throws TypeError */ protected function toBase32(string $str) : string diff --git a/app/Services/Migrators/PlainTextMigrator.php b/app/Services/Migrators/PlainTextMigrator.php index ba9ee203..aee63f5c 100644 --- a/app/Services/Migrators/PlainTextMigrator.php +++ b/app/Services/Migrators/PlainTextMigrator.php @@ -37,7 +37,7 @@ public function migrate(mixed $migrationPayload) : Collection Log::debug($exception->getMessage()); // 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->otp_type = substr($uri, 10, 4); // Only basic fields are filled to limit the risk of another exception. diff --git a/app/Services/Migrators/TwoFASMigrator.php b/app/Services/Migrators/TwoFASMigrator.php index e07321af..8d7129af 100644 --- a/app/Services/Migrators/TwoFASMigrator.php +++ b/app/Services/Migrators/TwoFASMigrator.php @@ -103,7 +103,7 @@ public function migrate(mixed $migrationPayload) : Collection Log::debug($exception->getMessage()); // 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->otp_type = $otp_parameters['otp']['tokenType'] ?? TwoFAccount::TOTP; // Only basic fields are filled to limit the risk of another exception. diff --git a/app/Services/Migrators/TwoFAuthMigrator.php b/app/Services/Migrators/TwoFAuthMigrator.php index ea2e84bb..67b270ce 100644 --- a/app/Services/Migrators/TwoFAuthMigrator.php +++ b/app/Services/Migrators/TwoFAuthMigrator.php @@ -93,7 +93,7 @@ public function migrate(mixed $migrationPayload) : Collection break; default: - throw new \Exception(); + throw new \Exception; } $parameters['icon_file'] = base64_decode($otp_parameters['icon_file']); } @@ -112,7 +112,7 @@ public function migrate(mixed $migrationPayload) : Collection Log::debug($exception->getMessage()); // 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->otp_type = $otp_parameters['otp']['tokenType'] ?? TwoFAccount::TOTP; // Only basic fields are filled to limit the risk of another exception. diff --git a/app/Services/QrCodeService.php b/app/Services/QrCodeService.php index bcd7f8ba..d84d7482 100644 --- a/app/Services/QrCodeService.php +++ b/app/Services/QrCodeService.php @@ -40,11 +40,11 @@ public static function encode(string $data) public static function decode(\Illuminate\Http\UploadedFile $file) { $qrcode = app()->make(QrReader::class, [ - 'imgSource' => $file->get(), - 'sourceType' => QrReader::SOURCE_TYPE_BLOB + 'imgSource' => $file->get(), + 'sourceType' => QrReader::SOURCE_TYPE_BLOB, ]); - $text = $qrcode->text(); + $text = $qrcode->text(); if (! $text) { $text = $qrcode->text([ diff --git a/app/Services/TwoFAccountService.php b/app/Services/TwoFAccountService.php index 72311428..f98f9d5c 100644 --- a/app/Services/TwoFAccountService.php +++ b/app/Services/TwoFAccountService.php @@ -46,8 +46,9 @@ public static function withdraw($ids) : void if ($affectedCount) { 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))); } /** diff --git a/routes/web.php b/routes/web.php index 26de87eb..4ce77b55 100644 --- a/routes/web.php +++ b/routes/web.php @@ -55,7 +55,7 @@ * that can be requested max 10 times per minute by the same IP */ 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::get('/socialite/redirect/{driver}', [SocialiteController::class, 'redirect'])->name('socialite.redirect'); @@ -100,10 +100,10 @@ }); Route::withoutMiddleware([ - SubstituteBindings::class, - SetLanguage::class, - CustomCreateFreshApiToken::class - ])->get('/up', function () { + SubstituteBindings::class, + SetLanguage::class, + CustomCreateFreshApiToken::class, +])->get('/up', function () { //Event::dispatch(new DiagnosingHealth); return view('health'); }); diff --git a/tests/Api/v1/Controllers/TwoFAccountControllerTest.php b/tests/Api/v1/Controllers/TwoFAccountControllerTest.php index 265c1ec9..25c9ad52 100644 --- a/tests/Api/v1/Controllers/TwoFAccountControllerTest.php +++ b/tests/Api/v1/Controllers/TwoFAccountControllerTest.php @@ -127,7 +127,7 @@ class TwoFAccountControllerTest extends FeatureTestCase 'algorithm', 'period', '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 = [ @@ -141,7 +141,7 @@ class TwoFAccountControllerTest extends FeatureTestCase 'algorithm', 'period', 'counter', - 'otp' => self::VALID_EMBEDDED_OTP_RESOURCE_STRUCTURE_FOR_TOTP + 'otp' => self::VALID_EMBEDDED_OTP_RESOURCE_STRUCTURE_FOR_TOTP, ]; 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') ->json('POST', '/api/v1/twofaccounts', array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => $this->userGroupA->id] + ['group_id' => $this->userGroupA->id] )) ->assertJsonFragment([ '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') ->json('POST', '/api/v1/twofaccounts', array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => 9999999] + ['group_id' => 9999999] )) ->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') ->json('POST', '/api/v1/twofaccounts', array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => null] + ['group_id' => null] )) ->assertJsonFragment([ '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') ->json('POST', '/api/v1/twofaccounts', array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => null] + ['group_id' => null] )) ->assertJsonFragment([ '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') ->json('POST', '/api/v1/twofaccounts', array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => 0] + ['group_id' => 0] )) ->assertJsonFragment([ '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') ->json('POST', '/api/v1/twofaccounts', array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => $this->userGroupB->id] + ['group_id' => $this->userGroupB->id] )) ->assertJsonFragment([ '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() { $this->assertNotEquals(null, $this->twofaccountA->group_id); - + $response = $this->actingAs($this->user, 'api-guard') ->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => null] + ['group_id' => null] )) ->assertOk() ->assertJsonFragment([ - 'group_id' => null + 'group_id' => null, ]) ->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() { $this->assertNotEquals(null, $this->twofaccountA->group_id); - + $response = $this->actingAs($this->user, 'api-guard') ->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => 0] + ['group_id' => 0] )) ->assertOk() ->assertJsonFragment([ - 'group_id' => null + 'group_id' => null, ]) ->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() { $this->assertEquals($this->userGroupA->id, $this->twofaccountA->group_id); - + $response = $this->actingAs($this->user, 'api-guard') ->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => $this->userGroupB->id] + ['group_id' => $this->userGroupB->id] )) ->assertOk() ->assertJsonFragment([ - 'group_id' => $this->userGroupB->id + 'group_id' => $this->userGroupB->id, ]) ->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') ->json('PUT', '/api/v1/twofaccounts/' . $this->twofaccountA->id, array_merge( OtpTestData::ARRAY_OF_FULL_VALID_PARAMETERS_FOR_CUSTOM_TOTP, - ['group_id' => 9999999] + ['group_id' => 9999999] )) ->assertJsonValidationErrorFor('group_id'); } diff --git a/tests/Api/v1/Controllers/UserManagerControllerTest.php b/tests/Api/v1/Controllers/UserManagerControllerTest.php index 61aa1060..3d7c9dd2 100644 --- a/tests/Api/v1/Controllers/UserManagerControllerTest.php +++ b/tests/Api/v1/Controllers/UserManagerControllerTest.php @@ -335,10 +335,10 @@ public function test_store_another_user_returns_forbidden() : void public function test_revokePATs_flushes_pats() { Artisan::call('passport:install', [ - '--verbose' => 2, - '--no-interaction' => 1 + '--verbose' => 2, + '--no-interaction' => 1, ]); - + $tokenRepository = app(TokenRepository::class); $this->actingAs($this->user, 'api-guard') diff --git a/tests/Api/v1/Requests/DataProviders/TwoFAccountDataProvider.php b/tests/Api/v1/Requests/DataProviders/TwoFAccountDataProvider.php index 0ff3b558..1896edbf 100644 --- a/tests/Api/v1/Requests/DataProviders/TwoFAccountDataProvider.php +++ b/tests/Api/v1/Requests/DataProviders/TwoFAccountDataProvider.php @@ -1,13 +1,12 @@ -once() ->andReturn(true); - $request = new GroupAssignRequest(); + $request = new GroupAssignRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new GroupAssignRequest(); + $request = new GroupAssignRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -59,7 +59,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new GroupAssignRequest(); + $request = new GroupAssignRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/GroupStoreRequestTest.php b/tests/Api/v1/Requests/GroupStoreRequestTest.php index 450baf88..a71360cf 100644 --- a/tests/Api/v1/Requests/GroupStoreRequestTest.php +++ b/tests/Api/v1/Requests/GroupStoreRequestTest.php @@ -43,7 +43,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new GroupStoreRequest(); + $request = new GroupStoreRequest; $this->assertTrue($request->authorize()); } diff --git a/tests/Api/v1/Requests/IconFetchRequestTest.php b/tests/Api/v1/Requests/IconFetchRequestTest.php index 0b81ef5e..2157461a 100644 --- a/tests/Api/v1/Requests/IconFetchRequestTest.php +++ b/tests/Api/v1/Requests/IconFetchRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Api\v1\Requests; -use App\Api\v1\Requests\GroupAssignRequest; use App\Api\v1\Requests\IconFetchRequest; use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Support\Facades\Auth; @@ -27,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new IconFetchRequest(); + $request = new IconFetchRequest; $this->assertTrue($request->authorize()); } @@ -36,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new IconFetchRequest(); + $request = new IconFetchRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -64,7 +63,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new IconFetchRequest(); + $request = new IconFetchRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/QrCodeDecodeRequestTest.php b/tests/Api/v1/Requests/QrCodeDecodeRequestTest.php index fb9dfddc..4180037e 100644 --- a/tests/Api/v1/Requests/QrCodeDecodeRequestTest.php +++ b/tests/Api/v1/Requests/QrCodeDecodeRequestTest.php @@ -27,7 +27,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new QrCodeDecodeRequest(); + $request = new QrCodeDecodeRequest; $this->assertTrue($request->authorize()); } @@ -36,7 +36,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new QrCodeDecodeRequest(); + $request = new QrCodeDecodeRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -60,7 +60,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new QrCodeDecodeRequest(); + $request = new QrCodeDecodeRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/SettingStoreRequestTest.php b/tests/Api/v1/Requests/SettingStoreRequestTest.php index 957ba178..ccb87e9d 100644 --- a/tests/Api/v1/Requests/SettingStoreRequestTest.php +++ b/tests/Api/v1/Requests/SettingStoreRequestTest.php @@ -29,7 +29,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new SettingStoreRequest(); + $request = new SettingStoreRequest; $this->assertTrue($request->authorize()); } @@ -38,7 +38,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new SettingStoreRequest(); + $request = new SettingStoreRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -71,7 +71,7 @@ public function test_invalid_data(array $data) : void { Settings::set(self::UNIQUE_KEY, 'uniqueValue'); - $request = new SettingStoreRequest(); + $request = new SettingStoreRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/SettingUpdateRequestTest.php b/tests/Api/v1/Requests/SettingUpdateRequestTest.php index f6003f08..29d51490 100644 --- a/tests/Api/v1/Requests/SettingUpdateRequestTest.php +++ b/tests/Api/v1/Requests/SettingUpdateRequestTest.php @@ -26,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new SettingUpdateRequest(); + $request = new SettingUpdateRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new SettingUpdateRequest(); + $request = new SettingUpdateRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -63,7 +63,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new SettingUpdateRequest(); + $request = new SettingUpdateRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/TwoFAccountBatchRequestTest.php b/tests/Api/v1/Requests/TwoFAccountBatchRequestTest.php index 7380ae67..a9b07d37 100644 --- a/tests/Api/v1/Requests/TwoFAccountBatchRequestTest.php +++ b/tests/Api/v1/Requests/TwoFAccountBatchRequestTest.php @@ -27,7 +27,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new TwoFAccountBatchRequest(); + $request = new TwoFAccountBatchRequest; $this->assertTrue($request->authorize()); } @@ -36,7 +36,7 @@ public function test_user_is_authorized() #[DataProviderExternal(TwoFAccountDataProvider::class, 'validIdsProvider')] public function test_valid_data(array $data) : void { - $request = new TwoFAccountBatchRequest(); + $request = new TwoFAccountBatchRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -46,7 +46,7 @@ public function test_valid_data(array $data) : void #[DataProviderExternal(TwoFAccountDataProvider::class, 'invalidIdsProvider')] public function test_invalid_data(array $data) : void { - $request = new TwoFAccountBatchRequest(); + $request = new TwoFAccountBatchRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/TwoFAccountDynamicRequestTest.php b/tests/Api/v1/Requests/TwoFAccountDynamicRequestTest.php index d88d5bb8..b5946642 100644 --- a/tests/Api/v1/Requests/TwoFAccountDynamicRequestTest.php +++ b/tests/Api/v1/Requests/TwoFAccountDynamicRequestTest.php @@ -26,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new TwoFAccountDynamicRequest(); + $request = new TwoFAccountDynamicRequest; $this->assertTrue($request->authorize()); } @@ -34,8 +34,8 @@ public function test_user_is_authorized() #[Test] public function test_returns_TwoFAccountUriRequest_rules_when_has_uri_input() { - $twofaccountUriRequest = new TwoFAccountUriRequest(); - $request = new TwoFAccountDynamicRequest(); + $twofaccountUriRequest = new TwoFAccountUriRequest; + $request = new TwoFAccountDynamicRequest; $request->merge(['uri' => 'uristring']); $this->assertEquals($twofaccountUriRequest->rules(), $request->rules()); @@ -44,8 +44,8 @@ public function test_returns_TwoFAccountUriRequest_rules_when_has_uri_input() #[Test] public function test_returns_TwoFAccountStoreRequest_rules_otherwise() { - $twofaccountStoreRequest = new TwoFAccountStoreRequest(); - $request = new TwoFAccountDynamicRequest(); + $twofaccountStoreRequest = new TwoFAccountStoreRequest; + $request = new TwoFAccountDynamicRequest; $this->assertEquals($twofaccountStoreRequest->rules(), $request->rules()); } diff --git a/tests/Api/v1/Requests/TwoFAccountImportRequestTest.php b/tests/Api/v1/Requests/TwoFAccountImportRequestTest.php index d3adaf1f..7684ed49 100644 --- a/tests/Api/v1/Requests/TwoFAccountImportRequestTest.php +++ b/tests/Api/v1/Requests/TwoFAccountImportRequestTest.php @@ -26,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new TwoFAccountImportRequest(); + $request = new TwoFAccountImportRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new TwoFAccountImportRequest(); + $request = new TwoFAccountImportRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -57,7 +57,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new TwoFAccountImportRequest(); + $request = new TwoFAccountImportRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/TwoFAccountIndexRequestTest.php b/tests/Api/v1/Requests/TwoFAccountIndexRequestTest.php index 32be50c4..908aba54 100644 --- a/tests/Api/v1/Requests/TwoFAccountIndexRequestTest.php +++ b/tests/Api/v1/Requests/TwoFAccountIndexRequestTest.php @@ -27,16 +27,16 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new TwoFAccountIndexRequest(); + $request = new TwoFAccountIndexRequest; $this->assertTrue($request->authorize()); } - + #[Test] #[DataProviderExternal(TwoFAccountDataProvider::class, 'validIdsProvider')] public function test_valid_data(array $data) : void { - $request = new TwoFAccountIndexRequest(); + $request = new TwoFAccountIndexRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -46,7 +46,7 @@ public function test_valid_data(array $data) : void #[DataProviderExternal(TwoFAccountDataProvider::class, 'invalidIdsProvider')] public function test_invalid_data(array $data) : void { - $request = new TwoFAccountIndexRequest(); + $request = new TwoFAccountIndexRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/TwoFAccountReorderRequestTest.php b/tests/Api/v1/Requests/TwoFAccountReorderRequestTest.php index 71220191..ea5c7946 100644 --- a/tests/Api/v1/Requests/TwoFAccountReorderRequestTest.php +++ b/tests/Api/v1/Requests/TwoFAccountReorderRequestTest.php @@ -26,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new TwoFAccountReorderRequest(); + $request = new TwoFAccountReorderRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new TwoFAccountReorderRequest(); + $request = new TwoFAccountReorderRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -60,7 +60,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new TwoFAccountReorderRequest(); + $request = new TwoFAccountReorderRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/TwoFAccountStoreRequestTest.php b/tests/Api/v1/Requests/TwoFAccountStoreRequestTest.php index 0f986c14..1a0360d4 100644 --- a/tests/Api/v1/Requests/TwoFAccountStoreRequestTest.php +++ b/tests/Api/v1/Requests/TwoFAccountStoreRequestTest.php @@ -28,7 +28,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new TwoFAccountStoreRequest(); + $request = new TwoFAccountStoreRequest; $this->assertTrue($request->authorize()); } @@ -37,7 +37,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new TwoFAccountStoreRequest(); + $request = new TwoFAccountStoreRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -111,7 +111,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new TwoFAccountStoreRequest(); + $request = new TwoFAccountStoreRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/TwoFAccountUpdateRequestTest.php b/tests/Api/v1/Requests/TwoFAccountUpdateRequestTest.php index 0ef2224a..4d7e6f47 100644 --- a/tests/Api/v1/Requests/TwoFAccountUpdateRequestTest.php +++ b/tests/Api/v1/Requests/TwoFAccountUpdateRequestTest.php @@ -28,7 +28,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new TwoFAccountUpdateRequest(); + $request = new TwoFAccountUpdateRequest; $this->assertTrue($request->authorize()); } @@ -37,7 +37,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new TwoFAccountUpdateRequest(); + $request = new TwoFAccountUpdateRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -87,7 +87,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new TwoFAccountUpdateRequest(); + $request = new TwoFAccountUpdateRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/TwoFAccountUriRequestTest.php b/tests/Api/v1/Requests/TwoFAccountUriRequestTest.php index 57aba71b..c592ae12 100644 --- a/tests/Api/v1/Requests/TwoFAccountUriRequestTest.php +++ b/tests/Api/v1/Requests/TwoFAccountUriRequestTest.php @@ -26,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new TwoFAccountUriRequest(); + $request = new TwoFAccountUriRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new TwoFAccountUriRequest(); + $request = new TwoFAccountUriRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -64,7 +64,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new TwoFAccountUriRequest(); + $request = new TwoFAccountUriRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/UserManagerPromoteRequestTest.php b/tests/Api/v1/Requests/UserManagerPromoteRequestTest.php index 53b85cf5..db3b45eb 100644 --- a/tests/Api/v1/Requests/UserManagerPromoteRequestTest.php +++ b/tests/Api/v1/Requests/UserManagerPromoteRequestTest.php @@ -26,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new UserManagerPromoteRequest(); + $request = new UserManagerPromoteRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new UserManagerPromoteRequest(); + $request = new UserManagerPromoteRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -66,7 +66,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new UserManagerPromoteRequest(); + $request = new UserManagerPromoteRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Api/v1/Requests/UserManagerStoreRequestTest.php b/tests/Api/v1/Requests/UserManagerStoreRequestTest.php index 41ed44a3..4520bd91 100644 --- a/tests/Api/v1/Requests/UserManagerStoreRequestTest.php +++ b/tests/Api/v1/Requests/UserManagerStoreRequestTest.php @@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Validator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\Attributes\Test; use Tests\FeatureTestCase; @@ -28,7 +27,7 @@ public function test_admin_is_authorized() ->once() ->andReturn(true); - $request = new UserManagerStoreRequest(); + $request = new UserManagerStoreRequest; $this->assertTrue($request->authorize()); } @@ -41,8 +40,8 @@ public function test_valid_data(array $data) : void 'name' => 'Jane', 'email' => 'jane@example.com', ]); - - $request = new UserManagerStoreRequest(); + + $request = new UserManagerStoreRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -80,7 +79,7 @@ public function test_invalid_data(array $data) : void 'email' => 'john@example.com', ]); - $request = new UserManagerStoreRequest(); + $request = new UserManagerStoreRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Feature/Console/FixServiceFieldEncryptionTest.php b/tests/Feature/Console/FixServiceFieldEncryptionTest.php index e578f192..5fb66e86 100644 --- a/tests/Feature/Console/FixServiceFieldEncryptionTest.php +++ b/tests/Feature/Console/FixServiceFieldEncryptionTest.php @@ -21,7 +21,7 @@ class FixServiceFieldEncryptionTest extends FeatureTestCase * 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'; - + /** * @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); $expectedServiceName = 'myService'; - $twofaccounts = TwoFAccount::factory()->for($this->user)->count(3)->create([ - 'service' => $expectedServiceName + $twofaccounts = TwoFAccount::factory()->for($this->user)->count(3)->create([ + 'service' => $expectedServiceName, ]); - + $testedAccount = $twofaccounts[2]; 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(); $testedAccount->refresh(); - + $this->assertEquals($expectedServiceName, $twofaccounts[0]->service); $this->assertEquals($expectedServiceName, $twofaccounts[1]->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); $expectedServiceName = 'myService'; - $twofaccounts = TwoFAccount::factory()->for($this->user)->count(3)->create([ - 'service' => $expectedServiceName + $twofaccounts = TwoFAccount::factory()->for($this->user)->count(3)->create([ + 'service' => $expectedServiceName, ]); - + $testedAccount = $twofaccounts[2]; 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.'); $testedAccount->refresh(); - + $this->assertEquals($expectedServiceName, $twofaccounts[0]->service); $this->assertEquals($expectedServiceName, $twofaccounts[1]->service); $this->assertEquals(__('errors.indecipherable'), $testedAccount->service); diff --git a/tests/Feature/Console/InstallTest.php b/tests/Feature/Console/InstallTest.php index 7cfc7886..35da7b40 100644 --- a/tests/Feature/Console/InstallTest.php +++ b/tests/Feature/Console/InstallTest.php @@ -3,7 +3,6 @@ namespace Tests\Feature\Console; use App\Console\Commands\Install; -use Illuminate\Support\Facades\Artisan; use Jackiedo\DotenvEditor\DotenvEditor; use PHPUnit\Framework\Attributes\CoversClass; 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 TWOFAUTH_REVIEW_ENV_VAR_CONFIRMATION = 'Existing .env file found. Do you wish to review its vars?'; - + #[Test] 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->shouldReceive('load') - ->andThrow(new \Exception()); + ->andThrow(new \Exception); $this->artisan('2fauth:install') ->expectsOutputToContain(config('2fauth.installDocUrl')) diff --git a/tests/Feature/Console/ResetDemoTest.php b/tests/Feature/Console/ResetDemoTest.php index 96434ac6..292a453a 100644 --- a/tests/Feature/Console/ResetDemoTest.php +++ b/tests/Feature/Console/ResetDemoTest.php @@ -21,10 +21,10 @@ public function test_reset_demo_without_demo_mode_succeeded() public function test_reset_demo_succeeded() { Artisan::call('passport:install', [ - '--verbose' => 2, - '--no-interaction' => 1 + '--verbose' => 2, + '--no-interaction' => 1, ]); - + Config::set('2fauth.config.isDemoApp', true); $this->artisan('2fauth:reset-demo') diff --git a/tests/Feature/Http/Auth/LoginTest.php b/tests/Feature/Http/Auth/LoginTest.php index 554b6593..33a42019 100644 --- a/tests/Feature/Http/Auth/LoginTest.php +++ b/tests/Feature/Http/Auth/LoginTest.php @@ -64,7 +64,7 @@ class LoginTest extends FeatureTestCase private const PASSWORD = 'password'; private const WRONG_PASSWORD = 'wrong_password'; - + private const USER_NAME = 'John'; private const USER_EMAIL = 'john@example.com'; @@ -383,11 +383,11 @@ public function test_successful_web_logout_is_logged() 'email' => $this->user->email, 'password' => self::PASSWORD, ])->assertOk(); - + $this->actingAs($this->user, self::WEB_GUARD) ->json('GET', '/user/logout') ->assertOk(); - + $authlog = $this->user->latestAuthentication()->first(); $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->json('GET', '/api/v1/groups', [], [ - 'HTTP_REMOTE_USER' => self::USER_NAME, + 'HTTP_REMOTE_USER' => self::USER_NAME, ]); $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->json('GET', '/api/v1/groups', [], [ - 'HTTP_REMOTE_USER' => self::USER_NAME, + 'HTTP_REMOTE_USER' => self::USER_NAME, ]); $this->json('GET', '/api/v1/groups', [], [ - 'HTTP_REMOTE_USER' => self::USER_NAME, + 'HTTP_REMOTE_USER' => self::USER_NAME, ]); $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->json('GET', '/api/v1/groups', [], [ - 'HTTP_REMOTE_USER' => self::USER_NAME, + 'HTTP_REMOTE_USER' => self::USER_NAME, ]); $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() { Notification::fake(); - + Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER'); $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->json('GET', '/api/v1/groups', [], [ - 'HTTP_REMOTE_USER' => self::USER_NAME, + 'HTTP_REMOTE_USER' => self::USER_NAME, ]); 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() { Notification::fake(); - + Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER'); $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->json('GET', '/api/v1/groups', [], [ - 'HTTP_REMOTE_USER' => self::USER_NAME, + 'HTTP_REMOTE_USER' => self::USER_NAME, ]); 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() { Notification::fake(); - + Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER'); $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->json('GET', '/api/v1/groups', [], [ - 'HTTP_REMOTE_USER' => self::USER_NAME, + 'HTTP_REMOTE_USER' => self::USER_NAME, ]); Notification::assertNothingSentTo($user); diff --git a/tests/Feature/Http/Auth/PasswordControllerTest.php b/tests/Feature/Http/Auth/PasswordControllerTest.php index 61a905e9..5676f656 100644 --- a/tests/Feature/Http/Auth/PasswordControllerTest.php +++ b/tests/Feature/Http/Auth/PasswordControllerTest.php @@ -23,7 +23,7 @@ class PasswordControllerTest extends FeatureTestCase private const PASSWORD = 'password'; private const NEW_PASSWORD = 'newPassword'; - + private const USER_NAME = 'John'; 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); - + $response = $this->json('PATCH', '/user/password', [ - 'currentPassword' => self::NEW_PASSWORD, - 'password' => self::NEW_PASSWORD, - 'password_confirmation' => self::NEW_PASSWORD, - ], [ - 'HTTP_REMOTE_USER' => self::USER_NAME, - ]) + 'currentPassword' => self::NEW_PASSWORD, + 'password' => self::NEW_PASSWORD, + 'password_confirmation' => self::NEW_PASSWORD, + ], [ + 'HTTP_REMOTE_USER' => self::USER_NAME, + ]) ->assertStatus(405) ->assertJsonStructure([ 'message', diff --git a/tests/Feature/Http/Auth/SocialiteControllerTest.php b/tests/Feature/Http/Auth/SocialiteControllerTest.php index af0a2a83..38f278db 100644 --- a/tests/Feature/Http/Auth/SocialiteControllerTest.php +++ b/tests/Feature/Http/Auth/SocialiteControllerTest.php @@ -116,13 +116,13 @@ public static function ssoConfigVarProvider() { return [ 'TOKEN_URL' => [ - 'token_url' + 'token_url', ], 'AUTHORIZE_URL' => [ - 'authorize_url' + 'authorize_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'; Socialite::shouldReceive('driver->user') - ->andThrow(new Exception()); + ->andThrow(new Exception); $response = $this->get('/socialite/callback/github', ['driver' => 'github']); diff --git a/tests/Feature/Http/Auth/WebAuthnDeviceLostControllerTest.php b/tests/Feature/Http/Auth/WebAuthnDeviceLostControllerTest.php index d0eb7fdf..49b128ab 100644 --- a/tests/Feature/Http/Auth/WebAuthnDeviceLostControllerTest.php +++ b/tests/Feature/Http/Auth/WebAuthnDeviceLostControllerTest.php @@ -107,7 +107,7 @@ public function test_sendRecoveryEmail_does_not_send_anything_to_not_WebAuthnAut { $mock = $this->mock(\App\Extensions\WebauthnCredentialBroker::class)->makePartial(); $mock->shouldReceive('getUser') - ->andReturn(new \Illuminate\Foundation\Auth\User()); + ->andReturn(new \Illuminate\Foundation\Auth\User); Notification::fake(); diff --git a/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php b/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php index d10d1c01..b3647a4d 100644 --- a/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php +++ b/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php @@ -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() { Settings::set('useSsoOnly', true); - + $this->user->promoteToAdministrator(true); $this->user->save(); @@ -151,7 +151,7 @@ public function test_webauthn_login_of_admin_returns_success_even_with_sso_only_ ->assertJsonStructure([ 'preferences', ]); - + $this->user->promoteToAdministrator(false); $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() { Notification::fake(); - + $this->user['preferences->notifyOnNewAuthDevice'] = 1; $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() { Notification::fake(); - + $this->user['preferences->notifyOnNewAuthDevice'] = 1; $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() { Notification::fake(); - - $this->user['preferences->notifyOnNewAuthDevice'] =01; + + $this->user['preferences->notifyOnNewAuthDevice'] = 0; $this->user->save(); $this->createWebauthnCredential(self::CREDENTIAL_ID_ALT, $this->user->id, self::USER_ID_ALT); diff --git a/tests/Feature/Http/Auth/WebAuthnRegisterControllerTest.php b/tests/Feature/Http/Auth/WebAuthnRegisterControllerTest.php index f297689e..01a24e96 100644 --- a/tests/Feature/Http/Auth/WebAuthnRegisterControllerTest.php +++ b/tests/Feature/Http/Auth/WebAuthnRegisterControllerTest.php @@ -39,7 +39,7 @@ public function test_uses_attestation_with_fastRegistration_request() : void $request = $this->mock(AttestationRequest::class); $request->expects('fastRegistration')->andReturnSelf(); - $request->expects('toCreate')->andReturn(new JsonTransport()); + $request->expects('toCreate')->andReturn(new JsonTransport); $this->actingAs($this->user, 'web-guard') ->json('POST', '/webauthn/register/options') @@ -54,7 +54,7 @@ public function test_uses_attestation_with_secureRegistration_request() : void $request = $this->mock(AttestationRequest::class); $request->expects('secureRegistration')->andReturnSelf(); - $request->expects('toCreate')->andReturn(new JsonTransport()); + $request->expects('toCreate')->andReturn(new JsonTransport); $this->actingAs($this->user, 'web-guard') ->json('POST', '/webauthn/register/options') diff --git a/tests/Feature/Http/Middlewares/AdminOnlyMiddlewareTest.php b/tests/Feature/Http/Middlewares/AdminOnlyMiddlewareTest.php index 16282351..85c9d9ca 100644 --- a/tests/Feature/Http/Middlewares/AdminOnlyMiddlewareTest.php +++ b/tests/Feature/Http/Middlewares/AdminOnlyMiddlewareTest.php @@ -28,8 +28,7 @@ public function test_users_are_rejected() $request = Request::create('/admin', 'GET'); $middleware = new AdminOnly; - $response = $middleware->handle($request, function () { - }); + $response = $middleware->handle($request, function () {}); } #[Test] @@ -45,8 +44,7 @@ public function test_admins_pass() $request = Request::create('/admin', 'GET'); $middleware = new AdminOnly; - $response = $middleware->handle($request, function () { - }); + $response = $middleware->handle($request, function () {}); $this->assertNull($response); } diff --git a/tests/Feature/Http/Middlewares/AuthenticateMiddlewareTest.php b/tests/Feature/Http/Middlewares/AuthenticateMiddlewareTest.php index 2075af98..5e659940 100644 --- a/tests/Feature/Http/Middlewares/AuthenticateMiddlewareTest.php +++ b/tests/Feature/Http/Middlewares/AuthenticateMiddlewareTest.php @@ -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.email', 'HTTP_REMOTE_EMAIL'); - + $this->app['auth']->shouldUse('reverse-proxy-guard'); $lang = 'fr'; @@ -71,7 +71,7 @@ public function test_it_overrides_locale_when_auth_is_successful() $user->save(); $this->json('GET', '/api/v1/groups', [], [ - 'HTTP_REMOTE_USER' => self::USER_NAME, + 'HTTP_REMOTE_USER' => self::USER_NAME, ]); $this->assertEquals($lang, App::getLocale()); diff --git a/tests/Feature/Http/Middlewares/RejectIfSsoOnlyAndNotForAdminMiddlewareTest.php b/tests/Feature/Http/Middlewares/RejectIfSsoOnlyAndNotForAdminMiddlewareTest.php index 5f5e5265..310008f0 100644 --- a/tests/Feature/Http/Middlewares/RejectIfSsoOnlyAndNotForAdminMiddlewareTest.php +++ b/tests/Feature/Http/Middlewares/RejectIfSsoOnlyAndNotForAdminMiddlewareTest.php @@ -36,7 +36,7 @@ public function setUp() : void $this->user = User::factory()->create(); $this->admin = User::factory()->administrator()->create([ - 'password' => self::PASSWORD + 'password' => self::PASSWORD, ]); Settings::set('useSsoOnly', true); diff --git a/tests/Feature/Http/Middlewares/SetLanguageMiddlewareTest.php b/tests/Feature/Http/Middlewares/SetLanguageMiddlewareTest.php index e2cc337d..2fdd58b3 100644 --- a/tests/Feature/Http/Middlewares/SetLanguageMiddlewareTest.php +++ b/tests/Feature/Http/Middlewares/SetLanguageMiddlewareTest.php @@ -67,7 +67,7 @@ public function test_it_applies_fallback_locale_if_header_ask_for_several_unsupp $this->assertEquals(self::IS_FR, App::getLocale()); } - + #[Test] 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] public function test_user_preference_overrides_header() { - $this->user = new User; + $this->user = new User; $this->user['preferences->lang'] = self::IS_FR; - + $this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => self::IS_DE]); $this->assertEquals(self::IS_FR, App::getLocale()); @@ -132,9 +132,9 @@ public function test_user_preference_overrides_header() #[Test] public function test_user_preference_applies_header() { - $this->user = new User; + $this->user = new User; $this->user['preferences->lang'] = 'browser'; - + $this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => self::IS_DE]); $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); - $this->user = new User; + $this->user = new User; $this->user['preferences->lang'] = self::IS_FR; - + $this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => null]); $this->assertEquals(self::IS_FR, App::getLocale()); diff --git a/tests/Feature/Http/Requests/LoginRequestTest.php b/tests/Feature/Http/Requests/LoginRequestTest.php index 69eb567e..f51ad5ee 100644 --- a/tests/Feature/Http/Requests/LoginRequestTest.php +++ b/tests/Feature/Http/Requests/LoginRequestTest.php @@ -22,7 +22,7 @@ class LoginRequestTest extends FeatureTestCase #[Test] public function test_user_is_authorized() { - $request = new LoginRequest(); + $request = new LoginRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_valid_data(array $data) : void 'email' => 'JOHN.DOE@example.com', ]); - $request = new LoginRequest(); + $request = new LoginRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -66,7 +66,7 @@ public function test_invalid_data(array $data) : void 'email' => 'JOHN.DOE@example.com', ]); - $request = new LoginRequest(); + $request = new LoginRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Feature/Http/Requests/UserDeleteRequestTest.php b/tests/Feature/Http/Requests/UserDeleteRequestTest.php index f5dba089..d14f07c0 100644 --- a/tests/Feature/Http/Requests/UserDeleteRequestTest.php +++ b/tests/Feature/Http/Requests/UserDeleteRequestTest.php @@ -26,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new UserDeleteRequest(); + $request = new UserDeleteRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new UserDeleteRequest(); + $request = new UserDeleteRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -57,7 +57,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new UserDeleteRequest(); + $request = new UserDeleteRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Feature/Http/Requests/UserPatchPwdRequestTest.php b/tests/Feature/Http/Requests/UserPatchPwdRequestTest.php index d60ae1cc..3742a013 100644 --- a/tests/Feature/Http/Requests/UserPatchPwdRequestTest.php +++ b/tests/Feature/Http/Requests/UserPatchPwdRequestTest.php @@ -26,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new UserPatchPwdRequest(); + $request = new UserPatchPwdRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new UserPatchPwdRequest(); + $request = new UserPatchPwdRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -59,7 +59,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new UserPatchPwdRequest(); + $request = new UserPatchPwdRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Feature/Http/Requests/UserStoreRequestTest.php b/tests/Feature/Http/Requests/UserStoreRequestTest.php index 42c4caa4..399d6d3a 100644 --- a/tests/Feature/Http/Requests/UserStoreRequestTest.php +++ b/tests/Feature/Http/Requests/UserStoreRequestTest.php @@ -22,7 +22,7 @@ class UserStoreRequestTest extends FeatureTestCase #[Test] public function test_user_is_authorized() { - $request = new UserStoreRequest(); + $request = new UserStoreRequest; $this->assertTrue($request->authorize()); } @@ -36,7 +36,7 @@ public function test_valid_data(array $data) : void 'email' => 'jane@example.com', ]); - $request = new UserStoreRequest(); + $request = new UserStoreRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -72,7 +72,7 @@ public function test_invalid_data(array $data) : void 'email' => 'john@example.com', ]); - $request = new UserStoreRequest(); + $request = new UserStoreRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Feature/Http/Requests/UserUpdateRequestTest.php b/tests/Feature/Http/Requests/UserUpdateRequestTest.php index 729b63a1..e98add76 100644 --- a/tests/Feature/Http/Requests/UserUpdateRequestTest.php +++ b/tests/Feature/Http/Requests/UserUpdateRequestTest.php @@ -28,7 +28,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new UserUpdateRequest(); + $request = new UserUpdateRequest; $this->assertTrue($request->authorize()); } diff --git a/tests/Feature/Http/Requests/WebauthnAssertedRequestTest.php b/tests/Feature/Http/Requests/WebauthnAssertedRequestTest.php index 2135cf82..e000c6ae 100644 --- a/tests/Feature/Http/Requests/WebauthnAssertedRequestTest.php +++ b/tests/Feature/Http/Requests/WebauthnAssertedRequestTest.php @@ -22,7 +22,7 @@ class WebauthnAssertedRequestTest extends TestCase #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new WebauthnAssertedRequest(); + $request = new WebauthnAssertedRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -53,7 +53,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new WebauthnAssertedRequest(); + $request = new WebauthnAssertedRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Feature/Http/Requests/WebauthnRenameRequestTest.php b/tests/Feature/Http/Requests/WebauthnRenameRequestTest.php index fd594504..726fae05 100644 --- a/tests/Feature/Http/Requests/WebauthnRenameRequestTest.php +++ b/tests/Feature/Http/Requests/WebauthnRenameRequestTest.php @@ -26,7 +26,7 @@ public function test_user_is_authorized() ->once() ->andReturn(true); - $request = new WebauthnRenameRequest(); + $request = new WebauthnRenameRequest; $this->assertTrue($request->authorize()); } @@ -35,7 +35,7 @@ public function test_user_is_authorized() #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { - $request = new WebauthnRenameRequest(); + $request = new WebauthnRenameRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); @@ -57,7 +57,7 @@ public static function provideValidData() : array #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { - $request = new WebauthnRenameRequest(); + $request = new WebauthnRenameRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); diff --git a/tests/Feature/Http/SystemControllerTest.php b/tests/Feature/Http/SystemControllerTest.php index cecfdbb2..2a9369cc 100644 --- a/tests/Feature/Http/SystemControllerTest.php +++ b/tests/Feature/Http/SystemControllerTest.php @@ -143,7 +143,7 @@ public function test_testEmail_returns_success_even_if_sending_fails() { 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') ->json('POST', '/system/test-email', []); diff --git a/tests/Feature/Models/AuthLogModelTest.php b/tests/Feature/Models/AuthLogModelTest.php index 485933bd..23ec3a0c 100644 --- a/tests/Feature/Models/AuthLogModelTest.php +++ b/tests/Feature/Models/AuthLogModelTest.php @@ -17,7 +17,7 @@ class AuthLogModelTest extends FeatureTestCase #[Test] public function test_equals_returns_true() { - $user = User::factory()->create(); + $user = User::factory()->create(); $lastAuthLog = AuthLog::factory()->for($user, 'authenticatable')->create(); $this->assertTrue($lastAuthLog->equals($lastAuthLog)); diff --git a/tests/Feature/Models/UserModelTest.php b/tests/Feature/Models/UserModelTest.php index 2964ca52..1449af06 100644 --- a/tests/Feature/Models/UserModelTest.php +++ b/tests/Feature/Models/UserModelTest.php @@ -108,10 +108,10 @@ public function test_resetPassword_dispatch_event() public function test_delete_removes_user_data() { Artisan::call('passport:install', [ - '--verbose' => 2, - '--no-interaction' => 1 + '--verbose' => 2, + '--no-interaction' => 1, ]); - + $user = User::factory()->create(); TwoFAccount::factory()->for($user)->create(); AuthLog::factory()->for($user, 'authenticatable')->create(); @@ -234,10 +234,10 @@ public function test_authentications_returns_user_auth_logs_sorted_by_latest_id( #[Test] public function test_authentications_returns_user_auth_logs_only() { - $user = User::factory()->create(); + $user = 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(); $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(); $threeMonthsAgoAuthLog = AuthLog::factory()->duringLastThreeMonth()->for($user, 'authenticatable')->create(); $duringLastMonthAuthLog = AuthLog::factory()->duringLastMonth()->for($user, 'authenticatable')->create(); - + $authentications = $user->authenticationsByPeriod(3); $this->assertCount(2, $authentications); @@ -293,7 +293,7 @@ public function test_latestAuthentication_returns_user_latest_auth_logs() #[Test] public function test_latestAuthentication_returns_user_latest_auth_logs_only() { - $user = User::factory()->create(); + $user = User::factory()->create(); $anotherUser = User::factory()->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() { $user = User::factory()->create(); - $now = now(); + $now = now(); $tenDaysAgoAuthLog = AuthLog::factory()->daysAgo(10)->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() { $user = User::factory()->create(); - $now = now(); + $now = now(); AuthLog::factory()->at($now)->for($user, 'authenticatable')->create(); $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() { $user = User::factory()->create(); - $now = now(); + $now = now(); AuthLog::factory()->at($now)->failedLogin()->for($user, 'authenticatable')->create(); $lastSuccessfulLoginAt = $user->lastSuccessfulLoginAt(); @@ -401,12 +401,12 @@ public function test_lastSuccessfulLoginIp_returns_null_if_user_has_no_successfu #[Test] public function test_previousLoginAt_returns_user_last_auth_date() { - $user = User::factory()->create(); - $now = now(); + $user = User::factory()->create(); + $now = now(); $yesterday = now()->subDay(); - $yesterdayAuthLog = AuthLog::factory()->at($yesterday)->for($user, 'authenticatable')->create(); - $lastAuthLog = AuthLog::factory()->at($now)->for($user, 'authenticatable')->create(); + $yesterdayAuthLog = AuthLog::factory()->at($yesterday)->for($user, 'authenticatable')->create(); + $lastAuthLog = AuthLog::factory()->at($now)->for($user, 'authenticatable')->create(); $previousLoginAt = $user->previousLoginAt(); @@ -426,7 +426,7 @@ public function test_previousLoginAt_returns_null_if_user_has_no_auth_log() #[Test] public function test_previousLoginIp_returns_user_last_auth_ip() { - $user = User::factory()->create(); + $user = User::factory()->create(); $yesterday = now()->subDay(); 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); } - - } diff --git a/tests/Feature/Notifications/FailedLoginNotificationTest.php b/tests/Feature/Notifications/FailedLoginNotificationTest.php index 15ad4093..541e5a8b 100644 --- a/tests/Feature/Notifications/FailedLoginNotificationTest.php +++ b/tests/Feature/Notifications/FailedLoginNotificationTest.php @@ -31,7 +31,6 @@ class FailedLoginNotificationTest extends FeatureTestCase */ protected $failedLogin; - public function setUp() : void { parent::setUp(); @@ -39,15 +38,15 @@ public function setUp() : void $this->user = User::factory()->create(); AuthLog::factory()->for($this->user, 'authenticatable')->failedLogin()->create(); - - $this->authLog = AuthLog::first(); + + $this->authLog = AuthLog::first(); $this->failedLogin = new FailedLoginNotification($this->authLog); } #[Test] public function test_it_renders_to_email() { - + $mail = $this->failedLogin->toMail($this->user); $this->assertInstanceOf(MailMessage::class, $mail); @@ -78,5 +77,4 @@ public function test_rendered_email_contains_expected_data() $mail ); } - } diff --git a/tests/Feature/Notifications/SignedInWithNewDeviceNotificationTest.php b/tests/Feature/Notifications/SignedInWithNewDeviceNotificationTest.php index 26ce50d4..e9958473 100644 --- a/tests/Feature/Notifications/SignedInWithNewDeviceNotificationTest.php +++ b/tests/Feature/Notifications/SignedInWithNewDeviceNotificationTest.php @@ -31,7 +31,6 @@ class SignedInWithNewDeviceNotificationTest extends FeatureTestCase */ protected $signedInWithNewDevice; - public function setUp() : void { parent::setUp(); @@ -39,14 +38,14 @@ public function setUp() : void $this->user = User::factory()->create(); AuthLog::factory()->for($this->user, 'authenticatable')->failedLogin()->create(); - - $this->authLog = AuthLog::first(); + + $this->authLog = AuthLog::first(); $this->signedInWithNewDevice = new SignedInWithNewDeviceNotification($this->authLog); } #[Test] public function test_it_renders_to_email() - { + { $mail = $this->signedInWithNewDevice->toMail($this->user); $this->assertInstanceOf(MailMessage::class, $mail); @@ -77,5 +76,4 @@ public function test_rendered_email_contains_expected_data() $mail ); } - } diff --git a/tests/Feature/Notifications/TestEmailSettingNotificationTest.php b/tests/Feature/Notifications/TestEmailSettingNotificationTest.php index 0ba67911..46bd3692 100644 --- a/tests/Feature/Notifications/TestEmailSettingNotificationTest.php +++ b/tests/Feature/Notifications/TestEmailSettingNotificationTest.php @@ -25,12 +25,11 @@ class TestEmailSettingNotificationTest extends FeatureTestCase */ protected $testEmailSettingNotification; - public function setUp() : void { parent::setUp(); - $this->user = User::factory()->create(); + $this->user = User::factory()->create(); $this->testEmailSettingNotification = new TestEmailSettingNotification('test_token'); } diff --git a/tests/Feature/Notifications/WebauthnRecoveryNotificationTest.php b/tests/Feature/Notifications/WebauthnRecoveryNotificationTest.php index 300a6753..ce56e6c0 100644 --- a/tests/Feature/Notifications/WebauthnRecoveryNotificationTest.php +++ b/tests/Feature/Notifications/WebauthnRecoveryNotificationTest.php @@ -30,13 +30,13 @@ public function setUp() : void { parent::setUp(); - $this->user = User::factory()->create(); + $this->user = User::factory()->create(); $this->webauthnRecoveryNotification = new WebauthnRecoveryNotification('test_token'); } #[Test] public function test_it_renders_to_email() - { + { $mail = $this->webauthnRecoveryNotification->toMail($this->user); $this->assertInstanceOf(MailMessage::class, $mail); @@ -77,5 +77,4 @@ public function test_rendered_email_contains_expected_data() $mail ); } - } diff --git a/tests/Feature/RouteTest.php b/tests/Feature/RouteTest.php index f6ff353e..72cf05b8 100644 --- a/tests/Feature/RouteTest.php +++ b/tests/Feature/RouteTest.php @@ -4,8 +4,8 @@ use App\Providers\RouteServiceProvider; use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Str; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Str; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -15,6 +15,7 @@ class RouteTest extends FeatureTestCase { const API_ROUTE_PREFIX = 'api/v1'; + const API_MIDDLEWARE = 'api.v1'; #[Test] @@ -61,9 +62,7 @@ public function test_router_has_expected_global_where_patterns($pattern) public static function wherePatternProvider() { return [ - 'SETTING_NAME' => ['settingName'] + 'SETTING_NAME' => ['settingName'], ]; } - - } diff --git a/tests/Feature/Services/GroupServiceTest.php b/tests/Feature/Services/GroupServiceTest.php index 6105c803..a403f0a8 100644 --- a/tests/Feature/Services/GroupServiceTest.php +++ b/tests/Feature/Services/GroupServiceTest.php @@ -165,8 +165,8 @@ public function test_user_can_assign_multiple_accounts() #[Test] public function test_setUser_sets_groups_user() { - $this->groupOne = Group::factory()->create(); - $this->groupTwo = Group::factory()->create(); + $this->groupOne = Group::factory()->create(); + $this->groupTwo = Group::factory()->create(); $this->assertEquals(null, $this->groupOne->user_id); $this->assertEquals(null, $this->groupTwo->user_id); diff --git a/tests/Feature/Services/LogoServiceTest.php b/tests/Feature/Services/LogoServiceTest.php index 92d05972..61275dfb 100644 --- a/tests/Feature/Services/LogoServiceTest.php +++ b/tests/Feature/Services/LogoServiceTest.php @@ -39,7 +39,7 @@ public function test_getIcon_returns_stored_icon_file_when_logo_exists() Storage::fake('icons'); Storage::fake('logos'); - $logoService = new LogoService(); + $logoService = new LogoService; $icon = $logoService->getIcon('twitter'); $this->assertNotNull($icon); @@ -56,7 +56,7 @@ public function test_getIcon_returns_null_when_github_request_fails() Storage::fake('icons'); Storage::fake('logos'); - $logoService = new LogoService(); + $logoService = new LogoService; $icon = $logoService->getIcon('twitter'); @@ -75,7 +75,7 @@ public function test_getIcon_returns_null_when_logo_fetching_fails() Storage::fake('icons'); Storage::fake('logos'); - $logoService = new LogoService(); + $logoService = new LogoService; $icon = $logoService->getIcon('twitter'); @@ -85,7 +85,7 @@ public function test_getIcon_returns_null_when_logo_fetching_fails() #[Test] 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'); @@ -105,7 +105,7 @@ public function test_logoService_loads_empty_collection_when_tfajson_fetching_fa Storage::fake('icons'); Storage::fake('logos'); - $logoService = new LogoService(); + $logoService = new LogoService; $icon = $logoService->getIcon('twitter'); $this->assertNull($icon); diff --git a/tests/Feature/Services/QrCodeServiceTest.php b/tests/Feature/Services/QrCodeServiceTest.php index 36b38adf..f987d74d 100644 --- a/tests/Feature/Services/QrCodeServiceTest.php +++ b/tests/Feature/Services/QrCodeServiceTest.php @@ -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 // to then bind it to the container $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('getError')->andReturn($exception); - - $this->app->bind(QrReader::class, function() use($qrReader) { + + $this->app->bind(QrReader::class, function () use ($qrReader) { return $qrReader; }); QrCode::decode(LocalFile::fake()->validQrcode()); } - /** - * - */ public static function QrReaderExceptionProvider() { return [ - 'NotFoundException' => [new NotFoundException()], - 'FormatException' => [new FormatException()], - 'ChecksumException' => [new ChecksumException()], - 'default' => [new Exception()], + 'NotFoundException' => [new NotFoundException], + 'FormatException' => [new FormatException], + 'ChecksumException' => [new ChecksumException], + 'default' => [new Exception], ]; } } diff --git a/tests/Feature/Services/SettingServiceTest.php b/tests/Feature/Services/SettingServiceTest.php index 5caf7537..98f207dc 100644 --- a/tests/Feature/Services/SettingServiceTest.php +++ b/tests/Feature/Services/SettingServiceTest.php @@ -337,7 +337,7 @@ public function test_cache_is_requested_at_instanciation() Cache::shouldReceive('remember') ->andReturn(collect([])); - $settingService = new SettingService(); + $settingService = new SettingService; Cache::shouldHaveReceived('remember'); } @@ -348,7 +348,7 @@ public function test_cache_is_updated_when_setting_is_set() Cache::shouldReceive('remember', 'put') ->andReturn(collect([]), true); - $settingService = new SettingService(); + $settingService = new SettingService; $settingService->set(self::SETTING_NAME, self::SETTING_VALUE_STRING); Cache::shouldHaveReceived('put'); @@ -360,7 +360,7 @@ public function test_cache_is_updated_when_setting_is_deleted() Cache::shouldReceive('remember', 'put') ->andReturn(collect([]), true); - $settingService = new SettingService(); + $settingService = new SettingService; $settingService->delete(self::SETTING_NAME); Cache::shouldHaveReceived('put'); diff --git a/tests/Feature/Services/TwoFAccountServiceTest.php b/tests/Feature/Services/TwoFAccountServiceTest.php index 40aa329f..61a89c80 100644 --- a/tests/Feature/Services/TwoFAccountServiceTest.php +++ b/tests/Feature/Services/TwoFAccountServiceTest.php @@ -325,8 +325,8 @@ public function test_delete_single_id() #[Test] public function test_setUser_sets_twofaccounts_user() { - $twofaccountA = TwoFAccount::factory()->create(); - $twofaccountB = TwoFAccount::factory()->create(); + $twofaccountA = TwoFAccount::factory()->create(); + $twofaccountB = TwoFAccount::factory()->create(); $this->assertEquals(null, $twofaccountA->user_id); $this->assertEquals(null, $twofaccountB->user_id); diff --git a/tests/Feature/ViewTest.php b/tests/Feature/ViewTest.php index 200e0b55..c4876691 100644 --- a/tests/Feature/ViewTest.php +++ b/tests/Feature/ViewTest.php @@ -35,7 +35,7 @@ public function test_landing_view_has_data() $response->assertViewHas('lang'); $response->assertViewHas('locales'); } - + #[Test] public function test_calling_index_fires_ScanForNewReleaseCalled_event() { @@ -45,6 +45,4 @@ public function test_calling_index_fires_ScanForNewReleaseCalled_event() Event::assertDispatched(ScanForNewReleaseCalled::class); } - - } diff --git a/tests/FeatureTestCase.php b/tests/FeatureTestCase.php index 888e3263..c94d30b6 100644 --- a/tests/FeatureTestCase.php +++ b/tests/FeatureTestCase.php @@ -4,7 +4,6 @@ use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; -use Illuminate\Support\Facades\Artisan; abstract class FeatureTestCase extends BaseTestCase { @@ -22,6 +21,6 @@ abstract class FeatureTestCase extends BaseTestCase */ protected function afterRefreshingDatabase() { - // + // } } diff --git a/tests/Unit/Api/v1/Controllers/GroupControllerTest.php b/tests/Unit/Api/v1/Controllers/GroupControllerTest.php index 40d4ff5b..d6c3c3bf 100644 --- a/tests/Unit/Api/v1/Controllers/GroupControllerTest.php +++ b/tests/Unit/Api/v1/Controllers/GroupControllerTest.php @@ -34,7 +34,7 @@ public function setUp() : void { parent::setUp(); - $this->user = new User(); + $this->user = new User; // We do not use $this->actingAs($this->user) to prevent intelephense // static analysis error. Dumb, but I don't like errors... @@ -48,7 +48,7 @@ public function test_index_returns_api_resources() $user = Mockery::mock(User::class); $request = Mockery::mock(Request::class); $groups = Group::factory()->count(3)->make(); - $controller = new GroupController(); + $controller = new GroupController; $user->shouldReceive('groups->withCount->get') ->once() @@ -70,7 +70,7 @@ public function test_index_returns_api_resources() public function test_store_uses_validated_data_and_returns_api_resource() { $request = Mockery::mock(GroupStoreRequest::class); - $controller = new GroupController(); + $controller = new GroupController; $group = Group::factory()->for($this->user)->make(); $validated = ['name' => $group->name]; diff --git a/tests/Unit/Events/VisitedByProxyUserTest.php b/tests/Unit/Events/VisitedByProxyUserTest.php index fa573908..db717cde 100644 --- a/tests/Unit/Events/VisitedByProxyUserTest.php +++ b/tests/Unit/Events/VisitedByProxyUserTest.php @@ -17,7 +17,7 @@ class VisitedByProxyUserTest extends TestCase #[Test] public function test_event_constructor() { - $user = new User(); + $user = new User; $event = new VisitedByProxyUser($user); $this->assertSame($user, $event->user); diff --git a/tests/Unit/Exceptions/HandlerTest.php b/tests/Unit/Exceptions/HandlerTest.php index 64aa5aa3..e979149b 100644 --- a/tests/Unit/Exceptions/HandlerTest.php +++ b/tests/Unit/Exceptions/HandlerTest.php @@ -36,7 +36,7 @@ public function test_exceptions_returns_badRequest_json_response($exception) $method = $class->getMethod('render'); $method->setAccessible(true); - $response = $method->invokeArgs($instance, [new Request(), $this->createMock($exception)]); + $response = $method->invokeArgs($instance, [new Request, $this->createMock($exception)]); $this->assertInstanceOf(JsonResponse::class, $response); @@ -93,7 +93,7 @@ public function test_exceptions_returns_notFound_json_response($exception) $method = $class->getMethod('render'); $method->setAccessible(true); - $response = $method->invokeArgs($instance, [new Request(), $this->createMock($exception)]); + $response = $method->invokeArgs($instance, [new Request, $this->createMock($exception)]); $this->assertInstanceOf(JsonResponse::class, $response); @@ -131,7 +131,7 @@ public function test_authenticationException_returns_unauthorized_json_response( $mockException = $this->createMock(\Illuminate\Auth\AuthenticationException::class); $mockException->method('guards')->willReturn(['web-guard']); - $response = $method->invokeArgs($instance, [new Request(), $mockException]); + $response = $method->invokeArgs($instance, [new Request, $mockException]); $this->assertInstanceOf(JsonResponse::class, $response); @@ -154,7 +154,7 @@ public function test_authenticationException_returns_proxyAuthRequired_json_resp $mockException = $this->createMock(\Illuminate\Auth\AuthenticationException::class); $mockException->method('guards')->willReturn(['reverse-proxy-guard']); - $response = $method->invokeArgs($instance, [new Request(), $mockException]); + $response = $method->invokeArgs($instance, [new Request, $mockException]); $this->assertInstanceOf(JsonResponse::class, $response); @@ -176,7 +176,7 @@ public function test_AccessDeniedException_returns_forbidden_json_response() $mockException = $this->createMock(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException::class); - $response = $method->invokeArgs($instance, [new Request(), $mockException]); + $response = $method->invokeArgs($instance, [new Request, $mockException]); $this->assertInstanceOf(JsonResponse::class, $response); diff --git a/tests/Unit/GroupModelTest.php b/tests/Unit/GroupModelTest.php index a7ca585d..6c651dc8 100644 --- a/tests/Unit/GroupModelTest.php +++ b/tests/Unit/GroupModelTest.php @@ -21,7 +21,7 @@ class GroupModelTest extends ModelTestCase public function test_model_configuration() { $this->runConfigurationAssertions( - new Group(), + new Group, ['name'], ['created_at', 'updated_at'], ['*'], @@ -41,9 +41,9 @@ public function test_model_configuration() #[Test] public function test_twofaccounts_relation() { - $group = new Group(); + $group = new Group; $accounts = $group->twofaccounts(); - $this->assertHasManyRelation($accounts, $group, new TwoFAccount()); + $this->assertHasManyRelation($accounts, $group, new TwoFAccount); } #[Test] diff --git a/tests/Unit/Listeners/Authentication/FailedLoginListenerTest.php b/tests/Unit/Listeners/Authentication/FailedLoginListenerTest.php index b4c22555..80845a67 100644 --- a/tests/Unit/Listeners/Authentication/FailedLoginListenerTest.php +++ b/tests/Unit/Listeners/Authentication/FailedLoginListenerTest.php @@ -35,7 +35,7 @@ public function test_FailedLoginListener_listen_to_Failed_event() public function test_handle_throws_exception_with_unexpected_event_type() { $this->expectException(TypeError::class); - + $request = Mockery::mock(Request::class); $event = Mockery::mock(UnexpectedEvent::class); $listener = new FailedLoginListener($request); @@ -47,13 +47,12 @@ public function test_handle_throws_exception_with_unexpected_event_type() public function test_handle_send_nothing_if_user_is_null() { Notification::fake(); - - $request = Mockery::mock(Request::class); - $event = Mockery::mock(Failed::class); + + $request = Mockery::mock(Request::class); + $event = Mockery::mock(Failed::class); (new FailedLoginListener($request))->handle($event); Notification::assertNothingSent(); } - } diff --git a/tests/Unit/Listeners/Authentication/LoginListenerTest.php b/tests/Unit/Listeners/Authentication/LoginListenerTest.php index 9cc6437e..93c1af0b 100644 --- a/tests/Unit/Listeners/Authentication/LoginListenerTest.php +++ b/tests/Unit/Listeners/Authentication/LoginListenerTest.php @@ -34,12 +34,11 @@ public function test_LoginListener_listen_to_Login_event() public function test_handle_throws_exception_with_unexpected_event_type() { $this->expectException(TypeError::class); - + $request = Mockery::mock(Request::class); $event = Mockery::mock(UnexpectedEvent::class); $listener = new LoginListener($request); $listener->handle($event); } - } diff --git a/tests/Unit/Listeners/Authentication/LogoutListenerTest.php b/tests/Unit/Listeners/Authentication/LogoutListenerTest.php index 32600db9..a18bd60a 100644 --- a/tests/Unit/Listeners/Authentication/LogoutListenerTest.php +++ b/tests/Unit/Listeners/Authentication/LogoutListenerTest.php @@ -34,7 +34,7 @@ public function test_LogoutListener_listen_to_Logout_event() public function test_handle_throws_exception_with_unexpected_event_type() { $this->expectException(TypeError::class); - + $request = Mockery::mock(Request::class); $event = Mockery::mock(UnexpectedEvent::class); $listener = new LogoutListener($request); diff --git a/tests/Unit/Listeners/Authentication/VisitedByProxyUserListenerTest.php b/tests/Unit/Listeners/Authentication/VisitedByProxyUserListenerTest.php index 14f5b78f..8d5c331a 100644 --- a/tests/Unit/Listeners/Authentication/VisitedByProxyUserListenerTest.php +++ b/tests/Unit/Listeners/Authentication/VisitedByProxyUserListenerTest.php @@ -34,7 +34,7 @@ public function test_VisitedByProxyUserListener_listen_to_VisitedByProxyUser_eve public function test_handle_throws_exception_with_unexpected_event_type() { $this->expectException(TypeError::class); - + $request = Mockery::mock(Request::class); $event = Mockery::mock(UnexpectedEvent::class); $listener = new VisitedByProxyUserListener($request); diff --git a/tests/Unit/Listeners/CleanIconStorageTest.php b/tests/Unit/Listeners/CleanIconStorageTest.php index a8cb85b9..bfb3c126 100644 --- a/tests/Unit/Listeners/CleanIconStorageTest.php +++ b/tests/Unit/Listeners/CleanIconStorageTest.php @@ -29,7 +29,7 @@ public function test_it_deletes_icon_file_using_storage_facade() $twofaccount = TwoFAccount::factory()->make(); $event = new TwoFAccountDeleted($twofaccount); - $listener = new CleanIconStorage(); + $listener = new CleanIconStorage; Storage::shouldReceive('disk->delete') ->with($event->twofaccount->icon) diff --git a/tests/Unit/Listeners/LogNotificationTest.php b/tests/Unit/Listeners/LogNotificationTest.php index 5dd59f0d..1116f3c3 100644 --- a/tests/Unit/Listeners/LogNotificationTest.php +++ b/tests/Unit/Listeners/LogNotificationTest.php @@ -32,8 +32,8 @@ public function test_LogNotificationTest_listen_to_NotificationSent_event() #[Test] public function test_handle_logs_notification_sending() { - $event = new NotificationSent((new User()), (new TestEmailSettingNotification()), 'channel'); - $listener = new LogNotificationListener(); + $event = new NotificationSent((new User), (new TestEmailSettingNotification), 'channel'); + $listener = new LogNotificationListener; Log::shouldReceive('info')->once(); diff --git a/tests/Unit/Listeners/ReleaseRadarTest.php b/tests/Unit/Listeners/ReleaseRadarTest.php index 05b6b694..c9af80b4 100644 --- a/tests/Unit/Listeners/ReleaseRadarTest.php +++ b/tests/Unit/Listeners/ReleaseRadarTest.php @@ -24,8 +24,8 @@ public function test_it_starts_release_scan() $releaseRadarService->shouldReceive('scheduledScan'); }); - $event = new ScanForNewReleaseCalled(); - $listener = new ReleaseRadar(); + $event = new ScanForNewReleaseCalled; + $listener = new ReleaseRadar; $this->assertNull($listener->handle($event)); } diff --git a/tests/Unit/MigratorTest.php b/tests/Unit/MigratorTest.php index 4b2caf5f..78f6886d 100644 --- a/tests/Unit/MigratorTest.php +++ b/tests/Unit/MigratorTest.php @@ -20,8 +20,8 @@ use Mockery\MockInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\UsesClass; use Tests\Data\MigrationTestData; use Tests\Data\OtpTestData; use Tests\TestCase; @@ -189,37 +189,37 @@ public static function validMigrationsProvider() { return [ 'PLAIN_TEXT_PAYLOAD' => [ - new PlainTextMigrator(), + new PlainTextMigrator, MigrationTestData::VALID_PLAIN_TEXT_PAYLOAD, 'custom', $hasSteam = true, ], 'PLAIN_TEXT_PAYLOAD_WITH_INTRUDER' => [ - new PlainTextMigrator(), + new PlainTextMigrator, MigrationTestData::VALID_PLAIN_TEXT_PAYLOAD_WITH_INTRUDER, 'custom', $hasSteam = true, ], 'AEGIS_JSON_MIGRATION_PAYLOAD' => [ - new AegisMigrator(), + new AegisMigrator, MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD, 'custom', $hasSteam = true, ], '2FAS_MIGRATION_PAYLOAD' => [ - new TwoFASMigrator(), + new TwoFASMigrator, MigrationTestData::VALID_2FAS_MIGRATION_PAYLOAD, 'custom', $hasSteam = false, ], 'GOOGLE_AUTH_MIGRATION_PAYLOAD' => [ - new GoogleAuthMigrator(), + new GoogleAuthMigrator, MigrationTestData::GOOGLE_AUTH_MIGRATION_URI, 'gauth', $hasSteam = false, ], '2FAUTH_MIGRATION_PAYLOAD' => [ - new TwoFAuthMigrator(), + new TwoFAuthMigrator, MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD, 'custom', $hasSteam = true, @@ -243,51 +243,51 @@ public static function invalidMigrationsProvider() { return [ 'INVALID_PLAIN_TEXT_NO_URI' => [ - new PlainTextMigrator(), + new PlainTextMigrator, MigrationTestData::INVALID_PLAIN_TEXT_NO_URI, ], 'INVALID_PLAIN_TEXT_ONLY_EMPTY_LINES' => [ - new PlainTextMigrator(), + new PlainTextMigrator, MigrationTestData::INVALID_PLAIN_TEXT_ONLY_EMPTY_LINES, ], 'INVALID_PLAIN_TEXT_NULL' => [ - new PlainTextMigrator(), + new PlainTextMigrator, null, ], 'INVALID_PLAIN_TEXT_EMPTY_STRING' => [ - new PlainTextMigrator(), + new PlainTextMigrator, '', ], 'INVALID_PLAIN_TEXT_INT' => [ - new PlainTextMigrator(), + new PlainTextMigrator, 10, ], 'INVALID_PLAIN_TEXT_BOOL' => [ - new PlainTextMigrator(), + new PlainTextMigrator, true, ], 'INVALID_AEGIS_JSON_MIGRATION_PAYLOAD' => [ - new AegisMigrator(), + new AegisMigrator, MigrationTestData::INVALID_AEGIS_JSON_MIGRATION_PAYLOAD, ], 'ENCRYPTED_AEGIS_JSON_MIGRATION_PAYLOAD' => [ - new AegisMigrator(), + new AegisMigrator, MigrationTestData::ENCRYPTED_AEGIS_JSON_MIGRATION_PAYLOAD, ], 'INVALID_2FAS_MIGRATION_PAYLOAD' => [ - new TwoFASMigrator(), + new TwoFASMigrator, MigrationTestData::INVALID_2FAS_MIGRATION_PAYLOAD, ], 'INVALID_GOOGLE_AUTH_MIGRATION_URI' => [ - new GoogleAuthMigrator(), + new GoogleAuthMigrator, MigrationTestData::INVALID_GOOGLE_AUTH_MIGRATION_URI, ], 'GOOGLE_AUTH_MIGRATION_URI_WITH_INVALID_DATA' => [ - new GoogleAuthMigrator(), + new GoogleAuthMigrator, MigrationTestData::GOOGLE_AUTH_MIGRATION_URI_WITH_INVALID_DATA, ], 'INVALID_2FAUTH_JSON_MIGRATION_PAYLOAD' => [ - new TwoFAuthMigrator(), + new TwoFAuthMigrator, MigrationTestData::INVALID_2FAUTH_JSON_MIGRATION_PAYLOAD, ], @@ -316,19 +316,19 @@ public static function migrationWithInvalidAccountsProvider() { return [ 'PLAIN_TEXT_PAYLOAD_WITH_INVALID_URI' => [ - new PlainTextMigrator(), + new PlainTextMigrator, MigrationTestData::PLAIN_TEXT_PAYLOAD_WITH_INVALID_URI, ], 'VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE' => [ - new AegisMigrator(), + new AegisMigrator, MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE, ], 'VALID_2FAS_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE' => [ - new TwoFASMigrator(), + new TwoFASMigrator, MigrationTestData::VALID_2FAS_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE, ], 'VALID_2FAUTH_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE' => [ - new TwoFAuthMigrator(), + new TwoFAuthMigrator, MigrationTestData::VALID_2FAUTH_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE, ], ]; @@ -339,7 +339,7 @@ public function test_migrate_gauth_returns_fake_accounts() { $migrator = $this->partialMock(GoogleAuthMigrator::class, function (MockInterface $migrator) { $migrator->shouldAllowMockingProtectedMethods()->shouldReceive('toBase32') - ->andThrow(new \Exception()); + ->andThrow(new \Exception); }); /** @disregard Undefined function */ @@ -362,7 +362,7 @@ public function test_migrate_aegis_payload_with_icon_sets_and_stores_the_icon($m { Storage::fake('icons'); - $migrator = new AegisMigrator(); + $migrator = new AegisMigrator; $accounts = $migrator->migrate($migration); $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts); @@ -394,7 +394,7 @@ public function test_migrate_aegis_payload_with_unsupported_icon_does_not_fail() { Storage::fake('icons'); - $migrator = new AegisMigrator(); + $migrator = new AegisMigrator; $accounts = $migrator->migrate(MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_ICON); $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts); @@ -410,7 +410,7 @@ public function test_migrate_2fauth_payload_with_icon_sets_and_stores_the_icon($ { Storage::fake('icons'); - $migrator = new TwoFAuthMigrator(); + $migrator = new TwoFAuthMigrator; $accounts = $migrator->migrate($migration); $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts); @@ -451,7 +451,7 @@ public function test_migrate_2fauth_payload_with_unsupported_icon_does_not_fail( { Storage::fake('icons'); - $migrator = new TwoFAuthMigrator(); + $migrator = new TwoFAuthMigrator; $accounts = $migrator->migrate(MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_ICON); $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts); @@ -465,7 +465,7 @@ public function test_migrate_2fauth_payload_with_unsupported_icon_does_not_fail( #[DataProvider('factoryProvider')] public function test_factory_returns_relevant_migrator($payload, $migratorClass) { - $factory = new MigratorFactory(); + $factory = new MigratorFactory; $migrator = $factory->create($payload); @@ -509,7 +509,7 @@ public static function factoryProvider() public function test_factory_throw_UnsupportedMigrationException() { $this->expectException(UnsupportedMigrationException::class); - $factory = new MigratorFactory(); + $factory = new MigratorFactory; $migrator = $factory->create('not_a_valid_payload'); } @@ -520,7 +520,7 @@ public function test_factory_throw_EncryptedMigrationException($payload) { $this->expectException(EncryptedMigrationException::class); - $factory = new MigratorFactory(); + $factory = new MigratorFactory; $migrator = $factory->create($payload); } diff --git a/tests/Unit/Providers/Socialite/OpenIdProviderStub.php b/tests/Unit/Providers/Socialite/OpenIdProviderStub.php index b1d2f379..d6df3eb9 100644 --- a/tests/Unit/Providers/Socialite/OpenIdProviderStub.php +++ b/tests/Unit/Providers/Socialite/OpenIdProviderStub.php @@ -3,8 +3,8 @@ namespace Tests\Unit\Providers\Socialite; use App\Providers\Socialite\OpenId; -use SocialiteProviders\Manager\OAuth2\User; use Mockery; +use SocialiteProviders\Manager\OAuth2\User; use stdClass; class OpenIdProviderStub extends OpenId diff --git a/tests/Unit/Providers/Socialite/OpenIdProviderTest.php b/tests/Unit/Providers/Socialite/OpenIdProviderTest.php index dfd06a47..73787ac7 100644 --- a/tests/Unit/Providers/Socialite/OpenIdProviderTest.php +++ b/tests/Unit/Providers/Socialite/OpenIdProviderTest.php @@ -29,7 +29,7 @@ public function test_it_can_map_a_user_from_an_access_token() $provider->stateless(); $provider->http = Mockery::mock(stdClass::class); - $provider->http->expects('get')->with(NULL, [ + $provider->http->expects('get')->with(null, [ RequestOptions::HEADERS => [ 'Authorization' => 'Bearer access_token', ], @@ -49,7 +49,7 @@ public function test_it_can_map_a_user_from_an_access_token() $this->assertSame('true', $user->email_verified); $this->assertSame('myGroup', $user->groups); } - + #[Test] public function test_it_can_map_a_user_from_an_access_token_with_missing_fields() { @@ -59,7 +59,7 @@ public function test_it_can_map_a_user_from_an_access_token_with_missing_fields( $provider->stateless(); $provider->http = Mockery::mock(stdClass::class); - $provider->http->expects('get')->with(NULL, [ + $provider->http->expects('get')->with(null, [ RequestOptions::HEADERS => [ 'Authorization' => 'Bearer access_token', ], @@ -87,18 +87,18 @@ public function test_it_fetches_token_url_from_config() config(['services.openid.token_url' => $tokenUrl]); $request = Request::create('/'); - $provider = new OpenIdProviderStub($request, 'client_id', 'client_secret', 'redirect_uri'); + $provider = new OpenIdProviderStub($request, 'client_id', 'client_secret', 'redirect_uri'); $provider->http = Mockery::mock(stdClass::class); $config = (new ConfigRetriever)->fromServices('openid', $provider->additionalConfigKeys()); $provider->setConfig($config); $provider->http->expects('post')->with($tokenUrl, [ - RequestOptions::HEADERS => ['Accept' => 'application/json'], + RequestOptions::HEADERS => ['Accept' => 'application/json'], RequestOptions::FORM_PARAMS => [ - 'grant_type' => 'refresh_token', + 'grant_type' => 'refresh_token', 'refresh_token' => 'refresh_token', - 'client_id' => null, + 'client_id' => null, 'client_secret' => null, ], ])->andReturns($response = Mockery::mock(stdClass::class)); @@ -116,7 +116,7 @@ public function test_it_redirects_to_url_from_config() config(['services.openid.authorize_url' => $authUrl]); $request = Request::create('/'); - $provider = new OpenIdProviderStub($request, 'client_id', 'client_secret', 'redirect_uri'); + $provider = new OpenIdProviderStub($request, 'client_id', 'client_secret', 'redirect_uri'); $provider->http = Mockery::mock(stdClass::class); $provider->stateless(); diff --git a/tests/Unit/TwoFAccountModelTest.php b/tests/Unit/TwoFAccountModelTest.php index adda61d1..d40d507b 100644 --- a/tests/Unit/TwoFAccountModelTest.php +++ b/tests/Unit/TwoFAccountModelTest.php @@ -24,7 +24,7 @@ class TwoFAccountModelTest extends ModelTestCase public function test_model_configuration() { $this->runConfigurationAssertions( - new TwoFAccount(), + new TwoFAccount, [], [], ['*'], @@ -138,7 +138,7 @@ public function test_secret_is_uppercased_and_padded_at_setup() #[Test] public function test_user_relation() { - $model = new TwoFAccount(); + $model = new TwoFAccount; $relation = $model->user(); $this->assertInstanceOf(BelongsTo::class, $relation); diff --git a/tests/Unit/UserModelTest.php b/tests/Unit/UserModelTest.php index 492e0aa5..32980463 100644 --- a/tests/Unit/UserModelTest.php +++ b/tests/Unit/UserModelTest.php @@ -18,7 +18,7 @@ class UserModelTest extends ModelTestCase #[Test] public function test_model_configuration() { - $this->runConfigurationAssertions(new User(), + $this->runConfigurationAssertions(new User, ['name', 'email', 'password', 'oauth_id', 'oauth_provider'], ['password', 'remember_token'], ['*'], @@ -47,17 +47,17 @@ public function test_email_is_set_lowercased() #[Test] public function test_twofaccounts_relation() { - $user = new User(); + $user = new User; $accounts = $user->twofaccounts(); - $this->assertHasManyRelation($accounts, $user, new TwoFAccount()); + $this->assertHasManyRelation($accounts, $user, new TwoFAccount); } #[Test] public function test_groups_relation() { - $user = new User(); + $user = new User; $groups = $user->groups(); - $this->assertHasManyRelation($groups, $user, new Group()); + $this->assertHasManyRelation($groups, $user, new Group); } #[Test]