Skip to content

Commit 04b682a

Browse files
committed
fix(Share20): Only set random token if no token is set
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 58c97a3 commit 04b682a

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

apps/sharebymail/lib/ShareByMailProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ protected function publishActivity(string $subject, array $parameters, string $a
224224
* @throws \Exception
225225
*/
226226
protected function createMailShare(IShare $share): string {
227-
$share->setToken($this->generateToken());
227+
if ($share->getToken() === '') {
228+
$share->setToken($this->generateToken());
229+
}
228230
return $this->addShareToDB(
229231
$share->getNodeId(),
230232
$share->getNodeType(),

apps/sharebymail/tests/ShareByMailProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ public function testCreateFailed(): void {
670670
}
671671

672672
public function testCreateMailShare(): void {
673-
$this->share->expects($this->any())->method('getToken')->willReturn('token');
673+
$this->share->expects($this->any())->method('getToken')->willReturn('');
674674
$this->share->expects($this->once())->method('setToken')->with('token');
675675
$this->share->expects($this->any())->method('getSharedBy')->willReturn('validby@valid.com');
676676
$this->share->expects($this->any())->method('getSharedWith')->willReturn('validwith@valid.com');

lib/private/Share20/Manager.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,11 @@ public function createShare(IShare $share): IShare {
567567
|| $share->getShareType() === IShare::TYPE_EMAIL) {
568568
$this->setLinkParent($share);
569569

570-
$token = $this->generateToken();
571-
// Set the unique token
572-
$share->setToken($token);
570+
if ($share->getToken() === '') {
571+
$token = $this->generateToken();
572+
// Set the unique token
573+
$share->setToken($token);
574+
}
573575

574576
// Verify the expiration date
575577
$share = $this->validateExpirationDateLink($share);

lib/private/Share20/Share.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Share implements IShare {
6060
/** @var bool */
6161
private $sendPasswordByTalk = false;
6262
/** @var string */
63-
private $token;
63+
private $token = '';
6464
private ?int $parent = null;
6565
/** @var string */
6666
private $target;

0 commit comments

Comments
 (0)