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