2FAuth/tests/Feature/Console/ResetDemoTest.php

161 lines
5.6 KiB
PHP
Raw Normal View History

2020-03-21 22:53:21 +01:00
<?php
2021-11-30 17:39:33 +01:00
namespace Tests\Feature\Console;
2020-03-21 22:53:21 +01:00
use Illuminate\Support\Facades\Config;
2022-11-22 15:15:52 +01:00
use Tests\FeatureTestCase;
2020-03-21 22:53:21 +01:00
2021-11-30 17:39:33 +01:00
class ResetDemoTest extends FeatureTestCase
2020-03-21 22:53:21 +01:00
{
/**
* @test
2020-03-21 22:53:21 +01:00
*/
public function test_reset_demo_without_demo_mode_succeeded()
2020-03-21 22:53:21 +01:00
{
$this->artisan('2fauth:reset-demo')
2023-12-20 16:55:58 +01:00
->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On')
->assertSuccessful();
2020-03-21 22:53:21 +01:00
}
/**
* @test
2020-03-21 22:53:21 +01:00
*/
public function test_reset_demo_succeeded()
2020-03-21 22:53:21 +01:00
{
2021-10-08 23:27:15 +02:00
Config::set('2fauth.config.isDemoApp', true);
2020-03-21 22:53:21 +01:00
$this->artisan('2fauth:reset-demo')
2023-12-20 16:55:58 +01:00
->expectsOutput('This will reset the app in order to run a clean and fresh demo.')
->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'demo')
->assertSuccessful();
2020-03-21 22:53:21 +01:00
$this->assertDatabaseCount('twofaccounts', 9);
$this->assertDatabaseHas('twofaccounts', [
2022-11-22 15:15:52 +01:00
'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',
]);
$this->assertDatabaseHas('twofaccounts', [
2022-11-22 15:15:52 +01:00
'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', [
2022-11-22 15:15:52 +01:00
'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', [
2022-11-22 15:15:52 +01:00
'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', [
2022-11-22 15:15:52 +01:00
'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', [
2022-11-22 15:15:52 +01:00
'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', [
2022-11-22 15:15:52 +01:00
'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', [
2022-11-22 15:15:52 +01:00
'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', [
2022-11-22 15:15:52 +01:00
'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',
]);
2020-03-21 22:53:21 +01:00
}
/**
* @test
2020-03-21 22:53:21 +01:00
*/
public function test_reset_demo_with_invalid_confirmation_succeeded()
2020-03-21 22:53:21 +01:00
{
2021-10-08 23:27:15 +02:00
Config::set('2fauth.config.isDemoApp', true);
2020-03-21 22:53:21 +01:00
$this->artisan('2fauth:reset-demo')
2023-12-20 16:55:58 +01:00
->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'null')
->expectsOutput('Bad confirmation word, nothing appened')
->assertSuccessful();
2020-03-21 22:53:21 +01:00
}
/**
* @test
2020-03-21 22:53:21 +01:00
*/
public function test_reset_demo_with_no_confirm_option_succeeded()
2020-03-21 22:53:21 +01:00
{
2021-10-08 23:27:15 +02:00
Config::set('2fauth.config.isDemoApp', true);
2020-03-21 22:53:21 +01:00
$this->artisan('2fauth:reset-demo', [
2022-11-22 15:15:52 +01:00
'--no-confirm' => true,
])
->assertSuccessful();
2020-03-21 22:53:21 +01:00
}
2022-11-22 15:15:52 +01:00
}