From 159c4653244bc63e068b9c557cbe48730b9547b9 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 25 Feb 2022 15:23:09 +0100 Subject: [PATCH 1/3] Redirect homepage and handle invalid name --- routes/web.php | 18 +++++++----------- tests/Feature/SailServerTest.php | 13 +++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/routes/web.php b/routes/web.php index 8eeeb36..5ba83a0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,20 +3,16 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Validator; +use Illuminate\Validation\ValidationException; -/* -|-------------------------------------------------------------------------- -| Web Routes -|-------------------------------------------------------------------------- -| -| Here is where you can register web routes for your application. These -| routes are loaded by the RouteServiceProvider within a group which -| contains the "web" middleware group. Now create something great! -| -*/ +Route::redirect('/', 'https://laravel.com/docs', 302); Route::get('/{name}', function (Request $request, $name) { - Validator::validate(['name' => $name], ['name' => 'string|alpha_dash']); + try { + Validator::validate(['name' => $name], ['name' => 'string|alpha_dash']); + } catch (ValidationException) { + return response('Invalid site name. Please only use alpha-numeric characters, dashes and underscores.', 400); + } $php = $request->query('php', '81'); diff --git a/tests/Feature/SailServerTest.php b/tests/Feature/SailServerTest.php index e660e30..04cfc2c 100644 --- a/tests/Feature/SailServerTest.php +++ b/tests/Feature/SailServerTest.php @@ -6,6 +6,11 @@ class SailServerTest extends TestCase { + public function test_the_homepage_redirects_to_the_laravel_docs() + { + $this->get('/')->assertRedirect('https://laravel.com/docs'); + } + public function test_it_can_return_the_sail_install_script() { $response = $this->get('/example-app'); @@ -30,4 +35,12 @@ public function test_it_adds_the_devcontainer_upon_request() $response->assertStatus(200); $response->assertSee('bash -c "laravel new example-app && cd example-app && php ./artisan sail:install --with=postgres --devcontainer"', false); } + + public function test_it_does_not_accepts_domains_with_a_dot() + { + $response = $this->get('/foo.test'); + + $response->assertStatus(400); + $response->assertSee('Invalid site name. Please only use alpha-numeric characters, dashes and underscores.'); + } } From a9c87f5714170d6ebe12911645a3dd5be1f90972 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 25 Feb 2022 15:27:45 +0100 Subject: [PATCH 2/3] wip --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index 5ba83a0..4a3180d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,7 +10,7 @@ Route::get('/{name}', function (Request $request, $name) { try { Validator::validate(['name' => $name], ['name' => 'string|alpha_dash']); - } catch (ValidationException) { + } catch (ValidationException $e) { return response('Invalid site name. Please only use alpha-numeric characters, dashes and underscores.', 400); } From c2ebecc50549c68d02228dce11c812c47a36367a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 25 Feb 2022 13:51:12 -0600 Subject: [PATCH 3/3] Update web.php --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index 4a3180d..16f9ed7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,7 +11,7 @@ try { Validator::validate(['name' => $name], ['name' => 'string|alpha_dash']); } catch (ValidationException $e) { - return response('Invalid site name. Please only use alpha-numeric characters, dashes and underscores.', 400); + return response('Invalid site name. Please only use alpha-numeric characters, dashes, and underscores.', 400); } $php = $request->query('php', '81');