瀏覽代碼

Fix & Complete tests

Bubka 1 月之前
父節點
當前提交
d87eb36cd9

+ 0 - 1
app/Models/TwoFAccount.php

@@ -552,7 +552,6 @@ class TwoFAccount extends Model implements Sortable
             $this->icon = Icons::buildFromRemoteImage($this->generator->getParameter('image'));
         }
 
-        $uuu = Auth::user()?->preferences;
         if (! $this->icon && ! $skipIconFetching && Auth::user()?->preferences['getOfficialIcons']) {
             $this->icon = Icons::buildFromOfficialLogo($this->service);
         }

+ 7 - 3
tests/Api/v1/Controllers/TwoFAccountControllerTest.php

@@ -243,8 +243,10 @@ class TwoFAccountControllerTest extends FeatureTestCase
 
         Http::preventStrayRequests();
         Http::fake([
-            CommonDataProvider::TFA_URL                     => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
-            TfaLogoLib::TFA_JSON_URL                             => Http::response(HttpRequestTestData::TFA_JSON_BODY, 200),
+            CommonDataProvider::TFA_URL                      => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
+            CommonDataProvider::SELFH_URL                    => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
+            CommonDataProvider::DASHBOARDICONS_URL           => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
+            TfaLogoLib::TFA_JSON_URL                         => Http::response(HttpRequestTestData::TFA_JSON_BODY, 200),
             OtpTestData::EXTERNAL_IMAGE_URL_DECODED          => Http::response((new FileFactory)->image('file.png', 10, 10)->tempFile, 200),
             OtpTestData::EXTERNAL_INFECTED_IMAGE_URL_DECODED => Http::response((new FileFactory)->createWithContent('infected.svg', OtpTestData::ICON_SVG_DATA_INFECTED)->tempFile, 200),
             'example.com/*'                                  => Http::response(null, 400),
@@ -929,8 +931,10 @@ class TwoFAccountControllerTest extends FeatureTestCase
     }
 
     #[Test]
-    public function test_migrate_identify_duplicates_in_authenticated_user_twofaccounts_only()
+    public function test_migrate_identifies_duplicates_in_authenticated_user_twofaccounts_only()
     {
+        $this->user['preferences->getOfficialIcons'] = false;
+
         $twofaccount = TwoFAccount::factory()->for($this->anotherUser)->create([
             'otp_type'   => 'totp',
             'account'    => OtpTestData::ACCOUNT,

+ 5 - 5
tests/Feature/Http/Auth/WebAuthnRegisterControllerTest.php

@@ -3,11 +3,11 @@
 namespace Tests\Feature\Http\Auth;
 
 use App\Http\Controllers\Auth\WebAuthnRegisterController;
+use App\Http\Requests\WebauthnAttestationRequest;
+use App\Http\Requests\WebauthnAttestedRequest;
 use App\Models\User;
 use Illuminate\Support\Facades\Config;
 use Laragear\WebAuthn\Enums\UserVerification;
-use Laragear\WebAuthn\Http\Requests\AttestationRequest;
-use Laragear\WebAuthn\Http\Requests\AttestedRequest;
 use Laragear\WebAuthn\JsonTransport;
 use PHPUnit\Framework\Attributes\CoversClass;
 use PHPUnit\Framework\Attributes\Test;
@@ -36,7 +36,7 @@ class WebAuthnRegisterControllerTest extends FeatureTestCase
     {
         Config::set('webauthn.user_verification', UserVerification::DISCOURAGED);
 
-        $request = $this->mock(AttestationRequest::class);
+        $request = $this->mock(WebauthnAttestationRequest::class);
 
         $request->expects('fastRegistration')->andReturnSelf();
         $request->expects('toCreate')->andReturn(new JsonTransport);
@@ -51,7 +51,7 @@ class WebAuthnRegisterControllerTest extends FeatureTestCase
     {
         Config::set('webauthn.user_verification', UserVerification::REQUIRED);
 
-        $request = $this->mock(AttestationRequest::class);
+        $request = $this->mock(WebauthnAttestationRequest::class);
 
         $request->expects('secureRegistration')->andReturnSelf();
         $request->expects('toCreate')->andReturn(new JsonTransport);
@@ -64,7 +64,7 @@ class WebAuthnRegisterControllerTest extends FeatureTestCase
     #[Test]
     public function test_register_uses_attested_request() : void
     {
-        $request = $this->mock(AttestedRequest::class);
+        $request = $this->mock(WebauthnAttestedRequest::class);
 
         $request->expects('save')->andReturn();
         $request->expects('user')->andReturn($this->user);

+ 6 - 0
tests/Feature/Http/Requests/WebauthnRenameRequestTest.php

@@ -5,6 +5,7 @@ namespace Tests\Feature\Http\Requests;
 use App\Http\Requests\WebauthnRenameRequest;
 use Illuminate\Foundation\Testing\WithoutMiddleware;
 use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Gate;
 use Illuminate\Support\Facades\Validator;
 use PHPUnit\Framework\Attributes\CoversClass;
 use PHPUnit\Framework\Attributes\DataProvider;
@@ -26,6 +27,11 @@ class WebauthnRenameRequestTest extends TestCase
             ->once()
             ->andReturn(true);
 
+        Gate::shouldReceive('allows')
+            ->with('manage-webauthn-credentials')
+            ->once()
+            ->andReturn(true);
+
         $request = new WebauthnRenameRequest;
 
         $this->assertTrue($request->authorize());

+ 1 - 1
tests/Feature/Services/IconServiceTest.php

@@ -43,7 +43,7 @@ class IconServiceTest extends FeatureTestCase
             CommonDataProvider::TFA_URL            => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
             CommonDataProvider::SELFH_URL          => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
             CommonDataProvider::DASHBOARDICONS_URL => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
-            TfaLogoLib::TFA_JSON_URL                    => Http::response(HttpRequestTestData::TFA_JSON_BODY, 200),
+            TfaLogoLib::TFA_JSON_URL               => Http::response(HttpRequestTestData::TFA_JSON_BODY, 200),
         ]);
         Http::fake([
             OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response((new FileFactory)->image('file.png', 10, 10)->tempFile, 200),