diff --git a/routes/web.php b/routes/web.php index 8eeeb36..16f9ed7 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 $e) { + 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.'); + } }