diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2020-08-09 19:13:14 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-08-11 22:58:51 +0300 |
commit | 4dd507675c8583a28b948872f6e2e9e3df043fb7 (patch) | |
tree | f7ea3ec15d7530b4a1b80d19e2a34f7d1f0bd667 /apps/sharebymail/tests | |
parent | 50fdd45e9bbeaff811888ea5ddc984a5966bd6f6 (diff) |
Generate password by password_policy app
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps/sharebymail/tests')
-rw-r--r-- | apps/sharebymail/tests/ShareByMailProviderTest.php | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index aeafc86c509..628487b2aee 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -30,11 +30,11 @@ namespace OCA\ShareByMail\Tests; -use OC\CapabilitiesManager; use OC\Mail\Message; use OCA\ShareByMail\Settings\SettingsManager; use OCA\ShareByMail\ShareByMailProvider; use OCP\Defaults; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; use OCP\Files\IRootFolder; use OCP\IDBConnection; @@ -46,10 +46,12 @@ use OCP\IUserManager; use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; use OCP\Mail\IMessage; +use OCP\Security\Events\GenerateSecurePasswordEvent; use OCP\Security\IHasher; use OCP\Security\ISecureRandom; use OCP\Share\IManager; use OCP\Share\IShare; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; /** @@ -102,8 +104,8 @@ class ShareByMailProviderTest extends TestCase { /** @var IHasher | \PHPUnit_Framework_MockObject_MockObject */ private $hasher; - /** @var CapabilitiesManager | \PHPUnit_Framework_MockObject_MockObject */ - private $capabilitiesManager; + /** @var IEventDispatcher */ + private $eventDispatcher; protected function setUp(): void { parent::setUp(); @@ -127,7 +129,7 @@ class ShareByMailProviderTest extends TestCase { $this->settingsManager = $this->getMockBuilder(SettingsManager::class)->disableOriginalConstructor()->getMock(); $this->defaults = $this->createMock(Defaults::class); $this->hasher = $this->getMockBuilder(IHasher::class)->getMock(); - $this->capabilitiesManager = $this->getMockBuilder(CapabilitiesManager::class)->disableOriginalConstructor()->getMock(); + $this->eventDispatcher = $this->getMockBuilder(IEventDispatcher::class)->getMock(); $this->userManager->expects($this->any())->method('userExists')->willReturn(true); } @@ -154,7 +156,7 @@ class ShareByMailProviderTest extends TestCase { $this->settingsManager, $this->defaults, $this->hasher, - $this->capabilitiesManager + $this->eventDispatcher ] ); @@ -176,7 +178,7 @@ class ShareByMailProviderTest extends TestCase { $this->settingsManager, $this->defaults, $this->hasher, - $this->capabilitiesManager + $this->eventDispatcher ); } @@ -294,7 +296,15 @@ class ShareByMailProviderTest extends TestCase { $node = $this->getMockBuilder(File::class)->getMock(); $node->expects($this->any())->method('getName')->willReturn('filename'); - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity']); + $this->secureRandom->expects($this->once()) + ->method('generate') + ->with(8, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS) + ->willReturn('autogeneratedPassword'); + $this->eventDispatcher->expects($this->once()) + ->method('dispatchTyped') + ->with(new GenerateSecurePasswordEvent()); + + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'createPasswordSendActivity']); $instance->expects($this->once())->method('getSharedWith')->willReturn([]); $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); @@ -310,7 +320,6 @@ class ShareByMailProviderTest extends TestCase { // 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'); $message = $this->createMock(IMessage::class); $message->expects($this->once())->method('setTo')->with(['receiver@example.com']); |