From 5cbe0f43ef3a1d695a1e44b25baad96d22630844 Mon Sep 17 00:00:00 2001 From: miladev-ent <98118400+milwad-dev@users.noreply.github.com> Date: Fri, 21 Jul 2023 00:34:37 +0330 Subject: [PATCH 1/3] Create CreateSecurityCookieControllerTest.php --- tests/Http/Controller/CreateSecurityCookieControllerTest.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/Http/Controller/CreateSecurityCookieControllerTest.php diff --git a/tests/Http/Controller/CreateSecurityCookieControllerTest.php b/tests/Http/Controller/CreateSecurityCookieControllerTest.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/tests/Http/Controller/CreateSecurityCookieControllerTest.php @@ -0,0 +1 @@ + Date: Fri, 21 Jul 2023 00:34:48 +0330 Subject: [PATCH 2/3] add `create security cookie` test --- .../Controller/CreateSecurityCookieControllerTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Http/Controller/CreateSecurityCookieControllerTest.php b/tests/Http/Controller/CreateSecurityCookieControllerTest.php index b3d9bbc..508f39d 100644 --- a/tests/Http/Controller/CreateSecurityCookieControllerTest.php +++ b/tests/Http/Controller/CreateSecurityCookieControllerTest.php @@ -1 +1,10 @@ get('_native/api/cookie')->assertRedirect('/'); + $cookie = $response->headers->getCookies()[0]; + + $this->assertEquals('_php_native', $cookie->getName()); + $this->assertEquals('localhost', $cookie->getDomain()); + $this->assertTrue($cookie->isHttpOnly()); +}); From e56ab0adbe0490bf4d27fa098aafa95aeabcf614 Mon Sep 17 00:00:00 2001 From: miladev-ent <98118400+milwad-dev@users.noreply.github.com> Date: Fri, 21 Jul 2023 00:44:01 +0330 Subject: [PATCH 3/3] add test for abort --- .../Controller/CreateSecurityCookieControllerTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Http/Controller/CreateSecurityCookieControllerTest.php b/tests/Http/Controller/CreateSecurityCookieControllerTest.php index 508f39d..33b17f1 100644 --- a/tests/Http/Controller/CreateSecurityCookieControllerTest.php +++ b/tests/Http/Controller/CreateSecurityCookieControllerTest.php @@ -8,3 +8,11 @@ $this->assertEquals('localhost', $cookie->getDomain()); $this->assertTrue($cookie->isHttpOnly()); }); + +it('check if secret is not equal of config secret key abort 403 page', function () { + config()->set('native-php.secret', 'milwad'); + + $response = $this->get('_native/api/cookie')->assertStatus(403); + + $this->assertEquals([], $response->headers->getCookies()); +});