aboutsummaryrefslogtreecommitdiffstats
path: root/apps/sharebymail/tests
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2017-04-10 18:36:23 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2017-04-20 16:33:26 +0200
commitd8dcd72118f7f5f83874e3a54a7fbc02bda10ce6 (patch)
tree7da5dbe03601c1c52398b4a32460e5aad0dadf11 /apps/sharebymail/tests
parent140580f9d8468b8450f31dca997916a07693277f (diff)
downloadnextcloud-server-d8dcd72118f7f5f83874e3a54a7fbc02bda10ce6.tar.gz
nextcloud-server-d8dcd72118f7f5f83874e3a54a7fbc02bda10ce6.zip
allow admin to enforce password on mail shares
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/sharebymail/tests')
-rw-r--r--apps/sharebymail/tests/SettingsTest.php34
-rw-r--r--apps/sharebymail/tests/ShareByMailProviderTest.php28
2 files changed, 56 insertions, 6 deletions
diff --git a/apps/sharebymail/tests/SettingsTest.php b/apps/sharebymail/tests/SettingsTest.php
index f415421b0cf..8b2fc200d57 100644
--- a/apps/sharebymail/tests/SettingsTest.php
+++ b/apps/sharebymail/tests/SettingsTest.php
@@ -24,6 +24,7 @@ namespace OCA\ShareByMail\Tests;
use OCA\ShareByMail\Settings;
+use OCA\ShareByMail\Settings\SettingsManager;
use Test\TestCase;
class SettingsTest extends TestCase {
@@ -31,10 +32,15 @@ class SettingsTest extends TestCase {
/** @var Settings */
private $instance;
+ /** @var SettingsManager | \PHPUnit_Framework_MockObject_MockObject */
+ private $settingsManager;
+
public function setUp() {
parent::setUp();
- $this->instance = new Settings();
+ $this->settingsManager = $this->getMockBuilder(SettingsManager::class)
+ ->disableOriginalConstructor()->getMock();
+ $this->instance = new Settings($this->settingsManager);
}
public function testAnnounceShareProvider() {
@@ -61,4 +67,30 @@ class SettingsTest extends TestCase {
$this->assertSame($after, $before);
}
+
+ public function testAnnounceShareByMailSettings() {
+ $this->settingsManager->expects($this->once())->method('enforcePasswordProtection')->willReturn(true);
+ $before = [
+ 'oc_appconfig' =>
+ json_encode([
+ 'key1' => 'value1',
+ 'key2' => 'value2'
+ ]),
+ 'oc_foo' => 'oc_bar'
+ ];
+
+ $after = [
+ 'oc_appconfig' =>
+ json_encode([
+ 'key1' => 'value1',
+ 'key2' => 'value2',
+ 'shareByMail' => ['enforcePasswordProtection' => true]
+ ]),
+ 'oc_foo' => 'oc_bar'
+ ];
+
+ $this->instance->announceShareByMailSettings(['array' => &$before]);
+ $this->assertSame($after, $before);
+ }
+
}
diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php
index 581ca9b1b95..4061ef4eb50 100644
--- a/apps/sharebymail/tests/ShareByMailProviderTest.php
+++ b/apps/sharebymail/tests/ShareByMailProviderTest.php
@@ -27,6 +27,7 @@ use OC\Mail\Message;
use OCA\ShareByMail\Settings\SettingsManager;
use OCA\ShareByMail\ShareByMailProvider;
use OCP\Defaults;
+use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IL10N;
@@ -36,6 +37,7 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
+use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use OCP\Share\IManager;
use OCP\Share\IShare;
@@ -88,6 +90,9 @@ class ShareByMailProviderTest extends TestCase {
/** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */
private $defaults;
+ /** @var IHasher | \PHPUnit_Framework_MockObject_MockObject */
+ private $hasher;
+
public function setUp() {
parent::setUp();
@@ -109,6 +114,7 @@ class ShareByMailProviderTest extends TestCase {
$this->activityManager = $this->getMockBuilder('OCP\Activity\IManager')->getMock();
$this->settingsManager = $this->getMockBuilder(SettingsManager::class)->disableOriginalConstructor()->getMock();
$this->defaults = $this->createMock(Defaults::class);
+ $this->hasher = $this->getMockBuilder(IHasher::class)->getMock();
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
}
@@ -134,7 +140,8 @@ class ShareByMailProviderTest extends TestCase {
$this->urlGenerator,
$this->activityManager,
$this->settingsManager,
- $this->defaults
+ $this->defaults,
+ $this->hasher
]
);
@@ -154,7 +161,8 @@ class ShareByMailProviderTest extends TestCase {
$this->urlGenerator,
$this->activityManager,
$this->settingsManager,
- $this->defaults
+ $this->defaults,
+ $this->hasher
);
}
@@ -167,15 +175,22 @@ class ShareByMailProviderTest extends TestCase {
public function testCreate() {
$share = $this->getMockBuilder('\OCP\Share\IShare')->getMock();
- $share->expects($this->once())->method('getSharedWith')->willReturn('user1');
+ $share->expects($this->any())->method('getSharedWith')->willReturn('user1');
+
+ $node = $this->getMockBuilder(File::class)->getMock();
+ $node->expects($this->any())->method('getName')->willReturn('filename');
- $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createActivity']);
+ $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createActivity', 'sendPassword']);
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createActivity')->with($share);
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
+ $instance->expects($this->any())->method('sendPassword')->willReturn(true);
+ $share->expects($this->any())->method('getNode')->willReturn($node);
+ $this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(false);
+ $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$this->assertSame('shareObject',
$instance->create($share)
@@ -273,6 +288,7 @@ class ShareByMailProviderTest extends TestCase {
$uidOwner = 'user2';
$permissions = 1;
$token = 'token';
+ $password = 'password';
$instance = $this->getInstance();
@@ -286,7 +302,8 @@ class ShareByMailProviderTest extends TestCase {
$sharedBy,
$uidOwner,
$permissions,
- $token
+ $token,
+ $password
]
);
@@ -305,6 +322,7 @@ class ShareByMailProviderTest extends TestCase {
$this->assertSame($uidOwner, $result[0]['uid_owner']);
$this->assertSame($permissions, (int)$result[0]['permissions']);
$this->assertSame($token, $result[0]['token']);
+ $this->assertSame($password, $result[0]['password']);
}