2015-08-15 12:32:31 -04:00
|
|
|
<?php
|
2016-07-21 11:09:48 -04:00
|
|
|
|
2020-10-10 06:08:58 -04:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-09 05:54:42 -04:00
|
|
|
use PrivateBin\Persistence\ServerSalt;
|
|
|
|
use PrivateBin\Vizhash16x16;
|
2016-07-21 11:09:48 -04:00
|
|
|
|
2020-10-10 06:08:58 -04:00
|
|
|
class Vizhash16x16Test extends TestCase
|
2015-08-15 12:32:31 -04:00
|
|
|
{
|
|
|
|
private $_file;
|
|
|
|
|
|
|
|
private $_path;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
/* Setup Routine */
|
2016-08-09 05:54:42 -04:00
|
|
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
2016-07-26 02:19:35 -04:00
|
|
|
if (!is_dir($this->_path)) {
|
|
|
|
mkdir($this->_path);
|
|
|
|
}
|
2015-08-27 15:41:21 -04:00
|
|
|
$this->_file = $this->_path . DIRECTORY_SEPARATOR . 'vizhash.png';
|
2016-08-09 05:54:42 -04:00
|
|
|
ServerSalt::setPath($this->_path);
|
2015-08-15 12:32:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
/* Tear Down Routine */
|
2015-08-27 15:41:21 -04:00
|
|
|
chmod($this->_path, 0700);
|
2016-08-09 05:54:42 -04:00
|
|
|
Helper::rmDir($this->_path);
|
2015-08-15 12:32:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testVizhashGeneratesUniquePngsPerIp()
|
|
|
|
{
|
2016-10-29 04:24:08 -04:00
|
|
|
$vz = new Vizhash16x16();
|
2016-08-10 11:41:46 -04:00
|
|
|
$pngdata = $vz->generate(hash('sha512', '127.0.0.1'));
|
2015-08-15 12:32:31 -04:00
|
|
|
file_put_contents($this->_file, $pngdata);
|
|
|
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
|
|
|
$this->assertEquals('image/png', $finfo->file($this->_file));
|
2016-08-10 11:41:46 -04:00
|
|
|
$this->assertNotEquals($pngdata, $vz->generate(hash('sha512', '2001:1620:2057:dead:beef::cafe:babe')));
|
|
|
|
$this->assertEquals($pngdata, $vz->generate(hash('sha512', '127.0.0.1')));
|
2015-08-15 12:32:31 -04:00
|
|
|
}
|
|
|
|
}
|