mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 00:03:09 +01:00
Fix tests after setting PHP 8.2 as default
This commit is contained in:
parent
a1ca1ec9bf
commit
96978accb3
@ -45,7 +45,7 @@ public function migrate(mixed $migrationPayload) : Collection
|
||||
$parameters['otp_type'] = GAuthValueMapping::OTP_TYPE[OtpType::name($otp_parameters->getType())];
|
||||
$parameters['service'] = $otp_parameters->getIssuer();
|
||||
$parameters['account'] = str_replace($parameters['service'] . ':', '', $otp_parameters->getName());
|
||||
$parameters['secret'] = Base32::encodeUpper($otp_parameters->getSecret());
|
||||
$parameters['secret'] = $this->toBase32($otp_parameters->getSecret());
|
||||
$parameters['algorithm'] = GAuthValueMapping::ALGORITHM[Algorithm::name($otp_parameters->getAlgorithm())];
|
||||
$parameters['digits'] = GAuthValueMapping::DIGIT_COUNT[DigitCount::name($otp_parameters->getDigits())];
|
||||
$parameters['counter'] = $parameters['otp_type'] === TwoFAccount::HOTP ? $otp_parameters->getCounter() : null;
|
||||
@ -73,4 +73,11 @@ public function migrate(mixed $migrationPayload) : Collection
|
||||
|
||||
return collect($twofaccounts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode into uppercase Base32
|
||||
*/
|
||||
protected function toBase32(string $str) {
|
||||
return Base32::encodeUpper($str);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public static function encode(string $data)
|
||||
|
||||
Log::info('data encoded to QR code');
|
||||
|
||||
return $qrcode->render($data);
|
||||
return $qrcode->render('stringToEncode');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,6 +34,7 @@
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<ini name="memory_limit" value="256M" />
|
||||
<env name="APP_ENV" value="testing"/>
|
||||
<!-- following values override .env.testing vars -->
|
||||
</php>
|
||||
|
@ -473,4 +473,20 @@ public function test_destroy_group_resets_user_preferences()
|
||||
$this->assertEquals(0, $this->user->preferences['defaultGroup']);
|
||||
$this->assertEquals(0, $this->user->preferences['activeGroup']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_twofaccount_is_released_on_group_destroy()
|
||||
{
|
||||
$this->actingAs($this->user, 'api-guard')
|
||||
->json('DELETE', '/api/v1/groups/' . $this->userGroupA->id)
|
||||
->assertNoContent();
|
||||
|
||||
$this->twofaccountA->refresh();
|
||||
$this->twofaccountB->refresh();
|
||||
|
||||
$this->assertNull($this->twofaccountA->group_id);
|
||||
$this->assertNull($this->twofaccountB->group_id);
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public function test_show_qrcode_returns_base64_image()
|
||||
])
|
||||
->assertOk();
|
||||
|
||||
$this->assertStringStartsWith('data:image/png;base64', $response->getData()->qrcode);
|
||||
$this->assertStringStartsWith('data:image/svg+xml;base64', $response->getData()->qrcode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
File diff suppressed because one or more lines are too long
@ -4,14 +4,8 @@
|
||||
|
||||
use App\Events\GroupDeleting;
|
||||
use App\Listeners\DissociateTwofaccountFromGroup;
|
||||
use App\Models\Group;
|
||||
use App\Models\TwoFAccount;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Mockery\MockInterface;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\PreserveGlobalState;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhp;
|
||||
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -20,27 +14,6 @@
|
||||
#[CoversClass(DissociateTwofaccountFromGroup::class)]
|
||||
class DissociateTwofaccountFromGroupTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
#[RunInSeparateProcess]
|
||||
#[PreserveGlobalState(false)]
|
||||
#[RequiresPhp('< 8.3.0')]
|
||||
public function test_twofaccount_is_released_on_group_deletion()
|
||||
{
|
||||
$this->mock('alias:' . TwoFAccount::class, function (MockInterface $twoFAccount) {
|
||||
$twoFAccount->shouldReceive('where->update')
|
||||
->once()
|
||||
->andReturn(1);
|
||||
});
|
||||
|
||||
$group = Group::factory()->make();
|
||||
$event = new GroupDeleting($group);
|
||||
$listener = new DissociateTwofaccountFromGroup();
|
||||
|
||||
$this->assertNull($listener->handle($event));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
@ -18,12 +18,8 @@
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
use ParagonIE\ConstantTime\Base32;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\PreserveGlobalState;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhp;
|
||||
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use Tests\Data\MigrationTestData;
|
||||
use Tests\Data\OtpTestData;
|
||||
@ -142,6 +138,20 @@ public function setUp() : void
|
||||
$this->fakeTwofaccount->id = TwoFAccount::FAKE_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up the testing environment before the next test.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Mockery\Exception\InvalidCountException
|
||||
*/
|
||||
protected function tearDown() : void
|
||||
{
|
||||
$this->forgetMock(SettingService::class);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
@ -332,17 +342,14 @@ public static function migrationWithInvalidAccountsProvider()
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
#[RunInSeparateProcess]
|
||||
#[PreserveGlobalState(false)]
|
||||
#[RequiresPhp('< 8.3.0')]
|
||||
public function test_migrate_gauth_returns_fake_accounts()
|
||||
{
|
||||
$this->mock('alias:' . Base32::class, function (MockInterface $baseEncoder) {
|
||||
$baseEncoder->shouldReceive('encodeUpper')
|
||||
$migrator = $this->partialMock(GoogleAuthMigrator::class, function (MockInterface $migrator) {
|
||||
$migrator->shouldAllowMockingProtectedMethods()->shouldReceive('toBase32')
|
||||
->andThrow(new \Exception());
|
||||
});
|
||||
|
||||
$migrator = new GoogleAuthMigrator();
|
||||
/** @disregard Undefined function */
|
||||
$accounts = $migrator->migrate(MigrationTestData::GOOGLE_AUTH_MIGRATION_URI);
|
||||
|
||||
$this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
|
||||
@ -352,6 +359,8 @@ public function test_migrate_gauth_returns_fake_accounts()
|
||||
// in the migration payload) so we do not use get() to retrieve items
|
||||
$this->assertEquals($this->fakeTwofaccount->id, $accounts->first()->id);
|
||||
$this->assertEquals($this->fakeTwofaccount->id, $accounts->last()->id);
|
||||
|
||||
$this->forgetMock(GoogleAuthMigrator::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -548,9 +557,4 @@ public static function encryptedMigrationDataProvider()
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function tearDown() : void
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,6 @@
|
||||
use Mockery\MockInterface;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\PreserveGlobalState;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhp;
|
||||
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
|
||||
use Tests\ModelTestCase;
|
||||
|
||||
/**
|
||||
@ -63,6 +60,7 @@ public function test_sensitive_attributes_are_stored_encrypted(string $attribute
|
||||
]);
|
||||
|
||||
$this->assertEquals('STRING==', Crypt::decryptString($twofaccount->getAttributes()[$attribute]));
|
||||
$this->forgetMock(SettingService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,6 +96,7 @@ public function test_sensitive_attributes_are_returned_clear(string $attribute)
|
||||
$twofaccount = TwoFAccount::factory()->make();
|
||||
|
||||
$this->assertEquals($twofaccount->getAttributes()[$attribute], $twofaccount->$attribute);
|
||||
$this->forgetMock(SettingService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,14 +117,12 @@ public function test_indecipherable_attributes_returns_masked_value(string $attr
|
||||
$twofaccount = TwoFAccount::factory()->make();
|
||||
|
||||
$this->assertEquals(__('errors.indecipherable'), $twofaccount->$attribute);
|
||||
$this->forgetMock(SettingService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
#[RunInSeparateProcess]
|
||||
#[PreserveGlobalState(false)]
|
||||
#[RequiresPhp('< 8.3.0')]
|
||||
public function test_secret_is_uppercased_and_padded_at_setup()
|
||||
{
|
||||
$settingService = $this->mock(SettingService::class, function (MockInterface $settingService) {
|
||||
@ -134,7 +131,7 @@ public function test_secret_is_uppercased_and_padded_at_setup()
|
||||
->andReturn(false);
|
||||
});
|
||||
|
||||
$helpers = $this->mock('alias:' . Helpers::class, function (MockInterface $helpers) {
|
||||
$helpers = $this->mock(Helpers::class, function (MockInterface $helpers) {
|
||||
$helpers->shouldReceive('PadToBase32Format')
|
||||
->andReturn('YYYY====');
|
||||
});
|
||||
@ -144,6 +141,7 @@ public function test_secret_is_uppercased_and_padded_at_setup()
|
||||
]);
|
||||
|
||||
$this->assertEquals('YYYY====', $twofaccount->secret);
|
||||
$this->forgetMock(SettingService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user