Adjust tests and statuscode

This commit is contained in:
Lukas Reschke 2015-04-16 10:48:25 +02:00
parent 8935369564
commit 9bc48451b9
3 changed files with 19 additions and 9 deletions

View File

@ -76,7 +76,7 @@ class CertificateController extends Controller {
'issuerOrganization' => $certificate->getIssuerOrganization(),
]);
} catch (\Exception $e) {
return new DataResponse('An error occurred.', Http::STATUS_INTERNAL_SERVER_ERROR);
return new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY);
}
}

View File

@ -14,8 +14,6 @@ class CertificateManagerTest extends \Test\TestCase {
private $certificateManager;
/** @var String */
private $username;
/** @var \OC\User\User */
private $user;
protected function setUp() {
parent::setUp();
@ -67,13 +65,25 @@ class CertificateManagerTest extends \Test\TestCase {
$this->certificateManager->addCertificate('InvalidCertificate', 'invalidCertificate');
}
/**
* @return array
*/
public function dangerousFileProvider() {
return [
['.htaccess'],
['../../foo.txt'],
['..\..\foo.txt'],
];
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Filename is not valid
* @dataProvider dangerousFileProvider
* @param string $filename
*/
function testAddDangerousFile() {
$this->certificateManager->addCertificate(file_get_contents(__DIR__.'/../../data/certificates/expiredCertificate.crt'), '.htaccess');
$this->certificateManager->addCertificate(file_get_contents(__DIR__.'/../../data/certificates/expiredCertificate.crt'), '../../foo.txt');
function testAddDangerousFile($filename) {
$this->certificateManager->addCertificate(file_get_contents(__DIR__.'/../../data/certificates/expiredCertificate.crt'), $filename);
}
function testRemoveDangerousFile() {

View File

@ -141,7 +141,7 @@ class CertificateControllerTest extends \Test\TestCase {
$this->assertEquals($expected, $this->certificateController->addPersonalRootCertificate());
}
public function testAddPersonalRootCertificateInValidCertificate() {
public function testAddPersonalRootCertificateInvalidCertificate() {
$uploadedFile = [
'tmp_name' => __DIR__ . '/../../data/certificates/badCertificate.crt',
'name' => 'badCertificate.crt',
@ -155,10 +155,10 @@ class CertificateControllerTest extends \Test\TestCase {
$this->certificateManager
->expects($this->once())
->method('addCertificate')
->with(file_get_contents($uploadedFile['tmp_name'], 'goodCertificate.crt'))
->with(file_get_contents($uploadedFile['tmp_name'], 'badCertificate.crt'))
->will($this->throwException(new \Exception()));
$expected = new DataResponse('An error occurred.', Http::STATUS_INTERNAL_SERVER_ERROR);
$expected = new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY);
$this->assertEquals($expected, $this->certificateController->addPersonalRootCertificate());
}