Skip to content

Commit

Permalink
404 pages are protected (statamic#7714)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Mar 16, 2023
1 parent 85a8a6a commit fc1c20a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Http/Controllers/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Http\Controllers;

use Illuminate\Http\Request;
use Statamic\Auth\Protect\Protection;
use Statamic\Exceptions\NotFoundHttpException;
use Statamic\Facades\Data;
use Statamic\Http\Responses\DataResponse;
Expand Down Expand Up @@ -30,6 +31,8 @@ public function index(Request $request)
return $data;
}

app(Protection::class)->protect();

throw new NotFoundHttpException;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/FrontendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Statamic\Facades\Blueprint;
use Statamic\Facades\Collection;
use Statamic\Facades\Site;
use Statamic\Facades\User;
use Statamic\Tags\Tags;
use Statamic\View\Antlers\Language\Utilities\StringUtilities;

Expand Down Expand Up @@ -834,4 +835,19 @@ public function redirectProvider()
],
];
}

/** @test */
public function it_protects_404_pages()
{
$this->get('/does-not-exist')->assertStatus(404);

config(['statamic.protect.default' => 'logged_in']);

$this->get('/does-not-exist')->assertRedirect('/login?redirect=http://localhost/does-not-exist');

$this
->actingAs(User::make())
->get('/does-not-exist')
->assertStatus(404);
}
}

0 comments on commit fc1c20a

Please sign in to comment.