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>
90 lines
2.6 KiB
Go
90 lines
2.6 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
|
|
)
|
|
|
|
func TestHandleGetMe_ReturnsAuthenticatedUser(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
user := seedUser(t, pool, "alice", "hunter2", true)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/api/me", nil)
|
|
req = withUser(req, user)
|
|
w := httptest.NewRecorder()
|
|
h.handleGetMe(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("status = %d body = %s", w.Code, w.Body.String())
|
|
}
|
|
var got meProfileResp
|
|
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if got.Username != "test-alice" || !got.IsAdmin {
|
|
t.Errorf("user = %+v, want test-alice/admin", got)
|
|
}
|
|
if got.DisplayName != nil {
|
|
t.Errorf("DisplayName = %v, want nil for a user with no profile set", *got.DisplayName)
|
|
}
|
|
if got.Email != nil {
|
|
t.Errorf("Email = %v, want nil for a user with no profile set", *got.Email)
|
|
}
|
|
}
|
|
|
|
// A user whose profile fields ARE set must see them in the /api/me
|
|
// response: a Settings → Profile form seeded without them would, on save,
|
|
// clear the stored values through PUT /api/me/profile's "empty string
|
|
// clears to NULL".
|
|
func TestHandleGetMe_IncludesDisplayNameAndEmail(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
user := seedUser(t, pool, "alice", "hunter2", false)
|
|
|
|
displayName := "Alice Liddell"
|
|
email := "alice@example.com"
|
|
updated, err := dbq.New(pool).UpdateUserProfile(context.Background(), dbq.UpdateUserProfileParams{
|
|
ID: user.ID,
|
|
DisplayName: &displayName,
|
|
Email: &email,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("UpdateUserProfile: %v", err)
|
|
}
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/api/me", nil)
|
|
req = withUser(req, updated)
|
|
w := httptest.NewRecorder()
|
|
h.handleGetMe(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("status = %d body = %s", w.Code, w.Body.String())
|
|
}
|
|
var got meProfileResp
|
|
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if got.DisplayName == nil || *got.DisplayName != displayName {
|
|
t.Errorf("DisplayName = %v, want %q", got.DisplayName, displayName)
|
|
}
|
|
if got.Email == nil || *got.Email != email {
|
|
t.Errorf("Email = %v, want %q", got.Email, email)
|
|
}
|
|
}
|
|
|
|
func TestHandleGetMe_MissingContextReturns500(t *testing.T) {
|
|
h, _ := testHandlers(t)
|
|
req := httptest.NewRequest(http.MethodGet, "/api/me", nil)
|
|
w := httptest.NewRecorder()
|
|
h.handleGetMe(w, req)
|
|
|
|
if w.Code != http.StatusInternalServerError {
|
|
t.Errorf("status = %d, want 500 (context should be populated by RequireUser)", w.Code)
|
|
}
|
|
_ = dbq.User{} // keep the import used
|
|
}
|