diff --git a/app/Http/Controllers/TwoFAccountController.php b/app/Http/Controllers/TwoFAccountController.php index e3e061ff..4a235e0c 100644 --- a/app/Http/Controllers/TwoFAccountController.php +++ b/app/Http/Controllers/TwoFAccountController.php @@ -31,7 +31,7 @@ public function store(Request $request) { $twofaccount = TwoFAccount::create([ 'name' => $request->name, - 'secret' => $request->secret + 'uri' => $request->uri ]); return response()->json($twofaccount, 201); @@ -59,7 +59,7 @@ public function show(TwoFAccount $twofaccount) public function generateTOTP(TwoFAccount $twofaccount) { try { - $otp = Factory::loadFromProvisioningUri($twofaccount->secret); + $otp = Factory::loadFromProvisioningUri($twofaccount->uri); } catch (InvalidArgumentException $exception) { return response()->json([ 'message' => 'Error generating TOTP', diff --git a/app/TwoFAccount.php b/app/TwoFAccount.php index 7ef9da29..21d02499 100644 --- a/app/TwoFAccount.php +++ b/app/TwoFAccount.php @@ -9,7 +9,7 @@ class TwoFAccount extends Model { use SoftDeletes; - protected $fillable = ['name', 'secret', 'icon']; + protected $fillable = ['name', 'uri', 'icon']; /** 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 bfb426cd..e1999b75 100644 --- a/database/migrations/2019_05_16_162730_create_twofaccounts_table.php +++ b/database/migrations/2019_05_16_162730_create_twofaccounts_table.php @@ -16,7 +16,7 @@ public function up() Schema::create('twofaccounts', function (Blueprint $table) { $table->increments('id'); $table->string('name')->unique(); - $table->string('secret'); + $table->string('uri'); $table->string('icon')->nullable(); $table->timestamps(); $table->softDeletes(); diff --git a/database/seeds/TwoFAccountsTableSeeder.php b/database/seeds/TwoFAccountsTableSeeder.php index d1f4edd3..e474f9b2 100644 --- a/database/seeds/TwoFAccountsTableSeeder.php +++ b/database/seeds/TwoFAccountsTableSeeder.php @@ -17,26 +17,26 @@ public function run() TwoFAccount::create([ 'name' => $faker->unique()->domainName, - 'secret' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test', + 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test', ]); $deletedResource = TwoFAccount::create([ 'name' => $faker->unique()->domainName, - 'secret' => $faker->password, + 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test', ]); $deletedResource->delete(); TwoFAccount::create([ 'name' => $faker->unique()->domainName, - 'secret' => $faker->password, + 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test', ]); TwoFAccount::create([ 'name' => $faker->unique()->domainName, - 'secret' => $faker->password, + 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test', ]); TwoFAccount::create([ 'name' => $faker->unique()->domainName, - 'secret' => $faker->password, + 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test', ]); } } diff --git a/tests/Unit/TwoFAccountTest.php b/tests/Unit/TwoFAccountTest.php index 0b6b56d3..3b29bc20 100644 --- a/tests/Unit/TwoFAccountTest.php +++ b/tests/Unit/TwoFAccountTest.php @@ -41,12 +41,12 @@ public function testTwoFAccountCreation() $response = $this->actingAs($user, 'api') ->json('POST', '/api/twofaccounts', [ 'name' => 'testCreation', - 'secret' => 'test', + 'uri' => 'test', ]) ->assertStatus(201) ->assertJson([ 'name' => 'testCreation', - 'secret' => 'test', + 'uri' => 'test', ]); } @@ -62,11 +62,11 @@ public function testTOTPgeneration() $twofaccount = TwoFAccount::create([ 'name' => 'testTOTP', - 'secret' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test' + 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test' ]); $response = $this->actingAs($user, 'api') - ->json('POST', '/api/twofaccounts/' . $twofaccount->id . '/totp') + ->json('GET', '/api/twofaccounts/' . $twofaccount->id . '/totp') ->assertStatus(200) ->assertJsonStructure([ 'totp', @@ -86,13 +86,13 @@ public function testTwoFAccountUpdate() $response = $this->actingAs($user, 'api') ->json('PUT', '/api/twofaccounts/1', [ 'name' => 'testUpdate', - 'secret' => 'testUpdate', + 'uri' => 'testUpdate', ]) ->assertStatus(200) ->assertJson([ 'id' => 1, 'name' => 'testUpdate', - 'secret' => 'testUpdate', + 'uri' => 'testUpdate', 'icon' => null, ]); } @@ -114,7 +114,7 @@ public function testTwoFAccountIndexListing() '*' => [ 'id', 'name', - 'secret', + 'uri', 'icon', 'created_at', 'updated_at', @@ -135,7 +135,7 @@ public function testTwoFAccountDeletion() $twofaccount = TwoFAccount::create([ 'name' => 'testDelete', - 'secret' => 'test' + 'uri' => 'test' ]); $response = $this->actingAs($user, 'api') @@ -154,7 +154,7 @@ public function testTwoFAccountPermanentDeletion() $twofaccount = TwoFAccount::create([ 'name' => 'testHardDelete', - 'secret' => 'test' + 'uri' => 'test' ]); $twofaccount->delete();