Verify the path is a file on avatar update
Fixes #21533 Before we just assumed that the passed path was a file. This does not have to be the case. Thus check if it actually is a file before doing any more tests.
This commit is contained in:
parent
a1a8a06042
commit
186e35d954
|
@ -160,6 +160,9 @@ class AvatarController extends Controller {
|
||||||
if (isset($path)) {
|
if (isset($path)) {
|
||||||
$path = stripslashes($path);
|
$path = stripslashes($path);
|
||||||
$node = $this->userFolder->get($path);
|
$node = $this->userFolder->get($path);
|
||||||
|
if (!($node instanceof \OCP\Files\File)) {
|
||||||
|
return new DataResponse(['data' => ['message' => $this->l->t('Please select a file.')]], Http::STATUS_OK, $headers);
|
||||||
|
}
|
||||||
if ($node->getSize() > 20*1024*1024) {
|
if ($node->getSize() > 20*1024*1024) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
['data' => ['message' => $this->l->t('File is too big')]],
|
['data' => ['message' => $this->l->t('File is too big')]],
|
||||||
|
|
|
@ -323,6 +323,23 @@ class AvatarControllerTest extends \Test\TestCase {
|
||||||
$this->assertEquals('notsquare', $response->getData()['data']);
|
$this->assertEquals('notsquare', $response->getData()['data']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test posting avatar from existing folder
|
||||||
|
*/
|
||||||
|
public function testPostAvatarFromNoFile() {
|
||||||
|
$file = $this->getMock('OCP\Files\Node');
|
||||||
|
$this->container['UserFolder']
|
||||||
|
->method('get')
|
||||||
|
->with('folder')
|
||||||
|
->willReturn($file);
|
||||||
|
|
||||||
|
//Create request return
|
||||||
|
$response = $this->avatarController->postAvatar('folder');
|
||||||
|
|
||||||
|
//On correct upload always respond with the notsquare message
|
||||||
|
$this->assertEquals(['data' => ['message' => 'Please select a file.']], $response->getData());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test what happens if the upload of the avatar fails
|
* Test what happens if the upload of the avatar fails
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue