Something went wrong. Try again.
Self-hosted web interface and downloader for Qobuz.
downloader self-hosted music qobuz
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153package bundle
import ( "testing")
// fakeBundleJS is a minimal snippet of bundle.js with all the patterns we extract.// Seeds have no mid-string = padding (base64 of 24-byte strings = 32 chars with no =).// Joined = 96 chars, trim 44 = 52 chars of valid base64.const fakeBundleJS = `var production:{api:{appId:"123456789",appSecret:"abcdef1234567890abcdef1234567890"}}a.initialSeed("QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB",window.utimezone.london)a.initialSeed("RERERERERERERERERERERERERERERERE",window.utimezone.berlin)name:"timezones/London",info:"QkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJC",extras:"Q0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0ND"name:"timezones/Berlin",info:"RUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVF",extras:"RkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZG"privateKey: "mySecretKey123"`
func TestBundleAppID(t *testing.T) { b := &Bundle{content: fakeBundleJS} id, err := b.AppID() if err != nil { t.Fatalf("AppID: %v", err) } if id != "123456789" { t.Errorf("AppID = %q, want %q", id, "123456789") }}
func TestBundleAppID_NotFound(t *testing.T) { b := &Bundle{content: "no app id here"} _, err := b.AppID() if err == nil { t.Error("expected error when app_id not in bundle") }}
func TestBundlePrivateKey(t *testing.T) { b := &Bundle{content: fakeBundleJS} key := b.PrivateKey() if key != "mySecretKey123" { t.Errorf("PrivateKey = %q, want %q", key, "mySecretKey123") }}
func TestBundlePrivateKey_Missing(t *testing.T) { b := &Bundle{content: "no private key here"} key := b.PrivateKey() if key != "" { t.Errorf("expected empty key, got %q", key) }}
func TestBundleSecrets_ReturnsMap(t *testing.T) { b := &Bundle{content: fakeBundleJS} secrets, err := b.Secrets() if err != nil { t.Fatalf("Secrets: %v", err) } if len(secrets) == 0 { t.Error("expected at least one secret") } // All secrets must be non-empty strings for tz, sec := range secrets { if sec == "" { t.Errorf("timezone %q has empty secret", tz) } }}
func TestBundleSecrets_NoSeeds(t *testing.T) { b := &Bundle{content: "no seeds here at all"} _, err := b.Secrets() if err == nil { t.Error("expected error when no seeds in bundle") }}
func TestBundleRegexes(t *testing.T) { // Verify each regex individually tests := []struct { name string content string found bool }{ { "app_id regex", `production:{api:{appId:"987654321",appSecret:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"`, true, }, { "app_id regex missing", `no app id`, false, }, { "private key regex", `privateKey: "abc123XYZ"`, true, }, { "bundle URL regex", `<script src="/resources/5.2.1-b042/bundle.js"></script>`, true, }, }
for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var found bool switch { case tt.name == "app_id regex" || tt.name == "app_id regex missing": found = reAppID.MatchString(tt.content) case tt.name == "private key regex": for _, re := range rePrivateKeyPatterns { if re.MatchString(tt.content) { found = true break } } case tt.name == "bundle URL regex": found = reBundleURL.MatchString(tt.content) } if found != tt.found { t.Errorf("regex match = %v, want %v for content: %q", found, tt.found, tt.content) } }) }}
func TestBundleSecrets_Decodes(t *testing.T) { // Seeds that produce a known decoded output // seed "dGVzdA==" decodes to "test" but we need to trim last 44 chars // So use longer seeds: base64("hello world this is a test secret") = ... // Let's just test that the real fakeBundleJS produces non-empty secrets b := &Bundle{content: fakeBundleJS} secrets, err := b.Secrets() if err != nil { // No seeds found -> error is acceptable if the fake JS doesn't have the right format t.Logf("Secrets returned error (may be due to short test seeds): %v", err) return } if len(secrets) == 0 { t.Error("expected at least one secret from valid fake bundle") } for tz, sec := range secrets { t.Logf("timezone %s -> secret len=%d", tz, len(sec)) if sec == "" { t.Errorf("empty secret for timezone %s", tz) } }}