X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/dav/lib/SystemTag/SystemTagPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
* @throws Conflict if a tag with the same properties already exists
* @throws UnsupportedMediaType if the content type is not supported
*/
private function createTag($data, $contentType = 'application/json') {
private function createTag($data, $contentType = 'application/json'): ISystemTag {
if (\explode(';', $contentType)[0] === 'application/json') {
$data = \json_decode($data, true);
} else {
Expand All @@ -171,6 +171,9 @@ private function createTag($data, $contentType = 'application/json') {
if (!isset($data['name'])) {
throw new BadRequest('Missing "name" attribute');
}
if (\strlen($data['name']) > 64) {
throw new BadRequest('Tag name too long');
}

$tagName = $data['name'];
$userVisible = true;
Expand Down
54 changes: 53 additions & 1 deletion apps/dav/tests/unit/SystemTag/SystemTagPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
use OCP\IUserSession;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\TagAlreadyExistsException;
use Sabre\DAV\Exception\BadRequest;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use OCA\DAV\SystemTag\SystemTagsByIdCollection;

class SystemTagPluginTest extends \Test\TestCase {
public const ID_PROPERTYNAME = \OCA\DAV\SystemTag\SystemTagPlugin::ID_PROPERTYNAME;
Expand Down Expand Up @@ -383,7 +387,7 @@ public function createTagInsufficientPermissionsProvider() {
* @dataProvider createTagInsufficientPermissionsProvider
*/
public function testCreateNotAssignableTagAsRegularUser($userVisible, $userAssignable, $userEditable, $groups) {
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
$this->expectException(BadRequest::class);
$this->expectExceptionMessage('Not sufficient permissions');

$this->user->expects($this->once())
Expand Down Expand Up @@ -442,6 +446,54 @@ public function testCreateNotAssignableTagAsRegularUser($userVisible, $userAssig
$this->plugin->httpPost($request, $response);
}

public function testPostTooLongTagName(): void {
$this->expectException(BadRequest::class);
$this->expectExceptionMessage('Tag name too long');

$requestData = [
'name' => 'ThisTagNameIsByFarTooLong.ThisTagNameIsByFarTooLong.ThisTagNameIsByFarTooLong',
'userVisible' => true,
'userAssignable' => true,
'userEditable' => true
];
$requestData = \json_encode($requestData);

$node = $this->getMockBuilder(SystemTagsByIdCollection::class)
->disableOriginalConstructor()
->getMock();
$this->tagManager->expects($this->never())
->method('createTag');
$this->tagManager->expects($this->never())
->method('setTagGroups');

$this->tree
->method('getNodeForPath')
->with('/systemtags')
->willReturn($node);

$request = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
$response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();

$request->expects($this->once())
->method('getPath')
->willReturn('/systemtags');

$request->expects($this->once())
->method('getBodyAsString')
->willReturn($requestData);

$request->expects($this->once())
->method('getHeader')
->with('Content-Type')
->willReturn('application/json');

$this->plugin->httpPost($request, $response);
}

public function testCreateTagInByIdCollectionAsRegularUser() {
$systemTag = new SystemTag(1, 'Test', true, false);

Expand Down
2 changes: 1 addition & 1 deletion changelog/unreleased/40726
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Change: fix name length check on federated shares

A federated share with a too long name results in inaccessible data.
A federated share with a too long name results in potentially inaccessible data.

https://github.com/owncloud/core/pull/40726
5 changes: 5 additions & 0 deletions changelog/unreleased/40804
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: fix name length check on system tag creation

A system tag with a too long name results in potentially inaccessible data.

https://github.com/owncloud/core/pull/40804
X Tutup