-
-
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.
[5.x] Bugfix redirect on OAuth Link Failed (#354)
* fix route not found * Add a test
- Loading branch information
1 parent
993b03b
commit 4f756c6
Showing
2 changed files
with
52 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,3 +189,54 @@ public function generate(string $provider): RedirectResponse | |
'email' => '[email protected]', | ||
]); | ||
}); | ||
|
||
test('linking and already linked provider fails', function () { | ||
// Arrange - existing user with account linked | ||
$this->actingAs(User::create([ | ||
'name' => 'Joel Butcher', | ||
'email' => '[email protected]', | ||
'password' => Hash::make('password'), | ||
])); | ||
|
||
$provider = mock(GithubProvider::class); | ||
$provider->shouldReceive('user')->andReturn((new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId = fake()->numerify('########'), | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'email' => '[email protected]', | ||
'avatar' => null, | ||
'avatar_original' => null, | ||
]) | ||
->setToken('user-token') | ||
->setRefreshToken('refresh-token') | ||
->setExpiresIn(3600)); | ||
|
||
Socialite::shouldReceive('driver')->with('github')->andReturn($provider); | ||
|
||
get('http://localhost/oauth/github/callback'); | ||
|
||
$this->assertAuthenticated(); | ||
$this->assertDatabaseHas('connected_accounts', [ | ||
'provider' => 'github', | ||
'provider_id' => $githubId, | ||
'email' => '[email protected]', | ||
]); | ||
|
||
// Arrange - new user | ||
$this->actingAs(User::create([ | ||
'name' => 'Joel Butcher', | ||
'email' => '[email protected]', | ||
'password' => Hash::make('password'), | ||
])); | ||
|
||
// Act | ||
get('http://localhost/oauth/github/callback') | ||
->assertRedirectToRoute('profile.show') | ||
->assertSessionHas([ | ||
'flash' => [ | ||
'banner' => 'It looks like this GitHub account is used by another user. Please log in.', | ||
'bannerStyle' => 'danger' | ||
] | ||
]); | ||
}); |