/** * Does the provided token match the one generated? * * @param string $value * @param mixed $context * @return bool */ public function isValid($value, $context = null) { if (!$this->tokenProvider->isTokenValid($this->tokenId, $value)) { $this->refreshToken($this->tokenId); $this->error(self::NOT_SAME); return false; } $this->tokenProvider->removeToken($this->tokenId); return true; }
function it_should_pass_validation_if_a_valid_token_is_provided(TokenProvider $provider) { $tokenId = '_login_csrf_token'; $token = 'e95b24c1586e4b3dbfadcdd85aee46e0'; $this->beConstructedWith(['tokenProvider' => $provider, 'tokenId' => $tokenId]); $provider->isTokenValid($tokenId, $token)->willReturn(true); $provider->removeToken($tokenId)->shouldBeCalled(); $isValid = $this->isValid($token); $isValid->shouldBe(true); $this->getMessages()->shouldHaveCount(0); }