From 56b66bbf6769082d2782d5328a0777072fce9422 Mon Sep 17 00:00:00 2001 From: Bilal Date: Mon, 29 Jun 2020 15:18:31 +0200 Subject: [PATCH 1/2] handle webhook request for unknown broadcast --- app/controllers/stream_notifications_controller.rb | 6 ++++-- spec/controllers/stream_notifications_controller_spec.rb | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/stream_notifications_controller.rb b/app/controllers/stream_notifications_controller.rb index 11cf20d..7b47a94 100644 --- a/app/controllers/stream_notifications_controller.rb +++ b/app/controllers/stream_notifications_controller.rb @@ -60,10 +60,12 @@ class StreamNotificationsController < ApplicationController def set_broadcast if notification_type == "video.asset.static_renditions.ready" live_stream_id = notification.dig(:stream_notification, :data, :live_stream_id) - @broadcast = Broadcast.find_by!(stream_uid: live_stream_id) + @broadcast = Broadcast.find_by(stream_uid: live_stream_id) else - @broadcast = Broadcast.find_by!(stream_uid: notification_object_id) + @broadcast = Broadcast.find_by(stream_uid: notification_object_id) end + + head :ok if @broadcast.nil? end def notify_users diff --git a/spec/controllers/stream_notifications_controller_spec.rb b/spec/controllers/stream_notifications_controller_spec.rb index 66f948e..8a9211f 100644 --- a/spec/controllers/stream_notifications_controller_spec.rb +++ b/spec/controllers/stream_notifications_controller_spec.rb @@ -7,6 +7,7 @@ RSpec.describe StreamNotificationsController, type: :controller do let(:active_status) { {type: "video.live_stream.active", object: { id: "mux_stream" }} } let(:disconnected_status) { {type: "video.live_stream.disconnected", object: { id: "mux_stream" }} } let(:idle_status) { {type: "video.live_stream.idle", object: { id: "mux_stream" }} } + let(:idle_status_for_unknown_broadcast) { {type: "video.live_stream.idle", object: { id: "unknown-id" }} } let(:asset_ready) { { type: "video.asset.static_renditions.ready", object: { id: "asset_uid" }, @@ -59,6 +60,12 @@ RSpec.describe StreamNotificationsController, type: :controller do expect(BroadcastsChannel).to have_received(:stream_recording_ready) end + + it "returns OK response even for non-existing broadcast" do + post :create, params: idle_status_for_unknown_broadcast + + expect(response).to be_successful + end end after do -- 2.47.3 From 848c02d88fe8d0678bb10f5b524fe043e2b62eb7 Mon Sep 17 00:00:00 2001 From: Bilal Date: Mon, 29 Jun 2020 17:10:06 +0200 Subject: [PATCH 2/2] add log when broadcast is ignored --- app/controllers/stream_notifications_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/stream_notifications_controller.rb b/app/controllers/stream_notifications_controller.rb index 7b47a94..c68fbce 100644 --- a/app/controllers/stream_notifications_controller.rb +++ b/app/controllers/stream_notifications_controller.rb @@ -65,6 +65,10 @@ class StreamNotificationsController < ApplicationController @broadcast = Broadcast.find_by(stream_uid: notification_object_id) end + if @broadcast.nil? + logger.info "Ignoring broadcast from other environment. Type = #{notification_type}. Id = #{live_stream_id} / #{notification_object_id}" + head :ok + end head :ok if @broadcast.nil? end -- 2.47.3