Browse Source

Added test for verifyPassword. Signed-off-by: Peter Edens <petere@conceiva.com>

pull/1020/head
Peter Edens 7 years ago
parent
commit
a0bd7aff09
  1. 2
      appinfo/info.xml
  2. 60
      tests/php/PasswordVerificationTest.php

2
appinfo/info.xml

@ -44,7 +44,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
<screenshot>https://raw.githubusercontent.com/nextcloud/spreed/master/docs/contacts-menu.png</screenshot>
<dependencies>
<nextcloud min-version="14" max-version="14" />
<nextcloud min-version="13" max-version="14" />
</dependencies>
<background-jobs>

60
tests/php/PasswordVerificationTest.php

@ -0,0 +1,60 @@
<?php
/**
* @copyright Copyright (c) 2018 Peter Edens <petere@conceiva.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Spreed\Tests\php;
use OCA\Spreed\Config;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use Test\TestCase;
class PasswordVerificationTest extends TestCase {
public function testVerifyPassword() {
$dispatcher = \OC::$server->getEventDispatcher();
$dispatcher->addListener('OCA\Spreed\Room::verifyPassword', function(GenericEvent $event) {
$password = $event->getArgument('password');
$room = $event->getSubject();
$hasPassword = $room->hasPassword();
if ($password == "1234") {
$event->setArgument('result', [ 'result' => true, 'url' => '']);
}
else {
$event->setArgument('result', [ 'result' => false, 'url' => 'https://test']);
}
});
$secureRandom = \OC::$server->getSecureRandom();
$config = \OC::$server->getConfig();
$dbConnection = \OC::$server->getDatabaseConnection();
$dispatcher = \OC::$server->getEventDispatcher();
$manager = new Manager($dbConnection, $config, $secureRandom, $dispatcher, $this->createMock(IHasher::class));
$room = $manager->createPublicRoom();
$verificationResult = $room->verifyPassword('1234');
$this->assertSame($verificationResult, ['result' => true, 'url' => '']);
$verificationResult = $room->verifyPassword('4321');
$this->assertSame($verificationResult, ['result' => false, 'url' => 'https://test']);
}
}
Loading…
Cancel
Save