Adjust tests and statuscode
This commit is contained in:
parent
8935369564
commit
9bc48451b9
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue