Browse Source

update external authentication tests

pull/846/head
aler9 4 years ago committed by Alessandro Ros
parent
commit
c208cb9aff
  1. 10
      internal/core/hls_server_test.go
  2. 6
      internal/core/rtmp_server_test.go
  3. 6
      internal/core/rtsp_server_test.go

10
internal/core/hls_server_test.go

@ -48,6 +48,7 @@ func (ts *testHTTPAuthenticator) onAuth(ctx *gin.Context) { @@ -48,6 +48,7 @@ func (ts *testHTTPAuthenticator) onAuth(ctx *gin.Context) {
Password string `json:"password"`
Path string `json:"path"`
Action string `json:"action"`
Query string `json:"query"`
}
err := json.NewDecoder(ctx.Request.Body).Decode(&in)
if err != nil {
@ -66,7 +67,10 @@ func (ts *testHTTPAuthenticator) onAuth(ctx *gin.Context) { @@ -66,7 +67,10 @@ func (ts *testHTTPAuthenticator) onAuth(ctx *gin.Context) {
in.User != user ||
in.Password != "testpass" ||
in.Path != "teststream" ||
in.Action != ts.action {
in.Action != ts.action ||
(in.Query != "user=testreader&pass=testpass&param=value" &&
in.Query != "user=testpublisher&pass=testpass&param=value" &&
in.Query != "param=value") {
ctx.AbortWithStatus(http.StatusBadRequest)
return
}
@ -156,7 +160,7 @@ func TestHLSServerAuth(t *testing.T) { @@ -156,7 +160,7 @@ func TestHLSServerAuth(t *testing.T) {
"-i", "emptyvideo.mkv",
"-c", "copy",
"-f", "rtsp",
"rtsp://testpublisher:testpass@127.0.0.1:8554/teststream",
"rtsp://testpublisher:testpass@127.0.0.1:8554/teststream?param=value",
})
require.NoError(t, err)
defer cnt1.close()
@ -178,7 +182,7 @@ func TestHLSServerAuth(t *testing.T) { @@ -178,7 +182,7 @@ func TestHLSServerAuth(t *testing.T) {
usr = "testreader2"
}
res, err := http.Get("http://" + usr + ":testpass@127.0.0.1:8888/teststream/index.m3u8")
res, err := http.Get("http://" + usr + ":testpass@127.0.0.1:8888/teststream/index.m3u8?param=value")
require.NoError(t, err)
defer res.Body.Close()

6
internal/core/rtmp_server_test.go

@ -120,7 +120,7 @@ func TestRTMPServerAuth(t *testing.T) { @@ -120,7 +120,7 @@ func TestRTMPServerAuth(t *testing.T) {
"-i", "emptyvideo.mkv",
"-c", "copy",
"-f", "flv",
"rtmp://127.0.0.1/teststream?user=testpublisher&pass=testpass",
"rtmp://127.0.0.1/teststream?user=testpublisher&pass=testpass&param=value",
})
require.NoError(t, err)
defer cnt1.close()
@ -135,7 +135,7 @@ func TestRTMPServerAuth(t *testing.T) { @@ -135,7 +135,7 @@ func TestRTMPServerAuth(t *testing.T) {
}
conn, err := rtmp.DialContext(context.Background(),
"rtmp://127.0.0.1/teststream?user=testreader&pass=testpass")
"rtmp://127.0.0.1/teststream?user=testreader&pass=testpass&param=value")
require.NoError(t, err)
defer conn.Close()
@ -189,7 +189,7 @@ func TestRTMPServerAuthFail(t *testing.T) { @@ -189,7 +189,7 @@ func TestRTMPServerAuthFail(t *testing.T) {
"-i", "emptyvideo.mkv",
"-c", "copy",
"-f", "flv",
"rtmp://localhost/teststream?user=testuser2&pass=testpass",
"rtmp://localhost/teststream?user=testuser2&pass=testpass&param=value",
})
require.NoError(t, err)
defer cnt1.close()

6
internal/core/rtsp_server_test.go

@ -236,7 +236,7 @@ func TestRTSPServerAuth(t *testing.T) { @@ -236,7 +236,7 @@ func TestRTSPServerAuth(t *testing.T) {
source := gortsplib.Client{}
err = source.StartPublishing(
"rtsp://testpublisher:testpass@127.0.0.1:8554/teststream",
"rtsp://testpublisher:testpass@127.0.0.1:8554/teststream?param=value",
gortsplib.Tracks{track})
require.NoError(t, err)
defer source.Close()
@ -251,7 +251,7 @@ func TestRTSPServerAuth(t *testing.T) { @@ -251,7 +251,7 @@ func TestRTSPServerAuth(t *testing.T) {
reader := gortsplib.Client{}
err = reader.StartReading("rtsp://testreader:testpass@127.0.0.1:8554/teststream")
err = reader.StartReading("rtsp://testreader:testpass@127.0.0.1:8554/teststream?param=value")
require.NoError(t, err)
defer reader.Close()
})
@ -407,7 +407,7 @@ func TestRTSPServerAuthFail(t *testing.T) { @@ -407,7 +407,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
c := gortsplib.Client{}
err = c.StartPublishing(
"rtsp://testpublisher2:testpass@localhost:8554/teststream",
"rtsp://testpublisher2:testpass@localhost:8554/teststream?param=value",
gortsplib.Tracks{track},
)
require.EqualError(t, err, "bad status code: 401 (Unauthorized)")

Loading…
Cancel
Save