Skip to content

Commit 1b336a7

Browse files
committed
Update tests to verify session middleware is actually applied
Changed auth callbacks from 'fn ($request) => true' to session checks that verify hasSession() and isStarted(). This ensures tests validate that session middleware is properly applied, not just that auth callbacks are invoked. Updated tests: - authentication works when APP_URL matches request domain - localhost requests work by default regardless of APP_URL - 127.0.0.1 requests work by default regardless of APP_URL - custom stateful domains override APP_URL behavior Verified test fails (403) when session middleware not applied.
1 parent 89422ed commit 1b336a7

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

tests/Feature/Authorization/ApiAuthenticationTest.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@
4949
test('authentication works when APP_URL matches request domain', function () {
5050
config(['app.url' => 'http://example.com']);
5151

52-
LogViewer::auth(fn ($request) => true);
52+
// Auth callback that requires session to be started (proving session middleware was applied)
53+
LogViewer::auth(function ($request) {
54+
if (! $request->hasSession() || ! $request->session()->isStarted()) {
55+
return false;
56+
}
57+
58+
return true;
59+
});
5360

5461
$response = getJson('http://example.com/log-viewer/api/folders', [
5562
'referer' => 'http://example.com/',
@@ -164,7 +171,14 @@
164171
test('localhost requests work by default regardless of APP_URL', function () {
165172
config(['app.url' => 'http://production.com']);
166173

167-
LogViewer::auth(fn ($request) => true);
174+
// Auth callback that requires session to be started (proving session middleware was applied)
175+
LogViewer::auth(function ($request) {
176+
if (! $request->hasSession() || ! $request->session()->isStarted()) {
177+
return false;
178+
}
179+
180+
return true;
181+
});
168182

169183
// Localhost is in the default stateful domains
170184
$response = getJson('http://localhost/log-viewer/api/folders', [
@@ -177,7 +191,14 @@
177191
test('127.0.0.1 requests work by default regardless of APP_URL', function () {
178192
config(['app.url' => 'http://production.com']);
179193

180-
LogViewer::auth(fn ($request) => true);
194+
// Auth callback that requires session to be started (proving session middleware was applied)
195+
LogViewer::auth(function ($request) {
196+
if (! $request->hasSession() || ! $request->session()->isStarted()) {
197+
return false;
198+
}
199+
200+
return true;
201+
});
181202

182203
// 127.0.0.1 is in the default stateful domains
183204
$response = getJson('http://127.0.0.1/log-viewer/api/folders', [
@@ -193,7 +214,14 @@
193214
'log-viewer.api_stateful_domains' => ['custom-domain.com'],
194215
]);
195216

196-
LogViewer::auth(fn ($request) => true);
217+
// Auth callback that requires session to be started (proving session middleware was applied)
218+
LogViewer::auth(function ($request) {
219+
if (! $request->hasSession() || ! $request->session()->isStarted()) {
220+
return false;
221+
}
222+
223+
return true;
224+
});
197225

198226
// Custom domain should work
199227
$response = getJson('http://custom-domain.com/log-viewer/api/folders', [

0 commit comments

Comments
 (0)