diff --git a/internal/core/authentication.go b/internal/core/authentication.go index 8d2e0d41..671f570b 100644 --- a/internal/core/authentication.go +++ b/internal/core/authentication.go @@ -69,6 +69,7 @@ func externalAuth( Password: password, Path: path, Protocol: string(protocol), + ID: id, Action: func() string { if publish { return "publish" diff --git a/internal/core/hls_manager_test.go b/internal/core/hls_manager_test.go index 62651777..3d9a454f 100644 --- a/internal/core/hls_manager_test.go +++ b/internal/core/hls_manager_test.go @@ -24,11 +24,9 @@ type testHTTPAuthenticator struct { s *http.Server } -func newTestHTTPAuthenticator(protocol string, action string) (*testHTTPAuthenticator, error) { +func newTestHTTPAuthenticator(t *testing.T, protocol string, action string) *testHTTPAuthenticator { ln, err := net.Listen("tcp", "127.0.0.1:9120") - if err != nil { - return nil, err - } + require.NoError(t, err) ts := &testHTTPAuthenticator{ protocol: protocol, @@ -41,7 +39,7 @@ func newTestHTTPAuthenticator(protocol string, action string) (*testHTTPAuthenti ts.s = &http.Server{Handler: router} go ts.s.Serve(ln) - return ts, nil + return ts } func (ts *testHTTPAuthenticator) close() { @@ -55,6 +53,7 @@ func (ts *testHTTPAuthenticator) onAuth(ctx *gin.Context) { Password string `json:"password"` Path string `json:"path"` Protocol string `json:"protocol"` + ID string `json:"id"` Action string `json:"action"` Query string `json:"query"` } @@ -76,6 +75,7 @@ func (ts *testHTTPAuthenticator) onAuth(ctx *gin.Context) { in.Password != "testpass" || in.Path != "teststream" || in.Protocol != ts.protocol || + in.ID == "" || in.Action != ts.action || (in.Query != "user=testreader&pass=testpass¶m=value" && in.Query != "user=testpublisher&pass=testpass¶m=value" && diff --git a/internal/core/rtmp_server_test.go b/internal/core/rtmp_server_test.go index 9994078c..76fa332b 100644 --- a/internal/core/rtmp_server_test.go +++ b/internal/core/rtmp_server_test.go @@ -209,9 +209,7 @@ func TestRTMPServerAuth(t *testing.T) { var a *testHTTPAuthenticator if ca == "external" { - var err error - a, err = newTestHTTPAuthenticator("rtmp", "publish") - require.NoError(t, err) + a = newTestHTTPAuthenticator(t, "rtmp", "publish") } u1, err := url.Parse("rtmp://127.0.0.1:1935/teststream?user=testpublisher&pass=testpass¶m=value") @@ -245,8 +243,7 @@ func TestRTMPServerAuth(t *testing.T) { if ca == "external" { a.close() - a, err = newTestHTTPAuthenticator("rtmp", "read") - require.NoError(t, err) + a = newTestHTTPAuthenticator(t, "rtmp", "read") defer a.close() } @@ -330,8 +327,7 @@ func TestRTMPServerAuthFail(t *testing.T) { require.Equal(t, true, ok) defer p.Close() - a, err := newTestHTTPAuthenticator("rtmp", "publish") - require.NoError(t, err) + a := newTestHTTPAuthenticator(t, "rtmp", "publish") defer a.close() u1, err := url.Parse("rtmp://127.0.0.1:1935/teststream?user=testuser1&pass=testpass") diff --git a/internal/core/rtsp_server_test.go b/internal/core/rtsp_server_test.go index 2a276101..68bd3bd8 100644 --- a/internal/core/rtsp_server_test.go +++ b/internal/core/rtsp_server_test.go @@ -71,9 +71,7 @@ func TestRTSPServerAuth(t *testing.T) { var a *testHTTPAuthenticator if ca == "external" { - var err error - a, err = newTestHTTPAuthenticator("rtsp", "publish") - require.NoError(t, err) + a = newTestHTTPAuthenticator(t, "rtsp", "publish") } medi := testMediaH264 @@ -88,9 +86,7 @@ func TestRTSPServerAuth(t *testing.T) { if ca == "external" { a.close() - var err error - a, err = newTestHTTPAuthenticator("rtsp", "read") - require.NoError(t, err) + a = newTestHTTPAuthenticator(t, "rtsp", "read") defer a.close() } @@ -257,15 +253,14 @@ func TestRTSPServerAuthFail(t *testing.T) { require.Equal(t, true, ok) defer p.Close() - a, err := newTestHTTPAuthenticator("rtsp", "publish") - require.NoError(t, err) + a := newTestHTTPAuthenticator(t, "rtsp", "publish") defer a.close() medi := testMediaH264 c := gortsplib.Client{} - err = c.StartRecording( + err := c.StartRecording( "rtsp://testpublisher2:testpass@localhost:8554/teststream?param=value", media.Medias{medi}, ) diff --git a/internal/highleveltests/hls_server_test.go b/internal/highleveltests/hls_server_test.go index 3ca33c11..dcb631f4 100644 --- a/internal/highleveltests/hls_server_test.go +++ b/internal/highleveltests/hls_server_test.go @@ -21,11 +21,9 @@ type testHTTPAuthenticator struct { s *http.Server } -func newTestHTTPAuthenticator(action string) (*testHTTPAuthenticator, error) { +func newTestHTTPAuthenticator(t *testing.T, action string) *testHTTPAuthenticator { ln, err := net.Listen("tcp", "127.0.0.1:9120") - if err != nil { - return nil, err - } + require.NoError(t, err) ts := &testHTTPAuthenticator{ action: action, @@ -37,7 +35,7 @@ func newTestHTTPAuthenticator(action string) (*testHTTPAuthenticator, error) { ts.s = &http.Server{Handler: router} go ts.s.Serve(ln) - return ts, nil + return ts } func (ts *testHTTPAuthenticator) close() { @@ -138,9 +136,7 @@ func TestHLSServerAuth(t *testing.T) { var a *testHTTPAuthenticator if mode == "external" { - var err error - a, err = newTestHTTPAuthenticator("publish") - require.NoError(t, err) + a = newTestHTTPAuthenticator(t, "publish") } cnt1, err := newContainer("ffmpeg", "source", []string{ @@ -158,9 +154,7 @@ func TestHLSServerAuth(t *testing.T) { if mode == "external" { a.close() - var err error - a, err = newTestHTTPAuthenticator("read") - require.NoError(t, err) + a = newTestHTTPAuthenticator(t, "read") defer a.close() }