Skip to content

Commit d3dc668

Browse files
committed
chore: test authentication
1 parent a290f00 commit d3dc668

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Controllers/ScalarController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ScalarController extends Controller
99
{
1010
public function __invoke()
1111
{
12-
if (! Gate::check('viewScalar') && ! app()->environment('local') && ! app()->environment('testing')) {
12+
if (! Gate::check('viewScalar') && ! app()->environment('local')) {
1313
return abort(403);
1414
}
1515

tests/ScalarTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Illuminate\Support\Facades\Gate;
34
use Illuminate\Support\Facades\Route;
45
use Scalar\Controllers\ScalarController;
56

@@ -22,7 +23,6 @@
2223
$response = $this->get(config('scalar.path'));
2324

2425
$response->assertOk()
25-
->assertViewIs('scalar::reference')
2626
->assertSee('data-url')
2727
->assertSee(config('scalar.url'));
2828
});
@@ -31,7 +31,6 @@
3131
$response = $this->get(config('scalar.path'));
3232

3333
$response->assertOk()
34-
->assertViewIs('scalar::reference')
3534
->assertSee('https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.json');
3635
});
3736

@@ -45,10 +44,24 @@
4544
$response = $this->get('/reference');
4645

4746
$response->assertOk()
48-
->assertViewIs('scalar::reference')
4947
->assertSee('https://example.com/cdn')
5048
->assertDontSee($originalCdn);
5149

5250
// Reset config
5351
config(['scalar.cdn' => $originalCdn]);
5452
});
53+
54+
it('doesn’t block access in production by default', function () {
55+
$response = $this->get(config('scalar.path'));
56+
57+
$response->assertOk();
58+
});
59+
60+
it('can block access in production', function () {
61+
// Overwrite the viewScalar Gate to block access
62+
Gate::define('viewScalar', fn ($user = null) => false);
63+
64+
$response = $this->get(config('scalar.path'));
65+
66+
$response->assertForbidden();
67+
});

0 commit comments

Comments
 (0)