-
-
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] fix: duplicate route names (#313)
* fix: duplicate route names * fix: inertia routes * test route caching * lint * fix: tests * Fix caching
- Loading branch information
1 parent
e0d3fb4
commit 819a30b
Showing
10 changed files
with
120 additions
and
30 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
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace JoelButcher\Socialstream\Tests\Feature; | ||
|
||
use App\Providers\RouteServiceProvider; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Laravel\Socialite\Facades\Socialite; | ||
use Laravel\Socialite\Two\GithubProvider; | ||
use Laravel\Socialite\Two\User as SocialiteUser; | ||
use Mockery; | ||
|
||
use function Pest\Laravel\get; | ||
use function Pest\Laravel\post; | ||
|
||
uses(RefreshDatabase::class); | ||
|
||
it('caches routes and redirects to provider', function () { | ||
$this->defineCacheRoutes(file_get_contents( | ||
__DIR__.'/../../workbench/routes/web.php' | ||
)); | ||
|
||
get('/oauth/github') | ||
->assertRedirect(); | ||
}); | ||
|
||
it('caches routes and authenticates via GET', function () { | ||
$this->defineCacheRoutes(file_get_contents( | ||
__DIR__.'/../../workbench/routes/web.php' | ||
)); | ||
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => fake()->numerify('########'), | ||
'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')->once()->andReturn($user); | ||
|
||
Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider); | ||
|
||
session()->put('socialstream.previous_url', route('register')); | ||
|
||
get('oauth/github/callback')->assertRedirect(RouteServiceProvider::HOME); | ||
}); | ||
|
||
it('caches routes and authenticates via POST', function () { | ||
$this->defineCacheRoutes(file_get_contents( | ||
__DIR__.'/../../workbench/routes/web.php' | ||
)); | ||
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => fake()->numerify('########'), | ||
'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')->once()->andReturn($user); | ||
|
||
Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider); | ||
|
||
session()->put('socialstream.previous_url', route('register')); | ||
|
||
post('oauth/github/callback')->assertRedirect(RouteServiceProvider::HOME); | ||
}); |
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,7 +5,6 @@ | |
use App\Models\User; | ||
use App\Providers\RouteServiceProvider; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Support\Facades\Config; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Route; | ||
|
@@ -18,9 +17,10 @@ | |
use Laravel\Socialite\Two\User as SocialiteUser; | ||
use Mockery; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
|
||
use function Pest\Laravel\get; | ||
|
||
uses(WithFaker::class, RefreshDatabase::class); | ||
uses(RefreshDatabase::class); | ||
|
||
it('redirects users', function (): void { | ||
$response = get('http://localhost/oauth/github'); | ||
|
@@ -74,7 +74,7 @@ public function generate(string $provider): RedirectResponse | |
test('users can register', function (): void { | ||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId = $this->faker->numerify('########'), | ||
'id' => $githubId = fake()->numerify('########'), | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'email' => '[email protected]', | ||
|
@@ -114,7 +114,7 @@ public function generate(string $provider): RedirectResponse | |
|
||
$user->connectedAccounts()->create([ | ||
'provider' => 'github', | ||
'provider_id' => $githubId = $this->faker->numerify('########'), | ||
'provider_id' => $githubId = fake()->numerify('########'), | ||
'email' => '[email protected]', | ||
'token' => Str::random(64), | ||
]); | ||
|
@@ -162,7 +162,7 @@ public function generate(string $provider): RedirectResponse | |
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId = $this->faker->numerify('########'), | ||
'id' => $githubId = fake()->numerify('########'), | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'email' => '[email protected]', | ||
|
@@ -199,7 +199,7 @@ public function generate(string $provider): RedirectResponse | |
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId = $this->faker->numerify('########'), | ||
'id' => $githubId = fake()->numerify('########'), | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'email' => '[email protected]', | ||
|
@@ -242,7 +242,7 @@ public function generate(string $provider): RedirectResponse | |
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId = $this->faker->numerify('########'), | ||
'id' => $githubId = fake()->numerify('########'), | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'email' => '[email protected]', | ||
|
@@ -278,7 +278,7 @@ public function generate(string $provider): RedirectResponse | |
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId = $this->faker->numerify('########'), | ||
'id' => $githubId = fake()->numerify('########'), | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'avatar' => 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Route; | ||
use JoelButcher\Socialstream\Http\Controllers\OAuthController; | ||
|
||
Route::group(['middleware' => config('socialstream.middleware', ['web'])], function () { | ||
Route::get('/oauth/{provider}', [OAuthController::class, 'redirect'])->name('oauth.redirect'); | ||
Route::match(['get', 'post'], '/oauth/{provider}/callback', [OAuthController::class, 'callback'])->name('oauth.callback'); | ||
}); | ||
|
||
Route::post('/login', function () { | ||
return 'login'; | ||
})->name('login'); | ||
|
||
Route::post('/register', function () { | ||
return 'register'; | ||
})->name('register'); |