mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 08:13:11 +01:00
Add missing Storage & Http facade fakes
This commit is contained in:
parent
b344f7756f
commit
15ee7d2e24
@ -235,6 +235,9 @@ public function setUp() : void
|
|||||||
Http::fake([
|
Http::fake([
|
||||||
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response((new FileFactory)->image('file.png', 10, 10)->tempFile, 200),
|
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response((new FileFactory)->image('file.png', 10, 10)->tempFile, 200),
|
||||||
]);
|
]);
|
||||||
|
Http::fake([
|
||||||
|
'example.com/*' => Http::response(null, 400),
|
||||||
|
]);
|
||||||
|
|
||||||
$this->user = User::factory()->create();
|
$this->user = User::factory()->create();
|
||||||
$this->userGroupA = Group::factory()->for($this->user)->create();
|
$this->userGroupA = Group::factory()->for($this->user)->create();
|
||||||
|
@ -80,9 +80,9 @@ class OtpTestData
|
|||||||
|
|
||||||
const HOTP_SHORT_URI = 'otpauth://hotp/' . self::ACCOUNT . '?secret=' . self::SECRET;
|
const HOTP_SHORT_URI = 'otpauth://hotp/' . self::ACCOUNT . '?secret=' . self::SECRET;
|
||||||
|
|
||||||
const UNREACHABLE_IMAGE_URL = 'https%3A%2F%2Fen.opensuse.org%2Fimage.png';
|
const UNREACHABLE_IMAGE_URL = 'https%3A%2F%2Fwww.example.com%2Fimage.png';
|
||||||
|
|
||||||
const UNREACHABLE_IMAGE_URL_DECODED = 'https://en.opensuse.or/image.png';
|
const UNREACHABLE_IMAGE_URL_DECODED = 'https://www.example.com/image.png';
|
||||||
|
|
||||||
const TOTP_URI_WITH_UNREACHABLE_IMAGE = 'otpauth://totp/service:account?secret=A4GRFHVVRBGY7UIW&image=' . self::UNREACHABLE_IMAGE_URL;
|
const TOTP_URI_WITH_UNREACHABLE_IMAGE = 'otpauth://totp/service:account?secret=A4GRFHVVRBGY7UIW&image=' . self::UNREACHABLE_IMAGE_URL;
|
||||||
|
|
||||||
|
@ -47,6 +47,11 @@ public function setUp() : void
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
Storage::fake('imagesLink');
|
||||||
|
Storage::fake('icons');
|
||||||
|
|
||||||
|
Http::preventStrayRequests();
|
||||||
|
|
||||||
/** @var \Illuminate\Contracts\Auth\Authenticatable $user */
|
/** @var \Illuminate\Contracts\Auth\Authenticatable $user */
|
||||||
$this->user = User::factory()->create();
|
$this->user = User::factory()->create();
|
||||||
$this->actingAs($this->user, 'api-guard');
|
$this->actingAs($this->user, 'api-guard');
|
||||||
@ -95,15 +100,10 @@ public function test_fill_with_custom_totp_uri_returns_correct_value()
|
|||||||
{
|
{
|
||||||
$file = (new FileFactory)->image('file.png', 10, 10);
|
$file = (new FileFactory)->image('file.png', 10, 10);
|
||||||
|
|
||||||
// TODO: set preventStrayRequests in parent class to ensure all tests use a fake
|
|
||||||
Http::preventStrayRequests();
|
|
||||||
Http::fake([
|
Http::fake([
|
||||||
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response($file->tempFile, 200),
|
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response($file->tempFile, 200),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Storage::fake('imagesLink');
|
|
||||||
Storage::fake('icons');
|
|
||||||
|
|
||||||
$twofaccount = new TwoFAccount;
|
$twofaccount = new TwoFAccount;
|
||||||
$twofaccount->fillWithURI(OtpTestData::TOTP_FULL_CUSTOM_URI);
|
$twofaccount->fillWithURI(OtpTestData::TOTP_FULL_CUSTOM_URI);
|
||||||
|
|
||||||
@ -162,14 +162,10 @@ public function test_fill_with_custom_hotp_uri_returns_correct_value()
|
|||||||
{
|
{
|
||||||
$file = (new FileFactory)->image('file.png', 10, 10);
|
$file = (new FileFactory)->image('file.png', 10, 10);
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
|
||||||
Http::fake([
|
Http::fake([
|
||||||
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response($file->tempFile, 200),
|
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response($file->tempFile, 200),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Storage::fake('imagesLink');
|
|
||||||
Storage::fake('icons');
|
|
||||||
|
|
||||||
$twofaccount = new TwoFAccount;
|
$twofaccount = new TwoFAccount;
|
||||||
$twofaccount->fillWithURI(OtpTestData::HOTP_FULL_CUSTOM_URI);
|
$twofaccount->fillWithURI(OtpTestData::HOTP_FULL_CUSTOM_URI);
|
||||||
|
|
||||||
@ -464,14 +460,10 @@ public function test_update_totp_persists_updated_model()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_getOTP_for_totp_returns_the_same_password()
|
public function test_getOTP_for_totp_returns_the_same_password()
|
||||||
{
|
{
|
||||||
Http::preventStrayRequests();
|
|
||||||
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),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Storage::fake('imagesLink');
|
|
||||||
Storage::fake('icons');
|
|
||||||
|
|
||||||
$twofaccount = new TwoFAccount;
|
$twofaccount = new TwoFAccount;
|
||||||
|
|
||||||
$otp_from_model = $this->customTotpTwofaccount->getOTP();
|
$otp_from_model = $this->customTotpTwofaccount->getOTP();
|
||||||
@ -492,14 +484,10 @@ public function test_getOTP_for_totp_returns_the_same_password()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_getOTP_for_hotp_returns_the_same_password()
|
public function test_getOTP_for_hotp_returns_the_same_password()
|
||||||
{
|
{
|
||||||
Http::preventStrayRequests();
|
|
||||||
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),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Storage::fake('imagesLink');
|
|
||||||
Storage::fake('icons');
|
|
||||||
|
|
||||||
$twofaccount = new TwoFAccount;
|
$twofaccount = new TwoFAccount;
|
||||||
|
|
||||||
$otp_from_model = $this->customHotpTwofaccount->getOTP();
|
$otp_from_model = $this->customHotpTwofaccount->getOTP();
|
||||||
@ -585,14 +573,10 @@ public function test_getURI_for_custom_hotp_model_returns_uri()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_fill_succeed_when_image_fetching_fails()
|
public function test_fill_succeed_when_image_fetching_fails()
|
||||||
{
|
{
|
||||||
Http::preventStrayRequests();
|
|
||||||
Http::fake([
|
Http::fake([
|
||||||
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => new \Exception,
|
OtpTestData::EXTERNAL_IMAGE_URL_DECODED => new \Exception,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Storage::fake('imagesLink');
|
|
||||||
Storage::fake('icons');
|
|
||||||
|
|
||||||
$twofaccount = new TwoFAccount;
|
$twofaccount = new TwoFAccount;
|
||||||
$twofaccount->fillWithURI(OtpTestData::TOTP_FULL_CUSTOM_URI);
|
$twofaccount->fillWithURI(OtpTestData::TOTP_FULL_CUSTOM_URI);
|
||||||
|
|
||||||
@ -684,6 +668,10 @@ public function test_equals_returns_false()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_scopeOrphans_retreives_accounts_without_owner()
|
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 = new TwoFAccount;
|
||||||
$orphan->fillWithURI(OtpTestData::HOTP_FULL_CUSTOM_URI);
|
$orphan->fillWithURI(OtpTestData::HOTP_FULL_CUSTOM_URI);
|
||||||
$orphan->save();
|
$orphan->save();
|
||||||
|
@ -200,7 +200,11 @@ public static function buildFromRemoteImageInvalidUrlProvider()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_buildFromRemoteImage_returns_null_when_remote_img_is_unreachable()
|
public function test_buildFromRemoteImage_returns_null_when_remote_img_is_unreachable()
|
||||||
{
|
{
|
||||||
$imageUrl = 'https://icon.png';
|
Http::fake([
|
||||||
|
'example.com/*' => Http::response(null, 400),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$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);
|
||||||
|
@ -23,12 +23,18 @@ class ReleaseRadarServiceTest extends FeatureTestCase
|
|||||||
{
|
{
|
||||||
use WithoutMiddleware;
|
use WithoutMiddleware;
|
||||||
|
|
||||||
|
public function setUp() : void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Http::preventStrayRequests();
|
||||||
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function test_manualScan_returns_no_new_release()
|
public function test_manualScan_returns_no_new_release()
|
||||||
{
|
{
|
||||||
$url = config('2fauth.latestReleaseUrl');
|
$url = config('2fauth.latestReleaseUrl');
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
|
||||||
Http::fake([
|
Http::fake([
|
||||||
$url => Http::response(HttpRequestTestData::LATEST_RELEASE_BODY_NO_NEW_RELEASE, 200),
|
$url => Http::response(HttpRequestTestData::LATEST_RELEASE_BODY_NO_NEW_RELEASE, 200),
|
||||||
]);
|
]);
|
||||||
@ -48,7 +54,6 @@ public function test_manualScan_returns_new_release()
|
|||||||
{
|
{
|
||||||
$url = config('2fauth.latestReleaseUrl');
|
$url = config('2fauth.latestReleaseUrl');
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
|
||||||
Http::fake([
|
Http::fake([
|
||||||
$url => Http::response(HttpRequestTestData::LATEST_RELEASE_BODY_NEW_RELEASE, 200),
|
$url => Http::response(HttpRequestTestData::LATEST_RELEASE_BODY_NEW_RELEASE, 200),
|
||||||
]);
|
]);
|
||||||
@ -66,8 +71,9 @@ public function test_manualScan_returns_new_release()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_manualScan_complete_when_http_call_fails()
|
public function test_manualScan_complete_when_http_call_fails()
|
||||||
{
|
{
|
||||||
// We do not fake the http request so an exception will be thrown
|
Http::fake([
|
||||||
Http::preventStrayRequests();
|
config('2fauth.latestReleaseUrl') => Http::response('not found', 404),
|
||||||
|
]);
|
||||||
|
|
||||||
$this->assertNull(ReleaseRadarService::manualScan());
|
$this->assertNull(ReleaseRadarService::manualScan());
|
||||||
}
|
}
|
||||||
@ -77,9 +83,8 @@ public function test_manualScan_succeed_when_github_is_unreachable()
|
|||||||
{
|
{
|
||||||
$url = config('2fauth.latestReleaseUrl');
|
$url = config('2fauth.latestReleaseUrl');
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
|
||||||
Http::fake([
|
Http::fake([
|
||||||
$url => Http::response(null, 400),
|
$url => Http::response(null, 404),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertNull(ReleaseRadarService::manualScan());
|
$this->assertNull(ReleaseRadarService::manualScan());
|
||||||
@ -90,7 +95,6 @@ public function test_scheduleScan_runs_after_one_week()
|
|||||||
{
|
{
|
||||||
$url = config('2fauth.latestReleaseUrl');
|
$url = config('2fauth.latestReleaseUrl');
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
|
||||||
Http::fake([
|
Http::fake([
|
||||||
$url => Http::response(HttpRequestTestData::LATEST_RELEASE_BODY_NEW_RELEASE, 200),
|
$url => Http::response(HttpRequestTestData::LATEST_RELEASE_BODY_NEW_RELEASE, 200),
|
||||||
]);
|
]);
|
||||||
@ -118,7 +122,6 @@ public function test_scheduleScan_does_not_run_before_one_week()
|
|||||||
{
|
{
|
||||||
$url = config('2fauth.latestReleaseUrl');
|
$url = config('2fauth.latestReleaseUrl');
|
||||||
|
|
||||||
Http::preventStrayRequests();
|
|
||||||
Http::fake([
|
Http::fake([
|
||||||
$url => Http::response(HttpRequestTestData::LATEST_RELEASE_BODY_NEW_RELEASE, 200),
|
$url => Http::response(HttpRequestTestData::LATEST_RELEASE_BODY_NEW_RELEASE, 200),
|
||||||
]);
|
]);
|
||||||
@ -144,8 +147,11 @@ public function test_scheduleScan_does_not_run_before_one_week()
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_scheduleScan_complete_when_http_call_fails()
|
public function test_scheduleScan_complete_when_http_call_fails()
|
||||||
{
|
{
|
||||||
// We do not fake the http request so an exception will be thrown
|
$url = config('2fauth.latestReleaseUrl');
|
||||||
Http::preventStrayRequests();
|
|
||||||
|
Http::fake([
|
||||||
|
$url => Http::response(null, 404),
|
||||||
|
]);
|
||||||
|
|
||||||
$this->assertNull(ReleaseRadarService::scheduledScan());
|
$this->assertNull(ReleaseRadarService::scheduledScan());
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,9 @@ class SettingServiceTest extends FeatureTestCase
|
|||||||
|
|
||||||
private const PERIOD_CUSTOM = 40;
|
private const PERIOD_CUSTOM = 40;
|
||||||
|
|
||||||
private const EXTERNAL_IMAGE_URL_ENCODED = 'https%3A%2F%2Fen.opensuse.org%2Fimages%2F4%2F44%2FButton-filled-colour.png';
|
|
||||||
|
|
||||||
private const ICON = 'test.png';
|
private const ICON = 'test.png';
|
||||||
|
|
||||||
private const TOTP_FULL_CUSTOM_URI = 'otpauth://totp/' . self::SERVICE . ':' . self::ACCOUNT . '?secret=' . self::SECRET . '&issuer=' . self::SERVICE . '&digits=' . self::DIGITS_CUSTOM . '&period=' . self::PERIOD_CUSTOM . '&algorithm=' . self::ALGORITHM_CUSTOM . '&image=' . self::EXTERNAL_IMAGE_URL_ENCODED;
|
private const TOTP_FULL_CUSTOM_URI = 'otpauth://totp/' . self::SERVICE . ':' . self::ACCOUNT . '?secret=' . self::SECRET . '&issuer=' . self::SERVICE . '&digits=' . self::DIGITS_CUSTOM . '&period=' . self::PERIOD_CUSTOM . '&algorithm=' . self::ALGORITHM_CUSTOM . '&image=' . OtpTestData::EXTERNAL_IMAGE_URL_ENCODED;
|
||||||
|
|
||||||
public function setUp() : void
|
public function setUp() : void
|
||||||
{
|
{
|
||||||
|
@ -5,13 +5,25 @@
|
|||||||
use App\Events\ScanForNewReleaseCalled;
|
use App\Events\ScanForNewReleaseCalled;
|
||||||
use App\Http\Controllers\SinglePageController;
|
use App\Http\Controllers\SinglePageController;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use PHPUnit\Framework\Attributes\Test;
|
use PHPUnit\Framework\Attributes\Test;
|
||||||
|
use Tests\Data\HttpRequestTestData;
|
||||||
use Tests\FeatureTestCase;
|
use Tests\FeatureTestCase;
|
||||||
|
|
||||||
#[CoversClass(SinglePageController::class)]
|
#[CoversClass(SinglePageController::class)]
|
||||||
class ViewTest extends FeatureTestCase
|
class ViewTest extends FeatureTestCase
|
||||||
{
|
{
|
||||||
|
public function setUp() : void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Http::preventStrayRequests();
|
||||||
|
Http::fake([
|
||||||
|
config('2fauth.latestReleaseUrl') => Http::response(HttpRequestTestData::LATEST_RELEASE_BODY_NO_NEW_RELEASE),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function test_landing_view_is_returned()
|
public function test_landing_view_is_returned()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user