mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-25 17:54:57 +01:00
Revert "Revert most of the previous changes as using bionic fixes travis"
This reverts commit 34db59a991
.
This commit is contained in:
parent
f3f658675a
commit
751ff5d1b0
@ -10,7 +10,7 @@ php:
|
||||
# - 8.0
|
||||
|
||||
services:
|
||||
- mysql
|
||||
# - mysql
|
||||
|
||||
before_install:
|
||||
# - mysql -e 'CREATE DATABASE 2fauth_test;'
|
||||
@ -20,12 +20,10 @@ before_script:
|
||||
- travis_retry composer install --no-interaction
|
||||
# no need to use a dedicated Travis .env file as phpunit
|
||||
# will use .env.testing by default
|
||||
- php artisan cache:clear
|
||||
|
||||
script:
|
||||
# - DATABASE=mysql vendor/bin/phpunit -c phpunit-mysql.xml
|
||||
- cp .env.travis .env
|
||||
- php artisan cache:clear
|
||||
- php artisan config:clear
|
||||
- php artisan key:generate
|
||||
- DATABASE=sqlite vendor/bin/phpunit -c phpunit.xml --coverage-clover=coverage.xml
|
||||
|
@ -19,7 +19,6 @@ public function up()
|
||||
|
||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||
$table->text('account')->change();
|
||||
$table->text('uri')->change();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AlterEncryptedColumnsToTextForSqliteBis extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$driver = Schema::connection($this->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) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
@ -16,44 +16,17 @@ 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);
|
||||
$table->text('secret');
|
||||
$table->string('algorithm', 20);
|
||||
$table->unsignedSmallInteger('digits');
|
||||
$table->string('otp_type', 10)->nullable();
|
||||
$table->text('secret')->nullable();
|
||||
$table->string('algorithm', 20)->nullable();
|
||||
$table->unsignedSmallInteger('digits')->nullable();
|
||||
$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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,9 +59,5 @@ public function down()
|
||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||
$table->dropColumn('counter');
|
||||
});
|
||||
|
||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||
$table->renameColumn('legacy_uri', 'uri');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class RenameUriToLegacyUri extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||
$table->renameColumn('uri', 'legacy_uri');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||
$table->renameColumn('legacy_uri', 'uri');
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ChangeNullableInTwofaccountsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||
$table->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()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user