mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-03-05 13:30:32 -05:00
updated test cases, added clarity in error messages
This commit is contained in:
@@ -364,7 +364,35 @@ class JsonApiTest extends TestCase
|
||||
@new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertStringContainsString('Error calling proxy.', $content, 'outputs error correctly');
|
||||
$this->assertStringContainsString('Proxy error: Bad response.', $content, 'outputs error correctly');
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @dataProvider baseShlinkUriProvider
|
||||
*/
|
||||
public function testShortenViaShlinkSuccessButMissingShortUrl($baseUri)
|
||||
{
|
||||
$mock_shlink_service = $this->_path . DIRECTORY_SEPARATOR . 'shlink.json';
|
||||
$options = parse_ini_file(CONF, true);
|
||||
$options['main']['basepath'] = 'https://example.com/path'; // missing slash gets added by Configuration constructor
|
||||
$options['main']['urlshortener'] = 'https://example.com' . $baseUri . 'link=';
|
||||
$options['shlink']['apiurl'] = $mock_shlink_service;
|
||||
Helper::createIniFile(CONF, $options);
|
||||
|
||||
// Ideally, this should never happen, just in case "shortUrl" is somehow missing in the 200 response
|
||||
file_put_contents($mock_shlink_service, '{}');
|
||||
|
||||
$_SERVER['REQUEST_URI'] = $baseUri . 'link=https%3A%2F%2Fexample.com%2Fpath%2F%3Ffoo%23bar';
|
||||
$_GET['link'] = 'https://example.com/path/?foo#bar';
|
||||
if (str_contains($baseUri, '?shortenviashlink')) {
|
||||
$_GET['shortenviashlink'] = null;
|
||||
}
|
||||
ob_start();
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertStringContainsString('Proxy error: Error parsing proxy response.', $content, 'outputs error correctly');
|
||||
}
|
||||
|
||||
public function baseUriProvider()
|
||||
@@ -399,7 +427,7 @@ class JsonApiTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertStringContainsString('Error calling proxy.', $content, 'outputs error correctly');
|
||||
$this->assertStringContainsString('Proxy error: Proxy URL is empty. This can be a configuration issue, like wrong or missing config keys.', $content, 'outputs error correctly');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,6 +444,6 @@ class JsonApiTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertStringContainsString('Error calling proxy.', $content, 'outputs error correctly');
|
||||
$this->assertStringContainsString('Proxy error: Proxy URL is empty. This can be a configuration issue, like wrong or missing config keys.', $content, 'outputs error correctly');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class YourlsProxyTest extends TestCase
|
||||
|
||||
$yourls = new YourlsProxy($this->_conf, 'https://example.com/?foo#bar');
|
||||
$this->assertTrue($yourls->isError());
|
||||
$this->assertEquals($yourls->getError(), 'Error parsing proxy response.');
|
||||
$this->assertEquals($yourls->getError(), 'Proxy error: Error parsing proxy response. This can be a configuration issue, like wrong or missing config keys.');
|
||||
}
|
||||
|
||||
public function testServerError()
|
||||
@@ -78,6 +78,6 @@ class YourlsProxyTest extends TestCase
|
||||
|
||||
$yourls = new YourlsProxy($this->_conf, 'https://example.com/?foo#bar');
|
||||
$this->assertTrue($yourls->isError());
|
||||
$this->assertEquals($yourls->getError(), 'Error calling proxy. Probably a configuration issue, like wrong or missing config keys.');
|
||||
$this->assertEquals($yourls->getError(), 'Proxy error: Error parsing proxy response. This can be a configuration issue, like wrong or missing config keys.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user