|
@@ -3,19 +3,17 @@
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
use App\User;
|
|
|
-use Tests\TestCase;
|
|
|
+use Tests\FeatureTestCase;
|
|
|
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.
|
|
|
- *
|
|
|
- * @return void
|
|
|
+ * @test
|
|
|
*/
|
|
|
- public function test2fauthResetDemowithoutDemoModeConsoleCommand()
|
|
|
+ public function test_reset_demo_without_demo_mode_succeeded()
|
|
|
{
|
|
|
$this->artisan('2fauth:reset-demo')
|
|
|
->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On')
|
|
@@ -23,11 +21,9 @@ class ConsoleTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Test 2fauth:reset-demo console command.
|
|
|
- *
|
|
|
- * @return void
|
|
|
+ * @test
|
|
|
*/
|
|
|
- public function test2fauthResetDemowithConfirmConsoleCommand()
|
|
|
+ public function test_reset_demo_succeeded()
|
|
|
{
|
|
|
Config::set('2fauth.config.isDemoApp', true);
|
|
|
|
|
@@ -39,85 +35,115 @@ class ConsoleTest extends TestCase
|
|
|
|
|
|
$user = User::find(1);
|
|
|
|
|
|
- $response = $this->actingAs($user, 'api')
|
|
|
- ->json('GET', '/api/twofaccounts/1')
|
|
|
- ->assertStatus(200)
|
|
|
- ->assertJson([
|
|
|
- 'service' => 'Amazon',
|
|
|
- 'icon' => 'amazon.png',
|
|
|
- ]);
|
|
|
-
|
|
|
- $response = $this->actingAs($user, 'api')
|
|
|
- ->json('GET', '/api/twofaccounts/2')
|
|
|
- ->assertStatus(200)
|
|
|
- ->assertJson([
|
|
|
- 'service' => 'Apple',
|
|
|
- 'icon' => 'apple.png',
|
|
|
- ]);
|
|
|
-
|
|
|
- $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',
|
|
|
- ]);
|
|
|
+ $this->assertDatabaseCount('twofaccounts', 9);
|
|
|
+
|
|
|
+ $this->assertDatabaseHas('twofaccounts', [
|
|
|
+ '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', [
|
|
|
+ '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',
|
|
|
+ ]);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * Test 2fauth:reset-demo console command.
|
|
|
- *
|
|
|
- * @return void
|
|
|
+ * @test
|
|
|
*/
|
|
|
- public function test2fauthResetDemowithBadConfirmationConsoleCommand()
|
|
|
+ public function test_reset_demo_with_invalid_confirmation_succeeded()
|
|
|
{
|
|
|
Config::set('2fauth.config.isDemoApp', true);
|
|
|
|
|
@@ -129,11 +155,9 @@ class ConsoleTest extends TestCase
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * Test 2fauth:reset-demo console command.
|
|
|
- *
|
|
|
- * @return void
|
|
|
+ * @test
|
|
|
*/
|
|
|
- public function test2fauthResetDemowithoutConfirmationConsoleCommand()
|
|
|
+ public function test_reset_demo_with_no_confirm_option_succeeded()
|
|
|
{
|
|
|
Config::set('2fauth.config.isDemoApp', true);
|
|
|
|