2FAuth/tests/Unit/QrcodeTest.php

82 lines
2.1 KiB
PHP
Raw Normal View History

2020-03-02 17:11:17 +01:00
<?php
namespace Tests\Unit;
use Zxing\QrReader;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Tests\TestCase;
2020-03-03 17:06:40 +01:00
use Tests\Classes\LocalFile;
2020-03-02 17:11:17 +01:00
class QrcodeTest extends TestCase
{
use WithoutMiddleware;
/**
2020-03-03 17:06:40 +01:00
* test Decode a qrcode without providing a file resource via API
2020-03-02 17:11:17 +01:00
*
* @test
*/
public function testQrcodeDecodeWithMissingImage()
{
$response = $this->json('POST', '/api/qrcode/decode', [
'qrcode' => '',
])
->assertStatus(422);
}
/**
* test delete an uploaded icon via API
*
* @test
*/
2020-03-03 17:06:40 +01:00
public function testDecodeInvalidQrcode()
2020-03-02 17:11:17 +01:00
{
2020-03-03 17:06:40 +01:00
$file = LocalFile::fake()->invalidQrcode();
2020-03-02 17:11:17 +01:00
$response = $this->withHeaders([
'Content-Type' => 'multipart/form-data',
])
->json('POST', '/api/qrcode/decode', [
2020-03-03 17:06:40 +01:00
'qrcode' => $file
2020-03-02 17:11:17 +01:00
]);
2020-03-03 17:06:40 +01:00
$response->assertStatus(422);
}
2020-03-02 17:11:17 +01:00
2020-03-03 17:06:40 +01:00
/**
* test Decode a qrcode via API
*
* @test
*/
public function testDecodeValidQrcode()
{
$file = LocalFile::fake()->validQrcode();
$response = $this->withHeaders(['Content-Type' => 'multipart/form-data'])
->json('POST', '/api/qrcode/decode', [
'qrcode' => $file
]);
$response->assertStatus(200)
->assertJsonFragment([
'service' => 'test@test.com',
'account' => '',
'options' => [
'algorithm' => 'sha1',
'digits' => 6,
'epoch' => 0,
'period' => 30,
'secret' => 'A4GRFHVIRBGY7UIW'
],
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVIRBGY7UIW'
]);
2020-03-02 17:11:17 +01:00
}
}