about summary refs log tree commit diff stats
path: root/tests_integration/ApiTestCase.php
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-05-27 21:43:15 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-05-27 21:43:15 +0300
commit03d1c9a1f0bd65cd7fb64a9bcb1c8c8a8961ff8e (patch)
treeefb792b888653d7fdb9e63c2699cd90fa80e339a /tests_integration/ApiTestCase.php
parent37f9ded993c7f01293167a705bffea1a7c8fa1d6 (diff)
downloadthe-epube-03d1c9a1f0bd65cd7fb64a9bcb1c8c8a8961ff8e.tar.gz
the-epube-03d1c9a1f0bd65cd7fb64a9bcb1c8c8a8961ff8e.tar.xz
remove unnecessary csrf token testing / local vars
Diffstat (limited to 'tests_integration/ApiTestCase.php')
-rw-r--r--tests_integration/ApiTestCase.php13
1 files changed, 9 insertions, 4 deletions
diff --git a/tests_integration/ApiTestCase.php b/tests_integration/ApiTestCase.php
index 1997653..e5cebee 100644
--- a/tests_integration/ApiTestCase.php
+++ b/tests_integration/ApiTestCase.php
@@ -5,6 +5,7 @@ abstract class ApiTestCase extends TestCase {
 	protected string $apiUrl;
 
 	private string $cookieFile;
+	private string $csrfToken = "";
 
 	protected function setUp(): void
 	{
@@ -23,11 +24,11 @@ abstract class ApiTestCase extends TestCase {
 	 * @param string|null $csrfToken  CSRF token to include in the POST body.
 	 * @return array<int, mixed>
 	 */
-	protected function post(string $endpoint, array $data, ?string $csrfToken = null): array
+	protected function post(string $endpoint, array $data): array
 	{
-		if ($csrfToken !== null) {
-			$data['csrf_token'] = $csrfToken;
-		}
+
+		if ($this->csrfToken)
+			$data['csrf_token'] = $this->csrfToken;
 
 		$ch = curl_init($endpoint);
 		curl_setopt_array($ch, [
@@ -51,6 +52,10 @@ abstract class ApiTestCase extends TestCase {
 
 		/** @var array<string, mixed>|null $decoded */
 		$decoded = json_decode($body, true);
+
+		if (isset($decoded["csrf_token"]))
+			$this->csrfToken = $decoded["csrf_token"];
+
 		return [$status, $decoded ?? []];
 	}
 }