@@ -16,6 +16,7 @@ import (
1616
1717 "github.com/bluenviron/mediacommon/v2/pkg/formats/fmp4"
1818 "github.com/bluenviron/mediacommon/v2/pkg/formats/mp4"
19+ "github.com/bluenviron/mediamtx/internal/auth"
1920 "github.com/bluenviron/mediamtx/internal/conf"
2021 "github.com/bluenviron/mediamtx/internal/test"
2122 "github.com/stretchr/testify/require"
@@ -320,3 +321,51 @@ func TestOnListCachedDuration(t *testing.T) {
320321 },
321322 }, out )
322323}
324+
325+ func TestOnListAuthError (t * testing.T ) {
326+ dir , err := os .MkdirTemp ("" , "mediamtx-playback" )
327+ require .NoError (t , err )
328+ defer os .RemoveAll (dir )
329+
330+ s := & Server {
331+ Address : "127.0.0.1:9996" ,
332+ ReadTimeout : conf .Duration (10 * time .Second ),
333+ PathConfs : map [string ]* conf.Path {
334+ "mypath" : {
335+ Name : "mypath" ,
336+ RecordPath : filepath .Join (dir , "%path/%Y-%m-%d_%H-%M-%S-%f" ),
337+ },
338+ },
339+ AuthManager : & test.AuthManager {
340+ AuthenticateImpl : func (_ * auth.Request ) error {
341+ return auth.Error {Wrapped : fmt .Errorf ("auth error" )}
342+ },
343+ RefreshJWTJWKSImpl : func () {
344+ },
345+ },
346+ Parent : test .NilLogger ,
347+ }
348+ err = s .Initialize ()
349+ require .NoError (t , err )
350+ defer s .Close ()
351+
352+ u , err := url .Parse ("http://myuser:mypass@localhost:9996/list" )
353+ require .NoError (t , err )
354+
355+ v := url.Values {}
356+ v .Set ("path" , "mypath" )
357+ u .RawQuery = v .Encode ()
358+
359+ req , err := http .NewRequest (http .MethodGet , u .String (), nil )
360+ require .NoError (t , err )
361+
362+ start := time .Now ()
363+
364+ res , err := http .DefaultClient .Do (req )
365+ require .NoError (t , err )
366+ defer res .Body .Close ()
367+
368+ require .Greater (t , time .Since (start ), 2 * time .Second )
369+
370+ require .Equal (t , http .StatusUnauthorized , res .StatusCode )
371+ }
0 commit comments