2019-05-20 07:37:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
2019-06-06 13:40:06 +02:00
|
|
|
use App\User;
|
2019-05-20 07:37:41 +02:00
|
|
|
use Tests\TestCase;
|
2019-05-25 23:51:20 +02:00
|
|
|
use App\TwoFAccount;
|
2019-05-20 07:37:41 +02:00
|
|
|
|
2019-05-25 23:51:20 +02:00
|
|
|
class TwoFAccountTest extends TestCase
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2019-06-06 13:40:06 +02:00
|
|
|
/** @var \App\User */
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->user = factory(User::class)->create();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-20 07:37:41 +02:00
|
|
|
/**
|
2019-05-25 23:51:20 +02:00
|
|
|
* test TwoFAccount creation via API
|
2019-05-20 07:37:41 +02:00
|
|
|
*
|
2019-06-06 13:40:06 +02:00
|
|
|
* @test
|
2019-05-20 07:37:41 +02:00
|
|
|
*/
|
2019-05-25 23:51:20 +02:00
|
|
|
public function testTwoFAccountCreation()
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2019-06-06 13:40:06 +02:00
|
|
|
$response = $this->actingAs($this->user, 'api')
|
2019-05-25 23:51:20 +02:00
|
|
|
->json('POST', '/api/twofaccounts', [
|
2020-01-06 21:45:14 +01:00
|
|
|
'service' => 'testCreation',
|
|
|
|
'account' => 'test@example.org',
|
2019-05-26 23:24:22 +02:00
|
|
|
'uri' => 'test',
|
2019-05-25 23:51:20 +02:00
|
|
|
])
|
|
|
|
->assertStatus(201)
|
|
|
|
->assertJson([
|
2020-01-06 21:45:14 +01:00
|
|
|
'service' => 'testCreation',
|
|
|
|
'account' => 'test@example.org',
|
2019-05-26 23:24:22 +02:00
|
|
|
'uri' => 'test',
|
2019-05-25 23:51:20 +02:00
|
|
|
]);
|
2019-05-20 07:37:41 +02:00
|
|
|
}
|
|
|
|
|
2019-05-25 23:51:20 +02:00
|
|
|
|
2019-05-26 16:42:09 +02:00
|
|
|
/**
|
|
|
|
* test TOTP generation via API
|
|
|
|
*
|
2019-06-06 13:40:06 +02:00
|
|
|
* @test
|
2019-05-26 16:42:09 +02:00
|
|
|
*/
|
|
|
|
public function testTOTPgeneration()
|
|
|
|
{
|
2019-06-06 13:40:06 +02:00
|
|
|
$twofaccount = factory(TwoFAccount::class)->create([
|
2020-01-06 21:45:14 +01:00
|
|
|
'service' => 'testTOTP',
|
|
|
|
'account' => 'test@test.com',
|
2019-05-26 23:24:22 +02:00
|
|
|
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test'
|
2019-05-26 16:42:09 +02:00
|
|
|
]);
|
|
|
|
|
2019-06-06 13:40:06 +02:00
|
|
|
$response = $this->actingAs($this->user, 'api')
|
2019-05-26 23:24:22 +02:00
|
|
|
->json('GET', '/api/twofaccounts/' . $twofaccount->id . '/totp')
|
2019-05-26 16:42:09 +02:00
|
|
|
->assertStatus(200)
|
|
|
|
->assertJsonStructure([
|
|
|
|
'totp',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-22 00:49:27 +02:00
|
|
|
/**
|
2019-05-25 23:51:20 +02:00
|
|
|
* test TwoFAccount update via API
|
2019-05-22 00:49:27 +02:00
|
|
|
*
|
2019-06-06 13:40:06 +02:00
|
|
|
* @test
|
2019-05-22 00:49:27 +02:00
|
|
|
*/
|
2019-05-25 23:51:20 +02:00
|
|
|
public function testTwoFAccountUpdate()
|
2019-05-22 00:49:27 +02:00
|
|
|
{
|
2019-06-06 13:40:06 +02:00
|
|
|
$twofaccount = factory(TwoFAccount::class)->create();
|
2019-05-22 00:49:27 +02:00
|
|
|
|
2019-06-06 13:40:06 +02:00
|
|
|
$response = $this->actingAs($this->user, 'api')
|
|
|
|
->json('PUT', '/api/twofaccounts/' . $twofaccount->id, [
|
2020-01-06 21:45:14 +01:00
|
|
|
'service' => 'testUpdate',
|
|
|
|
'account' => 'testUpdate@test.com',
|
2019-05-26 23:24:22 +02:00
|
|
|
'uri' => 'testUpdate',
|
2019-05-25 23:51:20 +02:00
|
|
|
])
|
|
|
|
->assertStatus(200)
|
|
|
|
->assertJson([
|
|
|
|
'id' => 1,
|
2020-01-06 21:45:14 +01:00
|
|
|
'service' => 'testUpdate',
|
|
|
|
'account' => 'testUpdate@test.com',
|
2019-05-26 23:24:22 +02:00
|
|
|
'uri' => 'testUpdate',
|
2019-05-25 23:51:20 +02:00
|
|
|
'icon' => null,
|
|
|
|
]);
|
2019-05-22 00:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-20 07:37:41 +02:00
|
|
|
/**
|
2019-05-24 14:44:41 +02:00
|
|
|
* test TwoFAccount index fetching via API
|
2019-05-20 07:37:41 +02:00
|
|
|
*
|
2019-06-06 13:40:06 +02:00
|
|
|
* @test
|
2019-05-20 07:37:41 +02:00
|
|
|
*/
|
2019-05-25 23:51:20 +02:00
|
|
|
public function testTwoFAccountIndexListing()
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2019-06-06 13:40:06 +02:00
|
|
|
$twofaccount = factory(TwoFAccount::class, 3)->create();
|
2019-05-20 07:37:41 +02:00
|
|
|
|
2019-06-06 13:40:06 +02:00
|
|
|
$response = $this->actingAs($this->user, 'api')
|
2019-05-24 14:44:41 +02:00
|
|
|
->json('GET', '/api/twofaccounts')
|
2019-05-25 23:51:20 +02:00
|
|
|
->assertStatus(200)
|
|
|
|
->assertJsonStructure([
|
2019-05-20 07:37:41 +02:00
|
|
|
'*' => [
|
|
|
|
'id',
|
2020-01-06 21:45:14 +01:00
|
|
|
'service',
|
|
|
|
'account',
|
2019-05-26 23:24:22 +02:00
|
|
|
'uri',
|
2019-05-20 07:37:41 +02:00
|
|
|
'icon',
|
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
'deleted_at'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-05-24 14:44:41 +02:00
|
|
|
* test TwoFAccount deletion via API
|
2019-06-06 13:40:06 +02:00
|
|
|
*
|
|
|
|
* @test
|
2019-05-20 07:37:41 +02:00
|
|
|
*/
|
2019-05-24 14:44:41 +02:00
|
|
|
public function testTwoFAccountDeletion()
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2019-06-06 13:40:06 +02:00
|
|
|
$twofaccount = factory(TwoFAccount::class)->create();
|
2019-05-20 07:37:41 +02:00
|
|
|
|
2019-06-06 13:40:06 +02:00
|
|
|
$response = $this->actingAs($this->user, 'api')
|
2019-05-25 23:51:20 +02:00
|
|
|
->json('DELETE', '/api/twofaccounts/' . $twofaccount->id)
|
|
|
|
->assertStatus(204);
|
|
|
|
}
|
|
|
|
|
2019-05-20 07:37:41 +02:00
|
|
|
}
|