Fix pint issues

This commit is contained in:
Bubka 2024-11-09 10:18:45 +01:00
parent 6158c6940b
commit fee7a684b2
32 changed files with 126 additions and 120 deletions

View File

@ -34,8 +34,8 @@ public function upload(Request $request)
$name = Helpers::getRandomFilename($icon->extension());
$isStored = IconStore::store($name, $content);
}
} catch (Exception) {
}
catch (Exception) { }
}
return $isStored

View File

@ -17,6 +17,7 @@
* @property int|null $period
* @property int|null $counter
* @property string $legacy_uri
*
* @method string getURI()
*/
class TwoFAccountExportResource extends JsonResource

View File

@ -5,7 +5,7 @@
/**
* @property mixed $id
* @property mixed $group_id
*
*
* @method App\Models\Dto\TotpDto|App\Models\Dto\HotpDto getOtp(int $time)
*/
class TwoFAccountReadResource extends TwoFAccountStoreResource

View File

@ -48,7 +48,7 @@ public function __construct()
public function handle()
{
$this->callSilently('config:clear');
if (! config('2fauth.config.isTestingApp') && ! $this->option('force')) {
$this->comment('2fauth:reset-testing can only run when isTestingApp option is On');

View File

@ -26,7 +26,7 @@ public function __construct()
public function handle(TwoFAccountDeleted $event)
{
IconStore::delete($event->twofaccount->icon ?? []);
Log::info(sprintf('Icon cleaned for deleted TwoFAccount #%d', $event->twofaccount->id));
}
}

View File

@ -10,14 +10,12 @@ class ToggleIconReplicationToDatabase
/**
* Create the event listener.
*/
public function __construct()
{
}
public function __construct() {}
/**
* Handle the event.
*/
public function handle(storeIconsInDatabaseSettingChanged $event): void
public function handle(storeIconsInDatabaseSettingChanged $event) : void
{
IconStore::setDatabaseReplication($event->newValue);
}

View File

@ -43,7 +43,9 @@
* @property string|null $method
* @property string|null $login_method
* @property-read Model|\Eloquent $authenticatable
*
* @mixin \Eloquent
*
* @method static \Database\Factories\AuthLogFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|AuthLog newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|AuthLog newQuery()

View File

@ -20,6 +20,7 @@
* @property int|null $user_id
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TwoFAccount[] $twofaccounts
* @property-read \App\Models\User|null $user
*
* @method static \Database\Factories\GroupFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery()
* @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 whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Group whereUserId($value)
*
* @mixin \Eloquent
*
* @method static \Illuminate\Database\Eloquent\Builder|Group orphans()
*/
class Group extends Model

View File

@ -17,6 +17,7 @@
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\TwoFAccount|null $twofaccount
*
* @method static \Database\Factories\IconFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Icon newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Icon newQuery()
@ -31,7 +32,7 @@ class Icon extends Model
/**
* @use HasFactory<IconFactory>
*/
use HasFactory, CanEncryptField;
use CanEncryptField, HasFactory;
/**
* The primary key for the model.
@ -40,7 +41,6 @@ class Icon extends Model
*/
protected $primaryKey = 'name';
/**
* The "type" of the primary key ID.
*
@ -57,7 +57,7 @@ class Icon extends Model
/**
* Get the twofaccount that owns the icon.
*
*
* @return BelongsTo<\App\Models\TwoFAccount, \App\Models\Icon>
*/
public function twofaccount() : BelongsTo
@ -71,7 +71,7 @@ public function twofaccount() : BelongsTo
* @var array
*/
protected $attributes = [];
/**
* The attributes that should be hidden for arrays.
*

View File

@ -10,12 +10,14 @@
* @property int $id
* @property string $key
* @property string $value
*
* @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Option newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Option query()
* @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 whereValue($value)
*
* @mixin \Eloquent
*/
class Option extends Model

View File

@ -70,8 +70,11 @@
* @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 whereUserId($value)
*
* @mixin \Eloquent
*
* @property-read \App\Models\Icon|null $iconResource
*
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount orphans()
*/
class TwoFAccount extends Model implements Sortable
@ -79,7 +82,7 @@ class TwoFAccount extends Model implements Sortable
/**
* @use HasFactory<TwoFAccountFactory>
*/
use HasFactory, SortableTrait, CanEncryptField;
use CanEncryptField, HasFactory, SortableTrait;
const TOTP = 'totp';
@ -233,10 +236,10 @@ public function user()
/**
* Get the relation between the icon resource and the model.
*
*
* @return HasOne<\App\Models\Icon>
*/
public function iconResource(): HasOne
public function iconResource() : HasOne
{
return $this->hasOne(Icon::class, 'name', 'icon');
}

View File

@ -47,6 +47,7 @@
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\AuthLog> $authentications
* @property-read int|null $authentications_count
* @property-read \App\Models\AuthLog|null $latestAuthentication
*
* @method static \Illuminate\Database\Eloquent\Builder|User admins()
* @method static \Database\Factories\UserFactory factory(...$parameters)
* @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 whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
*
* @mixin \Eloquent
*
* @method static \Illuminate\Database\Eloquent\Builder|User whereOauthId($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereOauthProvider($value)
*/

View File

@ -4,8 +4,8 @@
use App\Events\GroupDeleted;
use App\Events\GroupDeleting;
use App\Events\storeIconsInDatabaseSettingChanged;
use App\Events\ScanForNewReleaseCalled;
use App\Events\storeIconsInDatabaseSettingChanged;
use App\Events\TwoFAccountDeleted;
use App\Events\VisitedByProxyUser;
use App\Listeners\Authentication\FailedLoginListener;
@ -15,10 +15,10 @@
use App\Listeners\CleanIconStorage;
use App\Listeners\DissociateTwofaccountFromGroup;
use App\Listeners\LogNotificationListener;
use App\Listeners\ToggleIconReplicationToDatabase;
use App\Listeners\RegisterOpenId;
use App\Listeners\ReleaseRadar;
use App\Listeners\ResetUsersPreference;
use App\Listeners\ToggleIconReplicationToDatabase;
use App\Models\User;
use App\Observers\UserObserver;
use Illuminate\Auth\Events\Failed;

View File

@ -3,8 +3,8 @@
namespace App\Providers;
use App\Factories\MigratorFactoryInterface;
use App\Services\IconStoreService;
use App\Services\IconService;
use App\Services\IconStoreService;
use App\Services\LogoService;
use App\Services\ReleaseRadarService;
use App\Services\SettingService;

View File

@ -23,7 +23,7 @@ public function buildFromOfficialLogo(?string $service) : ?string
/**
* Build an icon from an image resource
*
*
* @param \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource $resource
* @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
{
@ -67,8 +67,8 @@ public function buildFromRemoteImage(string $url) : ?string
protected function storeRemoteImage(string $url) : ?string
{
try {
$path_parts = pathinfo($url);
$filename = Helpers::getRandomFilename($path_parts['extension']);
$path_parts = pathinfo($url);
$filename = Helpers::getRandomFilename($path_parts['extension']);
try {
$response = Http::withOptions([
@ -80,7 +80,7 @@ protected function storeRemoteImage(string $url) : ?string
}
} catch (\Exception $exception) {
Log::error(sprintf('Cannot fetch imageLink at "%s"', $url));
return null;
}
@ -129,7 +129,7 @@ public static function isValidImageResource($filename, $content) : bool
'image/x-ms-bmp',
'image/svg+xml',
];
$isValid = in_array($mimeType, $acceptedMimeTypes)
&& ($mimeType !== 'image/svg+xml' ? getimagesize(Storage::disk('temp')->path($filename)) : true)
&& Str::contains($mimeType, $extension, true);

View File

@ -19,7 +19,7 @@ class IconStoreService
/**
* The storage disk to use
*/
protected string|null $disk;
protected ?string $disk;
/**
* Icon replication to database to ease backup
@ -73,8 +73,7 @@ public function setDatabaseReplication(bool $usesDatabase) : void
if ($usesDatabase) {
$this->clearDatabase();
$this->mirrorDiskToDatabase();
}
else {
} else {
$this->mirrorDatabaseToDisk();
$this->clearDatabase();
}
@ -98,7 +97,7 @@ protected function mirrorDiskToDatabase() : void
DB::commit();
} catch (\Exception $e) {
DB::rollback();
throw new FailedIconStoreDatabaseTogglingException;
}
}
@ -117,14 +116,14 @@ protected function mirrorDatabaseToDisk() : void
/**
* Get the list of all icon names registered in the TwoFAccount table
*
*
* @return Collection<array-key, mixed>
*/
protected function registeredIcons()
{
return TwoFAccount::whereNotNull('icon')->pluck('icon');
}
/**
* 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();
$deletedFromDisk = $this->disk()->delete($names);
if ($deletedFromDisk && $this->usesDatabase) {
Icon::destroy($names);
@ -206,7 +205,7 @@ public function store(string $name, string $content) : bool
{
$storedToDisk = $this->storeToDisk($name, $content);
if ($this->usesDatabase) {
if ($this->usesDatabase) {
return $this->storeToDatabase($name, $content);
}

View File

@ -9,7 +9,7 @@
use Illuminate\Support\Facades\Storage;
class LogoService
{
{
/**
* @var \Illuminate\Support\Collection<string, string>
*/
@ -157,7 +157,7 @@ protected function cleanDomain(string $domain) : string
*
* @param string $logoFilename
* @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
{

View File

@ -3,8 +3,8 @@
namespace App\Services\Migrators;
use App\Exceptions\InvalidMigrationDataException;
use App\Services\IconService;
use App\Models\TwoFAccount;
use App\Services\IconService;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
@ -39,7 +39,7 @@ class AegisMigrator extends Migrator
public function migrate(mixed $migrationPayload) : Collection
{
$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) {
Log::error('Aegis JSON migration data cannot be read');

View File

@ -3,8 +3,8 @@
namespace App\Services\Migrators;
use App\Exceptions\InvalidMigrationDataException;
use App\Services\IconService;
use App\Models\TwoFAccount;
use App\Services\IconService;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
@ -43,7 +43,7 @@ class TwoFAuthMigrator extends Migrator
public function migrate(mixed $migrationPayload) : Collection
{
$iconService = App::make(IconService::class);
$json = json_decode(htmlspecialchars_decode($migrationPayload), true);
$json = json_decode(htmlspecialchars_decode($migrationPayload), true);
if (is_null($json)) {
Log::error('2FAuth JSON migration data cannot be read');

View File

@ -34,7 +34,7 @@ public function setUp() : void
Storage::fake('icons');
Storage::fake('logos');
Http::preventStrayRequests();
Http::fake([
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()
{
$iconName = 'testIcon.jpg';
$file = UploadedFile::fake()->image($iconName);
$file = UploadedFile::fake()->image($iconName);
$response = $this->actingAs($this->user, 'api-guard')
->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()
{
IconStore::spy();
$iconName = 'testIcon.jpg';
$response = $this->actingAs($this->user, 'api-guard')

View File

@ -237,7 +237,7 @@ public function setUp() : void
Storage::fake('icons');
Storage::fake('logos');
Storage::fake('imagesLink');
Http::preventStrayRequests();
Http::fake([
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),

View File

@ -48,30 +48,30 @@ public static function provideValidData() : array
{
return [
[[
'ids' => '1',
'ids' => '1',
'otpauth' => '1',
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => 1,
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => true,
]],
[[
'ids' => '1',
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => '0',
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => 0,
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => false,
]],
];
@ -94,31 +94,31 @@ public static function provideInvalidData() : array
{
return [
[[
'ids' => '1',
'ids' => '1',
'otpauth' => null,
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => '',
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => 2,
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => 'string',
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => 0.1,
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => '01/01/2020',
]],
[[
'ids' => '1',
'ids' => '1',
'otpauth' => '01',
]],
];

View File

@ -49,7 +49,7 @@ public function setUp() : void
Storage::fake('imagesLink');
Storage::fake('icons');
Http::preventStrayRequests();
/** @var \Illuminate\Contracts\Auth\Authenticatable $user */
@ -671,7 +671,7 @@ public function test_scopeOrphans_retreives_accounts_without_owner()
Http::fake([
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response(HttpRequestTestData::ICON_PNG, 200),
]);
$orphan = new TwoFAccount;
$orphan->fillWithURI(OtpTestData::HOTP_FULL_CUSTOM_URI);
$orphan->save();

View File

@ -4,7 +4,6 @@
use App\Facades\IconStore;
use App\Models\AuthLog;
use App\Models\Dto\IconDto;
use App\Models\Group;
use App\Models\TwoFAccount;
use App\Models\User;
@ -174,7 +173,7 @@ public function test_delete_flushes_icons_of_user_twofaccounts()
'icon' => OtpTestData::ICON_PNG,
]);
IconStore::store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
Storage::disk('icons')->assertExists($twofaccount->icon);
$user->delete();

View File

@ -34,11 +34,11 @@ class IconServiceTest extends FeatureTestCase
public function setUp() : void
{
parent::setUp();
Storage::fake('icons');
Storage::fake('logos');
Storage::fake('imagesLink');
Http::preventStrayRequests();
Http::fake([
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]
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';
$this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromResource($resource, $extension);
$iconName = $this->iconService->buildFromResource($resource, $extension);
Storage::disk('icons')->assertExists($iconName);
$this->assertEquals($resource, Storage::disk('icons')->get($iconName));
@ -80,7 +80,7 @@ public function test_buildFromResource_returns_null_when_store_fails()
->andReturn(false);
$this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromResource('lorem', 'ipsum');
$iconName = $this->iconService->buildFromResource('lorem', 'ipsum');
$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)
{
$this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromResource($resource, $extension);
$iconName = $this->iconService->buildFromResource($resource, $extension);
$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);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
Storage::disk('icons')->assertExists($iconName);
Storage::disk('imagesLink')->assertMissing($iconName);
@ -174,7 +174,7 @@ public function test_buildFromRemoteImage_returns_null_when_url_is_invalid()
->andReturn(false);
$this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$this->assertNull($iconName);
}
@ -203,11 +203,11 @@ public function test_buildFromRemoteImage_returns_null_when_remote_img_is_unreac
Http::fake([
'example.com/*' => Http::response(null, 400),
]);
$imageUrl = 'https://www.example.com/image.png';
$this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$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);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$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);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$this->assertNull($iconName);
}
}
}

View File

@ -40,7 +40,7 @@ public function setUp() : void
Storage::fake('icons');
$this->iconStore = $this->app->make(IconStoreService::class);
}
#[Test]
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);
}
/**
* Provide data for index tests
*/
@ -115,7 +115,7 @@ public static function supportedMimeTypesProvider()
'BPM' => [
OtpTestData::ICON_BMP,
OtpTestData::ICON_BMP_DATA,
'image/bmp|image/x-ms-bmp'
'image/bmp|image/x-ms-bmp',
],
'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));
}
#[Test]
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_JPEG);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG,
'name' => OtpTestData::ICON_PNG,
]);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_JPEG,
'name' => OtpTestData::ICON_JPEG,
]);
$result = $this->iconStore->clear();
@ -218,10 +218,10 @@ public function test_clear_empty_disk_deletes_icons_in_database()
]);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG,
'name' => OtpTestData::ICON_PNG,
]);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_JPEG,
'name' => OtpTestData::ICON_JPEG,
]);
$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()
{
Settings::set('storeIconsInDatabase', true);
Storage::disk('icons')->put(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
DB::table('icons')->insert([
'name' => OtpTestData::ICON_PNG,
'content' => OtpTestData::ICON_PNG_DATA,
]);
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG,
'name' => OtpTestData::ICON_PNG,
]);
$this->iconStore->delete(OtpTestData::ICON_PNG);
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
$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()
{
Settings::set('storeIconsInDatabase', true);
DB::table('icons')->insert([
'name' => OtpTestData::ICON_PNG,
'content' => OtpTestData::ICON_PNG_DATA,
]);
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG,
'name' => OtpTestData::ICON_PNG,
]);
$this->iconStore->delete(OtpTestData::ICON_PNG);
$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()
{
Settings::set('storeIconsInDatabase', true);
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));
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_JPEG);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG,
'name' => OtpTestData::ICON_PNG,
]);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_JPEG,
'name' => OtpTestData::ICON_JPEG,
]);
$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_JPEG);
$this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_PNG,
'name' => OtpTestData::ICON_PNG,
]);
$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()
{
Settings::set('storeIconsInDatabase', true);
DB::table('icons')->insert([
'name' => OtpTestData::ICON_PNG,
'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_JPEG);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG,
'name' => OtpTestData::ICON_PNG,
]);
$this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_JPEG,
'name' => OtpTestData::ICON_JPEG,
]);
$this->iconStore->delete([
@ -401,10 +401,10 @@ public function test_delete_deletes_provided_icons_in_database_when_disk_is_empt
]);
$this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_PNG,
'name' => OtpTestData::ICON_PNG,
]);
$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);
$this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_PNG,
'name' => OtpTestData::ICON_PNG,
]);
$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);
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
$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')
->with($iconName, $iconContent)
->andReturn(false);
$result = $this->iconStore->store($iconName, $iconContent);
$this->assertFalse($result);
@ -553,7 +553,7 @@ public function test_setDatabaseReplication_stores_icon_files_to_database()
#[Test]
public function test_setDatabaseReplication_stores_only_registered_icon_to_database()
{
$user = User::factory()->create();
$user = User::factory()->create();
TwoFAccount::factory()->for($user)->create([
'icon' => OtpTestData::ICON_PNG,
@ -594,7 +594,7 @@ public function test_setDatabaseReplication_clears_database_before_replication()
#[Test]
public function test_setDatabaseReplication_skips_icon_when_file_is_missing()
{
$user = User::factory()->create();
$user = User::factory()->create();
TwoFAccount::factory()->for($user)->create([
'icon' => OtpTestData::ICON_PNG,
@ -644,7 +644,7 @@ public function test_setDatabaseReplication_overrides_existing_files_during_rest
{
Settings::set('storeIconsInDatabase', true);
$user = User::factory()->create();
$user = User::factory()->create();
TwoFAccount::factory()->for($user)->create([
'icon' => OtpTestData::ICON_PNG,
@ -721,9 +721,9 @@ public function test_setDatabaseReplication_Off_sends_exception_and_does_nothing
]);
Storage::shouldReceive('disk->put')
->once()
->andThrow(new FailedIconStoreDatabaseTogglingException);
->once()
->andThrow(new FailedIconStoreDatabaseTogglingException);
$this->expectException(FailedIconStoreDatabaseTogglingException::class);
Settings::set('storeIconsInDatabase', false);

View File

@ -52,7 +52,7 @@ public function test_getIcon_returns_null_when_github_request_fails()
Http::preventStrayRequests();
Http::fake([
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);
@ -97,7 +97,7 @@ public function test_logoService_loads_empty_collection_when_tfajson_fetching_fa
Http::preventStrayRequests();
Http::fake([
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);

View File

@ -8,13 +8,11 @@
use App\Facades\Settings;
use App\Models\Icon;
use App\Models\TwoFAccount;
use App\Services\IconStoreService;
use App\Services\SettingService;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Mockery\MockInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
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()
{
$this->expectException(FailedIconStoreDatabaseTogglingException::class);
$newValue = true;
IconStore::shouldReceive('setDatabaseReplication')

View File

@ -17,7 +17,7 @@ class storeIconsInDatabaseSettingChangedTest extends TestCase
public function test_event_constructor()
{
$newValue = true;
$event = new storeIconsInDatabaseSettingChanged($newValue);
$event = new storeIconsInDatabaseSettingChanged($newValue);
$this->assertSame($newValue, $event->newValue);
}

View File

@ -3,7 +3,6 @@
namespace Tests\Unit\Listeners;
use App\Events\TwoFAccountDeleted;
use App\Facades\Settings;
use App\Listeners\CleanIconStorage;
use App\Models\TwoFAccount;
use App\Services\IconStoreService;
@ -42,7 +41,7 @@ public function test_it_deletes_icon_file_using_the_iconstore()
->with($event->twofaccount->icon)
->andReturn(true);
});
/**
* @disregard P1009 Undefined type
*/

View File

@ -6,7 +6,6 @@
use App\Exceptions\InvalidMigrationDataException;
use App\Exceptions\UnsupportedMigrationException;
use App\Facades\Icons;
use App\Facades\IconStore;
use App\Factories\MigratorFactory;
use App\Models\TwoFAccount;
use App\Providers\MigrationServiceProvider;
@ -416,13 +415,13 @@ public function test_migrate_2fauth_payload_with_icon_sets_and_stores_the_icon($
{
Icons::spy();
Storage::fake('icons');
$migrator = new TwoFAuthMigrator;
$accounts = $migrator->migrate($migration);
$this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
$this->assertCount(1, $accounts);
Icons::shouldHaveReceived('buildFromResource')->once();
Storage::disk('icons')->assertExists($accounts->first()->icon);
}

View File

@ -149,7 +149,7 @@ public function test_user_relation()
#[Test]
public function test_twofaccount_relation()
{
$model = new Icon();
$model = new Icon;
$relation = $model->twofaccount();
$this->assertInstanceOf(BelongsTo::class, $relation);