From a6b7e098b77cdf2cbc946c69ec0faf40a24a4ab5 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Fri, 1 May 2020 19:48:40 +0545 Subject: [PATCH 1/2] Fix to allow sharing with UID that is an integer --- changelog/unreleased/37324 | 7 +++++++ lib/private/Share20/Share.php | 3 +++ lib/public/Share/IShare.php | 2 +- tests/lib/Share20/ShareTest.php | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/37324 diff --git a/changelog/unreleased/37324 b/changelog/unreleased/37324 new file mode 100644 index 000000000000..56fe2616d89b --- /dev/null +++ b/changelog/unreleased/37324 @@ -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 diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php index 5ddec05509c3..0d139b8a66e8 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -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(); } diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php index 8830782879f5..46cc9af2b5e6 100644 --- a/lib/public/Share/IShare.php +++ b/lib/public/Share/IShare.php @@ -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 */ diff --git a/tests/lib/Share20/ShareTest.php b/tests/lib/Share20/ShareTest.php index c1524aefc7a5..0f8e52be5935 100644 --- a/tests/lib/Share20/ShareTest.php +++ b/tests/lib/Share20/ShareTest.php @@ -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() { From eac86e95f88eb4c5eb65a49a7fdf7cc771b3374f Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Sat, 2 May 2020 12:19:46 +0545 Subject: [PATCH 2/2] Add acceptance tests for sharing with unusual usernames --- .../createShareWithUsers.feature | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/acceptance/features/webUISharingInternalUsers1/createShareWithUsers.feature b/tests/acceptance/features/webUISharingInternalUsers1/createShareWithUsers.feature index 87125576a451..d1908fab09fa 100644 --- a/tests/acceptance/features/webUISharingInternalUsers1/createShareWithUsers.feature +++ b/tests/acceptance/features/webUISharingInternalUsers1/createShareWithUsers.feature @@ -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 | + | | 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 "" using the webUI + And the user re-logs in as "" 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: