-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9029f3
commit d1467b4
Showing
4 changed files
with
62 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,15 @@ | |
use App\Models\User; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Config; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Route; | ||
use Illuminate\Support\Facades\Session; | ||
use Illuminate\Support\Str; | ||
use JoelButcher\Socialstream\Contracts\GeneratesProviderRedirect; | ||
use JoelButcher\Socialstream\Providers; | ||
use JoelButcher\Socialstream\Socialstream; | ||
use Laravel\Fortify\Features; | ||
use Laravel\Socialite\Facades\Socialite; | ||
use Laravel\Socialite\Two\GithubProvider; | ||
use Laravel\Socialite\Two\User as SocialiteUser; | ||
|
@@ -151,6 +154,61 @@ public function generate(string $provider): RedirectResponse | |
$this->assertAuthenticated(); | ||
}); | ||
|
||
test('existing users with 2FA enabled are redirected', function (): void { | ||
Config::set('socialstream.providers', [Providers::github()]); | ||
Config::set('fortify.features', array_merge(Config::get('fortify.features'), [ | ||
Features::twoFactorAuthentication(options: [ | ||
'confirm' => false, | ||
'confirmPassword' => true, | ||
]), | ||
])); | ||
|
||
$user = Socialstream::$userModel::create([ | ||
'name' => 'Joel Butcher', | ||
'email' => '[email protected]', | ||
'password' => Hash::make('password'), | ||
'two_factor_secret' => 'foo', | ||
'two_factor_recovery_codes' => 'bar', | ||
]); | ||
|
||
$user->connectedAccounts()->create([ | ||
'provider' => 'github', | ||
'provider_id' => $githubId = fake()->numerify('########'), | ||
'email' => '[email protected]', | ||
'token' => Str::random(64), | ||
]); | ||
|
||
$this->assertDatabaseHas('users', ['email' => '[email protected]']); | ||
$this->assertDatabaseHas('connected_accounts', [ | ||
'provider' => 'github', | ||
'provider_id' => $githubId, | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId, | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'email' => '[email protected]', | ||
'avatar' => null, | ||
'avatar_original' => null, | ||
]) | ||
->setToken('user-token') | ||
->setRefreshToken('refresh-token') | ||
->setExpiresIn(3600); | ||
|
||
$provider = Mockery::mock(GithubProvider::class); | ||
$provider->shouldReceive('user')->andReturn($user); | ||
|
||
Socialite::shouldReceive('driver')->with('github')->andReturn($provider); | ||
|
||
Session::put('socialstream.previous_url', route('login')); | ||
|
||
get('http://localhost/oauth/github/callback') | ||
->assertRedirect(route('two-factor.login')); | ||
}); | ||
|
||
test('authenticated users can link to provider', function (): void { | ||
$this->actingAs(User::create([ | ||
'name' => 'Joel Butcher', | ||
|
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