123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace Tests\Unit;
- use App\Models\TwoFAccount;
- use App\Events\TwoFAccountDeleted;
- use Tests\ModelTestCase;
- use Illuminate\Support\Facades\Event;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Support\Facades\Crypt;
- /**
- * @covers \App\Models\TwoFAccount
- */
- class TwoFAccountModelTest extends ModelTestCase
- {
- /**
- * @test
- */
- public function test_model_configuration()
- {
- $this->runConfigurationAssertions(
- new TwoFAccount(),
- [
- 'service',
- 'account',
- 'otp_type',
- 'digits',
- 'secret',
- 'algorithm',
- 'counter',
- 'period',
- 'icon'
- ],
- [],
- ['*'],
- [],
- ['id' => 'int'],
- ['deleted' => TwoFAccountDeleted::class],
- ['created_at', 'updated_at'],
- \Illuminate\Database\Eloquent\Collection::class,
- 'twofaccounts',
- 'id',
- true
- );
- }
- /**
- * @test
- *
- * @dataProvider provideSensitiveAttributes
- */
- public function test_sensitive_attributes_are_stored_encrypted(string $attribute)
- {
- \Facades\App\Services\SettingService::shouldReceive('get')
- ->with('useEncryption')
- ->andReturn(true);
- $twofaccount = TwoFAccount::factory()->make([
- $attribute => 'string',
- ]);
- $this->assertEquals('string', Crypt::decryptString($twofaccount->getAttributes()[$attribute]));
- }
- /**
- * Provide attributes to test for encryption
- */
- public function provideSensitiveAttributes() : array
- {
- return [
- [
- 'legacy_uri'
- ],
- [
- 'secret'
- ],
- [
- 'account'
- ],
- ];
- }
- /**
- * @test
- *
- * @dataProvider provideSensitiveAttributes
- */
- public function test_sensitive_attributes_are_returned_clear(string $attribute)
- {
- \Facades\App\Services\SettingService::shouldReceive('get')
- ->with('useEncryption')
- ->andReturn(false);
- $twofaccount = TwoFAccount::factory()->make();
- $this->assertEquals($twofaccount->getAttributes()[$attribute], $twofaccount->$attribute);
- }
- /**
- * @test
- *
- * @dataProvider provideSensitiveAttributes
- */
- public function test_indecipherable_attributes_returns_masked_value(string $attribute)
- {
- \Facades\App\Services\SettingService::shouldReceive('get')
- ->with('useEncryption')
- ->andReturn(true);
- Crypt::shouldReceive('encryptString')
- ->andReturn('indecipherableString');
- $twofaccount = TwoFAccount::factory()->make();
- $this->assertEquals(__('errors.indecipherable'), $twofaccount->$attribute);
- }
- }
|