@@ -104,6 +104,7 @@ def test_password_not_required_when_login_disabled(monkeypatch):
104104def test_index_lists_streams_from_api (monkeypatch ):
105105 with patch ("app.Lrtmp2Client" ) as mock_client_cls :
106106 mock_client = mock_client_cls .return_value
107+ mock_client .health .return_value = {"rtmps_enabled" : False }
107108 mock_client .list_streams .return_value = [
108109 {
109110 "id" : "s1" ,
@@ -144,6 +145,156 @@ def test_index_lists_streams_from_api(monkeypatch):
144145 mock_client .list_streams .assert_called_once ()
145146
146147
148+ def test_index_shows_rtmps_urls_when_server_reports_enabled (monkeypatch ):
149+ with patch ("app.Lrtmp2Client" ) as mock_client_cls :
150+ mock_client = mock_client_cls .return_value
151+ mock_client .health .return_value = {
152+ "rtmp_port" : 1935 ,
153+ "rtmps_enabled" : True ,
154+ "rtmps_port" : 1936 ,
155+ }
156+ mock_client .list_streams .return_value = [
157+ {
158+ "id" : "s1" ,
159+ "name" : "Stream One" ,
160+ "app" : "live" ,
161+ "publish_key" : "pub_k" ,
162+ "play_key" : "pl_k" ,
163+ "stats_key" : "st_k" ,
164+ "players" : [
165+ {"id" : "vi_s1" , "name" : "Player 1" , "play_key" : "pl_k" }
166+ ],
167+ "enabled" : True ,
168+ "created_at" : 1 ,
169+ }
170+ ]
171+
172+ import app as app_module
173+
174+ monkeypatch .setattr (app_module .Config , "SESSION_COOKIE_SECURE" , False )
175+ monkeypatch .setattr (app_module .Config , "LRTMP2_RTMPS_PORT" , "1936" )
176+ application = app_module .create_app ()
177+ application .config ["TESTING" ] = True
178+ application .config ["WTF_CSRF_ENABLED" ] = False
179+ client = application .test_client ()
180+ client .post (
181+ "/login" ,
182+ data = {"username" : "admin" , "password" : os .environ ["PASSWORD" ]},
183+ )
184+
185+ r = client .get ("/" )
186+ assert r .status_code == 200
187+ assert b"RTMPS enabled" in r .data
188+ assert b"rtmps://localhost:1936/live" in r .data
189+
190+
191+ def test_index_prefers_public_rtmps_port_over_health_bind_port (monkeypatch ):
192+ with patch ("app.Lrtmp2Client" ) as mock_client_cls :
193+ mock_client = mock_client_cls .return_value
194+ mock_client .health .return_value = {
195+ "rtmp_port" : 1935 ,
196+ "rtmps_enabled" : True ,
197+ "rtmps_port" : 1936 ,
198+ }
199+ mock_client .list_streams .return_value = [
200+ {
201+ "id" : "s1" ,
202+ "name" : "Stream One" ,
203+ "app" : "live" ,
204+ "publish_key" : "pub_k" ,
205+ "play_key" : "pl_k" ,
206+ "stats_key" : "st_k" ,
207+ "players" : [
208+ {"id" : "vi_s1" , "name" : "Player 1" , "play_key" : "pl_k" }
209+ ],
210+ "enabled" : True ,
211+ "created_at" : 1 ,
212+ }
213+ ]
214+
215+ import app as app_module
216+
217+ monkeypatch .setattr (app_module .Config , "SESSION_COOKIE_SECURE" , False )
218+ monkeypatch .setattr (app_module .Config , "LRTMP2_RTMPS_PORT" , "443" )
219+ application = app_module .create_app ()
220+ application .config ["TESTING" ] = True
221+ application .config ["WTF_CSRF_ENABLED" ] = False
222+ client = application .test_client ()
223+ client .post (
224+ "/login" ,
225+ data = {"username" : "admin" , "password" : os .environ ["PASSWORD" ]},
226+ )
227+
228+ r = client .get ("/" )
229+ assert r .status_code == 200
230+ assert b"RTMPS enabled" in r .data
231+ assert b"rtmps://localhost:443/live" in r .data
232+ assert b"rtmps://localhost:1936/live" not in r .data
233+
234+
235+ def test_index_hides_rtmps_urls_when_server_reports_disabled (monkeypatch ):
236+ with patch ("app.Lrtmp2Client" ) as mock_client_cls :
237+ mock_client = mock_client_cls .return_value
238+ mock_client .health .return_value = {"rtmps_enabled" : False }
239+ mock_client .list_streams .return_value = [
240+ {
241+ "id" : "s1" ,
242+ "name" : "Stream One" ,
243+ "app" : "live" ,
244+ "publish_key" : "pub_k" ,
245+ "play_key" : "pl_k" ,
246+ "stats_key" : "st_k" ,
247+ "players" : [
248+ {"id" : "vi_s1" , "name" : "Player 1" , "play_key" : "pl_k" }
249+ ],
250+ "enabled" : True ,
251+ "created_at" : 1 ,
252+ }
253+ ]
254+
255+ import app as app_module
256+
257+ monkeypatch .setattr (app_module .Config , "SESSION_COOKIE_SECURE" , False )
258+ application = app_module .create_app ()
259+ application .config ["TESTING" ] = True
260+ application .config ["WTF_CSRF_ENABLED" ] = False
261+ client = application .test_client ()
262+ client .post (
263+ "/login" ,
264+ data = {"username" : "admin" , "password" : os .environ ["PASSWORD" ]},
265+ )
266+
267+ r = client .get ("/" )
268+ assert r .status_code == 200
269+ assert b"RTMPS disabled" in r .data
270+ assert b"rtmps://" not in r .data
271+
272+
273+ def test_index_treats_health_failure_as_rtmps_disabled (monkeypatch ):
274+ with patch ("app.Lrtmp2Client" ) as mock_client_cls :
275+ from lrtmp2_client import Lrtmp2ApiError
276+
277+ mock_client = mock_client_cls .return_value
278+ mock_client .health .side_effect = Lrtmp2ApiError ("unreachable" )
279+ mock_client .list_streams .return_value = []
280+
281+ import app as app_module
282+
283+ monkeypatch .setattr (app_module .Config , "SESSION_COOKIE_SECURE" , False )
284+ application = app_module .create_app ()
285+ application .config ["TESTING" ] = True
286+ application .config ["WTF_CSRF_ENABLED" ] = False
287+ client = application .test_client ()
288+ client .post (
289+ "/login" ,
290+ data = {"username" : "admin" , "password" : os .environ ["PASSWORD" ]},
291+ )
292+
293+ r = client .get ("/" )
294+ assert r .status_code == 200
295+ assert b"RTMPS disabled" in r .data
296+
297+
147298def test_create_stream_shows_keys_without_session_storage (monkeypatch ):
148299 mock_result = {
149300 "id" : "new-stream" ,
@@ -163,6 +314,7 @@ def test_create_stream_shows_keys_without_session_storage(monkeypatch):
163314
164315 with patch ("app.Lrtmp2Client" ) as mock_client_cls :
165316 mock_client = mock_client_cls .return_value
317+ mock_client .health .return_value = {"rtmps_enabled" : False }
166318 mock_client .create_stream .return_value = mock_result
167319 mock_client .list_streams .return_value = [mock_result ]
168320
@@ -199,6 +351,7 @@ def test_delete_stream_surfaces_api_error(monkeypatch):
199351 from lrtmp2_client import Lrtmp2ApiError
200352
201353 mock_client = mock_client_cls .return_value
354+ mock_client .health .return_value = {"rtmps_enabled" : False }
202355 mock_client .list_streams .return_value = []
203356 mock_client .delete_stream .side_effect = Lrtmp2ApiError ("server down" )
204357
0 commit comments