Null-DRM-Official/apps/pkg/capture/score_test.go
404errordeveloper 2fa8f2435f Initial commit: Null DRM Official
Capture, decrypt, and restream toolkit with compiled-in app modules
(RTE, TG4, BBC), on-device MITM proxy, streamd control plane, and www.
BBC module.yaml is published (clear streams); other module values stay local.
2026-10-06 00:25:35 +02:00

72 lines
2.4 KiB
Go

package capture
import "testing"
// provider-shaped config, supplied the way a module would.
func testScoreCfg() ScoreCfg {
return DefaultScoreCfg().Merge(ScoreCfg{
Deny: []string{"feed.entertainment", "metrics.example", "noise.example"},
Hosts: []string{"live.example.com", "fastly.live.example.com"},
})
}
func TestScoreCfgScore(t *testing.T) {
cfg := testScoreCfg()
cases := []struct {
url string
want string // "pos" or "neg"
}{
{"https://feed.entertainment.tv.example.eu/f/1uC-gC/prd-all-schedules?byListingTime=1~2", "neg"},
{"https://metrics.example.com/v2/tracker?foo=.m3u8", "neg"},
{"https://cdn.example.com/smarttv/playback_config.json", "neg"},
{"https://live.example.com/live/foo/manifest.mpd", "pos"},
{"https://fastly.live.example.com/x/playlist-hls.m3u8", "pos"},
{"https://unknown-host.test/video/master.m3u8", "pos"},
{"https://unknown-host.test/live/vc11.isml/Manifest", "pos"},
}
for _, tc := range cases {
sc := cfg.Score(tc.url)
if tc.want == "pos" && sc <= 0 {
t.Errorf("score(%q)=%d, want > 0", tc.url, sc)
}
if tc.want == "neg" && sc > 0 {
t.Errorf("score(%q)=%d, want <= 0", tc.url, sc)
}
}
}
// A known provider host must outrank a bare manifest on an unknown host, so the
// best candidate in a noisy MITM log is the provider's own origin.
func TestScoreCfgPrefersKnownHost(t *testing.T) {
cfg := testScoreCfg()
known := cfg.Score("https://live.example.com/live/foo/manifest.mpd")
unknown := cfg.Score("https://somewhere.test/live/foo/manifest.mpd")
if known <= unknown {
t.Fatalf("known host %d should outrank unknown host %d", known, unknown)
}
}
func TestDefaultScoreCfgNeedsNoProviderHosts(t *testing.T) {
cfg := DefaultScoreCfg()
if cfg.Score("https://anything.test/playlist.m3u8") <= 0 {
t.Fatal("format-level scoring must work without provider hosts")
}
if cfg.Score("https://anything.test/api/schedules?x=1") > 0 {
t.Fatal("schedule feeds must score out with the baseline config")
}
}
func TestHasUsefulIgnoresSchedulesMPD(t *testing.T) {
hints := DefaultPassiveHints()
hints.Score = testScoreCfg()
cap := Data{
"mpd": "https://feed.entertainment.tv.example.eu/f/1uC-gC/prd-all-schedules?byListingTime=1~2",
}
if hasUseful(cap, hints) {
t.Fatal("schedules feed must not count as useful capture")
}
cap["license_url"] = "https://widevine.example/license"
if !hasUseful(cap, hints) {
t.Fatal("license_url should count as useful")
}
}