Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/OpenViduTest.php
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | public function testJoinRoom(): void | ||||
// Unauth access, no session yet | // Unauth access, no session yet | ||||
$response = $this->post("api/v4/openvidu/rooms/{$room->name}"); | $response = $this->post("api/v4/openvidu/rooms/{$room->name}"); | ||||
$response->assertStatus(423); | $response->assertStatus(423); | ||||
// Non-existing room name | // Non-existing room name | ||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/non-existing"); | $response = $this->actingAs($john)->post("api/v4/openvidu/rooms/non-existing"); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
// TODO: Test accessing an existing room of deleted owner | |||||
// Non-owner, no session yet | // Non-owner, no session yet | ||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}"); | $response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}"); | ||||
$response->assertStatus(423); | $response->assertStatus(423); | ||||
// Room owner, no session yet | // Room owner, no session yet | ||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}"); | $response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}"); | ||||
$response->assertStatus(424); | $response->assertStatus(424); | ||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}", ['init' => 1]); | $response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}", ['init' => 1]); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$session_id = $room->fresh()->session_id; | $session_id = $room->fresh()->session_id; | ||||
$this->assertSame('PUBLISHER', $json['role']); | $this->assertSame(Room::ROLE_MODERATOR, $json['role']); | ||||
$this->assertSame($session_id, $json['session']); | $this->assertSame($session_id, $json['session']); | ||||
$this->assertTrue(is_string($session_id) && !empty($session_id)); | $this->assertTrue(is_string($session_id) && !empty($session_id)); | ||||
$this->assertTrue(strpos($json['token'], 'wss://') === 0); | $this->assertTrue(strpos($json['token'], 'wss://') === 0); | ||||
$this->assertTrue(!array_key_exists('shareToken', $json)); | $this->assertTrue(!array_key_exists('shareToken', $json)); | ||||
$john_token = $json['token']; | $john_token = $json['token']; | ||||
// Non-owner, now the session exists | // Non-owner, now the session exists | ||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}"); | $response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('PUBLISHER', $json['role']); | $this->assertSame(Room::ROLE_PUBLISHER, $json['role']); | ||||
$this->assertSame($session_id, $json['session']); | $this->assertSame($session_id, $json['session']); | ||||
$this->assertTrue(strpos($json['token'], 'wss://') === 0); | $this->assertTrue(strpos($json['token'], 'wss://') === 0); | ||||
$this->assertTrue($json['token'] != $john_token); | $this->assertTrue($json['token'] != $john_token); | ||||
$this->assertTrue(!array_key_exists('shareToken', $json)); | $this->assertTrue(!array_key_exists('shareToken', $json)); | ||||
$this->assertEmpty($json['config']['password']); | $this->assertEmpty($json['config']['password']); | ||||
$this->assertEmpty($json['config']['requires_password']); | $this->assertEmpty($json['config']['requires_password']); | ||||
// Non-owner, password protected room, password not provided | // Non-owner, password protected room, password not provided | ||||
Show All 19 Lines | public function testJoinRoom(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame($session_id, $json['session']); | $this->assertSame($session_id, $json['session']); | ||||
// Make sure the room owner can access the password protected room w/o password | // Make sure the room owner can access the password protected room w/o password | ||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}"); | $response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
} | |||||
// TODO: Test accessing an existing room of deleted owner | /** | ||||
* Test locked room and join requests | |||||
* | |||||
* @group openvidu | |||||
*/ | |||||
public function testJoinRequests(): void | |||||
{ | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | |||||
$room = Room::where('name', 'john')->first(); | |||||
$room->session_id = null; | |||||
$room->save(); | |||||
$room->setSettings(['password' => null, 'locked' => 'true']); | |||||
$this->assignBetaEntitlement($john, 'meet'); | |||||
// Create the session (also makes sure the owner can access a locked room) | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}", ['init' => 1]); | |||||
$response->assertStatus(200); | |||||
// Non-owner, locked room, invalid/missing input | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}"); | |||||
$response->assertStatus(426); | |||||
$json = $response->json(); | |||||
$this->assertCount(3, $json); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame('Failed to join the session. Room locked.', $json['message']); | |||||
$this->assertTrue($json['config']['locked']); | |||||
// Non-owner, locked room, invalid requestId | |||||
$post = ['nickname' => 'name', 'requestId' => '-----']; | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", $post); | |||||
$response->assertStatus(426); | |||||
// Non-owner, locked room, invalid requestId | |||||
$post = ['nickname' => 'name', 'picture' => '-----']; | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", $post); | |||||
$response->assertStatus(426); | |||||
// Non-owner, locked room, valid input | |||||
$reqId = '12345678'; | |||||
$post = ['nickname' => 'name', 'requestId' => $reqId, 'picture' => 'data:image/png;base64,01234']; | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", $post); | |||||
$response->assertStatus(427); | |||||
$json = $response->json(); | |||||
$this->assertCount(3, $json); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame('Failed to join the session. Room locked.', $json['message']); | |||||
$this->assertTrue($json['config']['locked']); | |||||
// TODO: How do we assert that a signal has been sent to the owner? | |||||
// Test denying a request | |||||
// Unknown room | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/unknown/request/unknown/deny"); | |||||
$response->assertStatus(404); | |||||
// Unknown request Id | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/request/unknown/deny"); | |||||
$response->assertStatus(500); | |||||
$json = $response->json(); | |||||
$this->assertCount(2, $json); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame('Failed to deny the join request.', $json['message']); | |||||
// Non-owner access forbidden | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}/request/{$reqId}/deny"); | |||||
$response->assertStatus(403); | |||||
// Valid request | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/request/{$reqId}/deny"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
// Non-owner, locked room, join request denied | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", $post); | |||||
$response->assertStatus(427); | |||||
// Test accepting a request | |||||
// Unknown room | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/unknown/request/unknown/accept"); | |||||
$response->assertStatus(404); | |||||
// Unknown request Id | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/request/unknown/accept"); | |||||
$response->assertStatus(500); | |||||
$json = $response->json(); | |||||
$this->assertCount(2, $json); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame('Failed to accept the join request.', $json['message']); | |||||
// Non-owner access forbidden | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}/request/{$reqId}/accept"); | |||||
$response->assertStatus(403); | |||||
// Valid request | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/request/{$reqId}/accept"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
// Non-owner, locked room, join request accepted | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", $post); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame(Room::ROLE_PUBLISHER, $json['role']); | |||||
$this->assertTrue(strpos($json['token'], 'wss://') === 0); | |||||
// TODO: Test a scenario where both password and lock are enabled | |||||
} | } | ||||
/** | /** | ||||
* Test joining the room | * Test joining the room | ||||
* | * | ||||
* @group openvidu | * @group openvidu | ||||
* @depends testJoinRoom | * @depends testJoinRoom | ||||
*/ | */ | ||||
public function testJoinRoomGuest(): void | public function testJoinRoomGuest(): void | ||||
{ | { | ||||
$this->assignBetaEntitlement('john@kolab.org', 'meet'); | $this->assignBetaEntitlement('john@kolab.org', 'meet'); | ||||
// There's no asy way to logout the user in the same test after | // There's no asy way to logout the user in the same test after | ||||
// using actingAs(). That's why this is moved to a separate test | // using actingAs(). That's why this is moved to a separate test | ||||
$room = Room::where('name', 'john')->first(); | $room = Room::where('name', 'john')->first(); | ||||
// Guest, request with screenShare token | // Guest, request with screenShare token | ||||
$response = $this->post("api/v4/openvidu/rooms/{$room->name}", ['screenShare' => 1]); | $response = $this->post("api/v4/openvidu/rooms/{$room->name}", ['screenShare' => 1]); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('PUBLISHER', $json['role']); | $this->assertSame(Room::ROLE_PUBLISHER, $json['role']); | ||||
$this->assertSame($room->session_id, $json['session']); | $this->assertSame($room->session_id, $json['session']); | ||||
$this->assertTrue(strpos($json['token'], 'wss://') === 0); | $this->assertTrue(strpos($json['token'], 'wss://') === 0); | ||||
$this->assertTrue(strpos($json['shareToken'], 'wss://') === 0); | $this->assertTrue(strpos($json['shareToken'], 'wss://') === 0); | ||||
$this->assertTrue($json['shareToken'] != $json['token']); | $this->assertTrue($json['shareToken'] != $json['token']); | ||||
} | } | ||||
/** | /** | ||||
* Test closing the room (session) | * Test closing the room (session) | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | public function testCloseRoom(): void | ||||
$this->assertSame('aaa', $room->fresh()->session_id); | $this->assertSame('aaa', $room->fresh()->session_id); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertSame("Failed to close the session.", $json['message']); | $this->assertSame("Failed to close the session.", $json['message']); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
} | } | ||||
/** | /** | ||||
* Test dismissing a participant (closing a connection) | |||||
* | |||||
* @group openvidu | |||||
*/ | |||||
public function testDismissConnection(): void | |||||
{ | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | |||||
$room = Room::where('name', 'john')->first(); | |||||
$room->session_id = null; | |||||
$room->save(); | |||||
$this->assignBetaEntitlement($john, 'meet'); | |||||
// First we create the session | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}", ['init' => 1]); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
// And the other user connection | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", ['init' => 1]); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$conn_id = $json['connectionId']; | |||||
$room->refresh(); | |||||
$conn_data = $room->getOVConnection($conn_id); | |||||
$this->assertSame($conn_id, $conn_data['connectionId']); | |||||
// Non-existing room name | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/non-existing/connections/{$conn_id}/dismiss"); | |||||
$response->assertStatus(404); | |||||
// TODO: Test accessing an existing room of deleted owner | |||||
// Non-existing connection | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/connections/123/dismiss"); | |||||
$response->assertStatus(500); | |||||
$json = $response->json(); | |||||
$this->assertCount(2, $json); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame('Failed to dismiss the connection.', $json['message']); | |||||
// Non-owner access | |||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}/connections/{$conn_id}/dismiss"); | |||||
$response->assertStatus(403); | |||||
// Expected success | |||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/connections/{$conn_id}/dismiss"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertNull($room->getOVConnection($conn_id)); | |||||
} | |||||
/** | |||||
* Test configuring the room (session) | * Test configuring the room (session) | ||||
* | * | ||||
* @group openvidu | * @group openvidu | ||||
*/ | */ | ||||
public function testSetRoomConfig(): void | public function testSetRoomConfig(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |