From 8b5f5223c086e3a3dd39c82571932051595673b4 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Mon, 10 Jun 2019 23:42:13 +0200 Subject: [PATCH] new email field in TwoFAccount entity --- app/Http/Controllers/TwoFAccountController.php | 1 + app/TwoFAccount.php | 2 +- database/factories/TwoFAccountFactory.php | 1 + .../2019_05_16_162730_create_twofaccounts_table.php | 1 + tests/Unit/TwoFAccountTest.php | 6 ++++++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/TwoFAccountController.php b/app/Http/Controllers/TwoFAccountController.php index 4a235e0c..d1770d9d 100644 --- a/app/Http/Controllers/TwoFAccountController.php +++ b/app/Http/Controllers/TwoFAccountController.php @@ -31,6 +31,7 @@ public function store(Request $request) { $twofaccount = TwoFAccount::create([ 'name' => $request->name, + 'email' => $request->email, 'uri' => $request->uri ]); diff --git a/app/TwoFAccount.php b/app/TwoFAccount.php index 21d02499..4cda6b6c 100644 --- a/app/TwoFAccount.php +++ b/app/TwoFAccount.php @@ -9,7 +9,7 @@ class TwoFAccount extends Model { use SoftDeletes; - protected $fillable = ['name', 'uri', 'icon']; + protected $fillable = ['name', 'email', 'uri', 'icon']; /** diff --git a/database/factories/TwoFAccountFactory.php b/database/factories/TwoFAccountFactory.php index 36b58c72..a68890ac 100644 --- a/database/factories/TwoFAccountFactory.php +++ b/database/factories/TwoFAccountFactory.php @@ -20,6 +20,7 @@ $factory->define(TwoFAccount::class, function (Faker $faker) { return [ 'name' => $faker->unique()->domainName, + 'email' => $faker->safeEmail, 'uri' => 'otpauth://totp/' . $faker->email . '?secret=' . $faker->regexify('[A-Z0-9]{16}') . '&issuer=test', ]; }); diff --git a/database/migrations/2019_05_16_162730_create_twofaccounts_table.php b/database/migrations/2019_05_16_162730_create_twofaccounts_table.php index e1999b75..cb180ff2 100644 --- a/database/migrations/2019_05_16_162730_create_twofaccounts_table.php +++ b/database/migrations/2019_05_16_162730_create_twofaccounts_table.php @@ -17,6 +17,7 @@ public function up() $table->increments('id'); $table->string('name')->unique(); $table->string('uri'); + $table->string('email'); $table->string('icon')->nullable(); $table->timestamps(); $table->softDeletes(); diff --git a/tests/Unit/TwoFAccountTest.php b/tests/Unit/TwoFAccountTest.php index 292a73a7..12e8dac5 100644 --- a/tests/Unit/TwoFAccountTest.php +++ b/tests/Unit/TwoFAccountTest.php @@ -33,11 +33,13 @@ public function testTwoFAccountCreation() $response = $this->actingAs($this->user, 'api') ->json('POST', '/api/twofaccounts', [ 'name' => 'testCreation', + 'email' => 'test@example.org', 'uri' => 'test', ]) ->assertStatus(201) ->assertJson([ 'name' => 'testCreation', + 'email' => 'test@example.org', 'uri' => 'test', ]); } @@ -52,6 +54,7 @@ public function testTOTPgeneration() { $twofaccount = factory(TwoFAccount::class)->create([ 'name' => 'testTOTP', + 'email' => 'test@test.com', 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test' ]); @@ -76,12 +79,14 @@ public function testTwoFAccountUpdate() $response = $this->actingAs($this->user, 'api') ->json('PUT', '/api/twofaccounts/' . $twofaccount->id, [ 'name' => 'testUpdate', + 'email' => 'testUpdate@test.com', 'uri' => 'testUpdate', ]) ->assertStatus(200) ->assertJson([ 'id' => 1, 'name' => 'testUpdate', + 'email' => 'testUpdate@test.com', 'uri' => 'testUpdate', 'icon' => null, ]); @@ -104,6 +109,7 @@ public function testTwoFAccountIndexListing() '*' => [ 'id', 'name', + 'email', 'uri', 'icon', 'created_at',