Skip to content

Commit

Permalink
Merge pull request #291 from owncloud/max-allowed-chars-group-name
Browse files Browse the repository at this point in the history
Validation for max allowed number of chars in custom groups name
  • Loading branch information
HanaGemela authored Jan 28, 2020
2 parents 077d32b + 5a13150 commit 8d3947a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
4 changes: 2 additions & 2 deletions js/GroupsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

// status 422 in case of validation error
if (response.status === 422) {
OC.Notification.showTemporary(t('customgroups', 'The group name can not be empty or start with space. The group name should at least have 2 characters. Or kindly check if a group with this name already exists'));
OC.Notification.showTemporary(t('customgroups', 'The group name can not be empty or start with space. The group name should at least have 2 characters or maximum 64 characters. Or kindly check if a group with this name already exists'));
return;
} else {
OC.Notification.showTemporary(t('customgroups', 'Could not rename group'));
Expand Down Expand Up @@ -269,7 +269,7 @@
return;
}
if (response.status === 422) {
OC.Notification.showTemporary(t('customgroups', "The group name can not be empty or start with space. The group name should at least have 2 characters"));
OC.Notification.showTemporary(t('customgroups', "The group name can not be empty or start with space. The group name should at least have 2 characters or maximum 64 characters"));
}
if (response.status === 403) {
OC.Notification.showTemporary(t('customgroups', 'Could not create group'));
Expand Down
5 changes: 5 additions & 0 deletions lib/Dav/GroupMembershipCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ public function updateDisplayName($displayName) {
throw new ValidationException("The group name should be at least 2 characters long.");
}

/* Verify if the multibyte character length is more than 64 */
if (\mb_strlen($displayName, 'UTF-8') > 64) {
throw new ValidationException('The group name should be maximum 64 characters long.');
}

if ($displayName[0] === ' ') {
throw new ValidationException('The group name can not start with space');
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Dav/GroupsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public function createExtendedCollection($name, Mkcol $mkCol) {
throw new ValidationException('The group name should be at least 2 characters long.');
}

/** Group name must be max 64 characters long */
if (\mb_strlen($name, 'UTF-8') > 64) {
throw new ValidationException('The group name should be maximum 64 characters long.');
}

/**
* A special case where index is appended with the group name
*/
Expand Down
24 changes: 24 additions & 0 deletions tests/acceptance/features/apiCustomGroups/customGroups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,27 @@ Feature: Custom Groups
And user "user0" has created a custom group called "group0"
When user "user0" makes user "non-existing-user" a member of custom group "group0" using the API
Then the HTTP status code should be "412"

Scenario Outline: user tries to create a custom group with name having more than 64 characters or less than 2 characters
Given user "user0" has been created with default attributes and without skeleton files
When user "user0" creates a custom group called "<customGroup>" using the API
Then the HTTP status code should be "422"
And custom group "<customGroup>" should not exist
Examples:
| customGroup |
| thisIsAGroupNameWhoseLengthIsGreaterThanSixtyFourCharactersWhichIsInvalid |
| यो समूह को नाम मा धेरै शब्द हरु छन तेसैले यो समूह अवैध हुनेछ यो समूह |
| a |
| य |

Scenario Outline: user tries to create a custom group with some valid names
Given user "user0" has been created with default attributes and without skeleton files
When user "user0" creates a custom group called "<customGroup>" using the API
Then the HTTP status code should be "201"
And custom group "<customGroup>" should exist
Examples:
| customGroup |
| thisIsAGroup |
| समूह |
| ab |
| hello-&#$% |
2 changes: 1 addition & 1 deletion tests/js/GroupsViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe('GroupsView test', function() {
expect($groupEl.find('input').length).toEqual(0);

expect(notificationStub.calledOnce).toEqual(true);
expect(notificationStub.calledWith('The group name can not be empty or start with space. The group name should at least have 2 characters. Or kindly check if a group with this name already exists')).toEqual(true);
expect(notificationStub.calledWith('The group name can not be empty or start with space. The group name should at least have 2 characters or maximum 64 characters. Or kindly check if a group with this name already exists')).toEqual(true);

notificationStub.restore();
});
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/Dav/GroupMembershipCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,15 +717,16 @@ public function providesUpdateDisplayNameValidateException() {
['a'],
[' a'],
['á'],
[' áé']
[' áé'],
['12345678911234567892123456789312345678941234567895123456789612345']
];
}

/**
* @dataProvider providesUpdateDisplayNameValidateException
* @param string $groupName
*/
public function testUpdateDisplayNameValidatException($groupName) {
public function testUpdateDisplayNameValidateException($groupName) {
$this->expectException(\OCA\CustomGroups\Exception\ValidationException::class);

$this->node->updateDisplayName($groupName);
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Dav/GroupsCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ public function providesTestCreateException() {
[' abc', 'starts with space'],
['a', 'only one char'],
['á', 'one char multibyte'],
['.', 'single dot']
['.', 'single dot'],
['12345678911234567892123456789312345678941234567895123456789612345', 'name longer than 64 characters']
];
}

Expand Down

0 comments on commit 8d3947a

Please sign in to comment.