Пример #1
0
 /**
  * @runInSeparateProcess
  */
 public function testPut()
 {
     $this->reset();
     $options = parse_ini_file(CONF, true);
     $options['traffic']['limit'] = 0;
     helper::confBackup();
     helper::createIniFile(CONF, $options);
     $paste = helper::getPaste();
     unset($paste['meta']);
     $file = tempnam(sys_get_temp_dir(), 'FOO');
     file_put_contents($file, http_build_query($paste));
     request::setInputStream($file);
     $_SERVER['QUERY_STRING'] = helper::getPasteId();
     $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
     $_SERVER['REQUEST_METHOD'] = 'PUT';
     $_SERVER['REMOTE_ADDR'] = '::1';
     ob_start();
     new zerobin();
     $content = ob_get_contents();
     $response = json_decode($content, true);
     $this->assertEquals(0, $response['status'], 'outputs status');
     $this->assertEquals(helper::getPasteId(), $response['id'], 'outputted paste ID matches input');
     $this->assertEquals(hash_hmac('sha1', $response['id'], serversalt::get()), $response['deletetoken'], 'outputs valid delete token');
     $this->assertStringEndsWith('?' . $response['id'], $response['url'], 'returned URL points to new paste');
     $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data');
 }
Пример #2
0
 public function reset()
 {
     parent::reset();
     // but then inject a db config
     $options = parse_ini_file(CONF, true);
     $options['model'] = array('class' => 'zerobin_db');
     $options['model_options'] = $this->_options;
     helper::confBackup();
     helper::createIniFile(CONF, $options);
 }
Пример #3
0
 public function setUp()
 {
     /* Setup Routine */
     $options = parse_ini_file(CONF, true);
     $options['model'] = array('class' => 'zerobin_db');
     $options['model_options'] = array('dsn' => 'sqlite::memory:', 'usr' => null, 'pwd' => null, 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
     helper::confBackup();
     helper::createIniFile(CONF, $options);
     $this->_conf = new configuration();
     $this->_model = new model($this->_conf);
     $_SERVER['REMOTE_ADDR'] = '::1';
 }
Пример #4
0
 public function testHandleMissingSubKeys()
 {
     $options = $this->_options;
     unset($options['expire_options']['1week']);
     unset($options['expire_options']['1year']);
     unset($options['expire_options']['never']);
     helper::createIniFile(CONF, $options);
     $conf = new configuration();
     $options['expire']['default'] = '5min';
     $this->assertEquals($options, $conf->get(), 'not overriding "missing" subkeys');
 }
Пример #5
0
 /**
  * @runInSeparateProcess
  */
 public function testCreateDuplicateComment()
 {
     $this->reset();
     $options = parse_ini_file(CONF, true);
     $options['traffic']['limit'] = 0;
     helper::confBackup();
     helper::createIniFile(CONF, $options);
     $this->_model->create(helper::getPasteId(), helper::getPaste());
     $this->_model->createComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId(), helper::getComment());
     $this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment exists before posting data');
     $_POST = helper::getCommentPost();
     $_POST['pasteid'] = helper::getPasteId();
     $_POST['parentid'] = helper::getPasteId();
     $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_SERVER['REMOTE_ADDR'] = '::1';
     ob_start();
     new zerobin();
     $content = ob_get_contents();
     $response = json_decode($content, true);
     $this->assertEquals(1, $response['status'], 'outputs error status');
     $this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data');
 }