about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-21 12:06:53 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-21 12:06:53 +0300
commit7edf66a0b06a9764084ef426e53eaa28d7bd4ade (patch)
tree73ab3c28aba500bf74870c9b38e019ac3efde6b9
parentcae23c5e14a0ed4d80e9edde351cb4066e3e350c (diff)
downloadthe-epube-7edf66a0b06a9764084ef426e53eaa28d7bd4ade.tar.gz
the-epube-7edf66a0b06a9764084ef426e53eaa28d7bd4ade.tar.xz
fix validate_session() not being used in AuthRequired check
-rw-r--r--classes/Router.php2
-rw-r--r--tests/RouterTest.php1
-rw-r--r--tests/bootstrap.php8
3 files changed, 10 insertions, 1 deletions
diff --git a/classes/Router.php b/classes/Router.php
index 34e0bde..13e967e 100644
--- a/classes/Router.php
+++ b/classes/Router.php
@@ -45,7 +45,7 @@ class Router
         }
 
         // Check auth for handlers that require it
-        if ($handler instanceof AuthRequired && empty($_SESSION["owner"])) {
+        if ($handler instanceof AuthRequired && !validate_session()) {
             return (new Response())
                 ->withStatus(401)
                 ->withBody(json_encode(["error" => "Unauthorized"]));
diff --git a/tests/RouterTest.php b/tests/RouterTest.php
index 1c2197c..58887c3 100644
--- a/tests/RouterTest.php
+++ b/tests/RouterTest.php
@@ -132,6 +132,7 @@ final class RouterTest extends TestCase
 		};
 		$this->router->addRoute('protected', $handler);
 		$_SESSION['owner'] = 'testuser';
+		$_SESSION['pass_hash'] = 'dummy';
 
 		$response = $this->router->dispatchResponse('protected');
 
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 8cae8e1..a484982 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -5,3 +5,11 @@
 	putenv("IS_TESTING=true");
 
 	require_once "common.php";
+
+	// Stub validate_session() for unit tests (no DB needed).
+	// Integration tests load sessions.php which defines the real function.
+	if (!function_exists('validate_session')) {
+		function validate_session() : bool {
+			return !empty($_SESSION["owner"]) && !empty($_SESSION["pass_hash"]);
+		}
+	}