feat: complete split camera credentials (#50)

This commit is contained in:
ila
2026-08-13 12:23:43 +08:00
parent d0e947ca02
commit 74070aa0f9
@@ -43,7 +43,8 @@ func TestProfilesDiscoversMediaServiceAndUsesDigest(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(profiles) != 1 || profiles[0].Width != 1920 || profiles[0].StreamURI != "rtsp://camera.invalid/live" {
serverURL, _ := url.Parse(server.URL)
if len(profiles) != 1 || profiles[0].Width != 1920 || profiles[0].StreamURI != "rtsp://"+serverURL.Hostname()+"/live" {
t.Fatalf("profiles=%#v", profiles)
}
if digestRequests.Load() != 2 {
@@ -80,6 +81,19 @@ func TestNormalizeServiceEndpoint(t *testing.T) {
}
}
func TestNormalizeStreamURI(t *testing.T) {
got, err := normalizeStreamURI("http://192.0.2.10:80/onvif/device_service", "rtsp://unusable.local:8554/live/main?channel=1")
if err != nil || got != "rtsp://192.0.2.10:8554/live/main?channel=1" {
t.Fatalf("got=%q err=%v", got, err)
}
if _, err := normalizeStreamURI("http://camera.local/onvif", "rtsp://user:pass@camera.local/live"); err == nil {
t.Fatal("credential stream URI accepted")
}
if _, err := normalizeStreamURI("http://camera.local/onvif", "http://camera.local/live"); err == nil {
t.Fatal("non-RTSP URI accepted")
}
}
func TestRejectUnsupportedDigestChallenge(t *testing.T) {
for _, challenge := range []string{
`Digest realm="camera", nonce="n", algorithm=SHA-512, qop="auth"`,