mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 00:03:09 +01:00
Fix pint issues
This commit is contained in:
parent
6158c6940b
commit
fee7a684b2
@ -34,8 +34,8 @@ public function upload(Request $request)
|
|||||||
$name = Helpers::getRandomFilename($icon->extension());
|
$name = Helpers::getRandomFilename($icon->extension());
|
||||||
$isStored = IconStore::store($name, $content);
|
$isStored = IconStore::store($name, $content);
|
||||||
}
|
}
|
||||||
|
} catch (Exception) {
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $isStored
|
return $isStored
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
* @property int|null $period
|
* @property int|null $period
|
||||||
* @property int|null $counter
|
* @property int|null $counter
|
||||||
* @property string $legacy_uri
|
* @property string $legacy_uri
|
||||||
|
*
|
||||||
* @method string getURI()
|
* @method string getURI()
|
||||||
*/
|
*/
|
||||||
class TwoFAccountExportResource extends JsonResource
|
class TwoFAccountExportResource extends JsonResource
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
/**
|
/**
|
||||||
* @property mixed $id
|
* @property mixed $id
|
||||||
* @property mixed $group_id
|
* @property mixed $group_id
|
||||||
*
|
*
|
||||||
* @method App\Models\Dto\TotpDto|App\Models\Dto\HotpDto getOtp(int $time)
|
* @method App\Models\Dto\TotpDto|App\Models\Dto\HotpDto getOtp(int $time)
|
||||||
*/
|
*/
|
||||||
class TwoFAccountReadResource extends TwoFAccountStoreResource
|
class TwoFAccountReadResource extends TwoFAccountStoreResource
|
||||||
|
@ -48,7 +48,7 @@ public function __construct()
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$this->callSilently('config:clear');
|
$this->callSilently('config:clear');
|
||||||
|
|
||||||
if (! config('2fauth.config.isTestingApp') && ! $this->option('force')) {
|
if (! config('2fauth.config.isTestingApp') && ! $this->option('force')) {
|
||||||
$this->comment('2fauth:reset-testing can only run when isTestingApp option is On');
|
$this->comment('2fauth:reset-testing can only run when isTestingApp option is On');
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public function __construct()
|
|||||||
public function handle(TwoFAccountDeleted $event)
|
public function handle(TwoFAccountDeleted $event)
|
||||||
{
|
{
|
||||||
IconStore::delete($event->twofaccount->icon ?? []);
|
IconStore::delete($event->twofaccount->icon ?? []);
|
||||||
|
|
||||||
Log::info(sprintf('Icon cleaned for deleted TwoFAccount #%d', $event->twofaccount->id));
|
Log::info(sprintf('Icon cleaned for deleted TwoFAccount #%d', $event->twofaccount->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,12 @@ class ToggleIconReplicationToDatabase
|
|||||||
/**
|
/**
|
||||||
* Create the event listener.
|
* Create the event listener.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the event.
|
* Handle the event.
|
||||||
*/
|
*/
|
||||||
public function handle(storeIconsInDatabaseSettingChanged $event): void
|
public function handle(storeIconsInDatabaseSettingChanged $event) : void
|
||||||
{
|
{
|
||||||
IconStore::setDatabaseReplication($event->newValue);
|
IconStore::setDatabaseReplication($event->newValue);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,9 @@
|
|||||||
* @property string|null $method
|
* @property string|null $method
|
||||||
* @property string|null $login_method
|
* @property string|null $login_method
|
||||||
* @property-read Model|\Eloquent $authenticatable
|
* @property-read Model|\Eloquent $authenticatable
|
||||||
|
*
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
|
*
|
||||||
* @method static \Database\Factories\AuthLogFactory factory($count = null, $state = [])
|
* @method static \Database\Factories\AuthLogFactory factory($count = null, $state = [])
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|AuthLog newModelQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|AuthLog newModelQuery()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|AuthLog newQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|AuthLog newQuery()
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
* @property int|null $user_id
|
* @property int|null $user_id
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TwoFAccount[] $twofaccounts
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TwoFAccount[] $twofaccounts
|
||||||
* @property-read \App\Models\User|null $user
|
* @property-read \App\Models\User|null $user
|
||||||
|
*
|
||||||
* @method static \Database\Factories\GroupFactory factory(...$parameters)
|
* @method static \Database\Factories\GroupFactory factory(...$parameters)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Group newQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Group newQuery()
|
||||||
@ -29,7 +30,9 @@
|
|||||||
* @method static \Illuminate\Database\Eloquent\Builder|Group whereName($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Group whereName($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Group whereUpdatedAt($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Group whereUpdatedAt($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Group whereUserId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Group whereUserId($value)
|
||||||
|
*
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
|
*
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Group orphans()
|
* @method static \Illuminate\Database\Eloquent\Builder|Group orphans()
|
||||||
*/
|
*/
|
||||||
class Group extends Model
|
class Group extends Model
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
* @property \Illuminate\Support\Carbon|null $created_at
|
* @property \Illuminate\Support\Carbon|null $created_at
|
||||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||||
* @property-read \App\Models\TwoFAccount|null $twofaccount
|
* @property-read \App\Models\TwoFAccount|null $twofaccount
|
||||||
|
*
|
||||||
* @method static \Database\Factories\IconFactory factory($count = null, $state = [])
|
* @method static \Database\Factories\IconFactory factory($count = null, $state = [])
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Icon newModelQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Icon newModelQuery()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Icon newQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Icon newQuery()
|
||||||
@ -31,7 +32,7 @@ class Icon extends Model
|
|||||||
/**
|
/**
|
||||||
* @use HasFactory<IconFactory>
|
* @use HasFactory<IconFactory>
|
||||||
*/
|
*/
|
||||||
use HasFactory, CanEncryptField;
|
use CanEncryptField, HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The primary key for the model.
|
* The primary key for the model.
|
||||||
@ -40,7 +41,6 @@ class Icon extends Model
|
|||||||
*/
|
*/
|
||||||
protected $primaryKey = 'name';
|
protected $primaryKey = 'name';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "type" of the primary key ID.
|
* The "type" of the primary key ID.
|
||||||
*
|
*
|
||||||
@ -57,7 +57,7 @@ class Icon extends Model
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the twofaccount that owns the icon.
|
* Get the twofaccount that owns the icon.
|
||||||
*
|
*
|
||||||
* @return BelongsTo<\App\Models\TwoFAccount, \App\Models\Icon>
|
* @return BelongsTo<\App\Models\TwoFAccount, \App\Models\Icon>
|
||||||
*/
|
*/
|
||||||
public function twofaccount() : BelongsTo
|
public function twofaccount() : BelongsTo
|
||||||
@ -71,7 +71,7 @@ public function twofaccount() : BelongsTo
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $attributes = [];
|
protected $attributes = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that should be hidden for arrays.
|
* The attributes that should be hidden for arrays.
|
||||||
*
|
*
|
||||||
|
@ -10,12 +10,14 @@
|
|||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $key
|
* @property string $key
|
||||||
* @property string $value
|
* @property string $value
|
||||||
|
*
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Option newQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Option newQuery()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Option query()
|
* @method static \Illuminate\Database\Eloquent\Builder|Option query()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Option whereId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Option whereId($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Option whereKey($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Option whereKey($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Option whereValue($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Option whereValue($value)
|
||||||
|
*
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
*/
|
*/
|
||||||
class Option extends Model
|
class Option extends Model
|
||||||
|
@ -70,8 +70,11 @@
|
|||||||
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereService($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereService($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUpdatedAt($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUpdatedAt($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUserId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUserId($value)
|
||||||
|
*
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
|
*
|
||||||
* @property-read \App\Models\Icon|null $iconResource
|
* @property-read \App\Models\Icon|null $iconResource
|
||||||
|
*
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount orphans()
|
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount orphans()
|
||||||
*/
|
*/
|
||||||
class TwoFAccount extends Model implements Sortable
|
class TwoFAccount extends Model implements Sortable
|
||||||
@ -79,7 +82,7 @@ class TwoFAccount extends Model implements Sortable
|
|||||||
/**
|
/**
|
||||||
* @use HasFactory<TwoFAccountFactory>
|
* @use HasFactory<TwoFAccountFactory>
|
||||||
*/
|
*/
|
||||||
use HasFactory, SortableTrait, CanEncryptField;
|
use CanEncryptField, HasFactory, SortableTrait;
|
||||||
|
|
||||||
const TOTP = 'totp';
|
const TOTP = 'totp';
|
||||||
|
|
||||||
@ -233,10 +236,10 @@ public function user()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the relation between the icon resource and the model.
|
* Get the relation between the icon resource and the model.
|
||||||
*
|
*
|
||||||
* @return HasOne<\App\Models\Icon>
|
* @return HasOne<\App\Models\Icon>
|
||||||
*/
|
*/
|
||||||
public function iconResource(): HasOne
|
public function iconResource() : HasOne
|
||||||
{
|
{
|
||||||
return $this->hasOne(Icon::class, 'name', 'icon');
|
return $this->hasOne(Icon::class, 'name', 'icon');
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\AuthLog> $authentications
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\AuthLog> $authentications
|
||||||
* @property-read int|null $authentications_count
|
* @property-read int|null $authentications_count
|
||||||
* @property-read \App\Models\AuthLog|null $latestAuthentication
|
* @property-read \App\Models\AuthLog|null $latestAuthentication
|
||||||
|
*
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User admins()
|
* @method static \Illuminate\Database\Eloquent\Builder|User admins()
|
||||||
* @method static \Database\Factories\UserFactory factory(...$parameters)
|
* @method static \Database\Factories\UserFactory factory(...$parameters)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
|
||||||
@ -63,7 +64,9 @@
|
|||||||
* @method static \Illuminate\Database\Eloquent\Builder|User wherePreferences($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|User wherePreferences($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
|
||||||
|
*
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
|
*
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereOauthId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|User whereOauthId($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereOauthProvider($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|User whereOauthProvider($value)
|
||||||
*/
|
*/
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
use App\Events\GroupDeleted;
|
use App\Events\GroupDeleted;
|
||||||
use App\Events\GroupDeleting;
|
use App\Events\GroupDeleting;
|
||||||
use App\Events\storeIconsInDatabaseSettingChanged;
|
|
||||||
use App\Events\ScanForNewReleaseCalled;
|
use App\Events\ScanForNewReleaseCalled;
|
||||||
|
use App\Events\storeIconsInDatabaseSettingChanged;
|
||||||
use App\Events\TwoFAccountDeleted;
|
use App\Events\TwoFAccountDeleted;
|
||||||
use App\Events\VisitedByProxyUser;
|
use App\Events\VisitedByProxyUser;
|
||||||
use App\Listeners\Authentication\FailedLoginListener;
|
use App\Listeners\Authentication\FailedLoginListener;
|
||||||
@ -15,10 +15,10 @@
|
|||||||
use App\Listeners\CleanIconStorage;
|
use App\Listeners\CleanIconStorage;
|
||||||
use App\Listeners\DissociateTwofaccountFromGroup;
|
use App\Listeners\DissociateTwofaccountFromGroup;
|
||||||
use App\Listeners\LogNotificationListener;
|
use App\Listeners\LogNotificationListener;
|
||||||
use App\Listeners\ToggleIconReplicationToDatabase;
|
|
||||||
use App\Listeners\RegisterOpenId;
|
use App\Listeners\RegisterOpenId;
|
||||||
use App\Listeners\ReleaseRadar;
|
use App\Listeners\ReleaseRadar;
|
||||||
use App\Listeners\ResetUsersPreference;
|
use App\Listeners\ResetUsersPreference;
|
||||||
|
use App\Listeners\ToggleIconReplicationToDatabase;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Observers\UserObserver;
|
use App\Observers\UserObserver;
|
||||||
use Illuminate\Auth\Events\Failed;
|
use Illuminate\Auth\Events\Failed;
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Factories\MigratorFactoryInterface;
|
use App\Factories\MigratorFactoryInterface;
|
||||||
use App\Services\IconStoreService;
|
|
||||||
use App\Services\IconService;
|
use App\Services\IconService;
|
||||||
|
use App\Services\IconStoreService;
|
||||||
use App\Services\LogoService;
|
use App\Services\LogoService;
|
||||||
use App\Services\ReleaseRadarService;
|
use App\Services\ReleaseRadarService;
|
||||||
use App\Services\SettingService;
|
use App\Services\SettingService;
|
||||||
|
@ -23,7 +23,7 @@ public function buildFromOfficialLogo(?string $service) : ?string
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an icon from an image resource
|
* Build an icon from an image resource
|
||||||
*
|
*
|
||||||
* @param \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource $resource
|
* @param \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource $resource
|
||||||
* @param string $extension The file extension, without the dot
|
* @param string $extension The file extension, without the dot
|
||||||
*/
|
*/
|
||||||
@ -49,7 +49,7 @@ public function buildFromResource($resource, $extension) : ?string
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an icon by fetching an image file on the internet
|
* Build an icon by fetching an image file on the internet
|
||||||
*/
|
*/
|
||||||
public function buildFromRemoteImage(string $url) : ?string
|
public function buildFromRemoteImage(string $url) : ?string
|
||||||
{
|
{
|
||||||
@ -67,8 +67,8 @@ public function buildFromRemoteImage(string $url) : ?string
|
|||||||
protected function storeRemoteImage(string $url) : ?string
|
protected function storeRemoteImage(string $url) : ?string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$path_parts = pathinfo($url);
|
$path_parts = pathinfo($url);
|
||||||
$filename = Helpers::getRandomFilename($path_parts['extension']);
|
$filename = Helpers::getRandomFilename($path_parts['extension']);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = Http::withOptions([
|
$response = Http::withOptions([
|
||||||
@ -80,7 +80,7 @@ protected function storeRemoteImage(string $url) : ?string
|
|||||||
}
|
}
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
Log::error(sprintf('Cannot fetch imageLink at "%s"', $url));
|
Log::error(sprintf('Cannot fetch imageLink at "%s"', $url));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ public static function isValidImageResource($filename, $content) : bool
|
|||||||
'image/x-ms-bmp',
|
'image/x-ms-bmp',
|
||||||
'image/svg+xml',
|
'image/svg+xml',
|
||||||
];
|
];
|
||||||
|
|
||||||
$isValid = in_array($mimeType, $acceptedMimeTypes)
|
$isValid = in_array($mimeType, $acceptedMimeTypes)
|
||||||
&& ($mimeType !== 'image/svg+xml' ? getimagesize(Storage::disk('temp')->path($filename)) : true)
|
&& ($mimeType !== 'image/svg+xml' ? getimagesize(Storage::disk('temp')->path($filename)) : true)
|
||||||
&& Str::contains($mimeType, $extension, true);
|
&& Str::contains($mimeType, $extension, true);
|
||||||
|
@ -19,7 +19,7 @@ class IconStoreService
|
|||||||
/**
|
/**
|
||||||
* The storage disk to use
|
* The storage disk to use
|
||||||
*/
|
*/
|
||||||
protected string|null $disk;
|
protected ?string $disk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Icon replication to database to ease backup
|
* Icon replication to database to ease backup
|
||||||
@ -73,8 +73,7 @@ public function setDatabaseReplication(bool $usesDatabase) : void
|
|||||||
if ($usesDatabase) {
|
if ($usesDatabase) {
|
||||||
$this->clearDatabase();
|
$this->clearDatabase();
|
||||||
$this->mirrorDiskToDatabase();
|
$this->mirrorDiskToDatabase();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$this->mirrorDatabaseToDisk();
|
$this->mirrorDatabaseToDisk();
|
||||||
$this->clearDatabase();
|
$this->clearDatabase();
|
||||||
}
|
}
|
||||||
@ -98,7 +97,7 @@ protected function mirrorDiskToDatabase() : void
|
|||||||
DB::commit();
|
DB::commit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
|
|
||||||
throw new FailedIconStoreDatabaseTogglingException;
|
throw new FailedIconStoreDatabaseTogglingException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,14 +116,14 @@ protected function mirrorDatabaseToDisk() : void
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of all icon names registered in the TwoFAccount table
|
* Get the list of all icon names registered in the TwoFAccount table
|
||||||
*
|
*
|
||||||
* @return Collection<array-key, mixed>
|
* @return Collection<array-key, mixed>
|
||||||
*/
|
*/
|
||||||
protected function registeredIcons()
|
protected function registeredIcons()
|
||||||
{
|
{
|
||||||
return TwoFAccount::whereNotNull('icon')->pluck('icon');
|
return TwoFAccount::whereNotNull('icon')->pluck('icon');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the content of a given icon resource, prior to the database record
|
* Get the content of a given icon resource, prior to the database record
|
||||||
*/
|
*/
|
||||||
@ -189,7 +188,7 @@ public function delete(array|string $names) : bool
|
|||||||
$names = is_array($names) ? $names : func_get_args();
|
$names = is_array($names) ? $names : func_get_args();
|
||||||
|
|
||||||
$deletedFromDisk = $this->disk()->delete($names);
|
$deletedFromDisk = $this->disk()->delete($names);
|
||||||
|
|
||||||
if ($deletedFromDisk && $this->usesDatabase) {
|
if ($deletedFromDisk && $this->usesDatabase) {
|
||||||
Icon::destroy($names);
|
Icon::destroy($names);
|
||||||
|
|
||||||
@ -206,7 +205,7 @@ public function store(string $name, string $content) : bool
|
|||||||
{
|
{
|
||||||
$storedToDisk = $this->storeToDisk($name, $content);
|
$storedToDisk = $this->storeToDisk($name, $content);
|
||||||
|
|
||||||
if ($this->usesDatabase) {
|
if ($this->usesDatabase) {
|
||||||
return $this->storeToDatabase($name, $content);
|
return $this->storeToDatabase($name, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class LogoService
|
class LogoService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Support\Collection<string, string>
|
* @var \Illuminate\Support\Collection<string, string>
|
||||||
*/
|
*/
|
||||||
@ -157,7 +157,7 @@ protected function cleanDomain(string $domain) : string
|
|||||||
*
|
*
|
||||||
* @param string $logoFilename
|
* @param string $logoFilename
|
||||||
* @param string $iconFilename
|
* @param string $iconFilename
|
||||||
* @return bool Whether the copy succeed or not
|
* @return bool Whether the copy succeed or not
|
||||||
*/
|
*/
|
||||||
protected function copyToIconStore($logoFilename, $iconFilename) : bool
|
protected function copyToIconStore($logoFilename, $iconFilename) : bool
|
||||||
{
|
{
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
namespace App\Services\Migrators;
|
namespace App\Services\Migrators;
|
||||||
|
|
||||||
use App\Exceptions\InvalidMigrationDataException;
|
use App\Exceptions\InvalidMigrationDataException;
|
||||||
use App\Services\IconService;
|
|
||||||
use App\Models\TwoFAccount;
|
use App\Models\TwoFAccount;
|
||||||
|
use App\Services\IconService;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
@ -39,7 +39,7 @@ class AegisMigrator extends Migrator
|
|||||||
public function migrate(mixed $migrationPayload) : Collection
|
public function migrate(mixed $migrationPayload) : Collection
|
||||||
{
|
{
|
||||||
$iconService = App::make(IconService::class);
|
$iconService = App::make(IconService::class);
|
||||||
$json = json_decode(htmlspecialchars_decode($migrationPayload), true);
|
$json = json_decode(htmlspecialchars_decode($migrationPayload), true);
|
||||||
|
|
||||||
if (is_null($json) || Arr::has($json, 'db.entries') == false) {
|
if (is_null($json) || Arr::has($json, 'db.entries') == false) {
|
||||||
Log::error('Aegis JSON migration data cannot be read');
|
Log::error('Aegis JSON migration data cannot be read');
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
namespace App\Services\Migrators;
|
namespace App\Services\Migrators;
|
||||||
|
|
||||||
use App\Exceptions\InvalidMigrationDataException;
|
use App\Exceptions\InvalidMigrationDataException;
|
||||||
use App\Services\IconService;
|
|
||||||
use App\Models\TwoFAccount;
|
use App\Models\TwoFAccount;
|
||||||
|
use App\Services\IconService;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
@ -43,7 +43,7 @@ class TwoFAuthMigrator extends Migrator
|
|||||||
public function migrate(mixed $migrationPayload) : Collection
|
public function migrate(mixed $migrationPayload) : Collection
|
||||||
{
|
{
|
||||||
$iconService = App::make(IconService::class);
|
$iconService = App::make(IconService::class);
|
||||||
$json = json_decode(htmlspecialchars_decode($migrationPayload), true);
|
$json = json_decode(htmlspecialchars_decode($migrationPayload), true);
|
||||||
|
|
||||||
if (is_null($json)) {
|
if (is_null($json)) {
|
||||||
Log::error('2FAuth JSON migration data cannot be read');
|
Log::error('2FAuth JSON migration data cannot be read');
|
||||||
|
@ -34,7 +34,7 @@ public function setUp() : void
|
|||||||
|
|
||||||
Storage::fake('icons');
|
Storage::fake('icons');
|
||||||
Storage::fake('logos');
|
Storage::fake('logos');
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
Http::preventStrayRequests();
|
||||||
Http::fake([
|
Http::fake([
|
||||||
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
@ -51,7 +51,7 @@ public function setUp() : void
|
|||||||
public function test_upload_icon_returns_filename_using_the_iconStore()
|
public function test_upload_icon_returns_filename_using_the_iconStore()
|
||||||
{
|
{
|
||||||
$iconName = 'testIcon.jpg';
|
$iconName = 'testIcon.jpg';
|
||||||
$file = UploadedFile::fake()->image($iconName);
|
$file = UploadedFile::fake()->image($iconName);
|
||||||
|
|
||||||
$response = $this->actingAs($this->user, 'api-guard')
|
$response = $this->actingAs($this->user, 'api-guard')
|
||||||
->json('POST', '/api/v1/icons', [
|
->json('POST', '/api/v1/icons', [
|
||||||
@ -111,7 +111,7 @@ public function test_fetch_unknown_logo_returns_nothing()
|
|||||||
public function test_delete_icon_returns_success_using_the_iconStore()
|
public function test_delete_icon_returns_success_using_the_iconStore()
|
||||||
{
|
{
|
||||||
IconStore::spy();
|
IconStore::spy();
|
||||||
|
|
||||||
$iconName = 'testIcon.jpg';
|
$iconName = 'testIcon.jpg';
|
||||||
|
|
||||||
$response = $this->actingAs($this->user, 'api-guard')
|
$response = $this->actingAs($this->user, 'api-guard')
|
||||||
|
@ -237,7 +237,7 @@ public function setUp() : void
|
|||||||
Storage::fake('icons');
|
Storage::fake('icons');
|
||||||
Storage::fake('logos');
|
Storage::fake('logos');
|
||||||
Storage::fake('imagesLink');
|
Storage::fake('imagesLink');
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
Http::preventStrayRequests();
|
||||||
Http::fake([
|
Http::fake([
|
||||||
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
|
@ -48,30 +48,30 @@ public static function provideValidData() : array
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => '1',
|
'otpauth' => '1',
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => 1,
|
'otpauth' => 1,
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => true,
|
'otpauth' => true,
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => '0',
|
'otpauth' => '0',
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => 0,
|
'otpauth' => 0,
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => false,
|
'otpauth' => false,
|
||||||
]],
|
]],
|
||||||
];
|
];
|
||||||
@ -94,31 +94,31 @@ public static function provideInvalidData() : array
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => null,
|
'otpauth' => null,
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => '',
|
'otpauth' => '',
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => 2,
|
'otpauth' => 2,
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => 'string',
|
'otpauth' => 'string',
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => 0.1,
|
'otpauth' => 0.1,
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => '01/01/2020',
|
'otpauth' => '01/01/2020',
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'ids' => '1',
|
'ids' => '1',
|
||||||
'otpauth' => '01',
|
'otpauth' => '01',
|
||||||
]],
|
]],
|
||||||
];
|
];
|
||||||
|
@ -49,7 +49,7 @@ public function setUp() : void
|
|||||||
|
|
||||||
Storage::fake('imagesLink');
|
Storage::fake('imagesLink');
|
||||||
Storage::fake('icons');
|
Storage::fake('icons');
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
Http::preventStrayRequests();
|
||||||
|
|
||||||
/** @var \Illuminate\Contracts\Auth\Authenticatable $user */
|
/** @var \Illuminate\Contracts\Auth\Authenticatable $user */
|
||||||
@ -671,7 +671,7 @@ public function test_scopeOrphans_retreives_accounts_without_owner()
|
|||||||
Http::fake([
|
Http::fake([
|
||||||
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response(HttpRequestTestData::ICON_PNG, 200),
|
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response(HttpRequestTestData::ICON_PNG, 200),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$orphan = new TwoFAccount;
|
$orphan = new TwoFAccount;
|
||||||
$orphan->fillWithURI(OtpTestData::HOTP_FULL_CUSTOM_URI);
|
$orphan->fillWithURI(OtpTestData::HOTP_FULL_CUSTOM_URI);
|
||||||
$orphan->save();
|
$orphan->save();
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
use App\Facades\IconStore;
|
use App\Facades\IconStore;
|
||||||
use App\Models\AuthLog;
|
use App\Models\AuthLog;
|
||||||
use App\Models\Dto\IconDto;
|
|
||||||
use App\Models\Group;
|
use App\Models\Group;
|
||||||
use App\Models\TwoFAccount;
|
use App\Models\TwoFAccount;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@ -174,7 +173,7 @@ public function test_delete_flushes_icons_of_user_twofaccounts()
|
|||||||
'icon' => OtpTestData::ICON_PNG,
|
'icon' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
IconStore::store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
|
IconStore::store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
|
||||||
|
|
||||||
Storage::disk('icons')->assertExists($twofaccount->icon);
|
Storage::disk('icons')->assertExists($twofaccount->icon);
|
||||||
|
|
||||||
$user->delete();
|
$user->delete();
|
||||||
|
@ -34,11 +34,11 @@ class IconServiceTest extends FeatureTestCase
|
|||||||
public function setUp() : void
|
public function setUp() : void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Storage::fake('icons');
|
Storage::fake('icons');
|
||||||
Storage::fake('logos');
|
Storage::fake('logos');
|
||||||
Storage::fake('imagesLink');
|
Storage::fake('imagesLink');
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
Http::preventStrayRequests();
|
||||||
Http::fake([
|
Http::fake([
|
||||||
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
@ -63,11 +63,11 @@ public function test_buildFromOfficialLogo_calls_logoservice_to_get_the_icon()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_buildFromResource_stores_icon_and_returns_name()
|
public function test_buildFromResource_stores_icon_and_returns_name()
|
||||||
{
|
{
|
||||||
$resource = base64_decode(OtpTestData::ICON_PNG_DATA);
|
$resource = base64_decode(OtpTestData::ICON_PNG_DATA);
|
||||||
$extension = 'png';
|
$extension = 'png';
|
||||||
|
|
||||||
$this->iconService = $this->app->make(IconService::class);
|
$this->iconService = $this->app->make(IconService::class);
|
||||||
$iconName = $this->iconService->buildFromResource($resource, $extension);
|
$iconName = $this->iconService->buildFromResource($resource, $extension);
|
||||||
|
|
||||||
Storage::disk('icons')->assertExists($iconName);
|
Storage::disk('icons')->assertExists($iconName);
|
||||||
$this->assertEquals($resource, Storage::disk('icons')->get($iconName));
|
$this->assertEquals($resource, Storage::disk('icons')->get($iconName));
|
||||||
@ -80,7 +80,7 @@ public function test_buildFromResource_returns_null_when_store_fails()
|
|||||||
->andReturn(false);
|
->andReturn(false);
|
||||||
|
|
||||||
$this->iconService = $this->app->make(IconService::class);
|
$this->iconService = $this->app->make(IconService::class);
|
||||||
$iconName = $this->iconService->buildFromResource('lorem', 'ipsum');
|
$iconName = $this->iconService->buildFromResource('lorem', 'ipsum');
|
||||||
|
|
||||||
$this->assertNull($iconName);
|
$this->assertNull($iconName);
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ public function test_buildFromResource_returns_null_when_store_fails()
|
|||||||
public function test_buildFromResource_with_bad_inputs_returns_null($resource, $extension)
|
public function test_buildFromResource_with_bad_inputs_returns_null($resource, $extension)
|
||||||
{
|
{
|
||||||
$this->iconService = $this->app->make(IconService::class);
|
$this->iconService = $this->app->make(IconService::class);
|
||||||
$iconName = $this->iconService->buildFromResource($resource, $extension);
|
$iconName = $this->iconService->buildFromResource($resource, $extension);
|
||||||
|
|
||||||
$this->assertNull($iconName);
|
$this->assertNull($iconName);
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ public function test_buildFromRemoteImage_stores_icon_and_returns_name($name, $b
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->iconService = $this->app->make(IconService::class);
|
$this->iconService = $this->app->make(IconService::class);
|
||||||
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
||||||
|
|
||||||
Storage::disk('icons')->assertExists($iconName);
|
Storage::disk('icons')->assertExists($iconName);
|
||||||
Storage::disk('imagesLink')->assertMissing($iconName);
|
Storage::disk('imagesLink')->assertMissing($iconName);
|
||||||
@ -174,7 +174,7 @@ public function test_buildFromRemoteImage_returns_null_when_url_is_invalid()
|
|||||||
->andReturn(false);
|
->andReturn(false);
|
||||||
|
|
||||||
$this->iconService = $this->app->make(IconService::class);
|
$this->iconService = $this->app->make(IconService::class);
|
||||||
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
||||||
|
|
||||||
$this->assertNull($iconName);
|
$this->assertNull($iconName);
|
||||||
}
|
}
|
||||||
@ -203,11 +203,11 @@ public function test_buildFromRemoteImage_returns_null_when_remote_img_is_unreac
|
|||||||
Http::fake([
|
Http::fake([
|
||||||
'example.com/*' => Http::response(null, 400),
|
'example.com/*' => Http::response(null, 400),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$imageUrl = 'https://www.example.com/image.png';
|
$imageUrl = 'https://www.example.com/image.png';
|
||||||
|
|
||||||
$this->iconService = $this->app->make(IconService::class);
|
$this->iconService = $this->app->make(IconService::class);
|
||||||
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
||||||
|
|
||||||
$this->assertNull($iconName);
|
$this->assertNull($iconName);
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ public function test_buildFromRemoteImage_returns_null_when_remote_img_is_not_su
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->iconService = $this->app->make(IconService::class);
|
$this->iconService = $this->app->make(IconService::class);
|
||||||
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
||||||
|
|
||||||
$this->assertNull($iconName);
|
$this->assertNull($iconName);
|
||||||
}
|
}
|
||||||
@ -240,8 +240,8 @@ public function test_buildFromRemoteImage_returns_null_when_remote_img_is_not_va
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->iconService = $this->app->make(IconService::class);
|
$this->iconService = $this->app->make(IconService::class);
|
||||||
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
|
||||||
|
|
||||||
$this->assertNull($iconName);
|
$this->assertNull($iconName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public function setUp() : void
|
|||||||
Storage::fake('icons');
|
Storage::fake('icons');
|
||||||
$this->iconStore = $this->app->make(IconStoreService::class);
|
$this->iconStore = $this->app->make(IconStoreService::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function test_get_returns_icon_content()
|
public function test_get_returns_icon_content()
|
||||||
{
|
{
|
||||||
@ -90,7 +90,7 @@ public function test_mimeType_returns_correct_mimetype($name, $base64content, $e
|
|||||||
|
|
||||||
$this->assertStringContainsStringIgnoringCase($mimeType, $expected);
|
$this->assertStringContainsStringIgnoringCase($mimeType, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide data for index tests
|
* Provide data for index tests
|
||||||
*/
|
*/
|
||||||
@ -115,7 +115,7 @@ public static function supportedMimeTypesProvider()
|
|||||||
'BPM' => [
|
'BPM' => [
|
||||||
OtpTestData::ICON_BMP,
|
OtpTestData::ICON_BMP,
|
||||||
OtpTestData::ICON_BMP_DATA,
|
OtpTestData::ICON_BMP_DATA,
|
||||||
'image/bmp|image/x-ms-bmp'
|
'image/bmp|image/x-ms-bmp',
|
||||||
],
|
],
|
||||||
'SVG' => [
|
'SVG' => [
|
||||||
OtpTestData::ICON_SVG,
|
OtpTestData::ICON_SVG,
|
||||||
@ -140,7 +140,7 @@ public function test_mimeType_returns_null_when_icon_is_missing()
|
|||||||
{
|
{
|
||||||
$this->assertFalse($this->iconStore->mimeType(OtpTestData::ICON_PNG));
|
$this->assertFalse($this->iconStore->mimeType(OtpTestData::ICON_PNG));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function test_mimeType_returns_null_when_nothing_is_requested()
|
public function test_mimeType_returns_null_when_nothing_is_requested()
|
||||||
{
|
{
|
||||||
@ -183,10 +183,10 @@ public function test_clear_deletes_all_icons_in_database_and_returns_true()
|
|||||||
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
|
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
|
||||||
Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG);
|
Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_JPEG,
|
'name' => OtpTestData::ICON_JPEG,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = $this->iconStore->clear();
|
$result = $this->iconStore->clear();
|
||||||
@ -218,10 +218,10 @@ public function test_clear_empty_disk_deletes_icons_in_database()
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_JPEG,
|
'name' => OtpTestData::ICON_JPEG,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = $this->iconStore->clear();
|
$result = $this->iconStore->clear();
|
||||||
@ -272,23 +272,23 @@ public function test_delete_deletes_provided_icon_and_returns_true()
|
|||||||
public function test_delete_deletes_provided_icon_in_database_and_returns_true()
|
public function test_delete_deletes_provided_icon_in_database_and_returns_true()
|
||||||
{
|
{
|
||||||
Settings::set('storeIconsInDatabase', true);
|
Settings::set('storeIconsInDatabase', true);
|
||||||
|
|
||||||
Storage::disk('icons')->put(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
|
Storage::disk('icons')->put(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
|
||||||
DB::table('icons')->insert([
|
DB::table('icons')->insert([
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
'content' => OtpTestData::ICON_PNG_DATA,
|
'content' => OtpTestData::ICON_PNG_DATA,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
|
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->iconStore->delete(OtpTestData::ICON_PNG);
|
$this->iconStore->delete(OtpTestData::ICON_PNG);
|
||||||
|
|
||||||
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
||||||
$this->assertDatabaseMissing('icons', [
|
$this->assertDatabaseMissing('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,21 +296,21 @@ public function test_delete_deletes_provided_icon_in_database_and_returns_true()
|
|||||||
public function test_delete_deletes_provided_icon_in_database_when_disk_is_empty()
|
public function test_delete_deletes_provided_icon_in_database_when_disk_is_empty()
|
||||||
{
|
{
|
||||||
Settings::set('storeIconsInDatabase', true);
|
Settings::set('storeIconsInDatabase', true);
|
||||||
|
|
||||||
DB::table('icons')->insert([
|
DB::table('icons')->insert([
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
'content' => OtpTestData::ICON_PNG_DATA,
|
'content' => OtpTestData::ICON_PNG_DATA,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->iconStore->delete(OtpTestData::ICON_PNG);
|
$this->iconStore->delete(OtpTestData::ICON_PNG);
|
||||||
|
|
||||||
$this->assertDatabaseMissing('icons', [
|
$this->assertDatabaseMissing('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ public function test_delete_deletes_provided_icons_and_returns_true()
|
|||||||
public function test_delete_deletes_provided_icons_in_database_and_returns_true()
|
public function test_delete_deletes_provided_icons_in_database_and_returns_true()
|
||||||
{
|
{
|
||||||
Settings::set('storeIconsInDatabase', true);
|
Settings::set('storeIconsInDatabase', true);
|
||||||
|
|
||||||
Storage::disk('icons')->put(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
|
Storage::disk('icons')->put(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
|
||||||
Storage::disk('icons')->put(OtpTestData::ICON_JPEG, base64_decode(OtpTestData::ICON_JPEG_DATA));
|
Storage::disk('icons')->put(OtpTestData::ICON_JPEG, base64_decode(OtpTestData::ICON_JPEG_DATA));
|
||||||
DB::table('icons')->insert([
|
DB::table('icons')->insert([
|
||||||
@ -351,10 +351,10 @@ public function test_delete_deletes_provided_icons_in_database_and_returns_true(
|
|||||||
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
|
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
|
||||||
Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG);
|
Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_JPEG,
|
'name' => OtpTestData::ICON_JPEG,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->iconStore->delete([
|
$this->iconStore->delete([
|
||||||
@ -365,10 +365,10 @@ public function test_delete_deletes_provided_icons_in_database_and_returns_true(
|
|||||||
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
||||||
Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG);
|
Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG);
|
||||||
$this->assertDatabaseMissing('icons', [
|
$this->assertDatabaseMissing('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseMissing('icons', [
|
$this->assertDatabaseMissing('icons', [
|
||||||
'name' => OtpTestData::ICON_JPEG,
|
'name' => OtpTestData::ICON_JPEG,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +376,7 @@ public function test_delete_deletes_provided_icons_in_database_and_returns_true(
|
|||||||
public function test_delete_deletes_provided_icons_in_database_when_disk_is_empty()
|
public function test_delete_deletes_provided_icons_in_database_when_disk_is_empty()
|
||||||
{
|
{
|
||||||
Settings::set('storeIconsInDatabase', true);
|
Settings::set('storeIconsInDatabase', true);
|
||||||
|
|
||||||
DB::table('icons')->insert([
|
DB::table('icons')->insert([
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
'content' => OtpTestData::ICON_PNG_DATA,
|
'content' => OtpTestData::ICON_PNG_DATA,
|
||||||
@ -389,10 +389,10 @@ public function test_delete_deletes_provided_icons_in_database_when_disk_is_empt
|
|||||||
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
||||||
Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG);
|
Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_JPEG,
|
'name' => OtpTestData::ICON_JPEG,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->iconStore->delete([
|
$this->iconStore->delete([
|
||||||
@ -401,10 +401,10 @@ public function test_delete_deletes_provided_icons_in_database_when_disk_is_empt
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertDatabaseMissing('icons', [
|
$this->assertDatabaseMissing('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseMissing('icons', [
|
$this->assertDatabaseMissing('icons', [
|
||||||
'name' => OtpTestData::ICON_JPEG,
|
'name' => OtpTestData::ICON_JPEG,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ public function test_store_writes_the_icon_to_disk_and_database_and_returns_true
|
|||||||
|
|
||||||
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
|
||||||
$this->assertDatabaseMissing('icons', [
|
$this->assertDatabaseMissing('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = $this->iconStore->store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
|
$result = $this->iconStore->store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
|
||||||
@ -466,7 +466,7 @@ public function test_store_writes_the_icon_to_disk_and_database_and_returns_true
|
|||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
|
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
|
||||||
$this->assertDatabaseHas('icons', [
|
$this->assertDatabaseHas('icons', [
|
||||||
'name' => OtpTestData::ICON_PNG,
|
'name' => OtpTestData::ICON_PNG,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,7 +481,7 @@ public function test_store_returns_false_when_it_fails()
|
|||||||
Storage::shouldReceive('disk->put')
|
Storage::shouldReceive('disk->put')
|
||||||
->with($iconName, $iconContent)
|
->with($iconName, $iconContent)
|
||||||
->andReturn(false);
|
->andReturn(false);
|
||||||
|
|
||||||
$result = $this->iconStore->store($iconName, $iconContent);
|
$result = $this->iconStore->store($iconName, $iconContent);
|
||||||
|
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
@ -553,7 +553,7 @@ public function test_setDatabaseReplication_stores_icon_files_to_database()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_setDatabaseReplication_stores_only_registered_icon_to_database()
|
public function test_setDatabaseReplication_stores_only_registered_icon_to_database()
|
||||||
{
|
{
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
|
|
||||||
TwoFAccount::factory()->for($user)->create([
|
TwoFAccount::factory()->for($user)->create([
|
||||||
'icon' => OtpTestData::ICON_PNG,
|
'icon' => OtpTestData::ICON_PNG,
|
||||||
@ -594,7 +594,7 @@ public function test_setDatabaseReplication_clears_database_before_replication()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_setDatabaseReplication_skips_icon_when_file_is_missing()
|
public function test_setDatabaseReplication_skips_icon_when_file_is_missing()
|
||||||
{
|
{
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
|
|
||||||
TwoFAccount::factory()->for($user)->create([
|
TwoFAccount::factory()->for($user)->create([
|
||||||
'icon' => OtpTestData::ICON_PNG,
|
'icon' => OtpTestData::ICON_PNG,
|
||||||
@ -644,7 +644,7 @@ public function test_setDatabaseReplication_overrides_existing_files_during_rest
|
|||||||
{
|
{
|
||||||
Settings::set('storeIconsInDatabase', true);
|
Settings::set('storeIconsInDatabase', true);
|
||||||
|
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
|
|
||||||
TwoFAccount::factory()->for($user)->create([
|
TwoFAccount::factory()->for($user)->create([
|
||||||
'icon' => OtpTestData::ICON_PNG,
|
'icon' => OtpTestData::ICON_PNG,
|
||||||
@ -721,9 +721,9 @@ public function test_setDatabaseReplication_Off_sends_exception_and_does_nothing
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
Storage::shouldReceive('disk->put')
|
Storage::shouldReceive('disk->put')
|
||||||
->once()
|
->once()
|
||||||
->andThrow(new FailedIconStoreDatabaseTogglingException);
|
->andThrow(new FailedIconStoreDatabaseTogglingException);
|
||||||
|
|
||||||
$this->expectException(FailedIconStoreDatabaseTogglingException::class);
|
$this->expectException(FailedIconStoreDatabaseTogglingException::class);
|
||||||
|
|
||||||
Settings::set('storeIconsInDatabase', false);
|
Settings::set('storeIconsInDatabase', false);
|
||||||
|
@ -52,7 +52,7 @@ public function test_getIcon_returns_null_when_github_request_fails()
|
|||||||
Http::preventStrayRequests();
|
Http::preventStrayRequests();
|
||||||
Http::fake([
|
Http::fake([
|
||||||
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
LogoService::TFA_URL => Http::response('not found', 404),
|
LogoService::TFA_URL => Http::response('not found', 404),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->logoService = $this->app->make(LogoService::class);
|
$this->logoService = $this->app->make(LogoService::class);
|
||||||
@ -97,7 +97,7 @@ public function test_logoService_loads_empty_collection_when_tfajson_fetching_fa
|
|||||||
Http::preventStrayRequests();
|
Http::preventStrayRequests();
|
||||||
Http::fake([
|
Http::fake([
|
||||||
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
LogoService::TFA_URL => Http::response('not found', 404),
|
LogoService::TFA_URL => Http::response('not found', 404),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->logoService = $this->app->make(LogoService::class);
|
$this->logoService = $this->app->make(LogoService::class);
|
||||||
|
@ -8,13 +8,11 @@
|
|||||||
use App\Facades\Settings;
|
use App\Facades\Settings;
|
||||||
use App\Models\Icon;
|
use App\Models\Icon;
|
||||||
use App\Models\TwoFAccount;
|
use App\Models\TwoFAccount;
|
||||||
use App\Services\IconStoreService;
|
|
||||||
use App\Services\SettingService;
|
use App\Services\SettingService;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Mockery\MockInterface;
|
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
use PHPUnit\Framework\Attributes\Test;
|
use PHPUnit\Framework\Attributes\Test;
|
||||||
@ -396,7 +394,7 @@ public function test_set_storeIconsInDatabase_setting_impacts_the_icon_store()
|
|||||||
public function test_set_storeIconsInDatabase_is_cancelled_if_database_toggling_failed()
|
public function test_set_storeIconsInDatabase_is_cancelled_if_database_toggling_failed()
|
||||||
{
|
{
|
||||||
$this->expectException(FailedIconStoreDatabaseTogglingException::class);
|
$this->expectException(FailedIconStoreDatabaseTogglingException::class);
|
||||||
|
|
||||||
$newValue = true;
|
$newValue = true;
|
||||||
|
|
||||||
IconStore::shouldReceive('setDatabaseReplication')
|
IconStore::shouldReceive('setDatabaseReplication')
|
||||||
|
@ -17,7 +17,7 @@ class storeIconsInDatabaseSettingChangedTest extends TestCase
|
|||||||
public function test_event_constructor()
|
public function test_event_constructor()
|
||||||
{
|
{
|
||||||
$newValue = true;
|
$newValue = true;
|
||||||
$event = new storeIconsInDatabaseSettingChanged($newValue);
|
$event = new storeIconsInDatabaseSettingChanged($newValue);
|
||||||
|
|
||||||
$this->assertSame($newValue, $event->newValue);
|
$this->assertSame($newValue, $event->newValue);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace Tests\Unit\Listeners;
|
namespace Tests\Unit\Listeners;
|
||||||
|
|
||||||
use App\Events\TwoFAccountDeleted;
|
use App\Events\TwoFAccountDeleted;
|
||||||
use App\Facades\Settings;
|
|
||||||
use App\Listeners\CleanIconStorage;
|
use App\Listeners\CleanIconStorage;
|
||||||
use App\Models\TwoFAccount;
|
use App\Models\TwoFAccount;
|
||||||
use App\Services\IconStoreService;
|
use App\Services\IconStoreService;
|
||||||
@ -42,7 +41,7 @@ public function test_it_deletes_icon_file_using_the_iconstore()
|
|||||||
->with($event->twofaccount->icon)
|
->with($event->twofaccount->icon)
|
||||||
->andReturn(true);
|
->andReturn(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @disregard P1009 Undefined type
|
* @disregard P1009 Undefined type
|
||||||
*/
|
*/
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
use App\Exceptions\InvalidMigrationDataException;
|
use App\Exceptions\InvalidMigrationDataException;
|
||||||
use App\Exceptions\UnsupportedMigrationException;
|
use App\Exceptions\UnsupportedMigrationException;
|
||||||
use App\Facades\Icons;
|
use App\Facades\Icons;
|
||||||
use App\Facades\IconStore;
|
|
||||||
use App\Factories\MigratorFactory;
|
use App\Factories\MigratorFactory;
|
||||||
use App\Models\TwoFAccount;
|
use App\Models\TwoFAccount;
|
||||||
use App\Providers\MigrationServiceProvider;
|
use App\Providers\MigrationServiceProvider;
|
||||||
@ -416,13 +415,13 @@ public function test_migrate_2fauth_payload_with_icon_sets_and_stores_the_icon($
|
|||||||
{
|
{
|
||||||
Icons::spy();
|
Icons::spy();
|
||||||
Storage::fake('icons');
|
Storage::fake('icons');
|
||||||
|
|
||||||
$migrator = new TwoFAuthMigrator;
|
$migrator = new TwoFAuthMigrator;
|
||||||
$accounts = $migrator->migrate($migration);
|
$accounts = $migrator->migrate($migration);
|
||||||
|
|
||||||
$this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
|
$this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
|
||||||
$this->assertCount(1, $accounts);
|
$this->assertCount(1, $accounts);
|
||||||
|
|
||||||
Icons::shouldHaveReceived('buildFromResource')->once();
|
Icons::shouldHaveReceived('buildFromResource')->once();
|
||||||
Storage::disk('icons')->assertExists($accounts->first()->icon);
|
Storage::disk('icons')->assertExists($accounts->first()->icon);
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ public function test_user_relation()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_twofaccount_relation()
|
public function test_twofaccount_relation()
|
||||||
{
|
{
|
||||||
$model = new Icon();
|
$model = new Icon;
|
||||||
$relation = $model->twofaccount();
|
$relation = $model->twofaccount();
|
||||||
|
|
||||||
$this->assertInstanceOf(BelongsTo::class, $relation);
|
$this->assertInstanceOf(BelongsTo::class, $relation);
|
||||||
|
Loading…
Reference in New Issue
Block a user