|
@@ -39,6 +39,7 @@ use OCP\Defaults;
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
|
|
use OCP\Files\File;
|
|
|
use OCP\Files\IRootFolder;
|
|
|
+use OCP\IConfig;
|
|
|
use OCP\IDBConnection;
|
|
|
use OCP\IL10N;
|
|
|
use OCP\ILogger;
|
|
@@ -63,6 +64,9 @@ use Test\TestCase;
|
|
|
*/
|
|
|
class ShareByMailProviderTest extends TestCase {
|
|
|
|
|
|
+ /** @var IConfig */
|
|
|
+ private $config;
|
|
|
+
|
|
|
/** @var IDBConnection */
|
|
|
private $connection;
|
|
|
|
|
@@ -111,6 +115,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
protected function setUp(): void {
|
|
|
parent::setUp();
|
|
|
|
|
|
+ $this->config = $this->getMockBuilder(IConfig::class)->getMock();
|
|
|
$this->connection = \OC::$server->getDatabaseConnection();
|
|
|
|
|
|
$this->l = $this->getMockBuilder(IL10N::class)->getMock();
|
|
@@ -145,6 +150,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
$instance = $this->getMockBuilder('OCA\ShareByMail\ShareByMailProvider')
|
|
|
->setConstructorArgs(
|
|
|
[
|
|
|
+ $this->config,
|
|
|
$this->connection,
|
|
|
$this->secureRandom,
|
|
|
$this->userManager,
|
|
@@ -168,6 +174,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
}
|
|
|
|
|
|
return new ShareByMailProvider(
|
|
|
+ $this->config,
|
|
|
$this->connection,
|
|
|
$this->secureRandom,
|
|
|
$this->userManager,
|
|
@@ -267,9 +274,43 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
$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 not be
|
|
|
+ // mailed to the receiver of the share because permanent passwords are not enforced.
|
|
|
+ $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false);
|
|
|
+ $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(false);
|
|
|
+ $instance->expects($this->never())->method('autoGeneratePassword');
|
|
|
+
|
|
|
+ $this->assertSame('shareObject',
|
|
|
+ $instance->create($share)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithPermanentPassword() {
|
|
|
+ $share = $this->getMockBuilder(IShare::class)->getMock();
|
|
|
+ $share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
|
|
+ $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.
|
|
|
+ // mailed to the receiver of the share because permanent passwords are enforced.
|
|
|
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false);
|
|
|
+ $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(true);
|
|
|
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
|
|
|
$instance->expects($this->never())->method('autoGeneratePassword');
|
|
|
|
|
@@ -290,7 +331,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public function testCreateSendPasswordByMailWithEnforcedPasswordProtection() {
|
|
|
+ public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword() {
|
|
|
$share = $this->getMockBuilder(IShare::class)->getMock();
|
|
|
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
|
|
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
|
@@ -320,8 +361,9 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
$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.
|
|
|
+ // The autogenerated password should be mailed to the receiver of the share because permanent passwords are enforced.
|
|
|
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true);
|
|
|
+ $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(true);
|
|
|
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
|
|
|
|
|
|
$message = $this->createMock(IMessage::class);
|
|
@@ -341,7 +383,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtection() {
|
|
|
+ public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtectionWithPermanentPassword() {
|
|
|
$share = $this->getMockBuilder(IShare::class)->getMock();
|
|
|
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
|
|
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
|
@@ -366,6 +408,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
// The given password (but not the autogenerated password) should be
|
|
|
// mailed to the receiver of the share.
|
|
|
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true);
|
|
|
+ $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(true);
|
|
|
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
|
|
|
$instance->expects($this->never())->method('autoGeneratePassword');
|
|
|
|
|
@@ -410,6 +453,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
|
|
|
// The autogenerated password should be mailed to the owner of the share.
|
|
|
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true);
|
|
|
+ $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(false);
|
|
|
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
|
|
|
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword');
|
|
|
|
|
@@ -531,6 +575,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
$hideDownload = true;
|
|
|
$label = 'label';
|
|
|
$expiration = new \DateTime();
|
|
|
+ $passwordExpirationTime = new \DateTime();
|
|
|
|
|
|
|
|
|
$instance = $this->getInstance();
|
|
@@ -546,6 +591,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
$permissions,
|
|
|
$token,
|
|
|
$password,
|
|
|
+ $passwordExpirationTime,
|
|
|
$sendPasswordByTalk,
|
|
|
$hideDownload,
|
|
|
$label,
|
|
@@ -572,6 +618,7 @@ class ShareByMailProviderTest extends TestCase {
|
|
|
$this->assertSame($permissions, (int)$result[0]['permissions']);
|
|
|
$this->assertSame($token, $result[0]['token']);
|
|
|
$this->assertSame($password, $result[0]['password']);
|
|
|
+ $this->assertSame($passwordExpirationTime->getTimestamp(), \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]['password_expiration_time'])->getTimestamp());
|
|
|
$this->assertSame($sendPasswordByTalk, (bool)$result[0]['password_by_talk']);
|
|
|
$this->assertSame($hideDownload, (bool)$result[0]['hide_download']);
|
|
|
$this->assertSame($label, $result[0]['label']);
|