diff options
author | Joachim Bauch <bauch@struktur.de> | 2021-10-21 15:31:51 +0300 |
---|---|---|
committer | Joachim Bauch <bauch@struktur.de> | 2021-10-21 15:38:00 +0300 |
commit | 9765879e31a46af42a733b6e7a53b38885463f50 (patch) | |
tree | ce32615aec4f4aa59a7336378a482a8453314d22 /tests | |
parent | 5d79ba9d5df477dcb3426b3f472cfdc7fb0d6991 (diff) |
Introduce event so other apps can override the list of TURN servers.
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/php/ConfigTest.php | 77 | ||||
-rw-r--r-- | tests/php/Controller/SignalingControllerTest.php | 4 | ||||
-rw-r--r-- | tests/php/Signaling/BackendNotifierTest.php | 4 |
3 files changed, 75 insertions, 10 deletions
diff --git a/tests/php/ConfigTest.php b/tests/php/ConfigTest.php index 3bcff2e12..c43670b5a 100644 --- a/tests/php/ConfigTest.php +++ b/tests/php/ConfigTest.php @@ -21,7 +21,9 @@ namespace OCA\Talk\Tests\php; use OCA\Talk\Config; +use OCA\Talk\Events\GetTurnServersEvent; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroupManager; use OCP\Security\ISecureRandom; @@ -41,6 +43,8 @@ class ConfigTest extends TestCase { $secureRandom = $this->createMock(ISecureRandom::class); /** @var MockObject|IGroupManager $secureRandom */ $groupManager = $this->createMock(IGroupManager::class); + /** @var MockObject|IEventDispatcher $dispatcher */ + $dispatcher = $this->createMock(IEventDispatcher::class); /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); $config @@ -54,7 +58,7 @@ class ConfigTest extends TestCase { ->with('has_internet_connection', true) ->willReturn(true); - $helper = new Config($config, $secureRandom, $groupManager, $timeFactory); + $helper = new Config($config, $secureRandom, $groupManager, $timeFactory, $dispatcher); $this->assertSame($helper->getStunServers(), $servers); } @@ -65,6 +69,8 @@ class ConfigTest extends TestCase { $secureRandom = $this->createMock(ISecureRandom::class); /** @var MockObject|IGroupManager $secureRandom */ $groupManager = $this->createMock(IGroupManager::class); + /** @var MockObject|IEventDispatcher $dispatcher */ + $dispatcher = $this->createMock(IEventDispatcher::class); /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); $config @@ -78,7 +84,7 @@ class ConfigTest extends TestCase { ->with('has_internet_connection', true) ->willReturn(true); - $helper = new Config($config, $secureRandom, $groupManager, $timeFactory); + $helper = new Config($config, $secureRandom, $groupManager, $timeFactory, $dispatcher); $this->assertSame(['stun.nextcloud.com:443'], $helper->getStunServers()); } @@ -89,6 +95,8 @@ class ConfigTest extends TestCase { $secureRandom = $this->createMock(ISecureRandom::class); /** @var MockObject|IGroupManager $secureRandom */ $groupManager = $this->createMock(IGroupManager::class); + /** @var MockObject|IEventDispatcher $dispatcher */ + $dispatcher = $this->createMock(IEventDispatcher::class); /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); $config @@ -102,7 +110,7 @@ class ConfigTest extends TestCase { ->with('has_internet_connection', true) ->willReturn(false); - $helper = new Config($config, $secureRandom, $groupManager, $timeFactory); + $helper = new Config($config, $secureRandom, $groupManager, $timeFactory, $dispatcher); $this->assertSame([], $helper->getStunServers()); } @@ -144,6 +152,8 @@ class ConfigTest extends TestCase { /** @var MockObject|IGroupManager $secureRandom */ $groupManager = $this->createMock(IGroupManager::class); + /** @var MockObject|IEventDispatcher $dispatcher */ + $dispatcher = $this->createMock(IEventDispatcher::class); /** @var MockObject|ISecureRandom $secureRandom */ $secureRandom = $this->createMock(ISecureRandom::class); @@ -152,7 +162,7 @@ class ConfigTest extends TestCase { ->method('generate') ->with(16) ->willReturn('abcdefghijklmnop'); - $helper = new Config($config, $secureRandom, $groupManager, $timeFactory); + $helper = new Config($config, $secureRandom, $groupManager, $timeFactory, $dispatcher); // $settings = $helper->getTurnSettings(); @@ -198,12 +208,65 @@ class ConfigTest extends TestCase { /** @var MockObject|ISecureRandom $secureRandom */ $secureRandom = $this->createMock(ISecureRandom::class); - $helper = new Config($config, $secureRandom, $groupManager, $timeFactory); + /** @var MockObject|IEventDispatcher $dispatcher */ + $dispatcher = $this->createMock(IEventDispatcher::class); + + $helper = new Config($config, $secureRandom, $groupManager, $timeFactory, $dispatcher); $settings = $helper->getTurnSettings(); $this->assertEquals(0, count($settings)); } + public function testGenerateTurnSettingsEvent() { + /** @var MockObject|IConfig $config */ + $config = $this->createMock(IConfig::class); + $config + ->expects($this->once()) + ->method('getAppValue') + ->with('spreed', 'turn_servers', '') + ->willReturn(json_encode([])); + + /** @var MockObject|ITimeFactory $timeFactory */ + $timeFactory = $this->createMock(ITimeFactory::class); + + /** @var MockObject|IGroupManager $secureRandom */ + $groupManager = $this->createMock(IGroupManager::class); + + /** @var MockObject|ISecureRandom $secureRandom */ + $secureRandom = $this->createMock(ISecureRandom::class); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = \OC::$server->query(IEventDispatcher::class); + + $servers = [ + [ + 'schemes' => 'turn', + 'server' => 'turn.domain.invalid', + 'username' => 'john', + 'password' => 'abcde', + 'protocols' => 'udp,tcp', + ], + [ + 'schemes' => 'turns', + 'server' => 'turns.domain.invalid', + 'username' => 'jane', + 'password' => 'ABCDE', + 'protocols' => 'tcp', + ], + ]; + + $listener = static function (GetTurnServersEvent $event) use ($servers) { + $event->setServers($servers); + }; + + $dispatcher->addListener(Config::EVENT_GET_TURN_SERVERS, $listener); + + $helper = new Config($config, $secureRandom, $groupManager, $timeFactory, $dispatcher); + + $settings = $helper->getTurnSettings(); + $this->assertSame($servers, $settings); + } + public function dataGetWebSocketDomainForSignalingServer() { return [ ['http://blabla.nextcloud.com', 'ws://blabla.nextcloud.com'], @@ -272,10 +335,12 @@ class ConfigTest extends TestCase { $secureRandom = $this->createMock(ISecureRandom::class); /** @var MockObject|IGroupManager $secureRandom */ $groupManager = $this->createMock(IGroupManager::class); + /** @var MockObject|IEventDispatcher $dispatcher */ + $dispatcher = $this->createMock(IEventDispatcher::class); /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); - $helper = new Config($config, $secureRandom, $groupManager, $timeFactory); + $helper = new Config($config, $secureRandom, $groupManager, $timeFactory, $dispatcher); $this->assertEquals( $expectedWebSocketDomain, diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php index 12276cbf3..b14312ce3 100644 --- a/tests/php/Controller/SignalingControllerTest.php +++ b/tests/php/Controller/SignalingControllerTest.php @@ -116,7 +116,8 @@ class SignalingControllerTest extends \Test\TestCase { ])); $config->setAppValue('spreed', 'signaling_ticket_secret', 'the-app-ticket-secret'); $config->setUserValue($this->userId, 'spreed', 'signaling_ticket_secret', 'the-user-ticket-secret'); - $this->config = new Config($config, $this->secureRandom, $groupManager, $timeFactory); + $this->dispatcher = \OC::$server->query(IEventDispatcher::class); + $this->config = new Config($config, $this->secureRandom, $groupManager, $timeFactory, $this->dispatcher); $this->session = $this->createMock(TalkSession::class); $this->dbConnection = \OC::$server->getDatabaseConnection(); $this->signalingManager = $this->createMock(\OCA\Talk\Signaling\Manager::class); @@ -127,7 +128,6 @@ class SignalingControllerTest extends \Test\TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->clientService = $this->createMock(IClientService::class); - $this->dispatcher = \OC::$server->query(IEventDispatcher::class); $this->logger = $this->createMock(LoggerInterface::class); $this->recreateSignalingController(); } diff --git a/tests/php/Signaling/BackendNotifierTest.php b/tests/php/Signaling/BackendNotifierTest.php index 73bf4a7ba..16d43b72e 100644 --- a/tests/php/Signaling/BackendNotifierTest.php +++ b/tests/php/Signaling/BackendNotifierTest.php @@ -132,13 +132,13 @@ class BackendNotifierTest extends \Test\TestCase { ->method('getSignalingServerForConversation') ->willReturn(['server' => $this->baseUrl]); - $this->config = new Config($config, $this->secureRandom, $groupManager, $this->timeFactory); + $this->dispatcher = \OC::$server->query(IEventDispatcher::class); + $this->config = new Config($config, $this->secureRandom, $groupManager, $this->timeFactory, $this->dispatcher); $this->recreateBackendNotifier(); $this->overwriteService(BackendNotifier::class, $this->controller); $dbConnection = \OC::$server->getDatabaseConnection(); - $this->dispatcher = \OC::$server->query(IEventDispatcher::class); $this->manager = new Manager( $dbConnection, $config, |