release / go (push) Successful in 2m7s
release / web (push) Successful in 1m25s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m30s
release / android (push) Successful in 4m39s
release / Build signed APK (push) Successful in 5m10s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- Module path: github.com/Fabled-Sword/minstrel, in go.mod, every import and the Dockerfile's version ldflags. - buildinfo.ProjectURL, the contact outside services see in Minstrel's User-Agent: https://github.com/Fabled-Sword/minstrel. - README's compose example pulls ghcr.io/fabled-sword/minstrel:latest. - docs/security.md sends problem reports to the GitHub issues. - The demo-library stack builds Minstrel from the checkout, since :dev is not published to GHCR. - hygiene.go's same-site example uses example.com names. The workbench CI (.gitea/, ci/, export-ignored) still builds and publishes :dev to the private registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"log/slog"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/library"
|
|
)
|
|
|
|
func TestGetFingerprintSettings_ServesDefaultsWithoutAService(t *testing.T) {
|
|
h := &handlers{logger: slog.New(slog.NewTextHandler(io.Discard, nil))}
|
|
rec := httptest.NewRecorder()
|
|
h.handleGetFingerprintSettings(rec, httptest.NewRequest(http.MethodGet, "/api/admin/library/fingerprint-settings", nil))
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("status = %d, want 200", rec.Code)
|
|
}
|
|
var got fingerprintSettingsBody
|
|
if err := json.NewDecoder(rec.Body).Decode(&got); err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
want := fingerprintSettingsBodyOf(library.DefaultFingerprintSettings)
|
|
// auto_resolve is a pointer, so it is compared by value and then set aside.
|
|
if got.AutoResolve == nil || *got.AutoResolve != *want.AutoResolve {
|
|
t.Fatalf("auto_resolve = %v, want %v", got.AutoResolve, *want.AutoResolve)
|
|
}
|
|
got.AutoResolve, want.AutoResolve = nil, nil
|
|
if got != want {
|
|
t.Fatalf("body = %+v, want the defaults %+v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestUpdateFingerprintSettings_Rejects(t *testing.T) {
|
|
h := &handlers{logger: slog.New(slog.NewTextHandler(io.Discard, nil))}
|
|
for name, tc := range map[string]struct {
|
|
body string
|
|
code string
|
|
mentions string
|
|
}{
|
|
"a value out of range, naming the field": {
|
|
body: `{"enabled":true,"chromaprint_length_sec":5,"acoustic_max_bit_error_rate":0.15,"backfill_concurrency":2,"sweep_interval_hours":1}`,
|
|
code: "invalid_setting",
|
|
mentions: "chromaprint_length_sec",
|
|
},
|
|
// A partial body would otherwise zero every field it left out.
|
|
"a body missing fields": {body: `{"enabled":false}`, code: "invalid_setting"},
|
|
"malformed JSON": {body: `{"enabled":`, code: "invalid_body"},
|
|
} {
|
|
rec := httptest.NewRecorder()
|
|
h.handleUpdateFingerprintSettings(rec, httptest.NewRequest(
|
|
http.MethodPut, "/api/admin/library/fingerprint-settings", strings.NewReader(tc.body)))
|
|
body := rec.Body.String()
|
|
if rec.Code != http.StatusBadRequest || !strings.Contains(body, `"`+tc.code+`"`) || !strings.Contains(body, tc.mentions) {
|
|
t.Errorf("%s: status %d body %s; want 400 %s mentioning %q", name, rec.Code, body, tc.code, tc.mentions)
|
|
}
|
|
}
|
|
}
|