Skip to content
Merged
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
31 changes: 0 additions & 31 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1417,37 +1417,6 @@ trigger:
- pull_request
- push

---
kind: pipeline
name: integration-sharing-v1-video-verification

steps:
- name: submodules
image: docker:git
commands:
- git submodule update --init
- name: install-talk
image: docker:git
commands:
# JavaScript files are not used in integration tests so it is not needed to
# build them.
- git clone --branch stable18 --depth 1 https://github.com/nextcloud/spreed apps/spreed
- name: integration-sharing-v1-video-verification
image: nextcloudci/integration-php7.3:integration-php7.3-2
commands:
- bash tests/drone-run-integration-tests.sh || exit 0
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
- cd build/integration
- ./run.sh sharing_features/sharing-v1-video-verification.feature

trigger:
branch:
- master
- stable*
event:
- pull_request
- push

---
kind: pipeline
name: integration-setup-features
Expand Down
10 changes: 4 additions & 6 deletions apps/sharebymail/lib/ShareByMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,12 @@ public function create(IShare $share) {

// if the admin enforces a password for all mail shares we create a
// random password and send it to the recipient
$password = $share->getPassword() ?: '';
$password = '';
$passwordEnforced = $this->settingsManager->enforcePasswordProtection();
if ($passwordEnforced && empty($password)) {
if ($passwordEnforced) {
$password = $this->autoGeneratePassword($share);
}

if (!empty($password)) {
$share->setPassword($this->hasher->hash($password));
}

$shareId = $this->createMailShare($share);
$send = $this->sendPassword($share, $password);
if ($passwordEnforced && $send === false) {
Expand Down Expand Up @@ -237,6 +233,8 @@ protected function autoGeneratePassword($share) {

$password = $this->secureRandom->generate($passwordLength, $passwordCharset);

$share->setPassword($this->hasher->hash($password));

return $password;
}

Expand Down
123 changes: 2 additions & 121 deletions apps/sharebymail/tests/ShareByMailProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,51 +242,6 @@ public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection()
);
}

public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtection() {
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');

$node = $this->getMockBuilder(File::class)->getMock();
$node->expects($this->any())->method('getName')->willReturn('filename');

$instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity']);

$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createShareActivity')->with($share);
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
$share->expects($this->any())->method('getNode')->willReturn($node);

$share->expects($this->once())->method('getPassword')->willReturn('password');
$this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed');
$share->expects($this->once())->method('setPassword')->with('passwordHashed');

// The given password (but not the autogenerated password) should be
// mailed to the receiver of the share.
$this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(false);
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$instance->expects($this->never())->method('autoGeneratePassword');

$message = $this->createMock(IMessage::class);
$message->expects($this->once())->method('setTo')->with(['[email protected]']);
$this->mailer->expects($this->once())->method('createMessage')->willReturn($message);
$this->mailer->expects($this->once())->method('createEMailTemplate')->with('sharebymail.RecipientPasswordNotification', [
'filename' => 'filename',
'password' => 'password',
'initiator' => 'owner',
'initiatorEmail' => null,
'shareWith' => '[email protected]',
]);
$this->mailer->expects($this->once())->method('send');

$this->assertSame('shareObject',
$instance->create($share)
);
}

public function testCreateSendPasswordByMailWithEnforcedPasswordProtection() {
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]');
Expand All @@ -305,70 +260,14 @@ public function testCreateSendPasswordByMailWithEnforcedPasswordProtection() {
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
$share->expects($this->any())->method('getNode')->willReturn($node);

$share->expects($this->once())->method('getPassword')->willReturn(null);
$this->hasher->expects($this->once())->method('hash')->with('autogeneratedPassword')->willReturn('autogeneratedPasswordHashed');
$share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed');

// The autogenerated password should be mailed to the receiver of the share.
$this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(true);
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword');
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('password');

$message = $this->createMock(IMessage::class);
$message->expects($this->once())->method('setTo')->with(['[email protected]']);
$this->mailer->expects($this->once())->method('createMessage')->willReturn($message);
$this->mailer->expects($this->once())->method('createEMailTemplate')->with('sharebymail.RecipientPasswordNotification', [
'filename' => 'filename',
'password' => 'autogeneratedPassword',
'initiator' => 'owner',
'initiatorEmail' => null,
'shareWith' => '[email protected]',
]);
$this->mailer->expects($this->once())->method('send');

$this->assertSame('shareObject',
$instance->create($share)
);
}

public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtection() {
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');

$node = $this->getMockBuilder(File::class)->getMock();
$node->expects($this->any())->method('getName')->willReturn('filename');

$instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity']);

$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createShareActivity')->with($share);
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
$share->expects($this->any())->method('getNode')->willReturn($node);

$share->expects($this->once())->method('getPassword')->willReturn('password');
$this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed');
$share->expects($this->once())->method('setPassword')->with('passwordHashed');

// The given password (but not the autogenerated password) should be
// mailed to the receiver of the share.
$this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(true);
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$instance->expects($this->never())->method('autoGeneratePassword');

$message = $this->createMock(IMessage::class);
$message->expects($this->once())->method('setTo')->with(['[email protected]']);
$this->mailer->expects($this->once())->method('createMessage')->willReturn($message);
$this->mailer->expects($this->once())->method('createEMailTemplate')->with('sharebymail.RecipientPasswordNotification', [
'filename' => 'filename',
'password' => 'password',
'initiator' => 'owner',
'initiatorEmail' => null,
'shareWith' => '[email protected]',
]);
$this->mailer->expects($this->once())->method('send');

$this->assertSame('shareObject',
Expand All @@ -394,25 +293,14 @@ public function testCreateSendPasswordByTalkWithEnforcedPasswordProtection() {
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
$share->expects($this->any())->method('getNode')->willReturn($node);

$share->expects($this->once())->method('getPassword')->willReturn(null);
$this->hasher->expects($this->once())->method('hash')->with('autogeneratedPassword')->willReturn('autogeneratedPasswordHashed');
$share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed');

// The autogenerated password should be mailed to the owner of the share.
$this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(true);
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword');
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('password');

$message = $this->createMock(IMessage::class);
$message->expects($this->once())->method('setTo')->with(['[email protected]' => 'Owner display name']);
$this->mailer->expects($this->once())->method('createMessage')->willReturn($message);
$this->mailer->expects($this->once())->method('createEMailTemplate')->with('sharebymail.OwnerPasswordNotification', [
'filename' => 'filename',
'password' => 'autogeneratedPassword',
'initiator' => 'Owner display name',
'initiatorEmail' => '[email protected]',
'shareWith' => '[email protected]',
]);
$this->mailer->expects($this->once())->method('send');

$user = $this->createMock(IUser::class);
Expand Down Expand Up @@ -645,13 +533,6 @@ public function testUpdateSendPassword($plainTextPassword, string $originalPassw
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn($newSendPasswordByTalk);

if ($sendMail) {
$this->mailer->expects($this->once())->method('createEMailTemplate')->with('sharebymail.RecipientPasswordNotification', [
'filename' => 'filename',
'password' => $plainTextPassword,
'initiator' => null,
'initiatorEmail' => null,
'shareWith' => '[email protected]',
]);
$this->mailer->expects($this->once())->method('send');
} else {
$this->mailer->expects($this->never())->method('send');
Expand Down
1 change: 0 additions & 1 deletion build/integration/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ default:
- admin
- admin
regular_user_password: 123456
- TalkContext
setup:
paths:
- "%paths.base%/../setup_features"
Expand Down
1 change: 0 additions & 1 deletion build/integration/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ trait BasicStructure {

use Auth;
use Download;
use Mail;
use Trashbin;

/** @var string */
Expand Down
Loading