mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-16 08:37:53 +02:00
Add ability to export data as otpauth URIs - Closes #386
This commit is contained in:
@ -166,7 +166,18 @@ class TwoFAccountControllerTest extends FeatureTestCase
|
||||
'period',
|
||||
'counter',
|
||||
'legacy_uri',
|
||||
], ],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
private const VALID_EXPORT_AS_URIS_STRUTURE = [
|
||||
'app',
|
||||
'datetime',
|
||||
'data' => [
|
||||
'*' => [
|
||||
'uri',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
private const JSON_FRAGMENTS_FOR_CUSTOM_TOTP = [
|
||||
@ -1221,6 +1232,34 @@ class TwoFAccountControllerTest extends FeatureTestCase
|
||||
->assertJsonFragment(self::JSON_FRAGMENTS_FOR_DEFAULT_HOTP);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function test_export_returns_plain_text_with_otpauth_uris()
|
||||
{
|
||||
$this->twofaccountA = TwoFAccount::factory()->for($this->user)->create(self::JSON_FRAGMENTS_FOR_DEFAULT_TOTP);
|
||||
$this->twofaccountB = TwoFAccount::factory()->for($this->user)->create(self::JSON_FRAGMENTS_FOR_DEFAULT_HOTP);
|
||||
|
||||
$this->actingAs($this->user, 'api-guard')
|
||||
->json('GET', '/api/v1/twofaccounts/export?ids=' . $this->twofaccountA->id . ',' . $this->twofaccountB->id . '&otpauth=1')
|
||||
->assertOk()
|
||||
->assertJsonStructure(self::VALID_EXPORT_AS_URIS_STRUTURE)
|
||||
->assertJsonFragment(['uri' => $this->twofaccountA->getURI()])
|
||||
->assertJsonFragment(['uri' => $this->twofaccountB->getURI()]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function test_export_returns_json_migration_resource_when_otpauth_param_is_off()
|
||||
{
|
||||
$this->twofaccountA = TwoFAccount::factory()->for($this->user)->create(self::JSON_FRAGMENTS_FOR_DEFAULT_TOTP);
|
||||
$this->twofaccountB = TwoFAccount::factory()->for($this->user)->create(self::JSON_FRAGMENTS_FOR_DEFAULT_HOTP);
|
||||
|
||||
$this->actingAs($this->user, 'api-guard')
|
||||
->json('GET', '/api/v1/twofaccounts/export?ids=' . $this->twofaccountA->id . ',' . $this->twofaccountB->id . '&otpauth=0')
|
||||
->assertOk()
|
||||
->assertJsonStructure(self::VALID_EXPORT_STRUTURE)
|
||||
->assertJsonFragment(self::JSON_FRAGMENTS_FOR_DEFAULT_TOTP)
|
||||
->assertJsonFragment(self::JSON_FRAGMENTS_FOR_DEFAULT_HOTP);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function test_export_too_many_ids_returns_bad_request()
|
||||
{
|
||||
|
Reference in New Issue
Block a user