mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-02-08 22:49:25 +01:00
Fix reset-demo artisan command and its test
This commit is contained in:
parent
22442f7af6
commit
a6d4b6c5f6
@ -75,9 +75,13 @@ public function handle()
|
|||||||
|
|
||||||
// Reset the db
|
// Reset the db
|
||||||
DB::table('users')->truncate();
|
DB::table('users')->truncate();
|
||||||
|
DB::table('password_resets')->truncate();
|
||||||
DB::table('oauth_access_tokens')->truncate();
|
DB::table('oauth_access_tokens')->truncate();
|
||||||
|
DB::table('oauth_personal_access_clients')->truncate();
|
||||||
|
DB::table('oauth_refresh_tokens')->truncate();
|
||||||
DB::table('twofaccounts')->truncate();
|
DB::table('twofaccounts')->truncate();
|
||||||
DB::table('options')->truncate();
|
DB::table('options')->truncate();
|
||||||
|
DB::table('groups')->truncate();
|
||||||
|
|
||||||
// Seed the db
|
// Seed the db
|
||||||
$this->callSilent('db:seed', [
|
$this->callSilent('db:seed', [
|
||||||
@ -93,9 +97,6 @@ public function handle()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static function generateIcon($serviceName, $base64icon) {
|
private static function generateIcon($serviceName, $base64icon) {
|
||||||
// $image = str_replace('data:image/png;base64,', '', $image);
|
|
||||||
// $image = str_replace(' ', '+', $image);
|
|
||||||
|
|
||||||
Storage::put('public/icons/' . $serviceName . '.png', base64_decode($base64icon));
|
Storage::put('public/icons/' . $serviceName . '.png', base64_decode($base64icon));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\User;
|
use App\User;
|
||||||
|
use App\Group;
|
||||||
use App\TwoFAccount;
|
use App\TwoFAccount;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
@ -19,12 +20,71 @@ public function run()
|
|||||||
'password' => bcrypt('demo'),
|
'password' => bcrypt('demo'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
TwoFAccount::create([
|
$groupSocialNetwork = Group::create([
|
||||||
|
'name' => 'Social Networks',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$groupSocialNetwork->twofaccounts()->createMany([
|
||||||
|
[
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'account' => 'johndoe@facebook.com',
|
||||||
|
'service' => 'Facebook',
|
||||||
|
'secret' => 'A4GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'facebook.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Facebook:johndoe@facebook.com?secret=A4GRFTVVRBGY7UIW',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'service' => 'Twitter',
|
||||||
|
'account' => '@john',
|
||||||
|
'secret' => 'A2GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'twitter.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Twitter:@john?secret=A2GRFTVVRBGY7UIW',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'service' => 'Instagram',
|
||||||
|
'account' => '@johndoe',
|
||||||
|
'secret' => 'A6GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'instagram.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Instagram:@johndoe?secret=A6GRFTVVRBGY7UIW',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'service' => 'LinkedIn',
|
||||||
|
'account' => '@johndoe',
|
||||||
|
'secret' => 'A7GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'linkedin.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/LinkedIn:@johndoe?secret=A7GRFTVVRBGY7UIW',
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$groupECommerce = Group::create([
|
||||||
|
'name' => 'eCommerce',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$groupSocialNetwork->twofaccounts()->create([
|
||||||
'otp_type' => 'totp',
|
'otp_type' => 'totp',
|
||||||
'account' => 'johndoe',
|
'account' => 'johndoe',
|
||||||
'service' => 'Amazon',
|
'service' => 'Amazon',
|
||||||
'secret' => 'A7GRFTVVRBGY7UIW',
|
'secret' => 'A7GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
'icon' => 'amazon.png',
|
'icon' => 'amazon.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Amazon:johndoe?secret=A7GRFTVVRBGY7UIW',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
TwoFAccount::create([
|
TwoFAccount::create([
|
||||||
@ -32,7 +92,11 @@ public function run()
|
|||||||
'account' => 'john.doe@icloud.com',
|
'account' => 'john.doe@icloud.com',
|
||||||
'service' => 'Apple',
|
'service' => 'Apple',
|
||||||
'secret' => 'A2GRFTVVRBGY7UIW',
|
'secret' => 'A2GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
'icon' => 'apple.png',
|
'icon' => 'apple.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Apple:john.doe@icloud.com?secret=A2GRFTVVRBGY7UIW',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
TwoFAccount::create([
|
TwoFAccount::create([
|
||||||
@ -40,15 +104,11 @@ public function run()
|
|||||||
'account' => 'john.doe',
|
'account' => 'john.doe',
|
||||||
'service' => 'Dropbox',
|
'service' => 'Dropbox',
|
||||||
'secret' => 'A3GRFTVVRBGY7UIW',
|
'secret' => 'A3GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
'icon' => 'dropbox.png',
|
'icon' => 'dropbox.png',
|
||||||
]);
|
'legacy_uri' => 'otpauth://totp/Dropbox:john.doe?secret=A3GRFTVVRBGY7UIW',
|
||||||
|
|
||||||
TwoFAccount::create([
|
|
||||||
'otp_type' => 'totp',
|
|
||||||
'account' => 'johndoe@facebook.com',
|
|
||||||
'service' => 'Facebook',
|
|
||||||
'secret' => 'A4GRFTVVRBGY7UIW',
|
|
||||||
'icon' => 'facebook.png',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
TwoFAccount::create([
|
TwoFAccount::create([
|
||||||
@ -56,7 +116,11 @@ public function run()
|
|||||||
'account' => '@john',
|
'account' => '@john',
|
||||||
'service' => 'Github',
|
'service' => 'Github',
|
||||||
'secret' => 'A2GRFTVVRBGY7UIW',
|
'secret' => 'A2GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
'icon' => 'github.png',
|
'icon' => 'github.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Github:@john?secret=A2GRFTVVRBGY7UIW',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
TwoFAccount::create([
|
TwoFAccount::create([
|
||||||
@ -64,31 +128,11 @@ public function run()
|
|||||||
'service' => 'Google',
|
'service' => 'Google',
|
||||||
'account' => 'john.doe@gmail.com',
|
'account' => 'john.doe@gmail.com',
|
||||||
'secret' => 'A5GRFTVVRBGY7UIW',
|
'secret' => 'A5GRFTVVRBGY7UIW',
|
||||||
'icon' => 'google.png'
|
'algorithm' => 'sha1',
|
||||||
]);
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
TwoFAccount::create([
|
'icon' => 'google.png',
|
||||||
'otp_type' => 'totp',
|
'legacy_uri' => 'otpauth://totp/Google:john.doe@gmail.com?secret=A5GRFTVVRBGY7UIW',
|
||||||
'service' => 'Instagram',
|
|
||||||
'account' => '@johndoe',
|
|
||||||
'secret' => 'A6GRFTVVRBGY7UIW',
|
|
||||||
'icon' => 'instagram.png'
|
|
||||||
]);
|
|
||||||
|
|
||||||
TwoFAccount::create([
|
|
||||||
'otp_type' => 'totp',
|
|
||||||
'service' => 'LinkedIn',
|
|
||||||
'account' => '@johndoe',
|
|
||||||
'secret' => 'A7GRFTVVRBGY7UIW',
|
|
||||||
'icon' => 'linkedin.png'
|
|
||||||
]);
|
|
||||||
|
|
||||||
TwoFAccount::create([
|
|
||||||
'otp_type' => 'totp',
|
|
||||||
'service' => 'Twitter',
|
|
||||||
'account' => '@john',
|
|
||||||
'secret' => 'A2GRFTVVRBGY7UIW',
|
|
||||||
'icon' => 'twitter.png'
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,17 @@
|
|||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
use App\User;
|
use App\User;
|
||||||
use Tests\TestCase;
|
use Tests\FeatureTestCase;
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class ConsoleTest extends TestCase
|
class ConsoleTest extends FeatureTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test 2fauth:reset-demo console command.
|
* @test
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function test2fauthResetDemowithoutDemoModeConsoleCommand()
|
public function test_reset_demo_without_demo_mode_succeeded()
|
||||||
{
|
{
|
||||||
$this->artisan('2fauth:reset-demo')
|
$this->artisan('2fauth:reset-demo')
|
||||||
->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On')
|
->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On')
|
||||||
@ -23,11 +21,9 @@ public function test2fauthResetDemowithoutDemoModeConsoleCommand()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test 2fauth:reset-demo console command.
|
* @test
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function test2fauthResetDemowithConfirmConsoleCommand()
|
public function test_reset_demo_succeeded()
|
||||||
{
|
{
|
||||||
Config::set('2fauth.config.isDemoApp', true);
|
Config::set('2fauth.config.isDemoApp', true);
|
||||||
|
|
||||||
@ -39,85 +35,115 @@ public function test2fauthResetDemowithConfirmConsoleCommand()
|
|||||||
|
|
||||||
$user = User::find(1);
|
$user = User::find(1);
|
||||||
|
|
||||||
$response = $this->actingAs($user, 'api')
|
$this->assertDatabaseCount('twofaccounts', 9);
|
||||||
->json('GET', '/api/twofaccounts/1')
|
|
||||||
->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'service' => 'Amazon',
|
|
||||||
'icon' => 'amazon.png',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->actingAs($user, 'api')
|
$this->assertDatabaseHas('twofaccounts', [
|
||||||
->json('GET', '/api/twofaccounts/2')
|
'otp_type' => 'totp',
|
||||||
->assertStatus(200)
|
'account' => 'johndoe@facebook.com',
|
||||||
->assertJson([
|
'service' => 'Facebook',
|
||||||
'service' => 'Apple',
|
'secret' => 'A4GRFTVVRBGY7UIW',
|
||||||
'icon' => 'apple.png',
|
'algorithm' => 'sha1',
|
||||||
]);
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'facebook.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Facebook:johndoe@facebook.com?secret=A4GRFTVVRBGY7UIW',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('twofaccounts', [
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'service' => 'Twitter',
|
||||||
|
'account' => '@john',
|
||||||
|
'secret' => 'A2GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'twitter.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Twitter:@john?secret=A2GRFTVVRBGY7UIW',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('twofaccounts', [
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'service' => 'Instagram',
|
||||||
|
'account' => '@johndoe',
|
||||||
|
'secret' => 'A6GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'instagram.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Instagram:@johndoe?secret=A6GRFTVVRBGY7UIW',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('twofaccounts', [
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'service' => 'LinkedIn',
|
||||||
|
'account' => '@johndoe',
|
||||||
|
'secret' => 'A7GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'linkedin.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/LinkedIn:@johndoe?secret=A7GRFTVVRBGY7UIW',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('twofaccounts', [
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'account' => 'johndoe',
|
||||||
|
'service' => 'Amazon',
|
||||||
|
'secret' => 'A7GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'amazon.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Amazon:johndoe?secret=A7GRFTVVRBGY7UIW',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('twofaccounts', [
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'account' => 'john.doe@icloud.com',
|
||||||
|
'service' => 'Apple',
|
||||||
|
'secret' => 'A2GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'apple.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Apple:john.doe@icloud.com?secret=A2GRFTVVRBGY7UIW',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('twofaccounts', [
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'account' => 'john.doe',
|
||||||
|
'service' => 'Dropbox',
|
||||||
|
'secret' => 'A3GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'dropbox.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Dropbox:john.doe?secret=A3GRFTVVRBGY7UIW',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('twofaccounts', [
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'account' => '@john',
|
||||||
|
'service' => 'Github',
|
||||||
|
'secret' => 'A2GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'github.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Github:@john?secret=A2GRFTVVRBGY7UIW',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('twofaccounts', [
|
||||||
|
'otp_type' => 'totp',
|
||||||
|
'service' => 'Google',
|
||||||
|
'account' => 'john.doe@gmail.com',
|
||||||
|
'secret' => 'A5GRFTVVRBGY7UIW',
|
||||||
|
'algorithm' => 'sha1',
|
||||||
|
'digits' => 6,
|
||||||
|
'period' => 30,
|
||||||
|
'icon' => 'google.png',
|
||||||
|
'legacy_uri' => 'otpauth://totp/Google:john.doe@gmail.com?secret=A5GRFTVVRBGY7UIW',
|
||||||
|
]);
|
||||||
|
|
||||||
$response = $this->actingAs($user, 'api')
|
|
||||||
->json('GET', '/api/twofaccounts/3')
|
|
||||||
->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'service' => 'Dropbox',
|
|
||||||
'icon' => 'dropbox.png',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->actingAs($user, 'api')
|
|
||||||
->json('GET', '/api/twofaccounts/4')
|
|
||||||
->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'service' => 'Facebook',
|
|
||||||
'icon' => 'facebook.png',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->actingAs($user, 'api')
|
|
||||||
->json('GET', '/api/twofaccounts/5')
|
|
||||||
->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'service' => 'Github',
|
|
||||||
'icon' => 'github.png',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->actingAs($user, 'api')
|
|
||||||
->json('GET', '/api/twofaccounts/6')
|
|
||||||
->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'service' => 'Google',
|
|
||||||
'icon' => 'google.png',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->actingAs($user, 'api')
|
|
||||||
->json('GET', '/api/twofaccounts/7')
|
|
||||||
->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'service' => 'Instagram',
|
|
||||||
'icon' => 'instagram.png',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->actingAs($user, 'api')
|
|
||||||
->json('GET', '/api/twofaccounts/8')
|
|
||||||
->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'service' => 'LinkedIn',
|
|
||||||
'icon' => 'linkedin.png',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->actingAs($user, 'api')
|
|
||||||
->json('GET', '/api/twofaccounts/9')
|
|
||||||
->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'service' => 'Twitter',
|
|
||||||
'icon' => 'twitter.png',
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test 2fauth:reset-demo console command.
|
* @test
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function test2fauthResetDemowithBadConfirmationConsoleCommand()
|
public function test_reset_demo_with_invalid_confirmation_succeeded()
|
||||||
{
|
{
|
||||||
Config::set('2fauth.config.isDemoApp', true);
|
Config::set('2fauth.config.isDemoApp', true);
|
||||||
|
|
||||||
@ -129,11 +155,9 @@ public function test2fauthResetDemowithBadConfirmationConsoleCommand()
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test 2fauth:reset-demo console command.
|
* @test
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function test2fauthResetDemowithoutConfirmationConsoleCommand()
|
public function test_reset_demo_with_no_confirm_option_succeeded()
|
||||||
{
|
{
|
||||||
Config::set('2fauth.config.isDemoApp', true);
|
Config::set('2fauth.config.isDemoApp', true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user