Remove duplicated query for email shares

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: npmbuildbot-nextcloud[bot] <npmbuildbot-nextcloud[bot]@users.noreply.github.com>
This commit is contained in:
Daniel Calviño Sánchez 2020-12-30 00:48:01 +01:00 committed by John Molakvoæ (skjnldsv)
parent 0f3f6a6c54
commit f99876997a
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
6 changed files with 100 additions and 102 deletions

View File

@ -556,7 +556,7 @@ class ShareAPIController extends OCSController {
} }
// Only share by mail have a recipient // Only share by mail have a recipient
if ($shareType === IShare::TYPE_EMAIL) { if (is_string($shareWith) && $shareType === IShare::TYPE_EMAIL) {
$share->setSharedWith($shareWith); $share->setSharedWith($shareWith);
} }
@ -1591,7 +1591,6 @@ class ShareAPIController extends OCSController {
IShare::TYPE_GROUP, IShare::TYPE_GROUP,
IShare::TYPE_LINK, IShare::TYPE_LINK,
IShare::TYPE_EMAIL, IShare::TYPE_EMAIL,
IShare::TYPE_EMAIL,
IShare::TYPE_CIRCLE, IShare::TYPE_CIRCLE,
IShare::TYPE_ROOM, IShare::TYPE_ROOM,
IShare::TYPE_DECK IShare::TYPE_DECK

View File

@ -27,7 +27,6 @@ declare(strict_types=1);
namespace OCA\ShareByMail; namespace OCA\ShareByMail;
use OCA\ShareByMail\Settings\SettingsManager;
use OCP\Capabilities\ICapability; use OCP\Capabilities\ICapability;
use OCP\Share\IManager; use OCP\Share\IManager;

View File

@ -740,25 +740,23 @@ class Manager implements IManager {
} }
try { try {
//Verify share type // Verify share type
if ($share->getShareType() === IShare::TYPE_USER) { if ($share->getShareType() === IShare::TYPE_USER) {
$this->userCreateChecks($share); $this->userCreateChecks($share);
//Verify the expiration date // Verify the expiration date
$share = $this->validateExpirationDateInternal($share); $share = $this->validateExpirationDateInternal($share);
} elseif ($share->getShareType() === IShare::TYPE_GROUP) { } elseif ($share->getShareType() === IShare::TYPE_GROUP) {
$this->groupCreateChecks($share); $this->groupCreateChecks($share);
//Verify the expiration date // Verify the expiration date
$share = $this->validateExpirationDateInternal($share); $share = $this->validateExpirationDateInternal($share);
} elseif ($share->getShareType() === IShare::TYPE_LINK } elseif ($share->getShareType() === IShare::TYPE_LINK
|| $share->getShareType() === IShare::TYPE_EMAIL) { || $share->getShareType() === IShare::TYPE_EMAIL) {
$this->linkCreateChecks($share); $this->linkCreateChecks($share);
$this->setLinkParent($share); $this->setLinkParent($share);
/* // For now ignore a set token.
* For now ignore a set token.
*/
$share->setToken( $share->setToken(
$this->secureRandom->generate( $this->secureRandom->generate(
\OC\Share\Constants::TOKEN_LENGTH, \OC\Share\Constants::TOKEN_LENGTH,
@ -767,7 +765,7 @@ class Manager implements IManager {
); );
// Verify the expiration date // Verify the expiration date
$share = $this->validateExpirationDateLink($share); $share = $this->validateExpirationDate($share);
// Verify the password // Verify the password
$this->verifyPassword($share->getPassword()); $this->verifyPassword($share->getPassword());
@ -799,7 +797,8 @@ class Manager implements IManager {
$oldShare = $share; $oldShare = $share;
$provider = $this->factory->getProviderForType($share->getShareType()); $provider = $this->factory->getProviderForType($share->getShareType());
$share = $provider->create($share); $share = $provider->create($share);
//reuse the node we already have
// Reuse the node we already have
$share->setNode($oldShare->getNode()); $share->setNode($oldShare->getNode());
// Reset the target if it is null for the new share // Reset the target if it is null for the new share
@ -987,38 +986,23 @@ class Manager implements IManager {
|| $share->getShareType() === IShare::TYPE_EMAIL) { || $share->getShareType() === IShare::TYPE_EMAIL) {
$this->linkCreateChecks($share); $this->linkCreateChecks($share);
// The new password is not set again if it is the same as the old one.
$plainTextPassword = $share->getPassword(); $plainTextPassword = $share->getPassword();
$this->updateSharePasswordIfNeeded($share, $originalShare); if (empty($plainTextPassword)) {
if (!$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) {
if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) { // If the same password was already sent by mail the recipient
throw new \InvalidArgumentException('Cant enable sending the password by Talk with an empty password'); // would already have access to the share without having to call
} // the sharer to verify her identity
throw new \InvalidArgumentException('Cant enable sending the password by Talk without setting a new password');
if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { }
//Verify the expiration date if ($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) {
$this->validateExpirationDateLink($share); throw new \InvalidArgumentException('Cant disable sending the password by Talk without setting a new password');
$expirationDateUpdated = true; }
}
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
// The new password is not set again if it is the same as the old
// one.
$plainTextPassword = $share->getPassword();
if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare)) {
$plainTextPassword = null;
} }
$this->updateSharePasswordIfNeeded($share, $originalShare); $this->updateSharePasswordIfNeeded($share, $originalShare);
if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) {
// If the same password was already sent by mail the recipient
// would already have access to the share without having to call
// the sharer to verify her identity
throw new \InvalidArgumentException('Cant enable sending the password by Talk without setting a new password');
} elseif (empty($plainTextPassword) && $originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) {
throw new \InvalidArgumentException('Cant disable sending the password by Talk without setting a new password');
}
if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
// Verify the expiration date // Verify the expiration date
$this->validateExpirationDate($share); $this->validateExpirationDate($share);

View File

@ -40,7 +40,7 @@ use OCP\IUserManager;
use OCP\Share\Exceptions\IllegalIDChangeException; use OCP\Share\Exceptions\IllegalIDChangeException;
use OCP\Share\IShare; use OCP\Share\IShare;
class Share implements \OCP\Share\IShare { class Share implements IShare {
/** @var string */ /** @var string */
private $id; private $id;

View File

@ -433,7 +433,7 @@ interface IShare {
* When the share is passed to the share manager to be created * When the share is passed to the share manager to be created
* or updated the password will be hashed. * or updated the password will be hashed.
* *
* @param string $password * @param string|null $password
* @return \OCP\Share\IShare The modified object * @return \OCP\Share\IShare The modified object
* @since 9.0.0 * @since 9.0.0
*/ */

View File

@ -50,7 +50,6 @@ use OCP\Mail\IMailer;
use OCP\Security\Events\ValidatePasswordPolicyEvent; use OCP\Security\Events\ValidatePasswordPolicyEvent;
use OCP\Security\IHasher; use OCP\Security\IHasher;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use OCP\Share\Exceptions\AlreadySharedException;
use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IProviderFactory; use OCP\Share\IProviderFactory;
use OCP\Share\IShare; use OCP\Share\IShare;
@ -1068,7 +1067,7 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setExpirationDate($past); $share->setExpirationDate($past);
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
} }
public function testValidateExpirationDateEnforceButNotSet() { public function testValidateExpirationDateEnforceButNotSet() {
@ -1084,7 +1083,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'shareapi_enforce_expire_date', 'no', 'yes'], ['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
]); ]);
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
} }
public function testValidateExpirationDateEnforceButNotEnabledAndNotSet() { public function testValidateExpirationDateEnforceButNotEnabledAndNotSet() {
@ -1096,7 +1095,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'shareapi_enforce_expire_date', 'no', 'yes'], ['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
]); ]);
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertNull($share->getExpirationDate()); $this->assertNull($share->getExpirationDate());
} }
@ -1116,7 +1115,7 @@ class ManagerTest extends \Test\TestCase {
$expected->setTime(0,0,0); $expected->setTime(0,0,0);
$expected->add(new \DateInterval('P3D')); $expected->add(new \DateInterval('P3D'));
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertNotNull($share->getExpirationDate()); $this->assertNotNull($share->getExpirationDate());
$this->assertEquals($expected, $share->getExpirationDate()); $this->assertEquals($expected, $share->getExpirationDate());
@ -1137,7 +1136,7 @@ class ManagerTest extends \Test\TestCase {
$expected->setTime(0,0,0); $expected->setTime(0,0,0);
$expected->add(new \DateInterval('P1D')); $expected->add(new \DateInterval('P1D'));
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertNotNull($share->getExpirationDate()); $this->assertNotNull($share->getExpirationDate());
$this->assertEquals($expected, $share->getExpirationDate()); $this->assertEquals($expected, $share->getExpirationDate());
@ -1160,7 +1159,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'shareapi_default_expire_date', 'no', 'yes'], ['core', 'shareapi_default_expire_date', 'no', 'yes'],
]); ]);
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
} }
public function testValidateExpirationDateEnforceValid() { public function testValidateExpirationDateEnforceValid() {
@ -1187,7 +1186,7 @@ class ManagerTest extends \Test\TestCase {
return $data['expirationDate'] == $future; return $data['expirationDate'] == $future;
})); }));
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertEquals($expected, $share->getExpirationDate()); $this->assertEquals($expected, $share->getExpirationDate());
} }
@ -1209,7 +1208,7 @@ class ManagerTest extends \Test\TestCase {
return $data['expirationDate'] == $expected && $data['passwordSet'] === false; return $data['expirationDate'] == $expected && $data['passwordSet'] === false;
})); }));
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertEquals($expected, $share->getExpirationDate()); $this->assertEquals($expected, $share->getExpirationDate());
} }
@ -1224,7 +1223,7 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setPassword('password'); $share->setPassword('password');
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertNull($share->getExpirationDate()); $this->assertNull($share->getExpirationDate());
} }
@ -1249,7 +1248,7 @@ class ManagerTest extends \Test\TestCase {
return $data['expirationDate'] == $expected; return $data['expirationDate'] == $expected;
})); }));
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertEquals($expected, $share->getExpirationDate()); $this->assertEquals($expected, $share->getExpirationDate());
} }
@ -1278,7 +1277,7 @@ class ManagerTest extends \Test\TestCase {
return $data['expirationDate'] == $expected; return $data['expirationDate'] == $expected;
})); }));
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertEquals($expected, $share->getExpirationDate()); $this->assertEquals($expected, $share->getExpirationDate());
} }
@ -1299,7 +1298,7 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setExpirationDate($nextWeek); $share->setExpirationDate($nextWeek);
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$save->sub(new \DateInterval('P2D')); $save->sub(new \DateInterval('P2D'));
$this->assertEquals($save, $share->getExpirationDate()); $this->assertEquals($save, $share->getExpirationDate());
@ -1323,7 +1322,7 @@ class ManagerTest extends \Test\TestCase {
$data['message'] = 'Invalid date!'; $data['message'] = 'Invalid date!';
}); });
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
} }
public function testValidateExpirationDateExistingShareNoDefault() { public function testValidateExpirationDateExistingShareNoDefault() {
@ -1337,7 +1336,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'shareapi_expire_after_n_days', '7', '6'], ['core', 'shareapi_expire_after_n_days', '7', '6'],
]); ]);
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertEquals(null, $share->getExpirationDate()); $this->assertEquals(null, $share->getExpirationDate());
} }
@ -2049,7 +2048,7 @@ class ManagerTest extends \Test\TestCase {
'generalCreateChecks', 'generalCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'pathCreateChecks', 'pathCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
'verifyPassword', 'verifyPassword',
'setLinkParent', 'setLinkParent',
]) ])
@ -2091,7 +2090,7 @@ class ManagerTest extends \Test\TestCase {
->method('pathCreateChecks') ->method('pathCreateChecks')
->with($path); ->with($path);
$manager->expects($this->once()) $manager->expects($this->once())
->method('validateExpirationDateLink') ->method('validateExpirationDate')
->with($share) ->with($share)
->willReturn($share); ->willReturn($share);
$manager->expects($this->once()) $manager->expects($this->once())
@ -2174,7 +2173,7 @@ class ManagerTest extends \Test\TestCase {
'generalCreateChecks', 'generalCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'pathCreateChecks', 'pathCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
'verifyPassword', 'verifyPassword',
'setLinkParent', 'setLinkParent',
]) ])
@ -2203,17 +2202,19 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once()) $manager->expects($this->once())
->method('generalCreateChecks') ->method('generalCreateChecks')
->with($share); ->with($share);
;
$manager->expects($this->never()) $manager->expects($this->once())
->method('linkCreateChecks'); ->method('linkCreateChecks');
$manager->expects($this->once()) $manager->expects($this->once())
->method('pathCreateChecks') ->method('pathCreateChecks')
->with($path); ->with($path);
$manager->expects($this->never()) $manager->expects($this->once())
->method('validateExpirationDateLink'); ->method('validateExpirationDate')
$manager->expects($this->never()) ->with($share)
->willReturn($share);
$manager->expects($this->once())
->method('verifyPassword'); ->method('verifyPassword');
$manager->expects($this->never()) $manager->expects($this->once())
->method('setLinkParent'); ->method('setLinkParent');
$this->secureRandom->method('generate') $this->secureRandom->method('generate')
@ -3024,7 +3025,7 @@ class ManagerTest extends \Test\TestCase {
'linkCreateChecks', 'linkCreateChecks',
'pathCreateChecks', 'pathCreateChecks',
'verifyPassword', 'verifyPassword',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3053,7 +3054,7 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
$manager->expects($this->once())->method('validateExpirationDateLink')->with($share); $manager->expects($this->once())->method('validateExpirationDate')->with($share);
$manager->expects($this->once())->method('verifyPassword')->with('password'); $manager->expects($this->once())->method('verifyPassword')->with('password');
$this->hasher->expects($this->once()) $this->hasher->expects($this->once())
@ -3095,7 +3096,7 @@ class ManagerTest extends \Test\TestCase {
public function testUpdateShareLinkEnableSendPasswordByTalkWithNoPassword() { public function testUpdateShareLinkEnableSendPasswordByTalkWithNoPassword() {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cant enable sending the password by Talk with an empty password'); $this->expectExceptionMessage('Cant enable sending the password by Talk without setting a new password');
$manager = $this->createManagerMock() $manager = $this->createManagerMock()
->setMethods([ ->setMethods([
@ -3105,7 +3106,7 @@ class ManagerTest extends \Test\TestCase {
'linkCreateChecks', 'linkCreateChecks',
'pathCreateChecks', 'pathCreateChecks',
'verifyPassword', 'verifyPassword',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3139,7 +3140,7 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('linkCreateChecks')->with($share); $manager->expects($this->once())->method('linkCreateChecks')->with($share);
$manager->expects($this->never())->method('verifyPassword'); $manager->expects($this->never())->method('verifyPassword');
$manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->never())->method('pathCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->never())->method('validateExpirationDate');
$this->hasher->expects($this->never()) $this->hasher->expects($this->never())
->method('hash'); ->method('hash');
@ -3171,7 +3172,7 @@ class ManagerTest extends \Test\TestCase {
'verifyPassword', 'verifyPassword',
'pathCreateChecks', 'pathCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3203,8 +3204,8 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('generalCreateChecks')->with($share); $manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->once())->method('verifyPassword')->with('password'); $manager->expects($this->once())->method('verifyPassword')->with('password');
$manager->expects($this->once())->method('pathCreateChecks')->with($file); $manager->expects($this->once())->method('pathCreateChecks')->with($file);
$manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->once())->method('linkCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->once())->method('validateExpirationDate');
$this->hasher->expects($this->once()) $this->hasher->expects($this->once())
->method('hash') ->method('hash')
@ -3218,7 +3219,12 @@ class ManagerTest extends \Test\TestCase {
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post'); $hookListener->expects($this->once())->method('post')->with([
'itemType' => 'file',
'itemSource' => 100,
'date' => $tomorrow,
'uidOwner' => 'owner',
]);
$hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
@ -3246,7 +3252,7 @@ class ManagerTest extends \Test\TestCase {
'verifyPassword', 'verifyPassword',
'pathCreateChecks', 'pathCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3281,8 +3287,8 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('generalCreateChecks')->with($share); $manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->once())->method('verifyPassword')->with('password'); $manager->expects($this->once())->method('verifyPassword')->with('password');
$manager->expects($this->once())->method('pathCreateChecks')->with($file); $manager->expects($this->once())->method('pathCreateChecks')->with($file);
$manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->once())->method('linkCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->once())->method('validateExpirationDate');
$this->hasher->expects($this->once()) $this->hasher->expects($this->once())
->method('hash') ->method('hash')
@ -3296,7 +3302,12 @@ class ManagerTest extends \Test\TestCase {
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post'); $hookListener->expects($this->once())->method('post')->with([
'itemType' => 'file',
'itemSource' => 100,
'date' => $tomorrow,
'uidOwner' => 'owner',
]);
$hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
@ -3324,7 +3335,7 @@ class ManagerTest extends \Test\TestCase {
'verifyPassword', 'verifyPassword',
'pathCreateChecks', 'pathCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3359,8 +3370,8 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('generalCreateChecks')->with($share); $manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->once())->method('verifyPassword')->with('password'); $manager->expects($this->once())->method('verifyPassword')->with('password');
$manager->expects($this->once())->method('pathCreateChecks')->with($file); $manager->expects($this->once())->method('pathCreateChecks')->with($file);
$manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->once())->method('linkCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->once())->method('validateExpirationDate');
$this->hasher->expects($this->once()) $this->hasher->expects($this->once())
->method('verify') ->method('verify')
@ -3379,7 +3390,12 @@ class ManagerTest extends \Test\TestCase {
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post'); $hookListener->expects($this->once())->method('post')->with([
'itemType' => 'file',
'itemSource' => 100,
'date' => $tomorrow,
'uidOwner' => 'owner',
]);
$hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
@ -3410,7 +3426,7 @@ class ManagerTest extends \Test\TestCase {
'verifyPassword', 'verifyPassword',
'pathCreateChecks', 'pathCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3445,8 +3461,8 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('generalCreateChecks')->with($share); $manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->never())->method('verifyPassword'); $manager->expects($this->never())->method('verifyPassword');
$manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->never())->method('pathCreateChecks');
$manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->once())->method('linkCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->never())->method('validateExpirationDate');
$this->hasher->expects($this->never()) $this->hasher->expects($this->never())
->method('hash'); ->method('hash');
@ -3482,7 +3498,7 @@ class ManagerTest extends \Test\TestCase {
'verifyPassword', 'verifyPassword',
'pathCreateChecks', 'pathCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3517,8 +3533,8 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('generalCreateChecks')->with($share); $manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->never())->method('verifyPassword'); $manager->expects($this->never())->method('verifyPassword');
$manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->never())->method('pathCreateChecks');
$manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->once())->method('linkCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->never())->method('validateExpirationDate');
$this->hasher->expects($this->never()) $this->hasher->expects($this->never())
->method('hash'); ->method('hash');
@ -3554,7 +3570,7 @@ class ManagerTest extends \Test\TestCase {
'verifyPassword', 'verifyPassword',
'pathCreateChecks', 'pathCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3589,8 +3605,8 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('generalCreateChecks')->with($share); $manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->never())->method('verifyPassword'); $manager->expects($this->never())->method('verifyPassword');
$manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->never())->method('pathCreateChecks');
$manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->once())->method('linkCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->never())->method('validateExpirationDate');
$this->hasher->expects($this->never()) $this->hasher->expects($this->never())
->method('hash'); ->method('hash');
@ -3626,7 +3642,7 @@ class ManagerTest extends \Test\TestCase {
'verifyPassword', 'verifyPassword',
'pathCreateChecks', 'pathCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3661,8 +3677,8 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('generalCreateChecks')->with($share); $manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->never())->method('verifyPassword'); $manager->expects($this->never())->method('verifyPassword');
$manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->never())->method('pathCreateChecks');
$manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->once())->method('linkCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->never())->method('validateExpirationDate');
$this->hasher->expects($this->once()) $this->hasher->expects($this->once())
->method('verify') ->method('verify')
@ -3702,7 +3718,7 @@ class ManagerTest extends \Test\TestCase {
'verifyPassword', 'verifyPassword',
'pathCreateChecks', 'pathCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3735,10 +3751,10 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
$manager->expects($this->once())->method('generalCreateChecks')->with($share); $manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->never())->method('verifyPassword'); $manager->expects($this->once())->method('verifyPassword');
$manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->once())->method('pathCreateChecks');
$manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->once())->method('linkCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->once())->method('validateExpirationDate');
$this->hasher->expects($this->once()) $this->hasher->expects($this->once())
->method('verify') ->method('verify')
@ -3778,7 +3794,7 @@ class ManagerTest extends \Test\TestCase {
'verifyPassword', 'verifyPassword',
'pathCreateChecks', 'pathCreateChecks',
'linkCreateChecks', 'linkCreateChecks',
'validateExpirationDateLink', 'validateExpirationDate',
]) ])
->getMock(); ->getMock();
@ -3811,10 +3827,10 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
$manager->expects($this->once())->method('generalCreateChecks')->with($share); $manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->never())->method('verifyPassword'); $manager->expects($this->once())->method('verifyPassword');
$manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->once())->method('pathCreateChecks');
$manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->once())->method('linkCreateChecks');
$manager->expects($this->never())->method('validateExpirationDateLink'); $manager->expects($this->once())->method('validateExpirationDate');
$this->hasher->expects($this->never()) $this->hasher->expects($this->never())
->method('verify'); ->method('verify');