diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-11-21 19:08:38 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2016-11-21 19:31:23 +0300 |
commit | 17c4da6bfeecab68b715f634c75bb748eb3efb65 (patch) | |
tree | eddf88cc015e91ad449ef1756d8b6437d18ae67e /tests/php | |
parent | d06d10c6974526c1bf3b1148d8eee86ffaa8600d (diff) |
Add admin setting to specify a TURN server and a shared secret
* then calculates the user credentials on the fly for 1 hour
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'tests/php')
-rw-r--r-- | tests/php/UtilTest.php | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/php/UtilTest.php b/tests/php/UtilTest.php index bc5979382..425f96fe9 100644 --- a/tests/php/UtilTest.php +++ b/tests/php/UtilTest.php @@ -21,7 +21,9 @@ namespace OCA\Spreed\Tests\php; use OCA\Spreed\Util; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\IConfig; +use OCP\ISession; use Test\TestCase; class UtilTest extends TestCase { @@ -34,7 +36,7 @@ class UtilTest extends TestCase { } public function testGetStunServer() { - $config = $this->getMock(IConfig::class); + $config = $this->createMock(IConfig::class); $config ->expects($this->once()) ->method('getAppValue') @@ -43,4 +45,44 @@ class UtilTest extends TestCase { $this->assertSame('88.198.160.129', $this->util->getStunServer($config)); } + + public function testGenerateTurnSettings() { + $session = $this->createMock(ISession::class); + $session + ->expects($this->once()) + ->method('get') + ->with('spreed-session') + ->willReturn('thisisalongsessionid'); + $config = $this->createMock(IConfig::class); + $config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('spreed', 'turn_server', '') + ->willReturn('turn.example.org'); + $config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('spreed', 'turn_server_secret', '') + ->willReturn('thisisasupersecretsecret'); + $config + ->expects($this->at(2)) + ->method('getAppValue') + ->with('spreed', 'turn_server_protocols', '') + ->willReturn('udp,tcp'); + $time = $this->createMock(ITimeFactory::class); + $time + ->expects($this->once()) + ->method('getTime') + ->willReturn(1479743025); + + $this->assertSame(array( + 'server' => 'turn.example.org', + 'username' => 'thisisalongsessionid', + 'password' => 'MTVT2kC2SL9I81lZrI6gJznKQKk=', + 'protocols' => 'udp,tcp', + ), $this->util->generateTurnSettings($config, $session, $time)); + + // command to calculate this by manually + // echo -n "$(($(date +"%s")+3600)):USERNAME" | openssl dgst -sha1 -hmac "SECRET" -binary | base64 + } } |