test(coverart, subsonic, server): merge repeated cases into tables (#8298)
release / web (push) Successful in 1m35s
release / go (push) Successful in 1m58s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m0s
release / android (push) Successful in 4m26s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 5m8s
release / web (push) Successful in 1m35s
release / go (push) Successful in 1m58s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m0s
release / android (push) Successful in 4m26s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 5m8s
- coverart: the four providers' identity and default tests, Last.fm's five not-found-without-asking tests, the four "which artists are asked again" database tests (now one reset over four artists), and the thumbnail-only and fanart-only tests. - subsonic: getUser's six tests and decodePassword's three, one table each. Dropped TestTokenMD5Derivation: it checked crypto/md5 against a constant and called no Minstrel code. - server: the four web-app-versus-API path tests start one server, not four. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,44 +1,21 @@
|
||||
package subsonic
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
func TestDecodePasswordEnc(t *testing.T) {
|
||||
out, err := decodePassword("enc:68656c6c6f")
|
||||
if err != nil {
|
||||
t.Fatalf("decode: %v", err)
|
||||
}
|
||||
if out != "hello" {
|
||||
t.Errorf("decode = %q, want hello", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodePasswordPlain(t *testing.T) {
|
||||
out, err := decodePassword("hunter2")
|
||||
if err != nil || out != "hunter2" {
|
||||
t.Errorf("plain passthrough = %q, %v", out, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodePasswordBadHex(t *testing.T) {
|
||||
if _, err := decodePassword("enc:zzzz"); err == nil {
|
||||
t.Error("expected error for malformed enc: prefix")
|
||||
}
|
||||
}
|
||||
|
||||
// TestTokenMD5Derivation documents the t = md5(password + salt) construction
|
||||
// so regressions in the auth path surface as a failing checksum rather than a
|
||||
// 40/wrong-credentials response that could be mistaken for bad inputs.
|
||||
func TestTokenMD5Derivation(t *testing.T) {
|
||||
password := "hunter2"
|
||||
salt := "NaClz"
|
||||
sum := md5.Sum([]byte(password + salt))
|
||||
want := hex.EncodeToString(sum[:])
|
||||
const expected = "91b894c3c9af9c16bec1b3f771e31462"
|
||||
if want != expected {
|
||||
t.Errorf("md5(password+salt) = %s, want %s", want, expected)
|
||||
// A Subsonic app sends its password as plain text or hex-encoded behind
|
||||
// "enc:"; malformed hex is an error rather than a wrong password.
|
||||
func TestDecodePassword(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
in, want string
|
||||
err bool
|
||||
}{
|
||||
{"enc:68656c6c6f", "hello", false},
|
||||
{"hunter2", "hunter2", false},
|
||||
{"enc:zzzz", "", true},
|
||||
} {
|
||||
out, err := decodePassword(tc.in)
|
||||
if (err != nil) != tc.err || (!tc.err && out != tc.want) {
|
||||
t.Errorf("decodePassword(%q) = %q, %v; want %q (error %v)", tc.in, out, err, tc.want, tc.err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,78 +13,50 @@ import (
|
||||
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
|
||||
)
|
||||
|
||||
func TestHandleGetUser_Self(t *testing.T) {
|
||||
user := dbq.User{Username: "alice", IsAdmin: false}
|
||||
w, body := callGetUser(t, user, "")
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want 200", w.Code)
|
||||
}
|
||||
if body.Resp.Status != "ok" {
|
||||
t.Errorf("status = %q, want ok", body.Resp.Status)
|
||||
}
|
||||
if body.Resp.User.Username != "alice" {
|
||||
t.Errorf("username = %q, want alice", body.Resp.User.Username)
|
||||
}
|
||||
if body.Resp.User.AdminRole {
|
||||
t.Error("non-admin should not have admin role")
|
||||
}
|
||||
if !body.Resp.User.StreamRole {
|
||||
t.Error("stream role must be on so clients enable playback")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGetUser_AdminGetsAdminRole(t *testing.T) {
|
||||
// getUser describes the caller, or for an admin any user asked about. The
|
||||
// stream role is always on, since clients disable playback without it; admin
|
||||
// and settings roles follow the user described, not the caller. A non-admin
|
||||
// asking about someone else is refused, an unknown name is not found, and
|
||||
// asking about yourself by name needs no lookup (none of the cases below
|
||||
// that name the caller supply a known user).
|
||||
func TestHandleGetUser(t *testing.T) {
|
||||
alice := dbq.User{Username: "alice"}
|
||||
admin := dbq.User{Username: "admin", IsAdmin: true}
|
||||
_, body := callGetUser(t, admin, "")
|
||||
if !body.Resp.User.AdminRole || !body.Resp.User.SettingsRole {
|
||||
t.Errorf("admin/settings roles = %v/%v, want true/true",
|
||||
body.Resp.User.AdminRole, body.Resp.User.SettingsRole)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGetUser_NonAdminCannotLookupOthers(t *testing.T) {
|
||||
user := dbq.User{Username: "alice", IsAdmin: false}
|
||||
_, body := callGetUser(t, user, "bob")
|
||||
if body.Resp.Status != "failed" || body.Resp.Error == nil ||
|
||||
body.Resp.Error.Code != ErrNotAuthorized {
|
||||
t.Errorf("expected ErrNotAuthorized, got status=%q err=%+v",
|
||||
body.Resp.Status, body.Resp.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGetUser_AdminLooksUpAnotherUser(t *testing.T) {
|
||||
admin := dbq.User{Username: "admin", IsAdmin: true}
|
||||
bob := dbq.User{Username: "bob", IsAdmin: false}
|
||||
_, body := callGetUser(t, admin, "bob", bob)
|
||||
if body.Resp.Status != "ok" {
|
||||
t.Fatalf("status = %q, want ok (err=%+v)", body.Resp.Status, body.Resp.Error)
|
||||
}
|
||||
if body.Resp.User.Username != "bob" {
|
||||
t.Errorf("username = %q, want bob: the answer must describe the user asked about, not the caller", body.Resp.User.Username)
|
||||
}
|
||||
if body.Resp.User.AdminRole || body.Resp.User.SettingsRole {
|
||||
t.Errorf("bob is not an admin, but the answer carries admin/settings roles %v/%v",
|
||||
body.Resp.User.AdminRole, body.Resp.User.SettingsRole)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGetUser_AdminLooksUpUnknownUser(t *testing.T) {
|
||||
admin := dbq.User{Username: "admin", IsAdmin: true}
|
||||
_, body := callGetUser(t, admin, "nobody")
|
||||
if body.Resp.Status != "failed" || body.Resp.Error == nil ||
|
||||
body.Resp.Error.Code != ErrDataNotFound {
|
||||
t.Errorf("expected ErrDataNotFound, got status=%q err=%+v",
|
||||
body.Resp.Status, body.Resp.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGetUser_OwnUsernameNeedsNoLookup(t *testing.T) {
|
||||
// No known users: a lookup would fail, so success proves none was made.
|
||||
user := dbq.User{Username: "alice", IsAdmin: false}
|
||||
_, body := callGetUser(t, user, "alice")
|
||||
if body.Resp.Status != "ok" || body.Resp.User.Username != "alice" {
|
||||
t.Errorf("status=%q username=%q, want ok/alice", body.Resp.Status, body.Resp.User.Username)
|
||||
bob := dbq.User{Username: "bob"}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
caller dbq.User
|
||||
asked string
|
||||
known []dbq.User
|
||||
wantErr int // 0 for success
|
||||
wantUser string
|
||||
wantAdmin bool
|
||||
}{
|
||||
{"yourself", alice, "", nil, 0, "alice", false},
|
||||
{"yourself by name", alice, "alice", nil, 0, "alice", false},
|
||||
{"an admin, yourself", admin, "", nil, 0, "admin", true},
|
||||
{"a non-admin asking about another", alice, "bob", []dbq.User{bob}, ErrNotAuthorized, "", false},
|
||||
{"an admin asking about another", admin, "bob", []dbq.User{bob}, 0, "bob", false},
|
||||
{"an admin asking about nobody", admin, "nobody", nil, ErrDataNotFound, "", false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
w, body := callGetUser(t, tc.caller, tc.asked, tc.known...)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("HTTP status = %d, want 200 (Subsonic errors ride in the body)", w.Code)
|
||||
}
|
||||
if tc.wantErr != 0 {
|
||||
if body.Resp.Status != "failed" || body.Resp.Error == nil || body.Resp.Error.Code != tc.wantErr {
|
||||
t.Errorf("status %q, error %+v; want error %d", body.Resp.Status, body.Resp.Error, tc.wantErr)
|
||||
}
|
||||
return
|
||||
}
|
||||
u := body.Resp.User
|
||||
if body.Resp.Status != "ok" || u.Username != tc.wantUser || !u.StreamRole ||
|
||||
u.AdminRole != tc.wantAdmin || u.SettingsRole != tc.wantAdmin {
|
||||
t.Errorf("got status %q, user %+v; want %q, stream role, admin and settings roles %v",
|
||||
body.Resp.Status, u, tc.wantUser, tc.wantAdmin)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user