Skip to content

Add cookie validation to auth methods #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
Expand Down Expand Up @@ -1080,7 +1081,10 @@ public function seeAuthentication(): void
$this->fail('There is no user in session');
}

$this->assertTrue($security->isGranted('IS_AUTHENTICATED_FULLY'), 'There is no authenticated user');
$this->assertTrue(
$security->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_FULLY),
'There is no authenticated user'
);
}

/**
Expand Down Expand Up @@ -1133,7 +1137,14 @@ public function seeRememberedAuthentication(): void
$this->fail('There is no user in session');
}

$this->assertTrue($security->isGranted('IS_AUTHENTICATED_REMEMBERED'), 'There is no authenticated user');
$hasRememberMeCookie = $this->client->getCookieJar()->get('REMEMBERME');
$hasRememberMeRole = $security->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);

$isRemembered = $hasRememberMeCookie && $hasRememberMeRole;
$this->assertTrue(
$isRemembered,
'User does not have remembered authentication'
);
}

/**
Expand All @@ -1149,9 +1160,13 @@ public function dontSeeRememberedAuthentication(): void
/** @var Security $security */
$security = $this->grabService('security.helper');

$hasRememberMeCookie = $this->client->getCookieJar()->get('REMEMBERME');
$hasRememberMeRole = $security->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);

$isRemembered = $hasRememberMeCookie && $hasRememberMeRole;
$this->assertFalse(
$security->isGranted('IS_AUTHENTICATED_REMEMBERED'),
'There is an user authenticated'
$isRemembered,
'User does have remembered authentication'
);
}

Expand Down Expand Up @@ -1200,7 +1215,7 @@ public function dontSeeAuthentication(): void
$security = $this->grabService('security.helper');

$this->assertFalse(
$security->isGranted('IS_AUTHENTICATED_FULLY'),
$security->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_FULLY),
'There is an user authenticated'
);
}
Expand Down