From a8973ab26bde36494707fcfcd1db9d9d8190d21d Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Sun, 11 Aug 2024 18:15:10 +0530 Subject: [PATCH] Improved header tests --- src/Appwrite/Functions/Validator/Headers.php | 4 ++++ tests/unit/Functions/Validator/HeadersTest.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Appwrite/Functions/Validator/Headers.php b/src/Appwrite/Functions/Validator/Headers.php index fcda90e6a3..ec129f57b6 100644 --- a/src/Appwrite/Functions/Validator/Headers.php +++ b/src/Appwrite/Functions/Validator/Headers.php @@ -47,6 +47,10 @@ class Headers extends Validator $value = \json_decode($value, true); } + if (!\is_array($value)) { + return false; + } + if (json_last_error() !== JSON_ERROR_NONE) { return false; } else { diff --git a/tests/unit/Functions/Validator/HeadersTest.php b/tests/unit/Functions/Validator/HeadersTest.php index 57baa1949c..b1f60a9aad 100644 --- a/tests/unit/Functions/Validator/HeadersTest.php +++ b/tests/unit/Functions/Validator/HeadersTest.php @@ -95,5 +95,14 @@ class HeadersTest extends TestCase 'a' => 'b', ]; $this->assertTrue($this->object->isValid($headers)); + + $headers = 123; + $this->assertFalse($this->object->isValid($headers)); + + $headers = true; + $this->assertFalse($this->object->isValid($headers)); + + $headers = 'string'; + $this->assertFalse($this->object->isValid($headers)); } }