This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from DarkGhostHunter/master
Laravel 8.0 and PHP 8.0 support.
- Loading branch information
Showing
19 changed files
with
316 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,102 @@ | ||
<?php | ||
/** @var \Illuminate\Database\Eloquent\Factory $factory */ | ||
|
||
namespace Database\Factories\DarkGhostHunter\Laraguard\Eloquent; | ||
|
||
use Faker\Generator as Faker; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Support\Collection; | ||
use DarkGhostHunter\Laraguard\Eloquent\TwoFactorAuthentication; | ||
|
||
$factory->define(TwoFactorAuthentication::class, function (Faker $faker) { | ||
class TwoFactorAuthenticationFactory extends Factory { | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = TwoFactorAuthentication::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
$config = config('laraguard'); | ||
|
||
$config = config('laraguard'); | ||
$array = array_merge([ | ||
'shared_secret' => TwoFactorAuthentication::generateRandomSecret(), | ||
'enabled_at' => $this->faker->dateTimeBetween('-1 year'), | ||
'label' => $this->faker->freeEmail, | ||
], $config['totp']); | ||
|
||
$array = array_merge([ | ||
'shared_secret' => TwoFactorAuthentication::generateRandomSecret(), | ||
'enabled_at' => $faker->dateTimeBetween('-1 year'), | ||
'label' => $faker->freeEmail, | ||
], $config['totp']); | ||
[$enabled, $amount, $length] = array_values($config['recovery']); | ||
|
||
[$enabled, $amount, $length] = array_values($config['recovery']); | ||
if ($enabled) { | ||
$array['recovery_codes'] = TwoFactorAuthentication::generateRecoveryCodes($amount, $length); | ||
$array['recovery_codes_generated_at'] = $this->faker->dateTimeBetween('-1 years'); | ||
} | ||
|
||
if ($enabled) { | ||
$array['recovery_codes'] = TwoFactorAuthentication::generateRecoveryCodes($amount, $length); | ||
$array['recovery_codes_generated_at'] = $faker->dateTimeBetween('-1 years'); | ||
return $array; | ||
} | ||
|
||
return $array; | ||
}); | ||
/** | ||
* Returns a model with unused recovery codes. | ||
* | ||
* @return TwoFactorAuthenticationFactory | ||
*/ | ||
public function withRecovery() | ||
{ | ||
return $this->state(function(array $attributes) { | ||
[$enabled, $amount, $length] = array_values(config('laraguard.recovery')); | ||
|
||
$factory->state(TwoFactorAuthentication::class, 'with recovery', function (Faker $faker) { | ||
[$enabled, $amount, $length] = array_values(config('laraguard.recovery')); | ||
return [ | ||
'recovery_codes' => TwoFactorAuthentication::generateRecoveryCodes($amount, $length), | ||
'recovery_codes_generated_at' => $faker->dateTimeBetween('-1 years'), | ||
]; | ||
}); | ||
return [ | ||
'recovery_codes' => TwoFactorAuthentication::generateRecoveryCodes($amount, $length), | ||
'recovery_codes_generated_at' => $this->faker->dateTimeBetween('-1 years'), | ||
]; | ||
}); | ||
} | ||
|
||
// This state will create a full set of safe devices, but it will leave the last as purposefully expired. | ||
$factory->state(TwoFactorAuthentication::class, 'with safe devices', function (Faker $faker) { | ||
/** | ||
* Returns an authentication with a list of safe devices. | ||
* | ||
* @return TwoFactorAuthenticationFactory | ||
*/ | ||
public function withSafeDevices() | ||
{ | ||
return $this->state(function (array $attributes) { | ||
$max = config('laraguard.safe_devices.max_devices'); | ||
|
||
$max = config('laraguard.safe_devices.max_devices'); | ||
return [ | ||
'safe_devices' => Collection::times($max, function ($step) use ($max) { | ||
|
||
return [ | ||
'safe_devices' => Collection::times($max, function ($step) use ($faker, $max) { | ||
$expiration_days = config('laraguard.safe_devices.expiration_days'); | ||
|
||
$expiration_days = config('laraguard.safe_devices.expiration_days'); | ||
$added_at = $max !== $step | ||
? now() | ||
: $this->faker->dateTimeBetween(now()->subDays($expiration_days * 2), now()->subDays($expiration_days)); | ||
|
||
$added_at = $max !== $step | ||
? now() | ||
: $faker->dateTimeBetween(now()->subDays($expiration_days * 2), now()->subDays($expiration_days)); | ||
return [ | ||
'2fa_remember' => TwoFactorAuthentication::generateDefaultTwoFactorRemember(), | ||
'ip' => $this->faker->ipv4, | ||
'added_at' => $added_at, | ||
]; | ||
}), | ||
]; | ||
}); | ||
} | ||
|
||
/** | ||
* Returns an enabled authentication. | ||
* | ||
* @return TwoFactorAuthenticationFactory | ||
*/ | ||
public function enabled() | ||
{ | ||
return $this->state(function (array $attributes) { | ||
return [ | ||
'2fa_remember' => TwoFactorAuthentication::generateDefaultTwoFactorRemember(), | ||
'ip' => $faker->ipv4, | ||
'added_at' => $added_at, | ||
'enabled_at' => null | ||
]; | ||
}), | ||
]; | ||
}); | ||
|
||
$factory->state(TwoFactorAuthentication::class, 'disabled', [ | ||
'enabled_at' => null, | ||
]); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="junit" target="build/report.junit.xml"/> | ||
<log type="coverage-html" target="build/coverage"/> | ||
<log type="coverage-text" target="build/coverage.txt"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/> | ||
<env name="DB_CONNECTION" value="testing"/> | ||
</php> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
<report> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
<html outputDirectory="build/coverage"/> | ||
<text outputFile="build/coverage.txt"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/> | ||
<env name="DB_CONNECTION" value="testing"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.