forked from External/greenlight
test bbb controller
This commit is contained in:
parent
246e7ec3ed
commit
b70ea41f4d
@ -21,7 +21,6 @@ class BbbController < ApplicationController
|
|||||||
before_action :load_and_authorize_room_owner!, only: [:end]
|
before_action :load_and_authorize_room_owner!, only: [:end]
|
||||||
|
|
||||||
skip_before_action :verify_authenticity_token, only: :callback
|
skip_before_action :verify_authenticity_token, only: :callback
|
||||||
before_action :validate_checksum, only: :callback
|
|
||||||
|
|
||||||
# GET /:resource/:id/join
|
# GET /:resource/:id/join
|
||||||
# GET /:resource/:room_id/:id/join
|
# GET /:resource/:room_id/:id/join
|
||||||
@ -104,9 +103,13 @@ class BbbController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /:resource/:id/callback
|
# POST /:resource/:room_id/:id/callback
|
||||||
# Endpoint for webhook calls from BigBlueButton
|
# Endpoint for webhook calls from BigBlueButton
|
||||||
def callback
|
def callback
|
||||||
|
# respond with 200 anyway so BigBlueButton knows the hook call was ok
|
||||||
|
# but abort execution
|
||||||
|
head(:ok) && return unless validate_checksum
|
||||||
|
|
||||||
begin
|
begin
|
||||||
data = JSON.parse(read_body(request))
|
data = JSON.parse(read_body(request))
|
||||||
treat_callback_event(data["event"])
|
treat_callback_event(data["event"])
|
||||||
@ -114,11 +117,10 @@ class BbbController < ApplicationController
|
|||||||
logger.error "Error parsing webhook data. Data: #{data}, exception: #{e.inspect}"
|
logger.error "Error parsing webhook data. Data: #{data}, exception: #{e.inspect}"
|
||||||
|
|
||||||
# respond with 200 anyway so BigBlueButton knows the hook call was ok
|
# respond with 200 anyway so BigBlueButton knows the hook call was ok
|
||||||
render head(:ok)
|
head(:ok) && return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /rooms/:id/end
|
|
||||||
# DELETE /rooms/:room_id/:id/end
|
# DELETE /rooms/:room_id/:id/end
|
||||||
def end
|
def end
|
||||||
load_and_authorize_room_owner!
|
load_and_authorize_room_owner!
|
||||||
@ -130,7 +132,7 @@ class BbbController < ApplicationController
|
|||||||
render_bbb_response bbb_res
|
render_bbb_response bbb_res
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /rooms/:id/recordings
|
# GET /rooms/:room_id/recordings
|
||||||
# GET /rooms/:room_id/:id/recordings
|
# GET /rooms/:room_id/:id/recordings
|
||||||
def recordings
|
def recordings
|
||||||
load_room!
|
load_room!
|
||||||
@ -144,7 +146,7 @@ class BbbController < ApplicationController
|
|||||||
render_bbb_response bbb_res, bbb_res[:recordings]
|
render_bbb_response bbb_res, bbb_res[:recordings]
|
||||||
end
|
end
|
||||||
|
|
||||||
# PATCH /rooms/:id/recordings/:record_id
|
# PATCH /rooms/:room_id/recordings/:record_id
|
||||||
# PATCH /rooms/:room_id/:id/recordings/:record_id
|
# PATCH /rooms/:room_id/:id/recordings/:record_id
|
||||||
def update_recordings
|
def update_recordings
|
||||||
published = params[:published] == 'true'
|
published = params[:published] == 'true'
|
||||||
@ -156,7 +158,7 @@ class BbbController < ApplicationController
|
|||||||
render_bbb_response bbb_res
|
render_bbb_response bbb_res
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /rooms/:id/recordings/:record_id
|
# DELETE /rooms/:room_id/recordings/:record_id
|
||||||
# DELETE /rooms/:room_id/:id/recordings/:record_id
|
# DELETE /rooms/:room_id/:id/recordings/:record_id
|
||||||
def delete_recordings
|
def delete_recordings
|
||||||
recording = bbb_get_recordings({recordID: params[:record_id]})[:recordings].first
|
recording = bbb_get_recordings({recordID: params[:record_id]})[:recordings].first
|
||||||
@ -259,10 +261,7 @@ class BbbController < ApplicationController
|
|||||||
|
|
||||||
if calculated_checksum != checksum
|
if calculated_checksum != checksum
|
||||||
logger.error "Checksum did not match. Calculated: #{calculated_checksum}, received: #{checksum}"
|
logger.error "Checksum did not match. Calculated: #{calculated_checksum}, received: #{checksum}"
|
||||||
|
false
|
||||||
# respond with 200 anyway so BigBlueButton knows the hook call was ok
|
|
||||||
# but abort execution
|
|
||||||
render head(:ok) && return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,13 +17,158 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class BbbControllerTest < ActionController::TestCase
|
class BbbControllerTest < ActionController::TestCase
|
||||||
# test "should get join" do
|
include BbbApi
|
||||||
# get :join
|
|
||||||
# assert_response :success
|
setup do
|
||||||
# end
|
@meeting_id = 'test_id'
|
||||||
#
|
@user = users :user1
|
||||||
# test "should get end" do
|
@name = 'test_name'
|
||||||
# get :close
|
@recording = 'test_recording'
|
||||||
# assert_response :success
|
end
|
||||||
# end
|
|
||||||
|
test "should get join URL from join for meeting" do
|
||||||
|
BbbController.any_instance.expects(:bbb_join_url)
|
||||||
|
.with() do |token, full_name, opts|
|
||||||
|
token == @meeting_id && full_name == @name && opts[:user_is_moderator]
|
||||||
|
end.returns(success_join_res('correct_url')).once
|
||||||
|
|
||||||
|
get :join, params: { id: @meeting_id, resource: 'meetings', name: @name }
|
||||||
|
assert_response :success
|
||||||
|
|
||||||
|
result = JSON.parse(response.body).deep_symbolize_keys
|
||||||
|
assert_equal 'correct_url', result[:response][:join_url]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get join URL from join for authenticated meeting" do
|
||||||
|
login @user
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_join_url)
|
||||||
|
.with() do |token, full_name, opts|
|
||||||
|
token == meeting_token(@user, @meeting_id) && opts[:wait_for_moderator] && opts[:user_is_moderator] && opts[:meeting_recorded]
|
||||||
|
end.returns(success_join_res('correct_url')).once
|
||||||
|
|
||||||
|
get :join, params: { room_id: @user.encrypted_id, id: @meeting_id, resource: 'rooms', name: @name }
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should wati for moderator on join for authenticated meeting when not room owner" do
|
||||||
|
BbbController.any_instance.expects(:bbb_join_url)
|
||||||
|
.with() do |token, full_name, opts|
|
||||||
|
opts[:wait_for_moderator] && !opts[:user_is_moderator]
|
||||||
|
end.returns(success_join_res('correct_url')).once
|
||||||
|
|
||||||
|
get :join, params: { room_id: @user.encrypted_id, id: @meeting_id, resource: 'rooms', name: @name }
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should end meeting" do
|
||||||
|
login @user
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_end_meeting)
|
||||||
|
.with() do |token|
|
||||||
|
token == meeting_token(@user, @meeting_id)
|
||||||
|
end.returns({status: :ok}).once
|
||||||
|
|
||||||
|
get :end, params: { room_id: @user.encrypted_id, id: @meeting_id, resource: 'rooms' }
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should not end meeting for unauthorized user" do
|
||||||
|
login users :user2
|
||||||
|
|
||||||
|
get :end, params: { room_id: @user.encrypted_id, id: @meeting_id, resource: 'rooms' }
|
||||||
|
assert_response :unauthorized
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get recordings" do
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_get_recordings)
|
||||||
|
.returns({status: :ok, recordings: []}).once
|
||||||
|
|
||||||
|
get :recordings, params: { room_id: @user.encrypted_id, resource: 'rooms' }
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update recording" do
|
||||||
|
login @user
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_get_recordings)
|
||||||
|
.returns({status: :ok, recordings: [{recordID: @recording}]}).once
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_update_recordings)
|
||||||
|
.returns({status: :ok}).once
|
||||||
|
|
||||||
|
patch :update_recordings, params: { room_id: @user.encrypted_id, resource: 'rooms', record_id: @recording }
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should delete recording" do
|
||||||
|
login @user
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_get_recordings)
|
||||||
|
.returns({status: :ok, recordings: [{recordID: @recording}]}).at_least_once
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_delete_recordings)
|
||||||
|
.returns({status: :ok}).once
|
||||||
|
|
||||||
|
delete :delete_recordings, params: { room_id: @user.encrypted_id, resource: 'rooms', record_id: @recording }
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should not delete recording if unauthorized" do
|
||||||
|
login users :user2
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_get_recordings)
|
||||||
|
.returns({status: :ok, recordings: [{recordID: @recording}]}).at_least_once
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_delete_recordings)
|
||||||
|
.returns({status: :ok}).once
|
||||||
|
|
||||||
|
delete :delete_recordings, params: { room_id: @user.encrypted_id, resource: 'rooms', record_id: @recording }
|
||||||
|
assert_response :unauthorized
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should not delete recording if not owner" do
|
||||||
|
login @user
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_get_recordings)
|
||||||
|
.returns({status: :ok, recordings: []}).once
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:bbb_update_recordings)
|
||||||
|
.returns({status: :ok}).once
|
||||||
|
|
||||||
|
patch :delete_recordings, params: { room_id: @user.encrypted_id, resource: 'rooms', record_id: @recording }
|
||||||
|
assert_response :not_found
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should return success on invalid checksum" do
|
||||||
|
|
||||||
|
BbbController.any_instance.expects(:treat_callback_event).never
|
||||||
|
|
||||||
|
post :callback, params: { room_id: @user.encrypted_id, resource: 'rooms', id: @meeting_id, event: {} }
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO fix this test
|
||||||
|
# test "should send notification on valid callback" do
|
||||||
|
#
|
||||||
|
# BbbController.any_instance.expects(:treat_callback_event).once
|
||||||
|
#
|
||||||
|
# BbbController.any_instance.expects(:validate_checksum)
|
||||||
|
# .returns(true).once
|
||||||
|
#
|
||||||
|
# post :callback, params: { room_id: @user.encrypted_id, resource: 'rooms', id: @meeting_id, event: {} }
|
||||||
|
# assert_response :success
|
||||||
|
# end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def meeting_token(user, id)
|
||||||
|
"#{user.encrypted_id}-#{id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def login(user)
|
||||||
|
session[:user_id] = user.id
|
||||||
|
@current_user = user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user