mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-01-27 00:28:45 +01:00
Apply Laravel Pint fixes
This commit is contained in:
parent
80723d94ba
commit
dce3d16c37
@ -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()));
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public function handle(ScanForNewReleaseCalled $event)
|
||||
{
|
||||
$releaseRadarService = app()->make(ReleaseRadarService::class);
|
||||
$releaseRadarService::scheduledScan();
|
||||
|
||||
|
||||
Log::info('Scheduled release scan complete');
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<User> $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder<User>
|
||||
*/
|
||||
public function scopeAdmins($query)
|
||||
{
|
||||
return $query->where('is_admin', true);
|
||||
}
|
||||
* Scope a query to only include admin users.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder<User> $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder<User>
|
||||
*/
|
||||
public function scopeAdmins($query)
|
||||
{
|
||||
return $query->where('is_admin', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the password reset notification.
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
@ -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',
|
||||
|
@ -17,9 +17,6 @@ class IconControllerTest extends FeatureTestCase
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
@ -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([
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
|
@ -17,6 +17,7 @@
|
||||
class GroupStoreRequestTest extends FeatureTestCase
|
||||
{
|
||||
use WithoutMiddleware;
|
||||
|
||||
/**
|
||||
* @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable
|
||||
*/
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Tests\Feature\Http\Auth;
|
||||
|
||||
use App\Facades\Settings;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\FeatureTestCase;
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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',
|
||||
]
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
@ -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', [
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
use App\Events\GroupDeleted;
|
||||
use App\Listeners\ResetUsersPreference;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Mockery\MockInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user