-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2.x] Fixes redirects to "www" when using subdomains (#108)
* Fixes redirects to "www" when using subdomains * Update EnsureOnNakedDomain.php Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
dca913e
commit 63b98ff
Showing
2 changed files
with
144 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
namespace Laravel\Vapor\Tests\Feature; | ||
|
||
use Illuminate\Support\Facades\Route; | ||
use Laravel\Vapor\Runtime\Http\Middleware\EnsureOnNakedDomain; | ||
use Laravel\Vapor\VaporServiceProvider; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class EnsureOnNakedDomainTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$_ENV['APP_VANITY_URL'] = 'https://something.vapor-farm.com'; | ||
|
||
Route::get('/', function () { | ||
return 'Hello World'; | ||
})->middleware(EnsureOnNakedDomain::class); | ||
} | ||
|
||
protected function getPackageProviders($app): array | ||
{ | ||
return [ | ||
VaporServiceProvider::class, | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider useCases | ||
*/ | ||
public function test_redirects($useCase) | ||
{ | ||
config()->set('vapor.redirect_to_root', $useCase['redirect_to_root']); | ||
config()->set('app.url', $useCase['app_url']); | ||
|
||
$response = $this->get($useCase['request_url']); | ||
|
||
$response->assertStatus($useCase['response_status']); | ||
|
||
if ($useCase['response_status'] == 301) { | ||
$response->assertRedirect($useCase['redirected_to']); | ||
} | ||
} | ||
|
||
public function useCases() | ||
{ | ||
return [ | ||
[[ | ||
'app_url' => 'https://domain.com', | ||
'request_url' => 'https://domain.com', | ||
'redirect_to_root' => true, | ||
'response_status' => 200, | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.net.io', | ||
'request_url' => 'https://domain.net.io', | ||
'redirect_to_root' => true, | ||
'response_status' => 200, | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.com', | ||
'request_url' => 'https://www.domain.com', | ||
'redirect_to_root' => true, | ||
'response_status' => 301, | ||
'redirected_to' => 'https://domain.com', | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.net.io', | ||
'request_url' => 'https://www.domain.net.io', | ||
'redirect_to_root' => true, | ||
'response_status' => 301, | ||
'redirected_to' => 'https://domain.net.io', | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.com', | ||
'request_url' => 'https://sub.domain.com', | ||
'redirect_to_root' => true, | ||
'response_status' => 200, | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.net.io', | ||
'request_url' => 'https://sub.domain.net.io', | ||
'redirect_to_root' => true, | ||
'response_status' => 200, | ||
]], | ||
|
||
// redirect_to_root => false | ||
[[ | ||
'app_url' => 'https://domain.com', | ||
'request_url' => 'https://www.domain.com', | ||
'redirect_to_root' => false, | ||
'response_status' => 200, | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.net.io', | ||
'request_url' => 'https://www.domain.net.io', | ||
'redirect_to_root' => false, | ||
'response_status' => 200, | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.com', | ||
'request_url' => 'https://domain.com', | ||
'redirect_to_root' => false, | ||
'response_status' => 301, | ||
'redirected_to' => 'https://www.domain.com', | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.net.io', | ||
'request_url' => 'https://domain.net.io', | ||
'redirect_to_root' => false, | ||
'response_status' => 301, | ||
'redirected_to' => 'https://www.domain.net.io', | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.com', | ||
'request_url' => 'https://sub.domain.com', | ||
'redirect_to_root' => false, | ||
'response_status' => 200, | ||
]], | ||
[[ | ||
'app_url' => 'https://domain.net.io', | ||
'request_url' => 'https://sub.domain.net.io', | ||
'redirect_to_root' => false, | ||
'response_status' => 200, | ||
]], | ||
]; | ||
} | ||
} |