From: Lukas Reschke Date: Thu, 16 Apr 2015 08:48:25 +0000 (+0200) Subject: Adjust tests and statuscode X-Git-Tag: v8.1.0alpha2~23^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9bc48451b939df58b7e7e90300c9c716c348027f;p=nextcloud-server.git Adjust tests and statuscode --- diff --git a/settings/controller/certificatecontroller.php b/settings/controller/certificatecontroller.php index c8d05a51240..d9026cd42af 100644 --- a/settings/controller/certificatecontroller.php +++ b/settings/controller/certificatecontroller.php @@ -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); } } diff --git a/tests/lib/security/certificatemanager.php b/tests/lib/security/certificatemanager.php index aea1fb71bc5..fab1c208443 100644 --- a/tests/lib/security/certificatemanager.php +++ b/tests/lib/security/certificatemanager.php @@ -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() { diff --git a/tests/settings/controller/CertificateControllerTest.php b/tests/settings/controller/CertificateControllerTest.php index 363175cca41..b6981195034 100644 --- a/tests/settings/controller/CertificateControllerTest.php +++ b/tests/settings/controller/CertificateControllerTest.php @@ -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()); }