diff --git a/.travis.yml b/.travis.yml index 61ea48bc..7ea8b326 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,13 +7,13 @@ language: php php: - 7.4 - # - 8.0 + - 8.0 services: - # - mysql + - mysql before_install: - # - mysql -e 'CREATE DATABASE 2fauth_test;' + - mysql -e 'CREATE DATABASE 2fauth_test;' before_script: - travis_retry composer self-update @@ -22,10 +22,8 @@ before_script: # will use .env.testing by default script: - # - DATABASE=mysql vendor/bin/phpunit -c phpunit-mysql.xml - - cp .env.travis .env + - DATABASE=mysql vendor/bin/phpunit -c phpunit-mysql.xml - php artisan config:clear - - php artisan key:generate - DATABASE=sqlite vendor/bin/phpunit -c phpunit.xml --coverage-clover=coverage.xml after_success: diff --git a/database/migrations/2020_12_04_073605_alter_encrypted_columns_to_text_for_sqlite.php b/database/migrations/2020_12_04_073605_alter_encrypted_columns_to_text_for_sqlite.php index ed874574..10be2de1 100644 --- a/database/migrations/2020_12_04_073605_alter_encrypted_columns_to_text_for_sqlite.php +++ b/database/migrations/2020_12_04_073605_alter_encrypted_columns_to_text_for_sqlite.php @@ -19,6 +19,7 @@ public function up() Schema::table('twofaccounts', function (Blueprint $table) { $table->text('account')->change(); + $table->text('uri')->change(); }); } } diff --git a/database/migrations/2020_12_04_073606_alter_encrypted_columns_to_text_for_sqlite_bis.php b/database/migrations/2020_12_04_073606_alter_encrypted_columns_to_text_for_sqlite_bis.php deleted file mode 100644 index f5e54a60..00000000 --- a/database/migrations/2020_12_04_073606_alter_encrypted_columns_to_text_for_sqlite_bis.php +++ /dev/null @@ -1,37 +0,0 @@ -getConnection())->getConnection()->getDriverName(); - - if ('sqlite' === $driver) { - - Schema::table('twofaccounts', function (Blueprint $table) { - $table->text('uri')->change(); - }); - } - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('twofaccounts', function (Blueprint $table) { - // - }); - } -} diff --git a/database/migrations/2021_09_08_191139_split_twofaccounts_uri_in_multiple_columns.php b/database/migrations/2021_09_08_191139_split_twofaccounts_uri_in_multiple_columns.php index bc1db2a6..aa6f3f4a 100644 --- a/database/migrations/2021_09_08_191139_split_twofaccounts_uri_in_multiple_columns.php +++ b/database/migrations/2021_09_08_191139_split_twofaccounts_uri_in_multiple_columns.php @@ -16,17 +16,44 @@ class SplitTwofaccountsUriInMultipleColumns extends Migration */ public function up() { - // as SQLITE disallow to add a not nullable column without default - // value when altering a table we add all columns as nullable and - // change them right after to not nullable column Schema::table('twofaccounts', function (Blueprint $table) { - $table->string('otp_type', 10)->nullable(); - $table->text('secret')->nullable(); - $table->string('algorithm', 20)->nullable(); - $table->unsignedSmallInteger('digits')->nullable(); + $table->string('otp_type', 10); + $table->text('secret'); + $table->string('algorithm', 20); + $table->unsignedSmallInteger('digits'); $table->unsignedInteger('period')->nullable(); $table->unsignedBigInteger('counter')->nullable(); }); + + Schema::table('twofaccounts', function (Blueprint $table) { + $table->renameColumn('uri', 'legacy_uri'); + }); + + + $twofaccounts = DB::table('twofaccounts')->select('id', 'legacy_uri')->get(); + $settingService = resolve('App\Services\SettingService'); + + foreach ($twofaccounts as $twofaccount) { + try { + $legacy_uri = $settingService->get('useEncryption') ? Crypt::decryptString($twofaccount->legacy_uri) : $twofaccount->legacy_uri; + $token = \OTPHP\Factory::loadFromProvisioningUri($legacy_uri); + + $affected = DB::table('twofaccounts') + ->where('id', $twofaccount->id) + ->update([ + 'otp_type' => get_class($token) === 'OTPHP\TOTP' ? 'totp' : 'hotp', + 'secret' => $settingService->get('useEncryption') ? Crypt::encryptString($token->getSecret()) : $token->getSecret(), + 'algorithm' => $token->getDigest(), + 'digits' => $token->getDigits(), + 'period' => $token->hasParameter('period') ? $token->getParameter('period') : null, + 'counter' => $token->hasParameter('counter') ? $token->getParameter('counter') : null + ]); + } + catch(Exception $ex) + { + Log::error($ex->getMessage()); + } + } } /** @@ -59,5 +86,9 @@ public function down() Schema::table('twofaccounts', function (Blueprint $table) { $table->dropColumn('counter'); }); + + Schema::table('twofaccounts', function (Blueprint $table) { + $table->renameColumn('legacy_uri', 'uri'); + }); } } diff --git a/database/migrations/2021_09_08_191140_rename_uri_to_legacy_uri.php b/database/migrations/2021_09_08_191140_rename_uri_to_legacy_uri.php deleted file mode 100644 index dcb8196e..00000000 --- a/database/migrations/2021_09_08_191140_rename_uri_to_legacy_uri.php +++ /dev/null @@ -1,32 +0,0 @@ -renameColumn('uri', 'legacy_uri'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('twofaccounts', function (Blueprint $table) { - $table->renameColumn('legacy_uri', 'uri'); - }); - } -} diff --git a/database/migrations/2021_09_14_195451_change_nullable_in_twofaccounts_table.php b/database/migrations/2021_09_14_195451_change_nullable_in_twofaccounts_table.php deleted file mode 100644 index 5958f51e..00000000 --- a/database/migrations/2021_09_14_195451_change_nullable_in_twofaccounts_table.php +++ /dev/null @@ -1,63 +0,0 @@ -text('account')->nullable(false)->change(); - $table->string('service')->nullable()->change(); - $table->string('otp_type', 10)->nullable(false)->change(); - $table->text('secret')->nullable(false)->change(); - $table->string('algorithm', 20)->nullable(false)->change(); - $table->unsignedSmallInteger('digits')->nullable(false)->change(); - }); - - - $twofaccounts = DB::table('twofaccounts')->select('id', 'legacy_uri')->get(); - $settingService = resolve('App\Services\SettingService'); - - foreach ($twofaccounts as $twofaccount) { - try { - $legacy_uri = $settingService->get('useEncryption') ? Crypt::decryptString($twofaccount->legacy_uri) : $twofaccount->legacy_uri; - $token = \OTPHP\Factory::loadFromProvisioningUri($legacy_uri); - - $affected = DB::table('twofaccounts') - ->where('id', $twofaccount->id) - ->update([ - 'otp_type' => get_class($token) === 'OTPHP\TOTP' ? 'totp' : 'hotp', - 'secret' => $settingService->get('useEncryption') ? Crypt::encryptString($token->getSecret()) : $token->getSecret(), - 'algorithm' => $token->getDigest(), - 'digits' => $token->getDigits(), - 'period' => $token->hasParameter('period') ? $token->getParameter('period') : null, - 'counter' => $token->hasParameter('counter') ? $token->getParameter('counter') : null - ]); - } - catch(Exception $ex) - { - Log::error($ex->getMessage()); - } - } - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - } -} diff --git a/phpunit-travis-sqlite.xml b/phpunit-travis-sqlite.xml deleted file mode 100644 index 65acb5ba..00000000 --- a/phpunit-travis-sqlite.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - ./app - - - - - ./tests/Unit - - - ./tests/Feature - - - ./tests/Api/v1 - - - - - - -