summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2023-02-24 08:42:01 +0100
committerGitHub <noreply@github.com>2023-02-24 08:42:01 +0100
commite938e9d1160846759d372d1bc98f37f8095252c3 (patch)
tree96fb26ea76e0ad6bfe23657691d1533355e5cfa8 /tests
parent13297d06ef54cb53345ee35dc686288b6b8473fc (diff)
parentc37d2d9834f9605bdf1cd76aaa2f75a71a1f6083 (diff)
Merge pull request #8836 from nextcloud/feature/remove-no-more-necessary-method
Remove isSignalingDev method
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/features/bootstrap/FakeSignalingServer.php60
-rw-r--r--tests/integration/features/bootstrap/RecordingTrait.php86
-rw-r--r--tests/integration/features/callapi/recording.feature28
3 files changed, 139 insertions, 35 deletions
diff --git a/tests/integration/features/bootstrap/FakeSignalingServer.php b/tests/integration/features/bootstrap/FakeSignalingServer.php
new file mode 100644
index 000000000..fcda6d789
--- /dev/null
+++ b/tests/integration/features/bootstrap/FakeSignalingServer.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * @copyright Copyright (c) 2023 Vitor Mattos <vitor@php.rio>
+ *
+ * @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/>.
+ *
+ */
+
+if (preg_match('/\/api\/v1\/room\/([^\/]+)/', $_SERVER['REQUEST_URI'], $matches)) {
+ if (empty($_SERVER['HTTP_SPREED_SIGNALING_RANDOM'])) {
+ error_log('fake-signaling-server: Missing Spreed-Signaling-Random header');
+
+ header('HTTP/1.0 403 Forbidden');
+
+ return;
+ }
+
+ if (empty($_SERVER['HTTP_SPREED_SIGNALING_CHECKSUM'])) {
+ error_log('fake-signaling-server: Missing Spreed-Signaling-Checksum header');
+
+ header('HTTP/1.0 403 Forbidden');
+
+ return;
+ }
+
+ $random = $_SERVER['HTTP_SPREED_SIGNALING_RANDOM'];
+ $checksum = $_SERVER['HTTP_SPREED_SIGNALING_CHECKSUM'];
+
+ $data = file_get_contents('php://input');
+
+ $hash = hash_hmac('sha256', $random . $data, 'the secret');
+ if (!hash_equals($hash, strtolower($checksum))) {
+ error_log('fake-signaling-server: Checksum does not match');
+
+ header('HTTP/1.0 403 Forbidden');
+
+ return;
+ }
+ header('X-Spreed-Signaling-Features: ' . implode(',', [
+ 'audio-video-permissions',
+ 'incall-all',
+ 'hello-v2',
+ 'switchto',
+ ]));
+} else {
+ header('HTTP/1.0 404 Not Found');
+}
diff --git a/tests/integration/features/bootstrap/RecordingTrait.php b/tests/integration/features/bootstrap/RecordingTrait.php
index cd346a005..d9d6d5b1f 100644
--- a/tests/integration/features/bootstrap/RecordingTrait.php
+++ b/tests/integration/features/bootstrap/RecordingTrait.php
@@ -30,11 +30,49 @@ use PHPUnit\Framework\Assert;
// - sendRequestFullUrl()
// - setAppConfig()
trait RecordingTrait {
- /** @var string */
- private $recordingServerPid = '';
+ private string $recordingServerPid = '';
+ private string $signalingServerPid = '';
- /** @var string */
- private $recordingServerAddress = 'localhost:9000';
+ private string $recordingServerAddress = 'localhost';
+ private int $recordingServerPort = 0;
+ private string $signalingServerAddress = 'localhost';
+ private int $signalingServerPort = 0;
+
+ private function getRecordingServerAddress(): string {
+ if (!str_contains($this->recordingServerAddress, ':')) {
+ $port = $this->getOpenPort($this->recordingServerAddress);
+ $this->recordingServerAddress = $this->recordingServerAddress . ':' . $port;
+ }
+ return $this->recordingServerAddress;
+ }
+
+ private function getSignalingServerAddress(): string {
+ if (!str_contains($this->signalingServerAddress, ':')) {
+ $port = $this->getOpenPort($this->signalingServerAddress);
+ $this->signalingServerAddress = $this->signalingServerAddress . ':' . $port;
+ }
+ return $this->signalingServerAddress;
+ }
+
+ /**
+ * Get an open port
+ */
+ private function getOpenPort(string $address): int {
+ $sock = socket_create(AF_INET, SOCK_STREAM, 0);
+
+ if (!socket_bind($sock, $address, 0)) {
+ throw new \Exception('Failute to bind socket to host ' . $address);
+ }
+
+ socket_getsockname($sock, $ipAddress, $port);
+ socket_close($sock);
+
+ if ($port > 0) {
+ return $port;
+ }
+
+ throw new \Exception('Impossible to find an open port');
+ }
/**
* @Given /^recording server is started$/
@@ -45,9 +83,39 @@ trait RecordingTrait {
}
// "the secret" is hardcoded in the fake recording server.
- $this->setAppConfig('spreed', new TableNode([['recording_servers', json_encode(['servers' => [['server' => 'http://' . $this->recordingServerAddress]], 'secret' => 'the secret'])]]));
+ $this->setAppConfig('spreed', new TableNode([['recording_servers', json_encode([
+ 'servers' => [
+ [
+ 'server' => 'http://' . $this->getRecordingServerAddress()
+ ]
+ ],
+ 'secret' => 'the secret'
+ ])]]));
+ $this->setAppConfig('spreed', new TableNode([['signaling_servers', json_encode([
+ 'servers' => [
+ [
+ 'server' => 'http://' . $this->getSignalingServerAddress()
+ ]
+ ],
+ 'secret' => 'the secret'
+ ])]]));
+
+ $path = 'features/bootstrap/FakeRecordingServer.php';
+ $this->recordingServerPid = exec(
+ 'php -S ' . $this->getRecordingServerAddress() . ' ' . $path . ' >/dev/null & echo $!'
+ );
+
+ $path = 'features/bootstrap/FakeSignalingServer.php';
+ $this->signalingServerPid = exec(
+ 'php -S ' . $this->getSignalingServerAddress() . ' ' . $path . ' >/dev/null & echo $!'
+ );
- $this->recordingServerPid = exec('php -S ' . $this->recordingServerAddress . ' features/bootstrap/FakeRecordingServer.php >/dev/null & echo $!');
+ register_shutdown_function(function () {
+ if ($this->recordingServerPid !== '') {
+ exec('kill ' . $this->recordingServerPid);
+ exec('kill ' . $this->signalingServerPid);
+ }
+ });
}
/**
@@ -64,8 +132,10 @@ trait RecordingTrait {
$this->getRecordingServerReceivedRequests();
exec('kill ' . $this->recordingServerPid);
+ exec('kill ' . $this->signalingServerPid);
$this->recordingServerPid = '';
+ $this->signalingServerPid = '';
}
/**
@@ -146,7 +216,7 @@ trait RecordingTrait {
'Talk-Recording-Checksum' => $checksum,
];
- $this->sendRequestFullUrl('POST', 'http://' . $this->recordingServerAddress . '/fake/send-backend-request', $body, $headers);
+ $this->sendRequestFullUrl('POST', 'http://' . $this->getRecordingServerAddress() . '/fake/send-backend-request', $body, $headers);
$this->assertStatusCode($this->response, $statusCode);
}
@@ -178,7 +248,7 @@ trait RecordingTrait {
}
private function getRecordingServerReceivedRequests() {
- $url = 'http://' . $this->recordingServerAddress . '/fake/requests';
+ $url = 'http://' . $this->getRecordingServerAddress() . '/fake/requests';
$client = new Client();
$response = $client->get($url);
diff --git a/tests/integration/features/callapi/recording.feature b/tests/integration/features/callapi/recording.feature
index dd9dc3d2d..917c00a65 100644
--- a/tests/integration/features/callapi/recording.feature
+++ b/tests/integration/features/callapi/recording.feature
@@ -5,8 +5,6 @@ Feature: callapi/recording
Scenario: Start and stop video recording
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -48,8 +46,6 @@ Feature: callapi/recording
Scenario: Start and stop audio recording
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -91,8 +87,6 @@ Feature: callapi/recording
Scenario: Recording failed to start
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -116,8 +110,6 @@ Feature: callapi/recording
Scenario: Video recording failed
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -147,8 +139,6 @@ Feature: callapi/recording
Scenario: Start and stop recording again after the previous one failed to start
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -201,8 +191,6 @@ Feature: callapi/recording
Scenario: Start and stop recording again after the previous one failed
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -263,8 +251,6 @@ Feature: callapi/recording
Scenario: Get error when start|stop recording and already did this
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -323,8 +309,6 @@ Feature: callapi/recording
Scenario: Get error when try to start recording with invalid status
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -338,9 +322,7 @@ Feature: callapi/recording
| 2 | room1 | 0 |
Scenario: Manager try without success to start recording when signaling is internal
- Given the following "spreed" app config is set
- | signaling_dev | no |
- And user "participant1" creates room "room1" (v4)
+ Given user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
And user "participant1" joins room "room1" with 200 (v4)
@@ -358,8 +340,6 @@ Feature: callapi/recording
Scenario: Get error when non moderator/owner try to start recording
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -377,8 +357,6 @@ Feature: callapi/recording
Scenario: Get error when try to start recording and no call started
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -410,8 +388,6 @@ Feature: callapi/recording
Scenario: Stop recording automatically when end the call
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |
@@ -439,8 +415,6 @@ Feature: callapi/recording
Scenario: Stop recording automatically when the last participant go out
Given recording server is started
- And the following "spreed" app config is set
- | signaling_dev | yes |
And user "participant1" creates room "room1" (v4)
| roomType | 2 |
| roomName | room1 |