Skip to content

Commit

Permalink
fix cookie test (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesargb authored Jan 4, 2025
1 parent 8934183 commit 0aae828
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions tests/AccessCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ public function test_forbidden_if_protected_with_access_code_and_send_bad()

$magiclink->protectWithAccessCode('1234');

$response = $this->get("{$magiclink->url}?access-code=123")
$this->get("{$magiclink->url}?access-code=123")
->assertStatus(403)
->assertViewIs('magiclink::ask-for-access-code-form');

$this->assertEquals(0, count($response->headers->getCookies()));
->assertViewIs('magiclink::ask-for-access-code-form')
->assertCookieMissing('magic-link-access-code');
}

public function test_forbidden_if_protected_with_access_code_and_send_null()
Expand All @@ -54,11 +53,10 @@ public function test_forbidden_if_protected_with_access_code_and_send_null()

$magiclink->protectWithAccessCode('1234');

$response = $this->get("{$magiclink->url}")
$this->get("{$magiclink->url}")
->assertStatus(403)
->assertViewIs('magiclink::ask-for-access-code-form');

$this->assertEquals(0, count($response->headers->getCookies()));
->assertViewIs('magiclink::ask-for-access-code-form')
->assertCookieMissing('magic-link-access-code');
}

public function test_sucessfull_if_provide_access_code()
Expand All @@ -70,10 +68,12 @@ public function test_sucessfull_if_provide_access_code()
$magiclink->protectWithAccessCode('1234');

$response = $this->get("{$magiclink->url}?access-code=1234")
->assertCookie('magic-link-access-code')
->assertStatus(302)
->assertRedirect($magiclink->url);

$cookie = $response->headers->getCookies()[0];
$cookie = collect($response->headers->getCookies())
->first(fn($cookie) => $cookie->getName() === 'magic-link-access-code');

$this->disableCookieEncryption()->withCookie($cookie->getName(), $cookie->getvalue())
->get($magiclink->url)
Expand All @@ -91,7 +91,8 @@ public function test_forbidden_if_provide_access_code_of_other_link()

$response = $this->get("{$magiclink->url}?access-code=1234");

$cookie = $response->headers->getCookies()[0];
$cookie = collect($response->headers->getCookies())
->first(fn($cookie) => $cookie->getName() === 'magic-link-access-code');

$magiclinkOther = MagicLink::create(new ResponseAction(function () {
return 'the other big secret';
Expand Down

0 comments on commit 0aae828

Please sign in to comment.