Update tests & minor fixes

This commit is contained in:
Bubka
2022-12-09 10:52:17 +01:00
parent 7ce7067380
commit 05a39b6501
61 changed files with 2773 additions and 526 deletions

View File

@ -60,8 +60,6 @@ class TwoFAccount extends Model implements Sortable
const FAKE_ID = -2;
private const IMAGELINK_STORAGE_PATH = 'imagesLink/';
/**
* List of OTP types supported by 2FAuth
*/
@ -376,10 +374,6 @@ class TwoFAccount extends Model implements Sortable
$this->enforceAsSteam();
}
if (! $this->icon && $skipIconFetching) {
$this->icon = $this->getDefaultIcon();
}
if (! $this->icon && Settings::get('getOfficialIcons') && ! $skipIconFetching) {
$this->icon = $this->getDefaultIcon();
}
@ -441,6 +435,22 @@ class TwoFAccount extends Model implements Sortable
return $this;
}
/**
* Compare 2 TwoFAccounts
*/
public function equals(self $other): bool
{
return $this->service === $other->service &&
$this->account === $other->account &&
$this->icon === $other->icon &&
$this->otp_type === $other->otp_type &&
$this->secret === $other->secret &&
$this->digits === $other->digits &&
$this->algorithm === $other->algorithm &&
$this->period === $other->period &&
$this->counter === $other->counter;
}
/**
* Sets model attributes to STEAM values
*/
@ -534,7 +544,6 @@ class TwoFAccount extends Model implements Sortable
try {
$path_parts = pathinfo($url);
$newFilename = Helpers::getUniqueFilename($path_parts['extension']);
$imageFile = self::IMAGELINK_STORAGE_PATH . $newFilename;
try {
$response = Http::retry(3, 100)->get($url);
@ -546,8 +555,10 @@ class TwoFAccount extends Model implements Sortable
Log::error(sprintf('Cannot fetch imageLink at "%s"', $url));
}
if (in_array(Storage::mimeType($imageFile), ['image/png', 'image/jpeg', 'image/webp', 'image/bmp'])
&& getimagesize(storage_path() . '/app/' . $imageFile)) {
if (
in_array(Storage::disk('imagesLink')->mimeType($newFilename), ['image/png', 'image/jpeg', 'image/webp', 'image/bmp'])
&& getimagesize(Storage::disk('imagesLink')->path($newFilename))
) {
// Should be a valid image, we move it to the icons disk
if (Storage::disk('icons')->put($newFilename, Storage::disk('imagesLink')->get($newFilename))) {
Storage::disk('imagesLink')->delete($newFilename);
@ -555,10 +566,8 @@ class TwoFAccount extends Model implements Sortable
Log::info(sprintf('Icon file %s stored', $newFilename));
} else {
// @codeCoverageIgnoreStart
Storage::disk('imagesLink')->delete($newFilename);
throw new \Exception('Unsupported mimeType or missing image on storage');
// @codeCoverageIgnoreEnd
}
return $newFilename;