1
0
Fork 0
forked from External/mediamtx

restore sending session ID to external authentication (#1871)

this fixes a regression introduced in v0.23.0
This commit is contained in:
Alessandro Ros 2023-05-28 13:45:19 +02:00 committed by GitHub
parent 128f2d3e20
commit 7d04742426
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 32 deletions

View file

@ -69,6 +69,7 @@ func externalAuth(
Password: password,
Path: path,
Protocol: string(protocol),
ID: id,
Action: func() string {
if publish {
return "publish"

View file

@ -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&param=value" &&
in.Query != "user=testpublisher&pass=testpass&param=value" &&

View file

@ -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&param=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")

View file

@ -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},
)

View file

@ -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()
}