PHP Classes

File: tests/AntiCSRFTest.php

Recommend this page to a friend!
  Packages of Scott Arciszewski   Anti-CSRF   tests/AntiCSRFTest.php   Download  
File: tests/AntiCSRFTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Anti-CSRF
Generate tokens to protect against CSRF exploits
Author: By
Last change: Fix tests
Date: 8 months ago
Size: 1,425 bytes
 

Contents

Class file image Download
<?php
use ParagonIE\AntiCSRF\AntiCSRF;
use
PHPUnit\Framework\TestCase;

/**
 * Class AntiCSRFTest
 */
class AntiCSRFTest extends TestCase
{
   
/**
     * @covers AntiCSRF::insertToken()
     */
   
public function testInsertToken()
    {
       
$post = [];
       
$session = [];
       
$server = $_SERVER;

       
$csrft = new AntiCSRF($post, $session, $server);
       
$token_html = $csrft->insertToken('', false);
       
       
$idx = $csrft->getSessionIndex();
       
$this->assertFalse(
            empty(
$csrft->session[$idx])
        );

       
$this->assertFalse(
            empty(
$session[$idx])
        );

       
$this->assertNotFalse(
           
strpos($token_html, "<input")
        );
    }

   
/**
     * @covers AntiCSRF::getTokenArray()
     */
   
public function testGetTokenArray()
    {
        @
session_start();

        try {
           
$csrft = new AntiCSRF();
        } catch (\
Throwable $ex) {
           
$post = [];
           
$session = [];
           
$server = $_SERVER;

           
$csrft = new AntiCSRF($post, $session, $server);
        }
       
$result = $csrft->getTokenArray();

       
$this->assertFalse(
            empty(
$csrft->session[$csrft->getSessionIndex()])
        );
       
$this->assertSame(
            [
               
$csrft->getFormIndex(),
               
$csrft->getFormToken(),
            ],
            \
array_keys($result)
        );
    }
}