2020-06-10 13:55:21 +02:00
|
|
|
<?php
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
namespace OCA\BigBlueButton\Tests\Controller;
|
2020-06-10 13:55:21 +02:00
|
|
|
|
|
|
|
use OCA\BigBlueButton\BigBlueButton\API;
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCA\BigBlueButton\Controller\JoinController;
|
2020-06-10 13:55:21 +02:00
|
|
|
use OCA\BigBlueButton\Db\Room;
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCA\BigBlueButton\NotFoundException;
|
2020-06-16 16:54:50 +02:00
|
|
|
use OCA\BigBlueButton\Permission;
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCA\BigBlueButton\Service\RoomService;
|
2020-06-17 15:09:20 +02:00
|
|
|
use OCP\AppFramework\Http;
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
2020-06-17 15:09:20 +02:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2022-03-16 16:12:33 +01:00
|
|
|
use OCP\BackgroundJob\IJobList;
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserSession;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-06-10 13:55:21 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
class JoinControllerTest extends TestCase {
|
2020-06-10 13:55:21 +02:00
|
|
|
private $request;
|
|
|
|
private $service;
|
|
|
|
private $userSession;
|
|
|
|
private $urlGenerator;
|
|
|
|
private $controller;
|
|
|
|
private $api;
|
2020-06-16 16:54:50 +02:00
|
|
|
private $permission;
|
2020-06-10 13:55:21 +02:00
|
|
|
private $room;
|
2022-03-16 16:12:33 +01:00
|
|
|
private $jobList;
|
2020-06-10 13:55:21 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function setUp(): void {
|
2020-06-10 13:55:21 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->request = $this->createMock(IRequest::class);
|
|
|
|
$this->service = $this->createMock(RoomService::class);
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
|
|
|
$this->api = $this->createMock(API::class);
|
2020-06-16 16:54:50 +02:00
|
|
|
$this->permission = $this->createMock(Permission::class);
|
2022-03-16 16:12:33 +01:00
|
|
|
$this->jobList = $this->createMock(IJobList::class);
|
2020-06-10 13:55:21 +02:00
|
|
|
|
|
|
|
$this->controller = new JoinController(
|
|
|
|
'bbb',
|
|
|
|
$this->request,
|
|
|
|
$this->service,
|
|
|
|
$this->urlGenerator,
|
|
|
|
$this->userSession,
|
2020-06-16 16:54:50 +02:00
|
|
|
$this->api,
|
2022-03-16 16:12:33 +01:00
|
|
|
$this->permission,
|
|
|
|
$this->jobList
|
2020-06-10 13:55:21 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->room = new Room();
|
2022-03-16 16:12:33 +01:00
|
|
|
$this->room->id = 1;
|
2020-06-10 13:55:21 +02:00
|
|
|
$this->room->uid = 'uid_foo';
|
|
|
|
$this->room->userId = 'user_foo';
|
|
|
|
$this->room->access = Room::ACCESS_PUBLIC;
|
|
|
|
$this->room->name = 'name_foo';
|
|
|
|
$this->room->password = 'password_foo';
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testNonExistingRoom() {
|
2021-02-13 16:14:40 +01:00
|
|
|
$this->controller->setToken('foobar');
|
2020-06-10 13:55:21 +02:00
|
|
|
$this->expectException(NotFoundException::class);
|
|
|
|
$this->service
|
|
|
|
->expects($this->once())
|
|
|
|
->method('findByUID')
|
|
|
|
->willReturn(null);
|
|
|
|
|
|
|
|
$this->controller->index(null);
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testUserIsLoggedIn() {
|
2020-06-10 13:55:21 +02:00
|
|
|
$this->controller->setToken($this->room->uid);
|
|
|
|
$this->service
|
|
|
|
->expects($this->once())
|
|
|
|
->method('findByUID')
|
|
|
|
->willReturn($this->room);
|
|
|
|
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isLoggedIn')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$user->method('getDisplayName')->willReturn('User Bar');
|
|
|
|
$user->method('getUID')->willReturn('user_bar');
|
|
|
|
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
$this->api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createMeeting')
|
|
|
|
->willReturn(12345);
|
|
|
|
|
|
|
|
$url = 'https://foobar';
|
|
|
|
$this->api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createJoinUrl')
|
2021-01-22 19:12:55 +01:00
|
|
|
->with($this->room, 12345, 'User Bar', false, 'user_bar')
|
2020-06-10 13:55:21 +02:00
|
|
|
->willReturn($url);
|
|
|
|
|
|
|
|
$result = $this->controller->index(null);
|
|
|
|
|
2020-08-25 13:17:35 +02:00
|
|
|
$this->assertInstanceOf(TemplateResponse::class, $result);
|
|
|
|
$this->assertEquals('forward', $result->getTemplateName());
|
|
|
|
$this->assertEquals($url, $result->getParams()['url']);
|
2020-06-10 13:55:21 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testUserNeedsToAuthenticateForInternal() {
|
2020-06-17 15:09:20 +02:00
|
|
|
$this->room->setAccess(Room::ACCESS_INTERNAL);
|
|
|
|
|
|
|
|
$this->controller->setToken($this->room->uid);
|
|
|
|
$this->service
|
|
|
|
->expects($this->once())
|
|
|
|
->method('findByUID')
|
|
|
|
->willReturn($this->room);
|
|
|
|
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isLoggedIn')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('linkToRoute')
|
|
|
|
->will($this->returnValueMap([
|
|
|
|
['core.login.showLoginForm', ['redirect_url' => 'https://join'], 'https://login'],
|
|
|
|
['bbb.join.index', ['token' => $this->room->uid], 'https://join'],
|
|
|
|
]));
|
|
|
|
|
|
|
|
$result = $this->controller->index(null);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result);
|
|
|
|
$this->assertEquals(Http::STATUS_SEE_OTHER, $result->getStatus());
|
2020-06-10 13:55:21 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testUserNeedsToAuthenticateForInternalRestricted() {
|
2020-06-17 15:09:20 +02:00
|
|
|
$this->room->setAccess(Room::ACCESS_INTERNAL_RESTRICTED);
|
|
|
|
|
|
|
|
$this->controller->setToken($this->room->uid);
|
|
|
|
$this->service
|
|
|
|
->expects($this->once())
|
|
|
|
->method('findByUID')
|
|
|
|
->willReturn($this->room);
|
|
|
|
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isLoggedIn')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('linkToRoute')
|
|
|
|
->will($this->returnValueMap([
|
|
|
|
['core.login.showLoginForm', ['redirect_url' => 'https://join'], 'https://login'],
|
|
|
|
['bbb.join.index', ['token' => $this->room->uid], 'https://join'],
|
|
|
|
]));
|
|
|
|
|
|
|
|
$result = $this->controller->index(null);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result);
|
|
|
|
$this->assertEquals(Http::STATUS_SEE_OTHER, $result->getStatus());
|
2020-06-10 13:55:21 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testDisplaynames() {
|
2020-06-17 15:09:20 +02:00
|
|
|
$this->controller->setToken($this->room->uid);
|
|
|
|
$this->service
|
|
|
|
->expects($this->once())
|
|
|
|
->method('findByUID')
|
|
|
|
->willReturn($this->room);
|
|
|
|
|
|
|
|
$this->api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createMeeting')
|
|
|
|
->willReturn(12345);
|
|
|
|
|
|
|
|
$url = 'https://foobar';
|
|
|
|
$this->api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createJoinUrl')
|
2021-01-22 19:12:55 +01:00
|
|
|
->with($this->room, 12345, 'Foo Bar', false, null)
|
2020-06-17 15:09:20 +02:00
|
|
|
->willReturn($url);
|
|
|
|
|
|
|
|
$this->invalidDisplayname('a');
|
|
|
|
$this->invalidDisplayname(' a');
|
|
|
|
$this->invalidDisplayname('aa');
|
|
|
|
|
|
|
|
$response = $this->controller->index('Foo Bar');
|
|
|
|
|
2020-08-25 13:17:35 +02:00
|
|
|
$this->assertInstanceOf(TemplateResponse::class, $response);
|
|
|
|
$this->assertEquals('forward', $response->getTemplateName());
|
|
|
|
$this->assertEquals($url, $response->getParams()['url']);
|
2020-06-10 13:55:21 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
private function invalidDisplayname($displayname) {
|
2020-06-17 15:09:20 +02:00
|
|
|
$response = $this->controller->index($displayname);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(TemplateResponse::class, $response);
|
|
|
|
$this->assertEquals('join', $response->getTemplateName());
|
|
|
|
$this->assertTrue($response->getParams()['wrongdisplayname']);
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testPasswordRequired() {
|
2020-06-17 15:09:20 +02:00
|
|
|
$this->room->setAccess(Room::ACCESS_PASSWORD);
|
|
|
|
$this->room->setPassword('asdf');
|
|
|
|
|
|
|
|
$this->controller->setToken($this->room->uid);
|
|
|
|
$this->service
|
|
|
|
->method('findByUID')
|
|
|
|
->willReturn($this->room);
|
|
|
|
|
|
|
|
$this->api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createMeeting')
|
|
|
|
->willReturn(12345);
|
|
|
|
|
|
|
|
$url = 'https://foobar';
|
|
|
|
$this->api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createJoinUrl')
|
|
|
|
->willReturn($url);
|
|
|
|
|
|
|
|
$response = $this->controller->index('Foo Bar', '', '', 'qwert');
|
|
|
|
|
|
|
|
$this->assertInstanceOf(TemplateResponse::class, $response);
|
|
|
|
$this->assertEquals('join', $response->getTemplateName());
|
|
|
|
$this->assertTrue($response->getParams()['passwordRequired']);
|
|
|
|
$this->assertTrue($response->getParams()['wrongPassword']);
|
|
|
|
|
|
|
|
$response = $this->controller->index('Foo Bar', '', '', 'asdf');
|
|
|
|
|
2020-08-25 13:17:35 +02:00
|
|
|
$this->assertInstanceOf(TemplateResponse::class, $response);
|
|
|
|
$this->assertEquals('forward', $response->getTemplateName());
|
|
|
|
$this->assertEquals($url, $response->getParams()['url']);
|
2020-06-10 13:55:21 +02:00
|
|
|
}
|
|
|
|
}
|