mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-03-30 09:56:05 +02:00
Apply Pint fixes
This commit is contained in:
parent
71840b000a
commit
ecd905c36c
@ -28,7 +28,7 @@ public function index(Request $request)
|
||||
Groups::setUser($groups, $request->user());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// We do not use fluent call all over the call chain to ease tests
|
||||
$user = $request->user();
|
||||
$groups = $user->groups()->withCount('twofaccounts')->get();
|
||||
|
@ -151,8 +151,8 @@ public function reorder(TwoFAccountReorderRequest $request)
|
||||
$orderedIds = $request->user()->twofaccounts->sortBy('order_column')->pluck('id');
|
||||
|
||||
return response()->json([
|
||||
'message' => 'order saved',
|
||||
'orderedIds' => $orderedIds
|
||||
'message' => 'order saved',
|
||||
'orderedIds' => $orderedIds,
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2023 Bubka
|
||||
* Copyright (c) 2018 Phan An (https://github.com/koel/koel/blob/master/app/Console/Commands/InitCommand.php)
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
* portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
@ -26,14 +25,10 @@
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Console\ConfirmableTrait;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Illuminate\Database\SQLiteDatabaseDoesNotExistException;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Jackiedo\DotenvEditor\DotenvEditor;
|
||||
use PDOException;
|
||||
use Throwable;
|
||||
|
||||
class Install extends Command
|
||||
@ -64,13 +59,11 @@ class Install extends Command
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @param \Jackiedo\DotenvEditor\DotenvEditor $dotenvEditor
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
protected DotenvEditor $dotenvEditor,
|
||||
)
|
||||
{
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@ -115,7 +108,7 @@ public function handle()
|
||||
$this->newLine();
|
||||
$this->components->error($e->getMessage());
|
||||
$this->components->info('See the error log at storage/logs/laravel.log for the full stack trace.');
|
||||
|
||||
|
||||
$this->newLine();
|
||||
$this->line('Fix the error and rerun the \'2fauth:install\' command to complete installation.');
|
||||
$this->newLine();
|
||||
@ -201,7 +194,6 @@ protected function setMainEnvVars() : void
|
||||
$this->dotenvEditor->setKey('APP_URL', $appUrl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prompt user for valid database credentials and set them to .env file.
|
||||
*/
|
||||
@ -232,7 +224,7 @@ protected function setDbEnvVars() : void
|
||||
|
||||
$config['DB_DATABASE'] = $this->ask('Absolute path to the DB file', $databasePath);
|
||||
} else {
|
||||
$defaultName = $this->dotenvEditor->getValue('DB_DATABASE') ?: '2fauth';
|
||||
$defaultName = $this->dotenvEditor->getValue('DB_DATABASE') ?: '2fauth';
|
||||
$databaseName = $this->dotenvEditor->getValue('DB_CONNECTION') == 'sqlite'
|
||||
? '2fauth'
|
||||
: $defaultName;
|
||||
@ -250,7 +242,7 @@ protected function setDbEnvVars() : void
|
||||
|
||||
// Set the config so that the next DB attempt uses refreshed credentials
|
||||
config([
|
||||
'database.default' => $config['DB_CONNECTION'],
|
||||
'database.default' => $config['DB_CONNECTION'],
|
||||
'database.connections.' . $config['DB_CONNECTION'] . '.database' => $config['DB_DATABASE'],
|
||||
'database.connections.' . $config['DB_CONNECTION'] . '.host' => $config['DB_HOST'],
|
||||
'database.connections.' . $config['DB_CONNECTION'] . '.port' => $config['DB_PORT'],
|
||||
@ -299,7 +291,7 @@ protected function loadEnvFile() : void
|
||||
}
|
||||
|
||||
$this->components->task('Preparing .env file', static function () : void {
|
||||
if (!file_exists(base_path('.env'))) {
|
||||
if (! file_exists(base_path('.env'))) {
|
||||
copy(base_path('.env.example'), base_path('.env'));
|
||||
}
|
||||
});
|
||||
@ -315,7 +307,7 @@ protected function maybeGenerateAppKey() : void
|
||||
$key = config('app.key');
|
||||
|
||||
$this->components->task($key ? 'Retrieving app key' : 'Generating app key', function () use (&$key) : void {
|
||||
if (!$key) {
|
||||
if (! $key) {
|
||||
// Generate the key manually to prevent some clashes with `php artisan key:generate`
|
||||
$key = $this->generateRandomKey();
|
||||
$this->dotenvEditor->setKey('APP_KEY', $key);
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Models\TwoFAccount;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
@ -31,7 +30,7 @@ class FixOrphanAccounts extends Command
|
||||
* @var bool
|
||||
*/
|
||||
protected $hidden = true;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
@ -50,12 +49,12 @@ public function __construct()
|
||||
public function handle()
|
||||
{
|
||||
$twofaccounts = TwoFAccount::where('otp_type', '')
|
||||
->where('secret', '')
|
||||
->where('algorithm', '')
|
||||
->where('digits', 0)
|
||||
->whereNull('period')
|
||||
->whereNull('counter')
|
||||
->get();
|
||||
->where('secret', '')
|
||||
->where('algorithm', '')
|
||||
->where('digits', 0)
|
||||
->whereNull('period')
|
||||
->whereNull('counter')
|
||||
->get();
|
||||
|
||||
$this->line(sprintf('%d inconsistent accounts found', $twofaccounts->count()));
|
||||
|
||||
|
@ -58,12 +58,12 @@ public function handle()
|
||||
}
|
||||
|
||||
$twofaccounts = TwoFAccount::where('otp_type', '')
|
||||
->where('secret', '')
|
||||
->where('algorithm', '')
|
||||
->where('digits', 0)
|
||||
->whereNull('period')
|
||||
->whereNull('counter')
|
||||
->get();
|
||||
->where('secret', '')
|
||||
->where('algorithm', '')
|
||||
->where('digits', 0)
|
||||
->whereNull('period')
|
||||
->whereNull('counter')
|
||||
->get();
|
||||
|
||||
$this->line(sprintf('%d inconsistent accounts found', $twofaccounts->count()));
|
||||
|
||||
|
@ -13,7 +13,7 @@ class WebauthnCredentialBroker extends PasswordBroker
|
||||
/**
|
||||
* Send a password reset link to a user.
|
||||
*/
|
||||
public function sendResetLink(array $credentials, Closure $callback = null) : string
|
||||
public function sendResetLink(array $credentials, ?Closure $callback = null) : string
|
||||
{
|
||||
/**
|
||||
* @var \App\Models\User
|
||||
|
@ -16,7 +16,6 @@ public static function cleanVersionNumber(?string $release) : string|false
|
||||
/**
|
||||
* Format a string to comply with Base32 format
|
||||
*
|
||||
* @param string $str
|
||||
* @return string The filename
|
||||
*/
|
||||
public static function PadToBase32Format(?string $str) : string
|
||||
|
@ -15,7 +15,7 @@ class SocialiteController extends Controller
|
||||
{
|
||||
/**
|
||||
* Redirect to the provider's authentication url
|
||||
*
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function redirect(Request $request, string $driver)
|
||||
@ -31,7 +31,7 @@ public function redirect(Request $request, string $driver)
|
||||
|
||||
/**
|
||||
* Register (if needed) the user and authenticate him
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function callback(Request $request, string $driver)
|
||||
@ -42,7 +42,7 @@ public function callback(Request $request, string $driver)
|
||||
return redirect('/error?err=sso_failed');
|
||||
}
|
||||
|
||||
$uniqueName = $socialiteUser->getId() . '@' . $driver;
|
||||
$uniqueName = $socialiteUser->getId() . '@' . $driver;
|
||||
$socialiteEmail = $socialiteUser->getEmail() ?? $uniqueName;
|
||||
$socialiteName = ($socialiteUser->getNickname() ?? $socialiteUser->getName()) . ' (' . $uniqueName . ')';
|
||||
|
||||
@ -55,11 +55,9 @@ public function callback(Request $request, string $driver)
|
||||
if (! $user->exists) {
|
||||
if (User::where('email', $socialiteEmail)->exists()) {
|
||||
return redirect('/error?err=sso_email_already_used');
|
||||
}
|
||||
else if (User::count() === 0) {
|
||||
} elseif (User::count() === 0) {
|
||||
$user->is_admin = true;
|
||||
}
|
||||
else if (Settings::get('disableRegistration')) {
|
||||
} elseif (Settings::get('disableRegistration')) {
|
||||
return redirect('/error?err=sso_no_register');
|
||||
}
|
||||
$user->password = bcrypt(Str::random());
|
||||
|
@ -41,7 +41,7 @@ public function index()
|
||||
'openid' => $openidAuth,
|
||||
'github' => $githubAuth,
|
||||
],
|
||||
'subdirectory' => $subdir,
|
||||
'subdirectory' => $subdir,
|
||||
])->toJson(),
|
||||
'defaultPreferences' => $defaultPreferences,
|
||||
'subdirectory' => $subdir,
|
||||
|
@ -55,7 +55,7 @@ class Kernel extends HttpKernel
|
||||
],
|
||||
|
||||
'api.v1' => [
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class . ':api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\App\Http\Middleware\KickOutInactiveUser::class,
|
||||
\App\Http\Middleware\LogUserLastSeen::class,
|
||||
|
@ -94,24 +94,24 @@ public function twofaccounts()
|
||||
return $this->hasMany(\App\Models\TwoFAccount::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that owns the group.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\User, \App\Models\Group>
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class);
|
||||
}
|
||||
/**
|
||||
* Get the user that owns the group.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\User, \App\Models\Group>
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include orphan (userless) groups.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder<User> $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder<User>
|
||||
*/
|
||||
public function scopeOrphans($query)
|
||||
{
|
||||
return $query->where('user_id', null);
|
||||
}
|
||||
/**
|
||||
* Scope a query to only include orphan (userless) groups.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder<User> $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder<User>
|
||||
*/
|
||||
public function scopeOrphans($query)
|
||||
{
|
||||
return $query->where('user_id', null);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@
|
||||
*/
|
||||
class TwoFAccount extends Model implements Sortable
|
||||
{
|
||||
use SortableTrait, HasFactory;
|
||||
use HasFactory, SortableTrait;
|
||||
|
||||
const TOTP = 'totp';
|
||||
|
||||
@ -634,7 +634,7 @@ public function setIcon($data, $extension = null) : void
|
||||
* @param string $extension The file extension, without the dot
|
||||
* @return string|null The filename of the stored icon or null if the operation fails
|
||||
*/
|
||||
private function storeFileDataAsIcon($content, $extension) : string|null
|
||||
private function storeFileDataAsIcon($content, $extension) : ?string
|
||||
{
|
||||
$filename = self::getUniqueFilename($extension);
|
||||
|
||||
@ -684,7 +684,7 @@ private function isValidIcon($filename, $disk) : bool
|
||||
*
|
||||
* @return string|null The filename of the stored icon or null if the operation fails
|
||||
*/
|
||||
private function storeRemoteImageAsIcon(string $url) : string|null
|
||||
private function storeRemoteImageAsIcon(string $url) : ?string
|
||||
{
|
||||
try {
|
||||
$path_parts = pathinfo($url);
|
||||
|
@ -40,8 +40,8 @@
|
||||
*/
|
||||
class User extends Authenticatable implements WebAuthnAuthenticatable
|
||||
{
|
||||
use WebAuthnAuthentication, WebAuthnManageCredentials;
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
use WebAuthnAuthentication, WebAuthnManageCredentials;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@ -49,7 +49,7 @@ class User extends Authenticatable implements WebAuthnAuthenticatable
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'oauth_id', 'oauth_provider'
|
||||
'name', 'email', 'password', 'oauth_id', 'oauth_provider',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -8,9 +8,9 @@
|
||||
use App\Events\TwoFAccountDeleted;
|
||||
use App\Listeners\CleanIconStorage;
|
||||
use App\Listeners\DissociateTwofaccountFromGroup;
|
||||
use App\Listeners\RegisterOpenId;
|
||||
use App\Listeners\ReleaseRadar;
|
||||
use App\Listeners\ResetUsersPreference;
|
||||
use App\Listeners\RegisterOpenId;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
@ -14,8 +14,6 @@ class MigrationServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() : void
|
||||
{
|
||||
|
@ -3,10 +3,8 @@
|
||||
namespace App\Providers\Socialite;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use InvalidArgumentException;
|
||||
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
|
||||
use SocialiteProviders\Manager\OAuth2\User;
|
||||
use SocialiteProviders\Manager\SocialiteWasCalled;
|
||||
|
||||
class OpenId extends AbstractProvider
|
||||
{
|
||||
@ -48,7 +46,7 @@ protected function getUserByToken($token)
|
||||
{
|
||||
$response = $this->getHttpClient()->get($this->getConfig('userinfo_url'), [
|
||||
RequestOptions::HEADERS => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
],
|
||||
]);
|
||||
|
||||
|
@ -12,7 +12,7 @@ class IsBase32Encoded implements ValidationRule
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
public function validate(string $attribute, mixed $value, Closure $fail) : void
|
||||
{
|
||||
try {
|
||||
$secret = Base32::decodeUpper(Helpers::PadToBase32Format($value));
|
||||
|
@ -19,7 +19,7 @@ class GroupService
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public static function assign($ids, User $user, Group $group = null) : void
|
||||
public static function assign($ids, User $user, ?Group $group = null) : void
|
||||
{
|
||||
if (! $group) {
|
||||
$group = self::defaultGroup($user);
|
||||
@ -62,9 +62,8 @@ public static function prependTheAllGroup(Collection $groups, User $user) : Coll
|
||||
|
||||
/**
|
||||
* Set owner of given groups
|
||||
*
|
||||
*
|
||||
* @param Collection<int, Group> $groups
|
||||
* @param \App\Models\User $user
|
||||
*/
|
||||
public static function setUser(Collection $groups, User $user) : void
|
||||
{
|
||||
|
@ -41,8 +41,8 @@ protected static function newRelease() : string|null|false
|
||||
|
||||
if ($latestRelease) {
|
||||
$latestReleaseData = json_decode($latestRelease);
|
||||
$githubVersion = Helpers::cleanVersionNumber($latestReleaseData->tag_name);
|
||||
$installedVersion = Helpers::cleanVersionNumber(config('2fauth.version'));
|
||||
$githubVersion = Helpers::cleanVersionNumber($latestReleaseData->tag_name);
|
||||
$installedVersion = Helpers::cleanVersionNumber(config('2fauth.version'));
|
||||
|
||||
if ($githubVersion && $installedVersion) {
|
||||
if (version_compare($githubVersion, $installedVersion) > 0 && $latestReleaseData->prerelease == false && $latestReleaseData->draft == false) {
|
||||
@ -63,7 +63,7 @@ protected static function newRelease() : string|null|false
|
||||
/**
|
||||
* Fetch releases on Github
|
||||
*/
|
||||
protected static function getLatestReleaseData() : string|null
|
||||
protected static function getLatestReleaseData() : ?string
|
||||
{
|
||||
$url = config('2fauth.latestReleaseUrl');
|
||||
|
||||
|
@ -215,6 +215,7 @@ private function updateRecords(bool $encrypted) : bool
|
||||
$item->secret = $encrypted ? Crypt::encryptString($item->secret) : Crypt::decryptString($item->secret);
|
||||
} catch (Exception $ex) {
|
||||
$success = false;
|
||||
|
||||
// Exit the each iteration
|
||||
return false;
|
||||
}
|
||||
|
@ -40,9 +40,9 @@ public static function withdraw($ids) : void
|
||||
$ids = is_array($ids) ? $ids : func_get_args();
|
||||
|
||||
TwoFAccount::whereIn('id', $ids)
|
||||
->update(
|
||||
['group_id' => null]
|
||||
);
|
||||
->update(
|
||||
['group_id' => null]
|
||||
);
|
||||
|
||||
Log::info(sprintf('TwoFAccounts IDs #%s withdrawn', implode(',', $ids)));
|
||||
}
|
||||
@ -96,9 +96,8 @@ public static function delete($ids) : int
|
||||
|
||||
/**
|
||||
* Set owner of given twofaccounts
|
||||
*
|
||||
*
|
||||
* @param \Illuminate\Support\Collection<int, TwoFAccount> $twofaccounts
|
||||
* @param \App\Models\User $user
|
||||
*/
|
||||
public static function setUser(Collection $twofaccounts, User $user) : void
|
||||
{
|
||||
|
@ -44,10 +44,10 @@ public function test_show_existing_user_when_authenticated_returns_success()
|
||||
->json('GET', '/api/v1/user')
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'name' => $this->user->name,
|
||||
'id' => $this->user->id,
|
||||
'email' => $this->user->email,
|
||||
'is_admin' => $this->user->is_admin,
|
||||
'name' => $this->user->name,
|
||||
'id' => $this->user->id,
|
||||
'email' => $this->user->email,
|
||||
'is_admin' => $this->user->is_admin,
|
||||
])
|
||||
->assertJsonStructure([
|
||||
'preferences',
|
||||
|
@ -444,7 +444,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',
|
||||
|
@ -18,11 +18,11 @@
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\Classes\LocalFile;
|
||||
use Tests\Data\MigrationTestData;
|
||||
use Tests\Data\OtpTestData;
|
||||
use Tests\FeatureTestCase;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
|
||||
/**
|
||||
* TwoFAccountControllerTest test class
|
||||
@ -1016,7 +1016,7 @@ public function test_export_missing_twofaccount_returns_existing_ones_only()
|
||||
public function test_export_twofaccount_of_another_user_is_forbidden()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api-guard')
|
||||
->json('GET', '/api/v1/twofaccounts/export?ids=' . $this->twofaccountC->id)
|
||||
->json('GET', '/api/v1/twofaccounts/export?ids=' . $this->twofaccountC->id)
|
||||
->assertForbidden()
|
||||
->assertJsonStructure([
|
||||
'message',
|
||||
@ -1296,7 +1296,7 @@ public function test_destroy_missing_twofaccount_returns_not_found()
|
||||
public function test_destroy_twofaccount_of_another_user_is_forbidden()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api-guard')
|
||||
->json('DELETE', '/api/v1/twofaccounts/' . $this->twofaccountC->id)
|
||||
->json('DELETE', '/api/v1/twofaccounts/' . $this->twofaccountC->id)
|
||||
->assertForbidden()
|
||||
->assertJsonStructure([
|
||||
'message',
|
||||
@ -1346,7 +1346,7 @@ public function test_batch_destroy_twofaccount_of_another_user_is_forbidden()
|
||||
->implode(',');
|
||||
|
||||
$response = $this->actingAs($this->user, 'api-guard')
|
||||
->json('DELETE', '/api/v1/twofaccounts?ids=' . $ids)
|
||||
->json('DELETE', '/api/v1/twofaccounts?ids=' . $ids)
|
||||
->assertForbidden()
|
||||
->assertJsonStructure([
|
||||
'message',
|
||||
|
@ -13,8 +13,8 @@ class ResetDemoTest extends FeatureTestCase
|
||||
public function test_reset_demo_without_demo_mode_succeeded()
|
||||
{
|
||||
$this->artisan('2fauth:reset-demo')
|
||||
->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On')
|
||||
->assertSuccessful();
|
||||
->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,9 +25,9 @@ public function test_reset_demo_succeeded()
|
||||
Config::set('2fauth.config.isDemoApp', true);
|
||||
|
||||
$this->artisan('2fauth:reset-demo')
|
||||
->expectsOutput('This will reset the app in order to run a clean and fresh demo.')
|
||||
->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'demo')
|
||||
->assertSuccessful();
|
||||
->expectsOutput('This will reset the app in order to run a clean and fresh demo.')
|
||||
->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'demo')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseCount('twofaccounts', 9);
|
||||
|
||||
@ -140,9 +140,9 @@ public function test_reset_demo_with_invalid_confirmation_succeeded()
|
||||
Config::set('2fauth.config.isDemoApp', true);
|
||||
|
||||
$this->artisan('2fauth:reset-demo')
|
||||
->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'null')
|
||||
->expectsOutput('Bad confirmation word, nothing appened')
|
||||
->assertSuccessful();
|
||||
->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'null')
|
||||
->expectsOutput('Bad confirmation word, nothing appened')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,8 +13,8 @@ class ResetTestingTest extends FeatureTestCase
|
||||
public function test_reset_testing_without_testing_mode_succeeded()
|
||||
{
|
||||
$this->artisan('2fauth:reset-testing')
|
||||
->expectsOutput('2fauth:reset-testing can only run when isTestingApp option is On')
|
||||
->assertSuccessful();
|
||||
->expectsOutput('2fauth:reset-testing can only run when isTestingApp option is On')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,9 +25,9 @@ public function test_reset_testing_succeeded()
|
||||
Config::set('2fauth.config.isTestingApp', true);
|
||||
|
||||
$this->artisan('2fauth:reset-testing')
|
||||
->expectsOutput('This will reset the app in order to run a clean and fresh testing app.')
|
||||
->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'testing')
|
||||
->assertSuccessful();
|
||||
->expectsOutput('This will reset the app in order to run a clean and fresh testing app.')
|
||||
->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'testing')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseCount('twofaccounts', 9);
|
||||
|
||||
@ -140,9 +140,9 @@ public function test_reset_testing_with_invalid_confirmation_succeeded()
|
||||
Config::set('2fauth.config.isTestingApp', true);
|
||||
|
||||
$this->artisan('2fauth:reset-testing')
|
||||
->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'null')
|
||||
->expectsOutput('Bad confirmation word, nothing appened')
|
||||
->assertSuccessful();
|
||||
->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'null')
|
||||
->expectsOutput('Bad confirmation word, nothing appened')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,6 +153,6 @@ public function test_reset_testing_with_no_confirm_option_succeeded()
|
||||
Config::set('2fauth.config.isTestingApp', true);
|
||||
|
||||
$this->artisan('2fauth:reset-testing --no-confirm')
|
||||
->assertSuccessful();
|
||||
->assertSuccessful();
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public function test_too_many_login_attempts_with_invalid_credentials_returns_to
|
||||
->assertUnauthorized();
|
||||
|
||||
$this->json('POST', '/user/login', $post)
|
||||
->assertStatus(429);
|
||||
->assertStatus(429);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,6 +145,6 @@ public function test_register_is_forbidden_when_registration_is_disabled()
|
||||
'password' => self::PASSWORD,
|
||||
'password_confirmation' => self::PASSWORD,
|
||||
])
|
||||
->assertStatus(403);
|
||||
->assertStatus(403);
|
||||
}
|
||||
}
|
||||
|
@ -53,14 +53,13 @@ public function setUp() : void
|
||||
'oauth_provider' => self::USER_OAUTH_PROVIDER,
|
||||
]);
|
||||
|
||||
|
||||
$this->socialiteUser = new \Laravel\Socialite\Two\User;
|
||||
$this->socialiteUser->id = self::USER_OAUTH_ID;
|
||||
$this->socialiteUser->name = self::USER_NAME;
|
||||
$this->socialiteUser->email = self::USER_EMAIL;
|
||||
$this->socialiteUser = new \Laravel\Socialite\Two\User;
|
||||
$this->socialiteUser->id = self::USER_OAUTH_ID;
|
||||
$this->socialiteUser->name = self::USER_NAME;
|
||||
$this->socialiteUser->email = self::USER_EMAIL;
|
||||
$this->socialiteUser->nickname = self::USER_NICKNAME;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
@ -116,9 +115,9 @@ public function test_callback_redirects_authenticated_user_to_accounts()
|
||||
*/
|
||||
public function test_callback_updates_user_informations()
|
||||
{
|
||||
$socialiteUpdatedUser = new \Laravel\Socialite\Two\User;
|
||||
$socialiteUpdatedUser->id = self::USER_OAUTH_ID;
|
||||
$socialiteUpdatedUser->email = 'new_email';
|
||||
$socialiteUpdatedUser = new \Laravel\Socialite\Two\User;
|
||||
$socialiteUpdatedUser->id = self::USER_OAUTH_ID;
|
||||
$socialiteUpdatedUser->email = 'new_email';
|
||||
$socialiteUpdatedUser->nickname = 'new_nickname';
|
||||
|
||||
Socialite::shouldReceive('driver->user')
|
||||
@ -138,9 +137,9 @@ public function test_callback_updates_user_informations()
|
||||
*/
|
||||
public function test_callback_updates_username_with_fallback_value()
|
||||
{
|
||||
$socialiteUpdatedUser = new \Laravel\Socialite\Two\User;
|
||||
$socialiteUpdatedUser->id = self::USER_OAUTH_ID;
|
||||
$socialiteUpdatedUser->name = 'new_name';
|
||||
$socialiteUpdatedUser = new \Laravel\Socialite\Two\User;
|
||||
$socialiteUpdatedUser->id = self::USER_OAUTH_ID;
|
||||
$socialiteUpdatedUser->name = 'new_name';
|
||||
$socialiteUpdatedUser->email = 'new_email';
|
||||
|
||||
Socialite::shouldReceive('driver->user')
|
||||
@ -160,9 +159,9 @@ public function test_callback_updates_username_with_fallback_value()
|
||||
*/
|
||||
public function test_callback_registers_new_user()
|
||||
{
|
||||
$newSocialiteUser = new \Laravel\Socialite\Two\User;
|
||||
$newSocialiteUser->id = 'new_id';
|
||||
$newSocialiteUser->name = 'jane';
|
||||
$newSocialiteUser = new \Laravel\Socialite\Two\User;
|
||||
$newSocialiteUser->id = 'new_id';
|
||||
$newSocialiteUser->name = 'jane';
|
||||
$newSocialiteUser->email = 'jane@provider.com';
|
||||
|
||||
Socialite::shouldReceive('driver->user')
|
||||
@ -183,10 +182,10 @@ public function test_callback_registers_new_user()
|
||||
*/
|
||||
public function test_callback_registers_new_user_with_existing_name()
|
||||
{
|
||||
$socialiteUserWithSameName = new \Laravel\Socialite\Two\User;
|
||||
$socialiteUserWithSameName->id = 'socialiteUserWithSameNameId';
|
||||
$socialiteUserWithSameName->name = self::USER_NAME;
|
||||
$socialiteUserWithSameName->email = 'socialiteuserwithsamename@example.com';
|
||||
$socialiteUserWithSameName = new \Laravel\Socialite\Two\User;
|
||||
$socialiteUserWithSameName->id = 'socialiteUserWithSameNameId';
|
||||
$socialiteUserWithSameName->name = self::USER_NAME;
|
||||
$socialiteUserWithSameName->email = 'socialiteuserwithsamename@example.com';
|
||||
$socialiteUserWithSameName->nickname = self::USER_NICKNAME;
|
||||
|
||||
Socialite::shouldReceive('driver->user')
|
||||
@ -233,10 +232,10 @@ public function test_callback_returns_error_when_email_is_already_used()
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$socialiteUserWithSameEmail = new \Laravel\Socialite\Two\User;
|
||||
$socialiteUserWithSameEmail->id = '666';
|
||||
$socialiteUserWithSameEmail->name = 'socialiteUserWithSameEmail';
|
||||
$socialiteUserWithSameEmail->email = 'other@example.com';
|
||||
$socialiteUserWithSameEmail = new \Laravel\Socialite\Two\User;
|
||||
$socialiteUserWithSameEmail->id = '666';
|
||||
$socialiteUserWithSameEmail->name = 'socialiteUserWithSameEmail';
|
||||
$socialiteUserWithSameEmail->email = 'other@example.com';
|
||||
$socialiteUserWithSameEmail->nickname = self::USER_NICKNAME;
|
||||
|
||||
Socialite::shouldReceive('driver->user')
|
||||
@ -258,9 +257,9 @@ public function test_callback_returns_error_when_registrations_are_closed()
|
||||
{
|
||||
Settings::set('disableRegistration', true);
|
||||
|
||||
$newSocialiteUser = new \Laravel\Socialite\Two\User;
|
||||
$newSocialiteUser->id = 'rejected_id';
|
||||
$newSocialiteUser->name = 'jane';
|
||||
$newSocialiteUser = new \Laravel\Socialite\Two\User;
|
||||
$newSocialiteUser->id = 'rejected_id';
|
||||
$newSocialiteUser->name = 'jane';
|
||||
$newSocialiteUser->email = 'jane@provider.com';
|
||||
|
||||
Socialite::shouldReceive('driver->user')
|
||||
@ -278,9 +277,9 @@ public function test_callback_skips_registration_when_registrations_are_closed()
|
||||
{
|
||||
Settings::set('disableRegistration', true);
|
||||
|
||||
$newSocialiteUser = new \Laravel\Socialite\Two\User;
|
||||
$newSocialiteUser->id = 'rejected_id';
|
||||
$newSocialiteUser->name = 'jane';
|
||||
$newSocialiteUser = new \Laravel\Socialite\Two\User;
|
||||
$newSocialiteUser->id = 'rejected_id';
|
||||
$newSocialiteUser->name = 'jane';
|
||||
$newSocialiteUser->email = 'jane@provider.com';
|
||||
|
||||
Socialite::shouldReceive('driver->user')
|
||||
@ -293,5 +292,4 @@ public function test_callback_skips_registration_when_registrations_are_closed()
|
||||
'oauth_provider' => self::USER_OAUTH_PROVIDER,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ public function test_too_many_invalid_login_attempts_returns_too_many_request_er
|
||||
->assertUnauthorized();
|
||||
|
||||
$this->json('POST', '/webauthn/login', self::ASSERTION_RESPONSE_INVALID)
|
||||
->assertStatus(429);
|
||||
->assertStatus(429);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,8 +24,8 @@ class UserDeleteRequestTest extends FeatureTestCase
|
||||
public function test_user_is_authorized()
|
||||
{
|
||||
Auth::shouldReceive('check')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
->once()
|
||||
->andReturn(true);
|
||||
|
||||
$request = new UserDeleteRequest();
|
||||
|
||||
|
@ -24,8 +24,8 @@ class UserPatchPwdRequestTest extends TestCase
|
||||
public function test_user_is_authorized()
|
||||
{
|
||||
Auth::shouldReceive('check')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
->once()
|
||||
->andReturn(true);
|
||||
|
||||
$request = new UserPatchPwdRequest();
|
||||
|
||||
|
@ -26,8 +26,8 @@ class UserUpdateRequestTest extends FeatureTestCase
|
||||
public function test_user_is_authorized()
|
||||
{
|
||||
Auth::shouldReceive('check')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
->once()
|
||||
->andReturn(true);
|
||||
|
||||
$request = new UserUpdateRequest();
|
||||
|
||||
|
@ -24,8 +24,8 @@ class WebauthnRenameRequestTest extends TestCase
|
||||
public function test_user_is_authorized()
|
||||
{
|
||||
Auth::shouldReceive('check')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
->once()
|
||||
->andReturn(true);
|
||||
|
||||
$request = new WebauthnRenameRequest();
|
||||
|
||||
|
@ -373,7 +373,7 @@ public function test_isEdited_returns_false()
|
||||
public function test_cache_is_requested_at_instanciation()
|
||||
{
|
||||
Cache::shouldReceive('remember')
|
||||
->andReturn(collect([]));
|
||||
->andReturn(collect([]));
|
||||
|
||||
$settingService = new SettingService();
|
||||
|
||||
@ -386,7 +386,7 @@ public function test_cache_is_requested_at_instanciation()
|
||||
public function test_cache_is_updated_when_setting_is_set()
|
||||
{
|
||||
Cache::shouldReceive('remember', 'put')
|
||||
->andReturn(collect([]), true);
|
||||
->andReturn(collect([]), true);
|
||||
|
||||
$settingService = new SettingService();
|
||||
$settingService->set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
|
||||
@ -400,7 +400,7 @@ public function test_cache_is_updated_when_setting_is_set()
|
||||
public function test_cache_is_updated_when_setting_is_deleted()
|
||||
{
|
||||
Cache::shouldReceive('remember', 'put')
|
||||
->andReturn(collect([]), true);
|
||||
->andReturn(collect([]), true);
|
||||
|
||||
$settingService = new SettingService();
|
||||
$settingService->delete(self::SETTING_NAME);
|
||||
|
@ -79,7 +79,7 @@ protected function runConfigurationAssertions(
|
||||
* - `getForeignKey()`: any `HasOneOrMany` or `BelongsTo` relation, but key type differs (see documentaiton).
|
||||
* - `getQualifiedParentKeyName()`: in case of `HasOneOrMany` relation, there is no `getLocalKey()` method, so this one should be asserted.
|
||||
*/
|
||||
protected function assertHasManyRelation($relation, Model $model, Model $related, $key = null, $parent = null, \Closure $queryCheck = null)
|
||||
protected function assertHasManyRelation($relation, Model $model, Model $related, $key = null, $parent = null, ?\Closure $queryCheck = null)
|
||||
{
|
||||
$this->assertInstanceOf(HasMany::class, $relation);
|
||||
|
||||
@ -111,7 +111,7 @@ protected function assertHasManyRelation($relation, Model $model, Model $related
|
||||
* - `getForeignKey()`: any `HasOneOrMany` or `BelongsTo` relation, but key type differs (see documentaiton).
|
||||
* - `getOwnerKey()`: `BelongsTo` relation and its extendings.
|
||||
*/
|
||||
protected function assertBelongsToRelation($relation, Model $model, Model $related, $key, $owner = null, \Closure $queryCheck = null)
|
||||
protected function assertBelongsToRelation($relation, Model $model, Model $related, $key, $owner = null, ?\Closure $queryCheck = null)
|
||||
{
|
||||
$this->assertInstanceOf(BelongsTo::class, $relation);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user