2015-08-15 16:32:31 +00:00
|
|
|
<?php
|
2016-07-21 15:09:48 +00:00
|
|
|
|
|
|
|
use PrivateBin\serversalt;
|
|
|
|
use PrivateBin\vizhash16x16;
|
|
|
|
|
2015-08-15 16:32:31 +00:00
|
|
|
class vizhash16x16Test extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
private $_file;
|
|
|
|
|
|
|
|
private $_path;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
/* Setup Routine */
|
2015-08-27 19:41:21 +00:00
|
|
|
$this->_path = PATH . 'data';
|
2016-07-26 06:19:35 +00:00
|
|
|
if (!is_dir($this->_path)) {
|
|
|
|
mkdir($this->_path);
|
|
|
|
}
|
2015-08-27 19:41:21 +00:00
|
|
|
$this->_file = $this->_path . DIRECTORY_SEPARATOR . 'vizhash.png';
|
|
|
|
serversalt::setPath($this->_path);
|
2015-08-15 16:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
/* Tear Down Routine */
|
2015-08-27 19:41:21 +00:00
|
|
|
chmod($this->_path, 0700);
|
2016-07-26 06:19:35 +00:00
|
|
|
if (!@unlink($this->_file)) {
|
2015-08-27 19:41:21 +00:00
|
|
|
throw new Exception('Error deleting file "' . $this->_file . '".');
|
2015-08-15 16:32:31 +00:00
|
|
|
}
|
2015-08-27 19:41:21 +00:00
|
|
|
helper::rmdir($this->_path);
|
2015-08-15 16:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testVizhashGeneratesUniquePngsPerIp()
|
|
|
|
{
|
|
|
|
$vz = new vizhash16x16();
|
|
|
|
$pngdata = $vz->generate('127.0.0.1');
|
|
|
|
file_put_contents($this->_file, $pngdata);
|
|
|
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
|
|
|
$this->assertEquals('image/png', $finfo->file($this->_file));
|
|
|
|
$this->assertNotEquals($pngdata, $vz->generate('2001:1620:2057:dead:beef::cafe:babe'));
|
|
|
|
$this->assertEquals($pngdata, $vz->generate('127.0.0.1'));
|
|
|
|
}
|
|
|
|
}
|