예제 #1
0
 public function testSettingNewSessionContainerSetsHashInNewContainer()
 {
     $hash        = $this->validator->getHash();
     $container   = new Container('foo', $this->sessionManager);
     $this->validator->setSession($container);
     $test        = $container->hash; // Doing this, as expiration hops are 1; have to grab on first access
     $this->assertEquals($hash, $test);
 }
예제 #2
0
    public function testValueAttributeIsSetToValidatorHash()
    {
        $element   = new CsrfElement('foo');
        $validator = $element->getValidator();
        $value     = $element->getAttribute('value');
        $this->assertSame($validator->getHash(), $value);

        $validator = new CsrfValidator(array(
            'salt' => 'foobar',
            'name' => $element->getName(),
        ));
        $validator->setSalt('foobarbaz');
        $element->setValidator($validator);
        $value2    = $element->getAttribute('value');
        $this->assertSame($validator->getHash(), $value2);
        $this->assertNotSame($value, $value2, "$value == $value2");
    }
예제 #3
0
파일: CsrfTest.php 프로젝트: pnaq57/zf2demo
 public function testCanValidateHasheWithoutId()
 {
     $method = new \ReflectionMethod(get_class($this->validator), 'getTokenFromHash');
     $method->setAccessible(true);
     $hash = $this->validator->getHash();
     $bareToken = $method->invoke($this->validator, $hash);
     $this->assertTrue($this->validator->isValid($bareToken));
 }
예제 #4
0
 public function getCsrfValidator()
 {
     if ($this->csrfValidator === NULL) {
         $validator = new Csrf();
         $validator->setOptions($this->getCsrfConfig())->setMessages(array(Csrf::NOT_SAME => $this->getErrorMessage('CSRF::NOT_SAME')));
         $this->setCsrfValidator($validator);
     }
     return $this->csrfValidator;
 }