Przeglądaj źródła

secret property now named uri to match otphp wording

Bubka 6 lat temu
rodzic
commit
e7695b64bc

+ 2 - 2
app/Http/Controllers/TwoFAccountController.php

@@ -31,7 +31,7 @@ class TwoFAccountController extends Controller
     {
         $twofaccount = TwoFAccount::create([
             'name' => $request->name,
-            'secret' => $request->secret
+            'uri' => $request->uri
         ]);
 
         return response()->json($twofaccount, 201);
@@ -59,7 +59,7 @@ class TwoFAccountController extends Controller
     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',

+ 1 - 1
app/TwoFAccount.php

@@ -9,7 +9,7 @@ class TwoFAccount extends Model
 {
         use SoftDeletes;
 
-        protected $fillable = ['name', 'secret', 'icon'];
+        protected $fillable = ['name', 'uri', 'icon'];
 
 
     /**

+ 1 - 1
database/migrations/2019_05_16_162730_create_twofaccounts_table.php

@@ -16,7 +16,7 @@ class CreateTwoFAccountsTable extends Migration
         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();

+ 5 - 5
database/seeds/TwoFAccountsTableSeeder.php

@@ -17,26 +17,26 @@ class TwoFAccountsTableSeeder extends Seeder
 
         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',
         ]);
     }
 }

+ 9 - 9
tests/Unit/TwoFAccountTest.php

@@ -41,12 +41,12 @@ class TwoFAccountTest extends TestCase
         $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 @@ class TwoFAccountTest extends TestCase
 
         $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 @@ class TwoFAccountTest extends TestCase
         $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 @@ class TwoFAccountTest extends TestCase
                 '*' => [
                     'id',
                     'name',
-                    'secret',
+                    'uri',
                     'icon',
                     'created_at',
                     'updated_at',
@@ -135,7 +135,7 @@ class TwoFAccountTest extends TestCase
 
         $twofaccount = TwoFAccount::create([
             'name' => 'testDelete',
-            'secret' => 'test'
+            'uri' => 'test'
         ]);
 
         $response = $this->actingAs($user, 'api')
@@ -154,7 +154,7 @@ class TwoFAccountTest extends TestCase
 
         $twofaccount = TwoFAccount::create([
             'name' => 'testHardDelete',
-            'secret' => 'test'
+            'uri' => 'test'
         ]);
 
         $twofaccount->delete();