mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
harden lastfm playlist parsing and url validation
This commit is contained in:
@@ -94,6 +94,28 @@ func TestParseLastFMArgsOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseLastFMArgsRejectsNonLastFMURL(t *testing.T) {
|
||||
_, err := parseLastFMArgs([]string{"https://example.com/user/x/playlists/123"}, "qobuz", "")
|
||||
if err == nil || !strings.Contains(strings.ToLower(err.Error()), "last.fm") {
|
||||
t.Fatalf("expected last.fm url validation error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsValidLastFMPlaylistURL(t *testing.T) {
|
||||
if !isValidLastFMPlaylistURL("https://www.last.fm/user/x/playlists/123") {
|
||||
t.Fatalf("expected canonical last.fm playlist url to be valid")
|
||||
}
|
||||
if !isValidLastFMPlaylistURL("http://last.fm/user/x/playlists/123") {
|
||||
t.Fatalf("expected http last.fm playlist url to be valid")
|
||||
}
|
||||
if isValidLastFMPlaylistURL("ftp://last.fm/user/x/playlists/123") {
|
||||
t.Fatalf("expected non-http scheme to be invalid")
|
||||
}
|
||||
if isValidLastFMPlaylistURL("https://example.com/user/x/playlists/123") {
|
||||
t.Fatalf("expected non-last.fm host to be invalid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractLastFMPlaylistInfoAndPairs(t *testing.T) {
|
||||
html := `<h1 class="playlisting-playlist-header-title">Road & Rain</h1>
|
||||
<div data-playlisting-entry-count="2"></div>
|
||||
@@ -191,6 +213,17 @@ func TestExtractLastFMTracksFromMirrorMarkdown(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractLastFMTracksFromMirrorMarkdownLowercasePlayTrack(t *testing.T) {
|
||||
md := `Title: My Playlist | user playlists | Last.fm
|
||||
| Play | Image | Loved | Name | Artist name | Buy | Options | Duration |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| [play track](https://x) | [img](https://i) | x | [Song A](https://a) | [Artist A](https://aa) | | | 3:00 |`
|
||||
_, tracks := extractLastFMTracksFromMirrorMarkdown(md)
|
||||
if len(tracks) != 1 {
|
||||
t.Fatalf("tracks len = %d, want 1", len(tracks))
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSearchArgsAllowsFirstAndOutputFileButCallerCanReject(t *testing.T) {
|
||||
opts, err := parseSearchArgs([]string{"q", "--first", "--output-file", "/tmp/out.json"}, 20)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user