From dce3d16c371526e563e379f5194f2feca009e68b Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Fri, 10 Mar 2023 22:59:46 +0100 Subject: [PATCH] Apply Laravel Pint fixes --- app/Api/v1/Controllers/GroupController.php | 2 +- .../WebauthnTwoFAuthUserProvider.php | 5 +- app/Http/Controllers/Auth/UserController.php | 4 +- app/Http/Controllers/SystemController.php | 8 +- app/Listeners/ReleaseRadar.php | 2 +- app/Models/TwoFAccount.php | 5 +- app/Models/User.php | 20 ++--- app/Policies/GroupPolicy.php | 1 - app/Providers/AuthServiceProvider.php | 1 - app/Providers/EventServiceProvider.php | 2 +- app/Services/GroupService.php | 9 ++- app/Services/TwoFAccountService.php | 4 +- .../Controllers/Auth/UserControllerTest.php | 80 +++++++++---------- .../v1/Controllers/GroupControllerTest.php | 27 +++++-- .../Api/v1/Controllers/IconControllerTest.php | 3 - .../v1/Controllers/QrCodeControllerTest.php | 6 +- .../v1/Controllers/SettingControllerTest.php | 6 +- .../Controllers/TwoFAccountControllerTest.php | 26 ++++-- .../Api/v1/Requests/GroupStoreRequestTest.php | 1 + tests/Feature/Http/Auth/LoginTest.php | 1 - .../Http/Auth/RegisterControllerTest.php | 8 +- .../Feature/Http/Auth/UserControllerTest.php | 24 +++--- .../Http/Auth/WebAuthnLoginControllerTest.php | 24 +++--- .../Http/Requests/UserStoreRequestTest.php | 2 +- .../Http/Requests/UserUpdateRequestTest.php | 2 +- tests/Feature/Http/SystemControllerTest.php | 6 +- tests/Feature/Models/TwoFAccountModelTest.php | 10 ++- tests/Feature/Services/GroupServiceTest.php | 6 +- .../Services/ReleaseRadarServiceTest.php | 8 +- .../Services/TwoFAccountServiceTest.php | 16 ++-- .../v1/Controllers/GroupControllerTest.php | 9 +-- tests/Unit/GroupModelTest.php | 5 +- tests/Unit/Listeners/ReleaseRadarTest.php | 4 +- .../Listeners/ResetUsersPreferenceTest.php | 1 - tests/Unit/MigratorTest.php | 6 +- tests/Unit/TwoFAccountModelTest.php | 2 +- tests/Unit/UserModelTest.php | 4 +- 37 files changed, 190 insertions(+), 160 deletions(-) diff --git a/app/Api/v1/Controllers/GroupController.php b/app/Api/v1/Controllers/GroupController.php index bcb2fb4c..7f3721e5 100644 --- a/app/Api/v1/Controllers/GroupController.php +++ b/app/Api/v1/Controllers/GroupController.php @@ -22,7 +22,7 @@ class GroupController extends Controller public function index(Request $request) { // We do not use fluent call all over the call chain to ease tests - $user = $request->user(); + $user = $request->user(); $groups = $user->groups()->withCount('twofaccounts')->get(); return GroupResource::collection(Groups::prependTheAllGroup($groups, $request->user())); diff --git a/app/Extensions/WebauthnTwoFAuthUserProvider.php b/app/Extensions/WebauthnTwoFAuthUserProvider.php index c86741de..cac96910 100644 --- a/app/Extensions/WebauthnTwoFAuthUserProvider.php +++ b/app/Extensions/WebauthnTwoFAuthUserProvider.php @@ -2,8 +2,8 @@ namespace App\Extensions; -use Illuminate\Auth\EloquentUserProvider; use App\Models\WebAuthnAuthenticatable; +use Illuminate\Auth\EloquentUserProvider; use Laragear\WebAuthn\Auth\WebAuthnUserProvider; class WebauthnTwoFAuthUserProvider extends WebAuthnUserProvider @@ -13,10 +13,9 @@ class WebauthnTwoFAuthUserProvider extends WebAuthnUserProvider * * @param \Illuminate\Contracts\Auth\Authenticatable|\App\Models\WebAuthnAuthenticatable|\App\Models\User $user * @param array $credentials - * * @return bool */ - public function validateCredentials($user, array $credentials): bool + public function validateCredentials($user, array $credentials) : bool { if ($user instanceof WebAuthnAuthenticatable && $this->isSignedChallenge($credentials)) { return $this->validateWebAuthn(); diff --git a/app/Http/Controllers/Auth/UserController.php b/app/Http/Controllers/Auth/UserController.php index 9a9e5748..2724550a 100644 --- a/app/Http/Controllers/Auth/UserController.php +++ b/app/Http/Controllers/Auth/UserController.php @@ -51,7 +51,7 @@ public function update(UserUpdateRequest $request) public function delete(UserDeleteRequest $request) { $validated = $request->validated(); - $user = Auth::user(); + $user = Auth::user(); Log::info(sprintf('Deletion of user ID #%s requested', $user->id)); @@ -81,7 +81,7 @@ public function delete(UserDeleteRequest $request) return response()->json(['message' => __('errors.user_deletion_failed')], 400); } // @codeCoverageIgnoreEnd - + Log::info(sprintf('User ID #%s deleted', $user->id)); return response()->json(null, 204); diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index a1da99e6..feaab658 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -17,7 +17,7 @@ class SystemController extends Controller */ public function infos(Request $request) { - $infos = []; + $infos = []; $infos['common']['Date'] = date(DATE_RFC2822); $infos['common']['userAgent'] = $request->header('user-agent'); // App info @@ -43,11 +43,11 @@ public function infos(Request $request) } $infos['common']['webauthn user verification'] = config('webauthn.user_verification'); $infos['common']['Trusted proxies'] = config('2fauth.config.trustedProxies') ?: 'none'; - + // Admin settings if ($request->user()->is_admin == true) { - $infos['admin_settings']['useEncryption'] = Settings::get('useEncryption'); - $infos['admin_settings']['lastRadarScan'] = Carbon::parse(Settings::get('lastRadarScan'))->format('Y-m-d H:i:s'); + $infos['admin_settings']['useEncryption'] = Settings::get('useEncryption'); + $infos['admin_settings']['lastRadarScan'] = Carbon::parse(Settings::get('lastRadarScan'))->format('Y-m-d H:i:s'); $infos['admin_settings']['checkForUpdate'] = Settings::get('CheckForUpdate'); } } diff --git a/app/Listeners/ReleaseRadar.php b/app/Listeners/ReleaseRadar.php index 6be84022..edec9f16 100644 --- a/app/Listeners/ReleaseRadar.php +++ b/app/Listeners/ReleaseRadar.php @@ -28,7 +28,7 @@ public function handle(ScanForNewReleaseCalled $event) { $releaseRadarService = app()->make(ReleaseRadarService::class); $releaseRadarService::scheduledScan(); - + Log::info('Scheduled release scan complete'); } } diff --git a/app/Models/TwoFAccount.php b/app/Models/TwoFAccount.php index 081a53bc..503cabdc 100644 --- a/app/Models/TwoFAccount.php +++ b/app/Models/TwoFAccount.php @@ -17,7 +17,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; @@ -465,7 +464,7 @@ public function fillWithURI(string $uri, bool $isSteamTotp = false, bool $skipIc if ($this->generator->hasParameter('image')) { self::setIcon($this->generator->getParameter('image')); } - + if (! $this->icon && $this->shouldGetOfficialIcon() && ! $skipIconFetching) { $this->icon = $this->getDefaultIcon(); } @@ -709,7 +708,7 @@ private function getDefaultIcon() /** * Tells if an official icon should be fetched - * + * * @return bool */ private function shouldGetOfficialIcon() : bool diff --git a/app/Models/User.php b/app/Models/User.php index 1ea07ecc..e8e57903 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -73,17 +73,17 @@ class User extends Authenticatable implements WebAuthnAuthenticatable 'twofaccounts_count' => 'integer', 'groups_count' => 'integer', ]; - + /** - * Scope a query to only include admin users. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeAdmins($query) - { - return $query->where('is_admin', true); - } + * Scope a query to only include admin users. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeAdmins($query) + { + return $query->where('is_admin', true); + } /** * Send the password reset notification. diff --git a/app/Policies/GroupPolicy.php b/app/Policies/GroupPolicy.php index 0852e7eb..f0e2882d 100644 --- a/app/Policies/GroupPolicy.php +++ b/app/Policies/GroupPolicy.php @@ -5,7 +5,6 @@ use App\Models\Group; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; -use Illuminate\Auth\Access\Response; use Illuminate\Support\Facades\Log; class GroupPolicy diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index c0ecb334..299c6ac1 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -4,7 +4,6 @@ use App\Extensions\RemoteUserProvider; use App\Extensions\WebauthnCredentialBroker; -use App\Facades\Settings; use App\Models\Group; use App\Models\TwoFAccount; use App\Policies\GroupPolicy; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index ee2039ba..c437928d 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,8 +2,8 @@ namespace App\Providers; -use App\Events\GroupDeleting; use App\Events\GroupDeleted; +use App\Events\GroupDeleting; use App\Events\ScanForNewReleaseCalled; use App\Events\TwoFAccountDeleted; use App\Listeners\CleanIconStorage; diff --git a/app/Services/GroupService.php b/app/Services/GroupService.php index ab25f632..cfb70d69 100644 --- a/app/Services/GroupService.php +++ b/app/Services/GroupService.php @@ -18,17 +18,17 @@ class GroupService * @param \App\Models\User $user * @param \App\Models\Group|null $group The group the accounts will be assigned to * @return void - * + * * @throws \Illuminate\Auth\Access\AuthorizationException */ public static function assign($ids, User $user, Group $group = null) : void { - if (!$group) { + if (! $group) { $group = self::defaultGroup($user); } if ($group) { - $ids = is_array($ids) ? $ids : [$ids]; + $ids = is_array($ids) ? $ids : [$ids]; $twofaccounts = TwoFAccount::find($ids); if ($user->cannot('updateEach', [(new TwoFAccount), $twofaccounts])) { @@ -39,8 +39,9 @@ public static function assign($ids, User $user, Group $group = null) : void $group->loadCount('twofaccounts'); Log::info(sprintf('Twofaccounts #%s assigned to group %s (ID #%s)', implode(',', $ids), var_export($group->name, true), $group->id)); + } else { + Log::info('Cannot find a group to assign the TwoFAccounts to'); } - else Log::info('Cannot find a group to assign the TwoFAccounts to'); } /** diff --git a/app/Services/TwoFAccountService.php b/app/Services/TwoFAccountService.php index 8747dac8..daf207e1 100644 --- a/app/Services/TwoFAccountService.php +++ b/app/Services/TwoFAccountService.php @@ -67,9 +67,9 @@ public function migrate(string $migrationPayload) : Collection */ public static function export($ids) : Collection { - $ids = Helpers::commaSeparatedToArray($ids); + $ids = Helpers::commaSeparatedToArray($ids); $ids = is_array($ids) ? $ids : func_get_args(); - + $twofaccounts = TwoFAccount::whereIn('id', $ids)->get(); return $twofaccounts; diff --git a/tests/Api/v1/Controllers/Auth/UserControllerTest.php b/tests/Api/v1/Controllers/Auth/UserControllerTest.php index c13b16b9..a96a5fc9 100644 --- a/tests/Api/v1/Controllers/Auth/UserControllerTest.php +++ b/tests/Api/v1/Controllers/Auth/UserControllerTest.php @@ -71,7 +71,7 @@ public function test_allPreferences_returns_preferences_with_default_values() foreach (config('2fauth.preferences') as $pref => $value) { $response->assertJsonFragment([ - 'key' => $pref, + 'key' => $pref, 'value' => $value, ]); } @@ -83,46 +83,46 @@ public function test_allPreferences_returns_preferences_with_default_values() public function test_allPreferences_returns_preferences_with_user_values() { $userPrefs = [ - 'showTokenAsDot' => true, - 'closeOtpOnCopy' => true, - 'copyOtpOnDisplay' => true, + 'showTokenAsDot' => true, + 'closeOtpOnCopy' => true, + 'copyOtpOnDisplay' => true, 'useBasicQrcodeReader' => true, - 'displayMode' => 'grid', - 'showAccountsIcons' => false, - 'kickUserAfter' => 5, - 'activeGroup' => 1, - 'rememberActiveGroup' => false, - 'defaultGroup' => 1, - 'defaultCaptureMode' => 'advancedForm', - 'useDirectCapture' => true, + 'displayMode' => 'grid', + 'showAccountsIcons' => false, + 'kickUserAfter' => 5, + 'activeGroup' => 1, + 'rememberActiveGroup' => false, + 'defaultGroup' => 1, + 'defaultCaptureMode' => 'advancedForm', + 'useDirectCapture' => true, 'useWebauthnAsDefault' => true, - 'useWebauthnOnly' => true, - 'getOfficialIcons' => false, - 'theme' => 'dark', - 'formatPassword' => false, - 'formatPasswordBy' => 1, - 'lang' => 'fr', + 'useWebauthnOnly' => true, + 'getOfficialIcons' => false, + 'theme' => 'dark', + 'formatPassword' => false, + 'formatPasswordBy' => 1, + 'lang' => 'fr', ]; - $this->user['preferences->showTokenAsDot'] = $userPrefs['showTokenAsDot']; - $this->user['preferences->closeOtpOnCopy'] = $userPrefs['closeOtpOnCopy']; - $this->user['preferences->copyOtpOnDisplay'] = $userPrefs['copyOtpOnDisplay']; + $this->user['preferences->showTokenAsDot'] = $userPrefs['showTokenAsDot']; + $this->user['preferences->closeOtpOnCopy'] = $userPrefs['closeOtpOnCopy']; + $this->user['preferences->copyOtpOnDisplay'] = $userPrefs['copyOtpOnDisplay']; $this->user['preferences->useBasicQrcodeReader'] = $userPrefs['useBasicQrcodeReader']; - $this->user['preferences->displayMode'] = $userPrefs['displayMode']; - $this->user['preferences->showAccountsIcons'] = $userPrefs['showAccountsIcons']; - $this->user['preferences->kickUserAfter'] = $userPrefs['kickUserAfter']; - $this->user['preferences->activeGroup'] = $userPrefs['activeGroup']; - $this->user['preferences->rememberActiveGroup'] = $userPrefs['rememberActiveGroup']; - $this->user['preferences->defaultGroup'] = $userPrefs['defaultGroup']; - $this->user['preferences->defaultCaptureMode'] = $userPrefs['defaultCaptureMode']; - $this->user['preferences->useDirectCapture'] = $userPrefs['useDirectCapture']; + $this->user['preferences->displayMode'] = $userPrefs['displayMode']; + $this->user['preferences->showAccountsIcons'] = $userPrefs['showAccountsIcons']; + $this->user['preferences->kickUserAfter'] = $userPrefs['kickUserAfter']; + $this->user['preferences->activeGroup'] = $userPrefs['activeGroup']; + $this->user['preferences->rememberActiveGroup'] = $userPrefs['rememberActiveGroup']; + $this->user['preferences->defaultGroup'] = $userPrefs['defaultGroup']; + $this->user['preferences->defaultCaptureMode'] = $userPrefs['defaultCaptureMode']; + $this->user['preferences->useDirectCapture'] = $userPrefs['useDirectCapture']; $this->user['preferences->useWebauthnAsDefault'] = $userPrefs['useWebauthnAsDefault']; - $this->user['preferences->useWebauthnOnly'] = $userPrefs['useWebauthnOnly']; - $this->user['preferences->getOfficialIcons'] = $userPrefs['getOfficialIcons']; - $this->user['preferences->theme'] = $userPrefs['theme']; - $this->user['preferences->formatPassword'] = $userPrefs['formatPassword']; - $this->user['preferences->formatPasswordBy'] = $userPrefs['formatPasswordBy']; - $this->user['preferences->lang'] = $userPrefs['lang']; + $this->user['preferences->useWebauthnOnly'] = $userPrefs['useWebauthnOnly']; + $this->user['preferences->getOfficialIcons'] = $userPrefs['getOfficialIcons']; + $this->user['preferences->theme'] = $userPrefs['theme']; + $this->user['preferences->formatPassword'] = $userPrefs['formatPassword']; + $this->user['preferences->formatPasswordBy'] = $userPrefs['formatPasswordBy']; + $this->user['preferences->lang'] = $userPrefs['lang']; $this->user->save(); $response = $this->actingAs($this->user, 'api-guard') @@ -131,7 +131,7 @@ public function test_allPreferences_returns_preferences_with_user_values() foreach ($userPrefs as $pref => $value) { $response->assertJsonFragment([ - 'key' => $pref, + 'key' => $pref, 'value' => $value, ]); } @@ -151,7 +151,7 @@ public function test_showPreference_returns_preference_with_default_value() ->json('GET', '/api/v1/user/preferences/showTokenAsDot') ->assertOk() ->assertExactJson([ - 'key' => 'showTokenAsDot', + 'key' => 'showTokenAsDot', 'value' => config('2fauth.preferences.showTokenAsDot'), ]); } @@ -161,14 +161,14 @@ public function test_showPreference_returns_preference_with_default_value() */ public function test_showPreference_returns_preference_with_custom_value() { - $showTokenAsDot = ! config('2fauth.preferences.showTokenAsDot'); + $showTokenAsDot = ! config('2fauth.preferences.showTokenAsDot'); $this->user['preferences->showTokenAsDot'] = $showTokenAsDot; $this->user->save(); $response = $this->actingAs($this->user, 'api-guard') ->json('GET', '/api/v1/user/preferences/showTokenAsDot') ->assertJsonFragment([ - 'key' => 'showTokenAsDot', + 'key' => 'showTokenAsDot', 'value' => $showTokenAsDot, ]); } @@ -202,7 +202,7 @@ public function test_setPreference_returns_updated_preference() ]) ->assertCreated() ->assertExactJson([ - 'key' => 'showTokenAsDot', + 'key' => 'showTokenAsDot', 'value' => $showTokenAsDot, ]); } diff --git a/tests/Api/v1/Controllers/GroupControllerTest.php b/tests/Api/v1/Controllers/GroupControllerTest.php index 055311f7..bc91d65a 100644 --- a/tests/Api/v1/Controllers/GroupControllerTest.php +++ b/tests/Api/v1/Controllers/GroupControllerTest.php @@ -16,17 +16,31 @@ class GroupControllerTest extends FeatureTestCase /** * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable */ - protected $user, $anotherUser; + protected $user; + + protected $anotherUser; /** * @var App\Models\Group */ - protected $userGroupA, $userGroupB, $anotherUserGroupA, $anotherUserGroupB; + protected $userGroupA; + + protected $userGroupB; + + protected $anotherUserGroupA; + + protected $anotherUserGroupB; /** * @var App\Models\TwoFAccount */ - protected $twofaccountA, $twofaccountB, $twofaccountC, $twofaccountD; + protected $twofaccountA; + + protected $twofaccountB; + + protected $twofaccountC; + + protected $twofaccountD; private const NEW_GROUP_NAME = 'MyNewGroup'; @@ -37,7 +51,7 @@ public function setUp() : void { parent::setUp(); - $this->user = User::factory()->create(); + $this->user = User::factory()->create(); $this->userGroupA = Group::factory()->for($this->user)->create(); $this->userGroupB = Group::factory()->for($this->user)->create(); @@ -48,7 +62,7 @@ public function setUp() : void 'group_id' => $this->userGroupA->id, ]); - $this->anotherUser = User::factory()->create(); + $this->anotherUser = User::factory()->create(); $this->anotherUserGroupA = Group::factory()->for($this->anotherUser)->create(); $this->anotherUserGroupB = Group::factory()->for($this->anotherUser)->create(); @@ -120,7 +134,6 @@ public function test_store_invalid_data_returns_validation_error() ->assertStatus(422); } - /** * @test */ @@ -425,7 +438,7 @@ public function test_destroy_missing_group_returns_not_found() public function test_destroy_group_of_another_user_is_forbidden() { $response = $this->actingAs($this->anotherUser, 'api-guard') - ->json('DELETE', '/api/v1/groups/'.$this->userGroupA->id) + ->json('DELETE', '/api/v1/groups/' . $this->userGroupA->id) ->assertForbidden() ->assertJsonStructure([ 'message', diff --git a/tests/Api/v1/Controllers/IconControllerTest.php b/tests/Api/v1/Controllers/IconControllerTest.php index f585df3d..cea197fb 100644 --- a/tests/Api/v1/Controllers/IconControllerTest.php +++ b/tests/Api/v1/Controllers/IconControllerTest.php @@ -17,9 +17,6 @@ class IconControllerTest extends FeatureTestCase */ protected $user; - /** - * - */ public function setUp() : void { parent::setUp(); diff --git a/tests/Api/v1/Controllers/QrCodeControllerTest.php b/tests/Api/v1/Controllers/QrCodeControllerTest.php index e8d4488a..3a59d109 100644 --- a/tests/Api/v1/Controllers/QrCodeControllerTest.php +++ b/tests/Api/v1/Controllers/QrCodeControllerTest.php @@ -15,7 +15,9 @@ class QrCodeControllerTest extends FeatureTestCase /** * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable */ - protected $user, $anotherUser; + protected $user; + + protected $anotherUser; /** * @var App\Models\TwoFAccount @@ -29,7 +31,7 @@ public function setUp() : void { parent::setUp(); - $this->user = User::factory()->create(); + $this->user = User::factory()->create(); $this->anotherUser = User::factory()->create(); $this->twofaccount = TwoFAccount::factory()->for($this->user)->create([ diff --git a/tests/Api/v1/Controllers/SettingControllerTest.php b/tests/Api/v1/Controllers/SettingControllerTest.php index 9f3f37a0..ef8d8d1c 100644 --- a/tests/Api/v1/Controllers/SettingControllerTest.php +++ b/tests/Api/v1/Controllers/SettingControllerTest.php @@ -14,7 +14,9 @@ class SettingControllerTest extends FeatureTestCase /** * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable */ - protected $user, $admin; + protected $user; + + protected $admin; private const SETTING_JSON_STRUCTURE = [ 'key', @@ -40,7 +42,7 @@ public function setUp() : void { parent::setUp(); - $this->user = User::factory()->create(); + $this->user = User::factory()->create(); $this->admin = User::factory()->administrator()->create(); } diff --git a/tests/Api/v1/Controllers/TwoFAccountControllerTest.php b/tests/Api/v1/Controllers/TwoFAccountControllerTest.php index 8a1f1009..bc1f06fd 100644 --- a/tests/Api/v1/Controllers/TwoFAccountControllerTest.php +++ b/tests/Api/v1/Controllers/TwoFAccountControllerTest.php @@ -25,17 +25,31 @@ class TwoFAccountControllerTest extends FeatureTestCase /** * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable */ - protected $user, $anotherUser; + protected $user; + + protected $anotherUser; /** * @var App\Models\Group */ - protected $userGroupA, $userGroupB, $anotherUserGroupA, $anotherUserGroupB; + protected $userGroupA; + + protected $userGroupB; + + protected $anotherUserGroupA; + + protected $anotherUserGroupB; /** * @var App\Models\TwoFAccount */ - protected $twofaccountA, $twofaccountB, $twofaccountC, $twofaccountD; + protected $twofaccountA; + + protected $twofaccountB; + + protected $twofaccountC; + + protected $twofaccountD; private const VALID_RESOURCE_STRUCTURE_WITHOUT_SECRET = [ 'id', @@ -134,7 +148,7 @@ public function setUp() : void { parent::setUp(); - $this->user = User::factory()->create(); + $this->user = User::factory()->create(); $this->userGroupA = Group::factory()->for($this->user)->create(); $this->userGroupB = Group::factory()->for($this->user)->create(); @@ -145,7 +159,7 @@ public function setUp() : void 'group_id' => $this->userGroupA->id, ]); - $this->anotherUser = User::factory()->create(); + $this->anotherUser = User::factory()->create(); $this->anotherUserGroupA = Group::factory()->for($this->anotherUser)->create(); $this->anotherUserGroupB = Group::factory()->for($this->anotherUser)->create(); @@ -1050,7 +1064,7 @@ public function test_get_otp_by_posting_invalid_parameters_returns_validation_er public function test_get_otp_of_another_user_twofaccount_is_forbidden() { $response = $this->actingAs($this->user, 'api-guard') - ->json('GET', '/api/v1/twofaccounts/'.$this->twofaccountC->id.'/otp') + ->json('GET', '/api/v1/twofaccounts/' . $this->twofaccountC->id . '/otp') ->assertForbidden() ->assertJsonStructure([ 'message', diff --git a/tests/Api/v1/Requests/GroupStoreRequestTest.php b/tests/Api/v1/Requests/GroupStoreRequestTest.php index 17f6fa88..af900e42 100644 --- a/tests/Api/v1/Requests/GroupStoreRequestTest.php +++ b/tests/Api/v1/Requests/GroupStoreRequestTest.php @@ -17,6 +17,7 @@ class GroupStoreRequestTest extends FeatureTestCase { use WithoutMiddleware; + /** * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable */ diff --git a/tests/Feature/Http/Auth/LoginTest.php b/tests/Feature/Http/Auth/LoginTest.php index c3139c2b..f123ade5 100644 --- a/tests/Feature/Http/Auth/LoginTest.php +++ b/tests/Feature/Http/Auth/LoginTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Http\Auth; -use App\Facades\Settings; use App\Models\User; use Illuminate\Support\Carbon; use Tests\FeatureTestCase; diff --git a/tests/Feature/Http/Auth/RegisterControllerTest.php b/tests/Feature/Http/Auth/RegisterControllerTest.php index eb8025fe..f0230032 100644 --- a/tests/Feature/Http/Auth/RegisterControllerTest.php +++ b/tests/Feature/Http/Auth/RegisterControllerTest.php @@ -47,8 +47,8 @@ public function test_register_returns_success() ]); $this->assertDatabaseHas('users', [ - 'name' => self::USERNAME, - 'email' => self::EMAIL, + 'name' => self::USERNAME, + 'email' => self::EMAIL, ]); } @@ -75,8 +75,8 @@ public function test_register_with_uppercased_email_returns_success() ]); $this->assertDatabaseHas('users', [ - 'name' => self::USERNAME, - 'email' => self::EMAIL, + 'name' => self::USERNAME, + 'email' => self::EMAIL, ]); } diff --git a/tests/Feature/Http/Auth/UserControllerTest.php b/tests/Feature/Http/Auth/UserControllerTest.php index 2533011a..5edf73ef 100644 --- a/tests/Feature/Http/Auth/UserControllerTest.php +++ b/tests/Feature/Http/Auth/UserControllerTest.php @@ -136,31 +136,31 @@ public function test_delete_user_returns_success() 'password' => self::PASSWORD, ]) ->assertNoContent(); - + $this->assertDatabaseMissing('users', [ - 'id' => $this->user->id + 'id' => $this->user->id, ]); $this->assertDatabaseHas('users', [ - 'id' => $admin->id + 'id' => $admin->id, ]); $this->assertDatabaseCount('users', 1); $this->assertDatabaseMissing('twofaccounts', [ - 'user_id' => $this->user->id + 'user_id' => $this->user->id, ]); $this->assertDatabaseMissing('groups', [ - 'user_id' => $this->user->id + 'user_id' => $this->user->id, ]); $this->assertDatabaseMissing('webauthn_credentials', [ - 'authenticatable_id' => $this->user->id + 'authenticatable_id' => $this->user->id, ]); $this->assertDatabaseMissing('webauthn_recoveries', [ - 'email' => $this->user->email + 'email' => $this->user->email, ]); $this->assertDatabaseMissing('oauth_access_tokens', [ - 'user_id' => $this->user->id + 'user_id' => $this->user->id, ]); $this->assertDatabaseMissing('password_resets', [ - 'email' => $this->user->email + 'email' => $this->user->email, ]); } @@ -182,7 +182,7 @@ public function test_delete_user_in_demo_mode_returns_unauthorized() ]); $this->assertDatabaseHas('users', [ - 'id' => $this->user->id + 'id' => $this->user->id, ]); } @@ -198,7 +198,7 @@ public function test_delete_user_passing_wrong_password_returns_bad_request() ->assertStatus(400); $this->assertDatabaseHas('users', [ - 'id' => $this->user->id + 'id' => $this->user->id, ]); } @@ -222,7 +222,7 @@ public function test_delete_the_only_admin_returns_bad_request() ->assertStatus(400); $this->assertDatabaseHas('users', [ - 'id' => $admin->id + 'id' => $admin->id, ]); } } diff --git a/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php b/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php index 13902737..a4044f23 100644 --- a/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php +++ b/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php @@ -195,8 +195,8 @@ public function test_get_options_for_securelogin_returns_success() ]); $response = $this->json('POST', '/webauthn/login/options', [ - 'email' => $this->user->email, - ]) + 'email' => $this->user->email, + ]) ->assertOk() ->assertJsonStructure([ 'challenge', @@ -237,8 +237,8 @@ public function test_get_options_for_fastlogin_returns_success() ]); $response = $this->json('POST', '/webauthn/login/options', [ - 'email' => $this->user->email, - ]) + 'email' => $this->user->email, + ]) ->assertOk() ->assertJsonStructure([ 'challenge', @@ -262,8 +262,8 @@ public function test_get_options_with_capitalized_email_returns_success() $this->user = User::factory()->create(); $this->json('POST', '/webauthn/login/options', [ - 'email' => strtoupper($this->user->email), - ]) + 'email' => strtoupper($this->user->email), + ]) ->assertOk(); } @@ -273,8 +273,8 @@ public function test_get_options_with_capitalized_email_returns_success() public function test_get_options_with_missing_email_returns_validation_errors() { $this->json('POST', '/webauthn/login/options', [ - 'email' => null, - ]) + 'email' => null, + ]) ->assertStatus(422) ->assertJsonValidationErrors([ 'email', @@ -287,8 +287,8 @@ public function test_get_options_with_missing_email_returns_validation_errors() public function test_get_options_with_invalid_email_returns_validation_errors() { $this->json('POST', '/webauthn/login/options', [ - 'email' => 'invalid', - ]) + 'email' => 'invalid', + ]) ->assertStatus(422) ->assertJsonValidationErrors([ 'email', @@ -301,8 +301,8 @@ public function test_get_options_with_invalid_email_returns_validation_errors() public function test_get_options_with_unknown_email_returns_validation_errors() { $this->json('POST', '/webauthn/login/options', [ - 'email' => 'john@example.com', - ]) + 'email' => 'john@example.com', + ]) ->assertStatus(422) ->assertJsonValidationErrors([ 'email', diff --git a/tests/Feature/Http/Requests/UserStoreRequestTest.php b/tests/Feature/Http/Requests/UserStoreRequestTest.php index 1f9e4ef4..bb735f0b 100644 --- a/tests/Feature/Http/Requests/UserStoreRequestTest.php +++ b/tests/Feature/Http/Requests/UserStoreRequestTest.php @@ -34,7 +34,7 @@ public function test_valid_data(array $data) : void 'name' => 'Jane', 'email' => 'jane@example.com', ]); - + $request = new UserStoreRequest(); $validator = Validator::make($data, $request->rules()); diff --git a/tests/Feature/Http/Requests/UserUpdateRequestTest.php b/tests/Feature/Http/Requests/UserUpdateRequestTest.php index 9095e8a7..22b72226 100644 --- a/tests/Feature/Http/Requests/UserUpdateRequestTest.php +++ b/tests/Feature/Http/Requests/UserUpdateRequestTest.php @@ -39,7 +39,7 @@ public function test_valid_data(array $data) : void 'name' => 'Jane', 'email' => 'jane@example.com', ]); - + $request = new UserUpdateRequest(); $validator = Validator::make($data, $request->rules()); diff --git a/tests/Feature/Http/SystemControllerTest.php b/tests/Feature/Http/SystemControllerTest.php index a0c28615..477c68d7 100644 --- a/tests/Feature/Http/SystemControllerTest.php +++ b/tests/Feature/Http/SystemControllerTest.php @@ -51,7 +51,7 @@ public function test_infos_returns_only_base_collection() 'PHP version', 'Operating system', 'interface', - ] + ], ]) ->assertJsonMissing([ 'user_preferences', @@ -107,7 +107,7 @@ public function test_infos_returns_admin_settings_when_signed_in_as_admin() 'useEncryption', 'lastRadarScan', 'checkForUpdate', - ] + ], ]); } @@ -123,7 +123,7 @@ public function test_infos_returns_proxy_collection_when_signed_in_behind_proxy( 'common' => [ 'Auth proxy header for user', 'Auth proxy header for email', - ] + ], ]); } diff --git a/tests/Feature/Models/TwoFAccountModelTest.php b/tests/Feature/Models/TwoFAccountModelTest.php index 9658c330..8a711dc5 100644 --- a/tests/Feature/Models/TwoFAccountModelTest.php +++ b/tests/Feature/Models/TwoFAccountModelTest.php @@ -19,12 +19,18 @@ class TwoFAccountModelTest extends FeatureTestCase /** * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable */ - protected $user, $anotherUser; + protected $user; + + protected $anotherUser; /** * @var \App\Models\TwoFAccount */ - protected $customTotpTwofaccount, $customHotpTwofaccount, $customSteamTotpTwofaccount; + protected $customTotpTwofaccount; + + protected $customHotpTwofaccount; + + protected $customSteamTotpTwofaccount; /** * Helpers $helpers; diff --git a/tests/Feature/Services/GroupServiceTest.php b/tests/Feature/Services/GroupServiceTest.php index 9f54c748..5be4ee4f 100644 --- a/tests/Feature/Services/GroupServiceTest.php +++ b/tests/Feature/Services/GroupServiceTest.php @@ -52,11 +52,11 @@ public function setUp() : void { parent::setUp(); - $this->user = User::factory()->create(); + $this->user = User::factory()->create(); $this->otherUser = User::factory()->create(); - $this->groupOne = Group::factory()->for($this->user)->create(); - $this->groupTwo = Group::factory()->for($this->user)->create(); + $this->groupOne = Group::factory()->for($this->user)->create(); + $this->groupTwo = Group::factory()->for($this->user)->create(); $this->groupThree = Group::factory()->for($this->otherUser)->create(); Group::factory()->count(2)->for($this->otherUser)->create(); diff --git a/tests/Feature/Services/ReleaseRadarServiceTest.php b/tests/Feature/Services/ReleaseRadarServiceTest.php index 22c3e5dc..1b1a14dd 100644 --- a/tests/Feature/Services/ReleaseRadarServiceTest.php +++ b/tests/Feature/Services/ReleaseRadarServiceTest.php @@ -107,12 +107,12 @@ public function test_scheduleScan_runs_after_one_week() ReleaseRadarService::scheduledScan(); $this->assertDatabaseHas('options', [ - 'key' => 'latestRelease', + 'key' => 'latestRelease', 'value' => HttpRequestTestData::NEW_TAG_NAME, ]); $this->assertDatabaseMissing('options', [ - 'key' => 'lastRadarScan', + 'key' => 'lastRadarScan', 'value' => $time, ]); } @@ -137,12 +137,12 @@ public function test_scheduleScan_does_not_run_before_one_week() ReleaseRadarService::scheduledScan(); $this->assertDatabaseHas('options', [ - 'key' => 'latestRelease', + 'key' => 'latestRelease', 'value' => 'v1', ]); $this->assertDatabaseHas('options', [ - 'key' => 'lastRadarScan', + 'key' => 'lastRadarScan', 'value' => $time, ]); } diff --git a/tests/Feature/Services/TwoFAccountServiceTest.php b/tests/Feature/Services/TwoFAccountServiceTest.php index 59f14cd9..1742dd06 100644 --- a/tests/Feature/Services/TwoFAccountServiceTest.php +++ b/tests/Feature/Services/TwoFAccountServiceTest.php @@ -24,12 +24,16 @@ class TwoFAccountServiceTest extends FeatureTestCase /** * @var \App\Models\TwoFAccount */ - protected $customTotpTwofaccount, $customHotpTwofaccount; + protected $customTotpTwofaccount; + + protected $customHotpTwofaccount; /** * @var \App\Models\Group */ - protected $userGroupA, $userGroupB; + protected $userGroupA; + + protected $userGroupB; /** * @test @@ -37,8 +41,8 @@ class TwoFAccountServiceTest extends FeatureTestCase public function setUp() : void { parent::setUp(); - - $this->user = User::factory()->create(); + + $this->user = User::factory()->create(); $this->userGroupA = Group::factory()->for($this->user)->create(); $this->userGroupB = Group::factory()->for($this->user)->create(); @@ -195,7 +199,7 @@ public function test_migrate_from_gauth_returns_correct_accounts() public function test_migrate_from_gauth_returns_flagged_duplicates() { $this->actingAs($this->user); - + $parameters = [ 'service' => OtpTestData::SERVICE, 'account' => OtpTestData::ACCOUNT, @@ -323,7 +327,7 @@ public function test_delete_single_id() $this->assertDatabaseHas('twofaccounts', [ 'id' => $twofaccount->id, ]); - + TwoFAccounts::delete($twofaccount->id); $this->assertDatabaseMissing('twofaccounts', [ diff --git a/tests/Unit/Api/v1/Controllers/GroupControllerTest.php b/tests/Unit/Api/v1/Controllers/GroupControllerTest.php index bfa79271..f977f93b 100644 --- a/tests/Unit/Api/v1/Controllers/GroupControllerTest.php +++ b/tests/Unit/Api/v1/Controllers/GroupControllerTest.php @@ -27,15 +27,12 @@ class GroupControllerTest extends TestCase */ protected $user; - /** - * - */ public function setUp() : void { parent::setUp(); $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... $this->app['auth']->guard(null)->setUser($this->user); @@ -51,7 +48,7 @@ public function test_index_returns_api_resources() $request = Mockery::mock(Request::class); $groups = Group::factory()->count(3)->make(); $controller = new GroupController(); - + $user->shouldReceive('groups->withCount->get') ->once() ->andReturn($groups); @@ -95,7 +92,7 @@ public function test_store_uses_validated_data_and_returns_api_resource() public function test_show_returns_api_resource() { $controller = Mockery::mock(GroupController::class)->makePartial(); - $group = Group::factory()->make(); + $group = Group::factory()->make(); $response = $controller->show($group); diff --git a/tests/Unit/GroupModelTest.php b/tests/Unit/GroupModelTest.php index fd2eb493..00f617c6 100644 --- a/tests/Unit/GroupModelTest.php +++ b/tests/Unit/GroupModelTest.php @@ -4,7 +4,6 @@ use App\Events\GroupDeleted; use App\Events\GroupDeleting; -use App\Models\User; use App\Models\Group; use App\Models\TwoFAccount; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -29,7 +28,7 @@ public function test_model_configuration() ['id' => 'int', 'twofaccounts_count' => 'integer'], [ 'deleting' => GroupDeleting::class, - 'deleted' => GroupDeleted::class + 'deleted' => GroupDeleted::class, ] ); } @@ -49,7 +48,7 @@ public function test_twofaccounts_relation() */ public function test_user_relation() { - $model = new Group; + $model = new Group; $relation = $model->user(); $this->assertInstanceOf(BelongsTo::class, $relation); diff --git a/tests/Unit/Listeners/ReleaseRadarTest.php b/tests/Unit/Listeners/ReleaseRadarTest.php index 45cb7a19..e2420104 100644 --- a/tests/Unit/Listeners/ReleaseRadarTest.php +++ b/tests/Unit/Listeners/ReleaseRadarTest.php @@ -23,8 +23,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/Listeners/ResetUsersPreferenceTest.php b/tests/Unit/Listeners/ResetUsersPreferenceTest.php index 26e28fce..2a82f3a7 100644 --- a/tests/Unit/Listeners/ResetUsersPreferenceTest.php +++ b/tests/Unit/Listeners/ResetUsersPreferenceTest.php @@ -5,7 +5,6 @@ use App\Events\GroupDeleted; use App\Listeners\ResetUsersPreference; use Illuminate\Support\Facades\Event; -use Mockery\MockInterface; use Tests\TestCase; /** diff --git a/tests/Unit/MigratorTest.php b/tests/Unit/MigratorTest.php index 12e39653..0b8a0172 100644 --- a/tests/Unit/MigratorTest.php +++ b/tests/Unit/MigratorTest.php @@ -7,7 +7,6 @@ use App\Exceptions\UnsupportedMigrationException; use App\Factories\MigratorFactory; use App\Models\TwoFAccount; -use App\Models\User; use App\Services\LogoService; use App\Services\Migrators\AegisMigrator; use App\Services\Migrators\GoogleAuthMigrator; @@ -59,7 +58,9 @@ class MigratorTest extends TestCase /** * App\Models\TwoFAccount $GAuthTotpBisTwofaccount */ - protected $GAuthTotpBisTwofaccount, $fakeTwofaccount; + protected $GAuthTotpBisTwofaccount; + + protected $fakeTwofaccount; public function setUp() : void { @@ -76,7 +77,6 @@ public function setUp() : void 'getIcon' => null, ]); }); - $this->totpTwofaccount = new TwoFAccount; $this->totpTwofaccount->legacy_uri = OtpTestData::TOTP_FULL_CUSTOM_URI_NO_IMG; diff --git a/tests/Unit/TwoFAccountModelTest.php b/tests/Unit/TwoFAccountModelTest.php index cb9566d4..dda1e61d 100644 --- a/tests/Unit/TwoFAccountModelTest.php +++ b/tests/Unit/TwoFAccountModelTest.php @@ -145,7 +145,7 @@ public function test_secret_is_uppercased_and_padded_at_setup() */ 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 9ee0d652..a9fdab43 100644 --- a/tests/Unit/UserModelTest.php +++ b/tests/Unit/UserModelTest.php @@ -23,7 +23,7 @@ public function test_model_configuration() ['*'], [], [ - 'id' => 'int', + 'id' => 'int', 'email_verified_at' => 'datetime', 'is_admin' => 'boolean', 'twofaccounts_count' => 'integer', @@ -49,7 +49,7 @@ public function test_email_is_set_lowercased() */ public function test_twofaccounts_relation() { - $user = new User(); + $user = new User(); $accounts = $user->twofaccounts(); $this->assertHasManyRelation($accounts, $user, new TwoFAccount()); }