Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to allow sharing with UID that is an integer #37327

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions changelog/unreleased/37324
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Cannot share with user name that has only numbers in the UI

A regression in 10.4.0 meant that new shares with user names that were numbers
could not be created in the UI. This regression has been fixed.

https://github.com/owncloud/core/issues/37324
https://github.com/owncloud/core/pull/37327
3 changes: 3 additions & 0 deletions lib/private/Share20/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ public function getShareType() {
* @inheritdoc
*/
public function setSharedWith($sharedWith) {
if (\is_int($sharedWith)) {
$sharedWith = (string) $sharedWith;
}
if (!\is_string($sharedWith)) {
throw new \InvalidArgumentException();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Share/IShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function getShareType();
/**
* Set the receiver of this share.
*
* @param string $sharedWith
* @param string|int $sharedWith
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,25 @@ Feature: Sharing files and folders with internal users
And file "lorem.txt" should not be listed in shared-with-others page on the webUI
And as "user2" file "lorem (2).txt" should not exist

Scenario: user shares a file with another user with uppercase username
Scenario Outline: user shares a file with another user with unusual usernames
Given user "user1" has been created with default attributes and skeleton files
And these users have been created without skeleton files:
| username |
| SomeUser |
| username |
| <username> |
And user "user1" has logged in using the webUI
When the user shares file "lorem.txt" with user "SomeUser" using the webUI
And the user re-logs in as "SomeUser" using the webUI
When the user shares file "lorem.txt" with user "<username>" using the webUI
And the user re-logs in as "<username>" using the webUI
And the user browses to the shared-with-you page
Then file "lorem.txt" should be listed on the webUI
Examples:
| username |
| 123456 |
| -12 |
| +12 |
| 1.2 |
| 1.2E3 |
| 0x10 |
| Some-User |

Scenario: multiple users share a file with the same name to a user
Given these users have been created with default attributes and without skeleton files:
Expand Down
33 changes: 33 additions & 0 deletions tests/lib/Share20/ShareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,39 @@ public function setUp(): void {
$this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
}

public function setSharedWithInvalidProvider() {
return [
[1.2],
[true],
[[]],
];
}

/**
* @dataProvider setSharedWithInvalidProvider
*/
public function testSetSharedWithInvalid($sharedWith) {
$this->expectException(\InvalidArgumentException::class);
$this->share->setSharedWith($sharedWith);
}

public function setSharedWithProvider() {
return [
[123, '123'],
[-12, '-12'],
['+12', '+12'],
['user.name@example.com', 'user.name@example.com'],
];
}

/**
* @dataProvider setSharedWithProvider
*/
public function testSetSharedWith($sharedWith, $expectedValue) {
$this->share->setSharedWith($sharedWith);
$this->assertSame($expectedValue, $this->share->getSharedWith());
}

/**
*/
public function testSetIdInvalid() {
Expand Down