summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2023-02-08 13:23:44 +0100
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2023-02-22 02:41:25 +0100
commit24bb1cf20f091c83f4de4cb42984534670c7313d (patch)
tree2e33eb4bc1b4b6879a181542a5f0d6e1f4b4b47b /tests
parent7ee0f148248305fbdc3d871fb94cb6c6877c72be (diff)
Change recording status when notified by the recording server
Before the recording status was immediately changed by the Nextcloud server when a recording was started or stopped. However starting or stopping (but mostly starting) can take some time due to the initialization of the display and audio device, starting the browser, joining the call... so the recording status did not match the actual status. To address that now the recording server sends a notification back to the Nextcloud server when the recording actually started or stopped, and only then the Nextcloud server changes the recording status. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/features/bootstrap/FakeRecordingServer.php19
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php2
-rw-r--r--tests/integration/features/bootstrap/RecordingTrait.php59
-rw-r--r--tests/integration/features/callapi/recording.feature62
4 files changed, 132 insertions, 10 deletions
diff --git a/tests/integration/features/bootstrap/FakeRecordingServer.php b/tests/integration/features/bootstrap/FakeRecordingServer.php
index 5d8a1f6d2..36ba4e105 100644
--- a/tests/integration/features/bootstrap/FakeRecordingServer.php
+++ b/tests/integration/features/bootstrap/FakeRecordingServer.php
@@ -74,6 +74,25 @@ if (preg_match('/\/api\/v1\/welcome/', $_SERVER['REQUEST_URI'])) {
unlink($receivedRequestsFile);
echo $requests;
+} elseif (preg_match('/\/fake\/send-backend-request/', $_SERVER['REQUEST_URI'])) {
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL, $_SERVER['HTTP_BACKEND_URL']);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [
+ 'OCS-APiRequest: true',
+ 'Talk-Recording-Random: ' . $_SERVER['HTTP_TALK_RECORDING_RANDOM'],
+ 'Talk-Recording-Checksum: ' . $_SERVER['HTTP_TALK_RECORDING_CHECKSUM'],
+ ]);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+ $result = curl_exec($ch);
+ $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
+
+ curl_close($ch);
+
+ http_response_code($responseCode);
+ echo $result;
} else {
header('HTTP/1.0 404 Not Found');
}
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index eb7b1d31b..7fe7f6f79 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -3336,6 +3336,8 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$options['form_params'] = $fd;
} elseif (is_array($body)) {
$options['form_params'] = $body;
+ } elseif (is_string($body)) {
+ $options['body'] = $body;
}
$options['headers'] = array_merge($headers, [
diff --git a/tests/integration/features/bootstrap/RecordingTrait.php b/tests/integration/features/bootstrap/RecordingTrait.php
index dcd0e00eb..7b6db6aac 100644
--- a/tests/integration/features/bootstrap/RecordingTrait.php
+++ b/tests/integration/features/bootstrap/RecordingTrait.php
@@ -22,8 +22,13 @@ use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Client;
use PHPUnit\Framework\Assert;
-// setAppConfig() method is expected to be available in the class that uses this
-// trait.
+// The following attributes and methods are expected to be available in the
+// class that uses this trait:
+// - baseUrl
+// - assertStatusCode()
+// - sendRequest()
+// - sendRequestFullUrl()
+// - setAppConfig()
trait RecordingTrait {
/** @var string */
private $recordingServerPid = '';
@@ -64,6 +69,56 @@ trait RecordingTrait {
}
/**
+ * @When /^recording server sent started request for "(audio|video)" recording in room "([^"]*)" with (\d+)(?: \((v1)\))?$/
+ */
+ public function recordingServerSentStartedRequestForRecordingInRoomWith(string $recordingType, string $identifier, int $statusCode, string $apiVersion = 'v1') {
+ $recordingTypes = [
+ 'video' => 1,
+ 'audio' => 2,
+ ];
+
+ $data = [
+ 'type' => 'started',
+ 'started' => [
+ 'token' => FeatureContext::getTokenForIdentifier($identifier),
+ 'status' => $recordingTypes[$recordingType],
+ ],
+ ];
+
+ $this->sendBackendRequestFromRecordingServer($data, $statusCode, $apiVersion);
+ }
+
+ /**
+ * @When /^recording server sent stopped request for recording in room "([^"]*)" with (\d+)(?: \((v1)\))?$/
+ */
+ public function recordingServerSentStoppedRequestForRecordingInRoomWith(string $identifier, int $statusCode, string $apiVersion = 'v1') {
+ $data = [
+ 'type' => 'stopped',
+ 'stopped' => [
+ 'token' => FeatureContext::getTokenForIdentifier($identifier),
+ ],
+ ];
+
+ $this->sendBackendRequestFromRecordingServer($data, $statusCode, $apiVersion);
+ }
+
+ private function sendBackendRequestFromRecordingServer(array $data, int $statusCode, string $apiVersion = 'v1') {
+ $body = json_encode($data);
+
+ $random = md5((string) rand());
+ $checksum = hash_hmac('sha256', $random . $body, "the secret");
+
+ $headers = [
+ 'Backend-Url' => $this->baseUrl . 'ocs/v2.php/apps/spreed/api/' . $apiVersion . '/recording/backend',
+ 'Talk-Recording-Random' => $random,
+ 'Talk-Recording-Checksum' => $checksum,
+ ];
+
+ $this->sendRequestFullUrl('POST', 'http://' . $this->recordingServerAddress . '/fake/send-backend-request', $body, $headers);
+ $this->assertStatusCode($this->response, $statusCode);
+ }
+
+ /**
* @Then /^recording server received the following requests$/
*/
public function recordingServerReceivedTheFollowingRequests(TableNode $formData = null) {
diff --git a/tests/integration/features/callapi/recording.feature b/tests/integration/features/callapi/recording.feature
index 9f83f6276..1aa815a79 100644
--- a/tests/integration/features/callapi/recording.feature
+++ b/tests/integration/features/callapi/recording.feature
@@ -13,10 +13,14 @@ Feature: callapi/recording
And user "participant1" joins room "room1" with 200 (v4)
And user "participant1" joins call "room1" with 200 (v4)
When user "participant1" starts "video" recording in room "room1" with 200 (v1)
- Then recording server received the following requests
+ And recording server received the following requests
| token | data |
| room1 | {"type":"start","start":{"status":1,"owner":"participant1"}} |
- And user "participant1" sees the following system messages in room "room1" with 200 (v1)
+ And user "participant1" is participant of the following unordered rooms (v4)
+ | type | name | callRecording |
+ | 2 | room1 | 0 |
+ And recording server sent started request for "video" recording in room "room1" with 200
+ Then user "participant1" sees the following system messages in room "room1" with 200 (v1)
| room | actorType | actorId | actorDisplayName | systemMessage |
| room1 | users | participant1 | participant1-displayname | recording_started |
| room1 | users | participant1 | participant1-displayname | call_started |
@@ -25,10 +29,14 @@ Feature: callapi/recording
| type | name | callRecording |
| 2 | room1 | 1 |
When user "participant1" stops recording in room "room1" with 200 (v1)
- Then recording server received the following requests
+ And recording server received the following requests
| token | data |
| room1 | {"type":"stop"} |
- And user "participant1" sees the following system messages in room "room1" with 200 (v1)
+ And user "participant1" is participant of the following unordered rooms (v4)
+ | type | name | callRecording |
+ | 2 | room1 | 1 |
+ And recording server sent stopped request for recording in room "room1" with 200
+ Then user "participant1" sees the following system messages in room "room1" with 200 (v1)
| room | actorType | actorId | actorDisplayName | systemMessage |
| room1 | users | participant1 | participant1-displayname | recording_stopped |
| room1 | users | participant1 | participant1-displayname | recording_started |
@@ -48,10 +56,14 @@ Feature: callapi/recording
And user "participant1" joins room "room1" with 200 (v4)
And user "participant1" joins call "room1" with 200 (v4)
When user "participant1" starts "audio" recording in room "room1" with 200 (v1)
- Then recording server received the following requests
+ And recording server received the following requests
| token | data |
| room1 | {"type":"start","start":{"status":2,"owner":"participant1"}} |
- And user "participant1" sees the following system messages in room "room1" with 200 (v1)
+ And user "participant1" is participant of the following unordered rooms (v4)
+ | type | name | callRecording |
+ | 2 | room1 | 0 |
+ And recording server sent started request for "audio" recording in room "room1" with 200
+ Then user "participant1" sees the following system messages in room "room1" with 200 (v1)
| room | actorType | actorId | actorDisplayName | systemMessage |
| room1 | users | participant1 | participant1-displayname | audio_recording_started |
| room1 | users | participant1 | participant1-displayname | call_started |
@@ -60,10 +72,14 @@ Feature: callapi/recording
| type | name | callRecording |
| 2 | room1 | 2 |
When user "participant1" stops recording in room "room1" with 200 (v1)
- Then recording server received the following requests
+ And recording server received the following requests
| token | data |
| room1 | {"type":"stop"} |
- And user "participant1" sees the following system messages in room "room1" with 200 (v1)
+ And user "participant1" is participant of the following unordered rooms (v4)
+ | type | name | callRecording |
+ | 2 | room1 | 2 |
+ And recording server sent stopped request for recording in room "room1" with 200
+ Then user "participant1" sees the following system messages in room "room1" with 200 (v1)
| room | actorType | actorId | actorDisplayName | systemMessage |
| room1 | users | participant1 | participant1-displayname | audio_recording_stopped |
| room1 | users | participant1 | participant1-displayname | audio_recording_started |
@@ -86,6 +102,11 @@ Feature: callapi/recording
And recording server received the following requests
| token | data |
| room1 | {"type":"start","start":{"status":2,"owner":"participant1"}} |
+ And user "participant1" starts "audio" recording in room "room1" with 200 (v1)
+ And recording server received the following requests
+ | token | data |
+ | room1 | {"type":"start","start":{"status":2,"owner":"participant1"}} |
+ And recording server sent started request for "audio" recording in room "room1" with 200
And user "participant1" starts "audio" recording in room "room1" with 400 (v1)
Then the response error matches with "recording"
And recording server received the following requests
@@ -97,6 +118,11 @@ Feature: callapi/recording
| token | data |
| room1 | {"type":"stop"} |
And user "participant1" stops recording in room "room1" with 200 (v1)
+ And recording server received the following requests
+ | token | data |
+ | room1 | {"type":"stop"} |
+ And recording server sent stopped request for recording in room "room1" with 200
+ And user "participant1" stops recording in room "room1" with 200 (v1)
Then recording server received the following requests
And user "participant1" is participant of the following unordered rooms (v4)
| type | name | callRecording |
@@ -105,6 +131,11 @@ Feature: callapi/recording
And recording server received the following requests
| token | data |
| room1 | {"type":"start","start":{"status":1,"owner":"participant1"}} |
+ And user "participant1" starts "video" recording in room "room1" with 200 (v1)
+ And recording server received the following requests
+ | token | data |
+ | room1 | {"type":"start","start":{"status":1,"owner":"participant1"}} |
+ And recording server sent started request for "video" recording in room "room1" with 200
And user "participant1" starts "video" recording in room "room1" with 400 (v1)
Then the response error matches with "recording"
And recording server received the following requests
@@ -116,6 +147,11 @@ Feature: callapi/recording
| token | data |
| room1 | {"type":"stop"} |
And user "participant1" stops recording in room "room1" with 200 (v1)
+ And recording server received the following requests
+ | token | data |
+ | room1 | {"type":"stop"} |
+ And recording server sent stopped request for recording in room "room1" with 200
+ And user "participant1" stops recording in room "room1" with 200 (v1)
Then recording server received the following requests
And user "participant1" is participant of the following unordered rooms (v4)
| type | name | callRecording |
@@ -221,6 +257,7 @@ Feature: callapi/recording
And recording server received the following requests
| token | data |
| room1 | {"type":"start","start":{"status":2,"owner":"participant1"}} |
+ And recording server sent started request for "audio" recording in room "room1" with 200
And user "participant1" is participant of the following unordered rooms (v4)
| type | name | callRecording |
| 2 | room1 | 2 |
@@ -230,6 +267,10 @@ Feature: callapi/recording
| room1 | {"type":"stop"} |
And user "participant1" is participant of the following unordered rooms (v4)
| type | name | callRecording |
+ | 2 | room1 | 2 |
+ And recording server sent stopped request for recording in room "room1" with 200
+ And user "participant1" is participant of the following unordered rooms (v4)
+ | type | name | callRecording |
| 2 | room1 | 0 |
Scenario: Stop recording automatically when the last participant go out
@@ -245,6 +286,7 @@ Feature: callapi/recording
And recording server received the following requests
| token | data |
| room1 | {"type":"start","start":{"status":2,"owner":"participant1"}} |
+ And recording server sent started request for "audio" recording in room "room1" with 200
And user "participant1" is participant of the following unordered rooms (v4)
| type | name | callRecording |
| 2 | room1 | 2 |
@@ -254,4 +296,8 @@ Feature: callapi/recording
| room1 | {"type":"stop"} |
And user "participant1" is participant of the following unordered rooms (v4)
| type | name | callRecording |
+ | 2 | room1 | 2 |
+ And recording server sent stopped request for recording in room "room1" with 200
+ And user "participant1" is participant of the following unordered rooms (v4)
+ | type | name | callRecording |
| 2 | room1 | 0 |