mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-24 14:02:09 +02:00
Complete phpunit tests update
This commit is contained in:
parent
d9b48e8806
commit
fc05d41120
@ -91,6 +91,12 @@ class ProtectDbTest extends TestCase
|
|||||||
->json('PUT', '/api/twofaccounts/' . $this->twofaccount->id, [
|
->json('PUT', '/api/twofaccounts/' . $this->twofaccount->id, [
|
||||||
'service' => 'testUpdate',
|
'service' => 'testUpdate',
|
||||||
'account' => 'testUpdate@test.com',
|
'account' => 'testUpdate@test.com',
|
||||||
|
'otpType' => 'totp',
|
||||||
|
'secret' => 'A4GRFHVVRBGY7UIW',
|
||||||
|
'secretIsBase32Encoded' => 1,
|
||||||
|
'digits' => 8,
|
||||||
|
'totpPeriod' => 30,
|
||||||
|
'algorithm' => 'sha256',
|
||||||
])
|
])
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
|
@ -115,7 +115,7 @@ class ApiExceptionTest extends TestCase
|
|||||||
'debug'
|
'debug'
|
||||||
])
|
])
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'message' => 'Whoops, looks like something went wrong'
|
'message' => 'Whoops, looks like something went wrong :('
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,132 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit;
|
|
||||||
|
|
||||||
use App\User;
|
|
||||||
use Tests\TestCase;
|
|
||||||
use App\Classes\OTP;
|
|
||||||
use OTPHP\TOTP;
|
|
||||||
use OTPHP\HOTP;
|
|
||||||
use App\TwoFAccount;
|
|
||||||
|
|
||||||
class OtpTest extends TestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
/** @var \App\User */
|
|
||||||
protected $user;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->user = factory(User::class)->create();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test TOTP generation (with $isPreview = false to prevent db update)
|
|
||||||
*
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function testTOTPGeneration()
|
|
||||||
{
|
|
||||||
$uri = 'otpauth://totp/test@test.com?secret=A4GRFHVIRBGY7UIW&issuer=test';
|
|
||||||
|
|
||||||
$result = OTP::generate($uri, true);
|
|
||||||
|
|
||||||
$this->assertArrayHasKey('otp', $result);
|
|
||||||
$this->assertArrayHasKey('position', $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test HOTP generation for Preview
|
|
||||||
*
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function testHOTPGenerationforPreview()
|
|
||||||
{
|
|
||||||
$uri = 'otpauth://hotp/test:test@test.com?counter=16&secret=A4GRFHVIRBGY7UIW';
|
|
||||||
|
|
||||||
$result = OTP::generate($uri, true);
|
|
||||||
|
|
||||||
$this->assertArrayHasKey('otp', $result);
|
|
||||||
$this->assertArrayHasKey('counter', $result);
|
|
||||||
$this->assertArrayHasKey('nextUri', $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test HOTP generation for existing HOTP account
|
|
||||||
*
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function testHOTPGenerationForExistingAccount()
|
|
||||||
{
|
|
||||||
$response = $this->actingAs($this->user, 'api')
|
|
||||||
->json('POST', '/api/twofaccounts', [
|
|
||||||
'service' => 'hotp',
|
|
||||||
'account' => 'test.com',
|
|
||||||
'uri' => 'otpauth://hotp/test@test.com?counter=1&secret=A4GRFHZVRBGY7UIW',
|
|
||||||
'icon' => 'test.png',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$testedAccount = TwoFAccount::where('service', 'hotp')->first();
|
|
||||||
|
|
||||||
$result = OTP::generate($testedAccount->uri, false);
|
|
||||||
|
|
||||||
$testedAccount->refresh();
|
|
||||||
|
|
||||||
$this->assertEquals($testedAccount->uri, 'otpauth://hotp/test@test.com?counter=2&secret=A4GRFHZVRBGY7UIW');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test if provided TOTP uri is valid
|
|
||||||
*
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function testTOTPUriIsValid()
|
|
||||||
{
|
|
||||||
$uri = 'otpauth://totp/test@test.com?secret=A4GRFHVIRBGY7UIW&issuer=test';
|
|
||||||
|
|
||||||
$result = OTP::get($uri);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(TOTP::class, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test if provided HOTP uri is valid
|
|
||||||
*
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function testHOTPUriIsValid()
|
|
||||||
{
|
|
||||||
$uri = 'otpauth://hotp/test:test@test.com?counter=16&secret=A4GRFHVIRBGY7UIW';
|
|
||||||
|
|
||||||
$result = OTP::get($uri);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(HOTP::class, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test invalid privded uri returns a ValidationException exception
|
|
||||||
*
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function testInvalidUriReturnValidationException()
|
|
||||||
{
|
|
||||||
$uri = 'otpauth://totp/';
|
|
||||||
|
|
||||||
$this->expectException(\Illuminate\Validation\ValidationException::class);
|
|
||||||
|
|
||||||
OTP::get($uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -62,21 +62,17 @@ class QrcodeTest extends TestCase
|
|||||||
public function testDecodeValidUri()
|
public function testDecodeValidUri()
|
||||||
{
|
{
|
||||||
$response = $this->json('POST', '/api/qrcode/decode', [
|
$response = $this->json('POST', '/api/qrcode/decode', [
|
||||||
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVIRBGY7UIW'
|
'uri' => 'otpauth://totp/service:account?secret=A4GRFHVIRBGY7UIW'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(200)
|
$response->assertStatus(200)
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'service' => 'test@test.com',
|
'service' => 'service',
|
||||||
'account' => '',
|
'account' => 'account',
|
||||||
'options' => [
|
'algorithm' => 'sha1',
|
||||||
'algorithm' => 'sha1',
|
'digits' => 6,
|
||||||
'digits' => 6,
|
'totpPeriod' => 30,
|
||||||
'epoch' => 0,
|
'secret' => 'A4GRFHVIRBGY7UIW'
|
||||||
'period' => 30,
|
|
||||||
'secret' => 'A4GRFHVIRBGY7UIW'
|
|
||||||
],
|
|
||||||
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVIRBGY7UIW'
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,16 +96,11 @@ class QrcodeTest extends TestCase
|
|||||||
|
|
||||||
$response->assertStatus(200)
|
$response->assertStatus(200)
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'service' => 'test@test.com',
|
'account' => 'test@test.com',
|
||||||
'account' => '',
|
'algorithm' => 'sha1',
|
||||||
'options' => [
|
'digits' => 6,
|
||||||
'algorithm' => 'sha1',
|
'totpPeriod' => 30,
|
||||||
'digits' => 6,
|
'secret' => 'A4GRFHVIRBGY7UIW'
|
||||||
'epoch' => 0,
|
|
||||||
'period' => 30,
|
|
||||||
'secret' => 'A4GRFHVIRBGY7UIW'
|
|
||||||
],
|
|
||||||
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVIRBGY7UIW'
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user