mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Critical (6):
- C1: SQL injection in VACUUM INTO backup path — strict character allowlist
- C2: Unlimited binary download in updater — 500MB LimitReader
- C3: JSON injection in SSE log stream — json.Marshal instead of concat
- C4: CSS injection via custom themes — reject () and {} in values
- C5: Silent DM message loss — error response on participant lookup failure
- C6: LiveKit URL credential leak — strip creds from diagnostics endpoint
High (11):
- H1: DB errors no longer trigger login rate-limit lockout
- H2: Permission fetch failure returns 500, not empty channel list
- H3: TOCTOU race on duplicate WS — atomic check-and-register in hub
- H5: LiveKit webhook verifies voice channel match (already implemented)
- H7: Server host address validated before storage (hostname regex)
- H8: WS message deduplication on reconnect replay (1000-entry Set)
- H9: Admin setup endpoint rate limited (5/min/IP)
- H10: Backup responses return filename only, not full path
- H11: Update binary recovery failure now alerts admin
Medium (17):
- M1: MIME type from magic bytes, not client header
- M3: Nil guard on DM broadcast recipient
- M5: LiveKit process run-done channel race fixed
- M6: Backup restore calls fsync before close
- M7: Partial download file cleaned up on error
- M8: Admin CSP uses nonce instead of unsafe-inline
- M9: Client rate limiter enforced for presence_update
- M10: Voice joinedAt not reset on double-join
- M11: Unread count skips increment during reconnect replay
- M13: Category type uses exact match, not substring
- M14: Storage LimitReader off-by-one fixed
- M15: GitHub token only sent to GitHub hosts
- M16: Content-parser ReDoS regex replaced with split approach
- M17: Audio device switch error handling added
Low (11):
- L1: CORS uses configured origins instead of wildcard
- L2: HSTS header added when TLS enabled
- L3: Consistent JSON error responses across all endpoints
- L4: File modtime from stat, not time.Now()
- L5: Malformed invite JSON returns 400
- L6: TouchSession failure logged at warn
- L8: MessageInput timers cleared on destroy
- L9: Log persistence flush errors caught
- L10: Credential save failure surfaced to user
- L11: Case-insensitive asset name matching in updater
Found by GitHub Copilot full-project review (claude-sonnet-4.6 + claude-haiku-4.5).
149 lines
3.9 KiB
Go
149 lines
3.9 KiB
Go
package admin_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/owncord/server/admin"
|
|
)
|
|
|
|
func TestSetupStatus_NeedsSetup(t *testing.T) {
|
|
database := openAdminTestDB(t)
|
|
handler := admin.NewAdminAPI(database, "1.0.0", nil, nil, nil)
|
|
|
|
rr := doRequest(t, handler, "GET", "/setup/status", "", nil)
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("GET /setup/status = %d, want 200", rr.Code)
|
|
}
|
|
|
|
var resp struct {
|
|
NeedsSetup bool `json:"needs_setup"`
|
|
}
|
|
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
|
t.Fatalf("unmarshal: %v", err)
|
|
}
|
|
if !resp.NeedsSetup {
|
|
t.Error("needs_setup = false, want true (no users)")
|
|
}
|
|
}
|
|
|
|
func TestSetupStatus_NoSetupNeeded(t *testing.T) {
|
|
database := openAdminTestDB(t)
|
|
createAdminUser(t, database) // Create a user first
|
|
handler := admin.NewAdminAPI(database, "1.0.0", nil, nil, nil)
|
|
|
|
rr := doRequest(t, handler, "GET", "/setup/status", "", nil)
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("GET /setup/status = %d, want 200", rr.Code)
|
|
}
|
|
|
|
var resp struct {
|
|
NeedsSetup bool `json:"needs_setup"`
|
|
}
|
|
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
|
t.Fatalf("unmarshal: %v", err)
|
|
}
|
|
if resp.NeedsSetup {
|
|
t.Error("needs_setup = true, want false (user exists)")
|
|
}
|
|
}
|
|
|
|
func TestSetup_CreatesOwner(t *testing.T) {
|
|
admin.ResetSetupLimiter()
|
|
database := openAdminTestDB(t)
|
|
handler := admin.NewAdminAPI(database, "1.0.0", nil, nil, nil)
|
|
|
|
rr := doRequest(t, handler, "POST", "/setup", "", map[string]string{
|
|
"username": "myadmin",
|
|
"password": "SecurePass123!",
|
|
})
|
|
|
|
if rr.Code != http.StatusCreated {
|
|
t.Fatalf("POST /setup = %d, want 201; body=%s", rr.Code, rr.Body.String())
|
|
}
|
|
|
|
var resp struct {
|
|
Token string `json:"token"`
|
|
UserID int64 `json:"user_id"`
|
|
Username string `json:"username"`
|
|
InviteCode string `json:"invite_code"`
|
|
}
|
|
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
|
t.Fatalf("unmarshal: %v", err)
|
|
}
|
|
if resp.Token == "" {
|
|
t.Error("token is empty")
|
|
}
|
|
if resp.Username != "myadmin" {
|
|
t.Errorf("username = %q, want %q", resp.Username, "myadmin")
|
|
}
|
|
if resp.InviteCode == "" {
|
|
t.Error("invite_code is empty")
|
|
}
|
|
if resp.UserID == 0 {
|
|
t.Error("user_id is 0")
|
|
}
|
|
|
|
// Verify user was created with Owner role.
|
|
user, err := database.GetUserByUsername("myadmin")
|
|
if err != nil || user == nil {
|
|
t.Fatal("user not found in database after setup")
|
|
}
|
|
if user.RoleID != 1 {
|
|
t.Errorf("role_id = %d, want 1 (Owner)", user.RoleID)
|
|
}
|
|
}
|
|
|
|
func TestSetup_BlockedAfterFirstUser(t *testing.T) {
|
|
admin.ResetSetupLimiter()
|
|
database := openAdminTestDB(t)
|
|
handler := admin.NewAdminAPI(database, "1.0.0", nil, nil, nil)
|
|
|
|
// First setup succeeds.
|
|
rr := doRequest(t, handler, "POST", "/setup", "", map[string]string{
|
|
"username": "owner1",
|
|
"password": "SecurePass123!",
|
|
})
|
|
if rr.Code != http.StatusCreated {
|
|
t.Fatalf("first setup = %d, want 201; body=%s", rr.Code, rr.Body.String())
|
|
}
|
|
|
|
// Second setup is blocked.
|
|
rr2 := doRequest(t, handler, "POST", "/setup", "", map[string]string{
|
|
"username": "hacker",
|
|
"password": "EvilPass456!",
|
|
})
|
|
if rr2.Code != http.StatusForbidden {
|
|
t.Errorf("second setup = %d, want 403", rr2.Code)
|
|
}
|
|
}
|
|
|
|
func TestSetup_WeakPassword(t *testing.T) {
|
|
admin.ResetSetupLimiter()
|
|
database := openAdminTestDB(t)
|
|
handler := admin.NewAdminAPI(database, "1.0.0", nil, nil, nil)
|
|
|
|
rr := doRequest(t, handler, "POST", "/setup", "", map[string]string{
|
|
"username": "admin",
|
|
"password": "short",
|
|
})
|
|
if rr.Code != http.StatusBadRequest {
|
|
t.Errorf("weak password = %d, want 400; body=%s", rr.Code, rr.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestSetup_MissingFields(t *testing.T) {
|
|
admin.ResetSetupLimiter()
|
|
database := openAdminTestDB(t)
|
|
handler := admin.NewAdminAPI(database, "1.0.0", nil, nil, nil)
|
|
|
|
rr := doRequest(t, handler, "POST", "/setup", "", map[string]string{
|
|
"username": "",
|
|
"password": "",
|
|
})
|
|
if rr.Code != http.StatusBadRequest {
|
|
t.Errorf("missing fields = %d, want 400", rr.Code)
|
|
}
|
|
}
|