Refactor all references to computer to Superbrain
release gate / check (push) Failing after 6m55s

This commit is contained in:
Andrew S Erwin
2026-10-22 00:33:44 -05:00
parent 45aa3c80aa
commit d870eece1e
84 changed files with 438 additions and 381 deletions
+6 -6
View File
@@ -17,8 +17,8 @@ func collectionBookmark(t *testing.T, c apiClient, url string) string {
func TestCollectionsLifecycle(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "coll-life@computer.test")
bob := newAPIUser(t, srv, "coll-other@computer.test")
alice := newAPIUser(t, srv, "coll-life@superbrain.test")
bob := newAPIUser(t, srv, "coll-other@superbrain.test")
bm1 := collectionBookmark(t, alice, "https://127.0.0.1/one")
@@ -149,7 +149,7 @@ func TestCollectionsLifecycle(t *testing.T) {
func TestCollectionViewsFilterSortPaginate(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "coll-views@computer.test")
alice := newAPIUser(t, srv, "coll-views@superbrain.test")
col := alice.request("POST", "/api/collections", map[string]any{"name": "Pipeline"}, 201)
cid := col["id"].(string)
@@ -278,9 +278,9 @@ func TestCollectionViewsFilterSortPaginate(t *testing.T) {
func TestCollectionRevocationReachesItems(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "coll-rev@computer.test")
alice := newAPIUser(t, srv, "coll-rev@superbrain.test")
aliceID := alice.request("GET", "/api/me", nil, 200)["user"].(map[string]any)["id"].(string)
bob := newAPIUser(t, srv, "coll-rev-owner@computer.test")
bob := newAPIUser(t, srv, "coll-rev-owner@superbrain.test")
// Bob owns a bookmark and shares it with Alice; Alice puts it in HER
// collection. Revocation must make the item vanish from every surface
@@ -338,7 +338,7 @@ func TestCollectionRevocationReachesItems(t *testing.T) {
// based on the pre-reorder / pre-deletion state get 409s.
func TestCollectionIndirectMutationsAdvanceVersions(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "coll-rev@computer.test")
alice := newAPIUser(t, srv, "coll-rev@superbrain.test")
bm1 := collectionBookmark(t, alice, "https://127.0.0.1/r1")
bm2 := collectionBookmark(t, alice, "https://127.0.0.1/r2")
col := alice.request("POST", "/api/collections", map[string]any{"name": "Revisions"}, 201)
+8 -8
View File
@@ -17,8 +17,8 @@ func pageVersion(t *testing.T, c apiClient, id string) int {
func TestPageHierarchy(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "pages-tree@computer.test")
bob := newAPIUser(t, srv, "pages-tree-other@computer.test")
alice := newAPIUser(t, srv, "pages-tree@superbrain.test")
bob := newAPIUser(t, srv, "pages-tree-other@superbrain.test")
root := alice.request("POST", "/api/pages", map[string]any{"title": "Root"}, 201)["id"].(string)
child := alice.request("POST", "/api/pages", map[string]any{"title": "Child", "parentId": root}, 201)["id"].(string)
@@ -71,8 +71,8 @@ func TestPageHierarchy(t *testing.T) {
func TestPageBacklinksAndEmbeds(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "pages-graph@computer.test")
bob := newAPIUser(t, srv, "pages-graph-other@computer.test")
alice := newAPIUser(t, srv, "pages-graph@superbrain.test")
bob := newAPIUser(t, srv, "pages-graph-other@superbrain.test")
target := alice.request("POST", "/api/pages", map[string]any{"title": "Target page"}, 201)["id"].(string)
bobTarget := bob.request("POST", "/api/pages", map[string]any{"title": "Private title"}, 201)["id"].(string)
@@ -82,9 +82,9 @@ func TestPageBacklinksAndEmbeds(t *testing.T) {
foreignCollection := bob.request("POST", "/api/collections", map[string]any{"name": "Bob private"}, 201)["id"].(string)
content := "# Connected\n\n" +
"- [Target](computer:page/" + target + ")\n" +
"- [Target](superbrain:page/" + target + ")\n" +
"- [Alias](/pages?id=" + target + ")\n" +
"- [Bob's page](computer:page/" + bobTarget + ")\n\n" +
"- [Bob's page](superbrain:page/" + bobTarget + ")\n\n" +
"{{collection:" + collection + "|view=" + view + "}}\n" +
"{{collection:" + foreignCollection + "}}\n"
source := alice.request("POST", "/api/pages", map[string]any{"title": "Source page", "content": content}, 201)["id"].(string)
@@ -140,7 +140,7 @@ func TestPageBacklinksAndEmbeds(t *testing.T) {
// Re-linking re-establishes the edge; deleting the target removes it.
alice.request("PATCH", "/api/pages/"+source, map[string]any{
"content": "[Target](computer:page/" + target + ")", "version": pageVersion(t, alice, source),
"content": "[Target](superbrain:page/" + target + ")", "version": pageVersion(t, alice, source),
}, 200)
if b := alice.request("GET", "/api/pages/"+target, nil, 200)["backlinks"].([]any); len(b) != 1 {
t.Fatalf("re-link was not resolved: %v", b)
@@ -151,7 +151,7 @@ func TestPageBacklinksAndEmbeds(t *testing.T) {
}
// Self-links are ignored (a page is not its own backlink).
selfContent := "[Me](computer:page/" + source + ")"
selfContent := "[Me](superbrain:page/" + source + ")"
alice.request("PATCH", "/api/pages/"+source, map[string]any{
"content": selfContent, "version": pageVersion(t, alice, source),
}, 200)
+20 -20
View File
@@ -16,8 +16,8 @@ import (
"testing"
"time"
"github.com/andrew/go-computer/internal/auth"
"github.com/andrew/go-computer/internal/signals"
"github.com/andrew/superbrain/internal/auth"
"github.com/andrew/superbrain/internal/signals"
"github.com/emersion/go-imap/backend/memory"
imapserver "github.com/emersion/go-imap/server"
"github.com/golang-jwt/jwt/v5"
@@ -71,8 +71,8 @@ func newAPIUser(t *testing.T, srv *httptest.Server, email string) apiClient {
func TestPreviouslyUncoveredRoutes(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "coverage-alice@computer.test")
newAPIUser(t, srv, "coverage-searchable@computer.test")
alice := newAPIUser(t, srv, "coverage-alice@superbrain.test")
newAPIUser(t, srv, "coverage-searchable@superbrain.test")
// GET /api/preview — handler plumbing (auth + query + parse).
html := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -98,15 +98,15 @@ func TestPreviouslyUncoveredRoutes(t *testing.T) {
// GET /api/users/search — name substring, exact email, masked output,
// no email-substring enumeration, 2-rune guard.
users := alice.getJSON("/api/users/search?q=coverage-sea", 200)
if len(users) != 1 || users[0]["email"] != "c***@computer.test" {
if len(users) != 1 || users[0]["email"] != "c***@superbrain.test" {
t.Fatal("users/search name match:", users)
}
if users := alice.getJSON("/api/users/search?q=coverage-searchable@computer.test", 200); len(users) != 1 {
if users := alice.getJSON("/api/users/search?q=coverage-searchable@superbrain.test", 200); len(users) != 1 {
t.Fatal("users/search exact email:", users)
}
// "able@computer.test" is a substring of the target's email but not a
// "able@superbrain.test" is a substring of the target's email but not a
// full email and not part of any name: must not match.
if users := alice.getJSON("/api/users/search?q=able%40computer.test", 200); len(users) != 0 {
if users := alice.getJSON("/api/users/search?q=able%40superbrain.test", 200); len(users) != 0 {
t.Fatal("users/search must not substring-match emails:", users)
}
if users := alice.getJSON("/api/users/search?q=c", 200); len(users) != 0 {
@@ -180,9 +180,9 @@ func TestPreviouslyUncoveredRoutes(t *testing.T) {
// cookie: a token copied before signout stops working.
func TestSignoutRevokesIssuedTokens(t *testing.T) {
srv := testServer(t)
u := newAPIUser(t, srv, "revoke@computer.test")
u := newAPIUser(t, srv, "revoke@superbrain.test")
creds, _ := json.Marshal(map[string]any{"email": "revoke@computer.test", "password": "coverage-test-password"})
creds, _ := json.Marshal(map[string]any{"email": "revoke@superbrain.test", "password": "coverage-test-password"})
req, _ := http.NewRequest("POST", srv.URL+"/api/auth/login", bytes.NewReader(creds))
req.Header.Set("Content-Type", "application/json")
res, e := u.c.Do(req)
@@ -192,7 +192,7 @@ func TestSignoutRevokesIssuedTokens(t *testing.T) {
res.Body.Close()
var stale string
for _, c := range res.Cookies() {
if c.Name == "computer_session" {
if c.Name == "superbrain_session" {
stale = c.Value
}
}
@@ -205,7 +205,7 @@ func TestSignoutRevokesIssuedTokens(t *testing.T) {
// Replay the pre-signout token directly (no jar): must be rejected.
replay := func(path string) int {
rq, _ := http.NewRequest("GET", srv.URL+path, nil)
rq.AddCookie(&http.Cookie{Name: "computer_session", Value: stale})
rq.AddCookie(&http.Cookie{Name: "superbrain_session", Value: stale})
rs, e := u.c.Do(rq)
if e != nil {
t.Fatal(e)
@@ -221,7 +221,7 @@ func TestSignoutRevokesIssuedTokens(t *testing.T) {
t.Fatalf("stale cookie accepted on data route: %d", code)
}
rq, _ := http.NewRequest("GET", srv.URL+"/api/auth/session", nil)
rq.AddCookie(&http.Cookie{Name: "computer_session", Value: stale})
rq.AddCookie(&http.Cookie{Name: "superbrain_session", Value: stale})
rs, e := u.c.Do(rq)
if e != nil {
t.Fatal(e)
@@ -236,7 +236,7 @@ func TestSignoutRevokesIssuedTokens(t *testing.T) {
// One scheduler tick creates signals and marks sources checked (TEST-2).
func TestSignalSchedulerRunOnce(t *testing.T) {
srv, d := testServerDB(t)
alice := newAPIUser(t, srv, "scheduler@computer.test")
alice := newAPIUser(t, srv, "scheduler@superbrain.test")
listener, e := net.Listen("tcp", "127.0.0.1:0")
if e != nil {
@@ -282,7 +282,7 @@ func TestSignalSchedulerRunOnce(t *testing.T) {
// the per-user backoff so the next ticks are skipped.
func TestSchedulerBacksOffAfterMailboxFailure(t *testing.T) {
srv, d := testServerDB(t)
alice := newAPIUser(t, srv, "backoff@computer.test")
alice := newAPIUser(t, srv, "backoff@superbrain.test")
id := alice.request("POST", "/api/bookmarks", map[string]any{"url": "https://example.org/backoff"}, 201)["id"].(string)
alice.request("POST", "/api/bookmarks/"+id+"/signals", map[string]any{"type": "email", "config": map[string]any{"subject": "anything"}}, 201)
// Deliberately no saved IMAP configuration: every pass fails in LoadMailbox.
@@ -317,7 +317,7 @@ func TestSchedulerBacksOffAfterMailboxFailure(t *testing.T) {
// bodies (review PERF-01).
func TestPageVersionAndListProjection(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "pagever@computer.test")
alice := newAPIUser(t, srv, "pagever@superbrain.test")
created := alice.request("POST", "/api/pages", map[string]any{"title": "Doc", "content": "first"}, 201)
id := created["id"].(string)
if created["version"].(float64) != 1 {
@@ -369,7 +369,7 @@ func TestPageVersionAndListProjection(t *testing.T) {
// competing writer's committed revision.
func TestConcurrentPageSaveAckReportsOwnWrite(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "pageack@computer.test")
alice := newAPIUser(t, srv, "pageack@superbrain.test")
id := alice.request("POST", "/api/pages", map[string]any{"title": "Ack", "content": "v1"}, 201)["id"].(string)
const writers = 8
@@ -426,7 +426,7 @@ func TestConcurrentPageSaveAckReportsOwnWrite(t *testing.T) {
// the revision, and tag replacement rides the same contract.
func TestBookmarkVersionContract(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "bmver@computer.test")
alice := newAPIUser(t, srv, "bmver@superbrain.test")
created := alice.request("POST", "/api/bookmarks", map[string]any{"url": "https://example.org/ver", "title": "v0"}, 201)
id := created["id"].(string)
if created["version"].(float64) != 0 {
@@ -457,7 +457,7 @@ func TestBookmarkVersionContract(t *testing.T) {
// must revoke NextAuth-backed Bearer assertions, not just Go cookie sessions.
func TestAssertionRevocationFollowsTokenVersion(t *testing.T) {
srv, d := testServerDB(t)
u := newAPIUser(t, srv, "assert-revoke@computer.test")
u := newAPIUser(t, srv, "assert-revoke@superbrain.test")
uid := u.request("GET", "/api/me", nil, 200)["user"].(map[string]any)["id"].(string)
var ver int
if e := d.QueryRow(`SELECT "tokenVersion" FROM "User" WHERE id=$1`, uid).Scan(&ver); e != nil {
@@ -468,7 +468,7 @@ func TestAssertionRevocationFollowsTokenVersion(t *testing.T) {
tok := jwt.NewWithClaims(jwt.SigningMethodHS256, auth.SessionClaims{
UserID: uid, Type: auth.TokenTypeAssertion, Ver: v,
RegisteredClaims: jwt.RegisteredClaims{
Issuer: "computer",
Issuer: "superbrain",
IssuedAt: jwt.NewNumericDate(now),
ExpiresAt: jwt.NewNumericDate(now.Add(60 * time.Second)),
},
+9 -9
View File
@@ -3,9 +3,9 @@ package http
import (
"bytes"
"encoding/json"
"github.com/andrew/go-computer/internal/auth"
"github.com/andrew/go-computer/internal/config"
"github.com/andrew/go-computer/internal/db"
"github.com/andrew/superbrain/internal/auth"
"github.com/andrew/superbrain/internal/config"
"github.com/andrew/superbrain/internal/db"
"io"
"net/http"
"net/http/cookiejar"
@@ -128,16 +128,16 @@ func TestApplicationFlows(t *testing.T) {
post := func(email string) map[string]any {
return map[string]any{"email": email, "password": "a-long-test-password"}
}
alice.request("POST", "/api/signup", post("alice@computer.test"), 201)
bob.request("POST", "/api/signup", post("bob@computer.test"), 201)
alice.request("POST", "/api/signup", post("alice@superbrain.test"), 201)
bob.request("POST", "/api/signup", post("bob@superbrain.test"), 201)
// Review SEC-4/CR-03: a duplicate signup returns the SAME 201 {"ok":true}
// body as a fresh creation (no 409, no distinguishing field).
dup := alice.request("POST", "/api/signup", post("alice@computer.test"), 201)
dup := alice.request("POST", "/api/signup", post("alice@superbrain.test"), 201)
if len(dup) != 1 || dup["ok"] != true {
t.Fatalf("duplicate signup body differs from a fresh creation: %v", dup)
}
alice.request("POST", "/api/auth/login", post("alice@computer.test"), 200)
bob.request("POST", "/api/auth/login", post("bob@computer.test"), 200)
alice.request("POST", "/api/auth/login", post("alice@superbrain.test"), 200)
bob.request("POST", "/api/auth/login", post("bob@superbrain.test"), 200)
au := meID(alice)
bu := meID(bob)
if alice.request("GET", "/api/me", nil, 200)["isAdmin"] != true {
@@ -189,7 +189,7 @@ func TestApplicationFlows(t *testing.T) {
t.Fatal("alert dismissal")
}
putBookmark(alice, id, map[string]any{"alertAt": "2000-01-02"}, 200)
source := alice.request("POST", "/api/bookmarks/"+id+"/signals", map[string]any{"type": "email", "config": map[string]any{"from": "sender@computer.test"}}, 201)["id"].(string)
source := alice.request("POST", "/api/bookmarks/"+id+"/signals", map[string]any{"type": "email", "config": map[string]any{"from": "sender@superbrain.test"}}, 201)["id"].(string)
alice.request("POST", "/api/bookmarks/"+id+"/signals", map[string]any{"action": "check"}, 200)
alice.request("PATCH", "/api/signal-sources/"+source, map[string]any{"enabled": false}, 200)
bob.request("DELETE", "/api/signal-sources/"+source, nil, 404)
+10 -10
View File
@@ -3,8 +3,8 @@ package http
import (
"context"
"encoding/json"
crypt "github.com/andrew/go-computer/internal/crypto"
"github.com/andrew/go-computer/internal/signals"
crypt "github.com/andrew/superbrain/internal/crypto"
"github.com/andrew/superbrain/internal/signals"
"github.com/emersion/go-imap/backend/memory"
imapserver "github.com/emersion/go-imap/server"
"io"
@@ -22,7 +22,7 @@ func TestExternalIntegrations(t *testing.T) {
srv, d := testServerDB(t)
jar, _ := cookiejar.New(nil)
a := apiClient{t, &http.Client{Jar: jar}, srv.URL}
credentials := map[string]any{"email": "integrations@computer.test", "password": "test-password"}
credentials := map[string]any{"email": "integrations@superbrain.test", "password": "test-password"}
a.request("POST", "/api/signup", credentials, 201)
a.request("POST", "/api/auth/login", credentials, 200)
// CardDAV fixture (reviews CR-07/CR-08): the served multistatus is
@@ -48,14 +48,14 @@ func TestExternalIntegrations(t *testing.T) {
card1 := `<d:response><d:href>/card.vcf</d:href><d:propstat><d:prop><card:address-data>BEGIN:VCARD
UID:contact-1
FN:Contact Name
EMAIL:last@computer.test
EMAIL;TYPE=PREF:preferred@computer.test
EMAIL:last@superbrain.test
EMAIL;TYPE=PREF:preferred@superbrain.test
TEL:1234
END:VCARD</card:address-data></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response>`
card2 := `<d:response><d:href>/card2.vcf</d:href><d:propstat><d:prop><card:address-data>BEGIN:VCARD
UID:contact-2
FN:Second Contact
EMAIL:second@computer.test
EMAIL:second@superbrain.test
END:VCARD</card:address-data></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response>`
card2Withheld := `<d:response><d:href>/card2.vcf</d:href><d:propstat><d:prop/><d:status>HTTP/1.1 404 Not Found</d:status></d:propstat></d:response>`
wrap := func(responses ...string) string {
@@ -85,7 +85,7 @@ END:VCARD</card:address-data></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:pr
t.Fatal("CardDAV import count", contacts)
}
for _, c := range contacts {
if c["uid"] == "contact-1" && c["email"] != "preferred@computer.test" {
if c["uid"] == "contact-1" && c["email"] != "preferred@superbrain.test" {
t.Fatal("repeated EMAIL did not resolve to the PREF value:", c)
}
}
@@ -173,7 +173,7 @@ END:VCARD</card:address-data></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:pr
// Nextcloud URL is rejected at the API boundary — no dial, no credentials.
func TestCardDAVRequiresTLSOutsideFixtures(t *testing.T) {
srv := testServer(t)
a := newAPIUser(t, srv, "carddav-tls@computer.test")
a := newAPIUser(t, srv, "carddav-tls@superbrain.test")
t.Setenv("INTEGRATIONS_ALLOW_PRIVATE", "")
a.request("POST", "/api/contacts/sync", map[string]any{
"nextcloudUrl": "http://nextcloud.example.test", "username": "u", "password": "p",
@@ -194,7 +194,7 @@ func TestCardDAVRequiresTLSOutsideFixtures(t *testing.T) {
// rewrites the password column at all.
func TestImapCredentialWritesNeverRestoreStalePasswords(t *testing.T) {
srv, d := testServerDB(t)
alice := newAPIUser(t, srv, "imap-stale@computer.test")
alice := newAPIUser(t, srv, "imap-stale@superbrain.test")
t.Setenv("ENCRYPTION_KEY", "dedicated-encryption-key")
uid := alice.request("GET", "/api/me", nil, 200)["user"].(map[string]any)["id"].(string)
@@ -246,6 +246,6 @@ func TestImapCredentialWritesNeverRestoreStalePasswords(t *testing.T) {
// A masked save with no stored configuration is a 400, never an empty
// or resurrected password.
bob := newAPIUser(t, srv, "imap-nocfg@computer.test")
bob := newAPIUser(t, srv, "imap-nocfg@superbrain.test")
bob.request("POST", "/api/settings/imap", map[string]any{"host": "h.example.test", "port": 993, "tls": true, "username": "user", "password": "••••••••", "folder": "INBOX"}, 400)
}
+2 -2
View File
@@ -7,7 +7,7 @@ import "testing"
// still honors the bookmark concurrency version (review CR-04).
func TestKanbanCardMovePersistsOrdering(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "kanban-order@computer.test")
alice := newAPIUser(t, srv, "kanban-order@superbrain.test")
cols := alice.getJSON("/api/kanban/columns", 200)
if len(cols) < 2 {
t.Fatalf("expected default columns, got %d", len(cols))
@@ -113,7 +113,7 @@ func TestKanbanCardMovePersistsOrdering(t *testing.T) {
}
// Foreign columns are never accepted.
bob := newAPIUser(t, srv, "kanban-other@computer.test")
bob := newAPIUser(t, srv, "kanban-other@superbrain.test")
bobCols := bob.getJSON("/api/kanban/columns", 200)
foreign := bobCols[0]["id"].(string)
firstNow := alice.request("GET", "/api/bookmarks/"+first["id"].(string), nil, 200)
+3 -3
View File
@@ -10,8 +10,8 @@ import (
// trigram indexes introduced alongside the escaping change.
func TestPageSearchEscapesWildcards(t *testing.T) {
srv, d := testServerDB(t)
alice, _ := accountClient(t, srv.URL, "pagesearch@computer.test")
other, _ := accountClient(t, srv.URL, "pagesearch-other@computer.test")
alice, _ := accountClient(t, srv.URL, "pagesearch@superbrain.test")
other, _ := accountClient(t, srv.URL, "pagesearch-other@superbrain.test")
alice.request("POST", "/api/pages", map[string]any{"title": "100% done", "content": "literal percent"}, 201)
alice.request("POST", "/api/pages", map[string]any{"title": "100x done", "content": "not a percent"}, 201)
@@ -44,7 +44,7 @@ func TestPageSearchEscapesWildcards(t *testing.T) {
// instead of persisting them (the 1 MiB body cap alone is too coarse).
func TestTextFieldSizeLimits(t *testing.T) {
srv := testServer(t)
alice, _ := accountClient(t, srv.URL, "limits@computer.test")
alice, _ := accountClient(t, srv.URL, "limits@superbrain.test")
const (
urlLimit = 2048
+1 -1
View File
@@ -12,7 +12,7 @@ import (
// every file twice in order cannot change the backfill guarantees.
func TestUpgradeBackfillsLegacyWatchesWithoutChangingExistingSources(t *testing.T) {
srv, d := testServerDB(t)
_, uid := accountClient(t, srv.URL, "watcher@computer.test")
_, uid := accountClient(t, srv.URL, "watcher@superbrain.test")
if _, err := d.Exec(`INSERT INTO "Bookmark"(id,url,"ownerId","imapWatchEnabled","imapQuery") VALUES('old','https://127.0.0.1',$1,true,'Invoices'),('paused','https://127.0.0.1',$1,true,'Receipts'),('off','https://127.0.0.1',$1,false,'Other')`, uid); err != nil {
t.Fatal(err)
}
+2 -2
View File
@@ -9,8 +9,8 @@ import (
func TestBookmarkPaginationPreservesCollectionAndOwnership(t *testing.T) {
srv, d := testServerDB(t)
owner, uid := accountClient(t, srv.URL, "owner@computer.test")
other, oid := accountClient(t, srv.URL, "other@computer.test")
owner, uid := accountClient(t, srv.URL, "owner@superbrain.test")
other, oid := accountClient(t, srv.URL, "other@superbrain.test")
for _, user := range []string{uid, oid} {
if _, err := d.Exec(`INSERT INTO "Bookmark"(id,url,title,"ownerId","updatedAt") SELECT $1||'-'||lpad(n::text,4,'0'),'https://127.0.0.1/test','Match '||n,$1,'2026-10-07T12:00:00Z' FROM generate_series(1,205) n`, user); err != nil {
t.Fatal(err)
+12 -12
View File
@@ -42,8 +42,8 @@ func rawCall(t *testing.T, c apiClient, method, path string, body []byte, header
// one of them win and the other observe the committed count.
func TestConcurrentAdminDemotionsKeepOneAdmin(t *testing.T) {
srv, d := testServerDB(t)
a, _ := accountClient(t, srv.URL, "admin-a@computer.test")
b, bID := accountClient(t, srv.URL, "admin-b@computer.test")
a, _ := accountClient(t, srv.URL, "admin-a@superbrain.test")
b, bID := accountClient(t, srv.URL, "admin-b@superbrain.test")
a.request("PATCH", "/api/admin/users", map[string]any{"userId": bID, "role": "ADMIN"}, 200)
aID := meID(a)
@@ -93,7 +93,7 @@ func TestSignupTrimsWhitespaceName(t *testing.T) {
srv, _ := testServerDB(t)
jar, _ := cookiejar.New(nil)
c := apiClient{t, &http.Client{Jar: jar}, srv.URL}
body := map[string]any{"email": "trimmed@computer.test", "password": "test-long-password", "name": " "}
body := map[string]any{"email": "trimmed@superbrain.test", "password": "test-long-password", "name": " "}
c.request("POST", "/api/signup", body, 201)
c.request("POST", "/api/auth/login", body, 200)
me := c.request("GET", "/api/me", nil, 200)
@@ -107,7 +107,7 @@ func TestSignupTrimsWhitespaceName(t *testing.T) {
// INSERT per id inside a user-locked transaction.
func TestShareRecipientListsAreCapped(t *testing.T) {
srv, _ := testServerDB(t)
owner, _ := accountClient(t, srv.URL, "cap-owner@computer.test")
owner, _ := accountClient(t, srv.URL, "cap-owner@superbrain.test")
id := owner.request("POST", "/api/bookmarks", map[string]any{"url": "https://example.com/cap"}, 201)["id"].(string)
tooMany := make([]string, maxTestShareRecipients+1)
@@ -132,7 +132,7 @@ const (
// Review L-8: an oversized direct API body is 413, not a misleading 400.
func TestOversizedDirectBodyReturns413(t *testing.T) {
srv, _ := testServerDB(t)
owner, _ := accountClient(t, srv.URL, "oversized@computer.test")
owner, _ := accountClient(t, srv.URL, "oversized@superbrain.test")
body := []byte(`{"url":"https://example.com","notes":"` + strings.Repeat("a", 1<<20) + `"}`)
status, _ := rawCall(t, owner, "POST", "/api/bookmarks", body, nil)
if status != http.StatusRequestEntityTooLarge {
@@ -144,7 +144,7 @@ func TestOversizedDirectBodyReturns413(t *testing.T) {
// endpoints, while an idempotent same-origin call still succeeds.
func TestSignoutRejectsCrossOrigin(t *testing.T) {
srv, _ := testServerDB(t)
owner, _ := accountClient(t, srv.URL, "signout@computer.test")
owner, _ := accountClient(t, srv.URL, "signout@superbrain.test")
body := []byte(`{}`)
status, _ := rawCall(t, owner, "POST", "/api/auth/signout", body, map[string]string{"Origin": "https://attacker.invalid"})
if status != http.StatusForbidden {
@@ -160,7 +160,7 @@ func TestSignoutRejectsCrossOrigin(t *testing.T) {
// groups instead of trusting a client to keep them apart.
func TestPageReorderKeepsPinnedGrouping(t *testing.T) {
srv, _ := testServerDB(t)
owner, _ := accountClient(t, srv.URL, "reorder@computer.test")
owner, _ := accountClient(t, srv.URL, "reorder@superbrain.test")
pinned := owner.request("POST", "/api/pages", map[string]any{"title": "Pinned", "pinned": true}, 201)["id"].(string)
second := owner.request("POST", "/api/pages", map[string]any{"title": "Second"}, 201)["id"].(string)
third := owner.request("POST", "/api/pages", map[string]any{"title": "Third"}, 201)["id"].(string)
@@ -193,7 +193,7 @@ func TestPageReorderKeepsPinnedGrouping(t *testing.T) {
// rejected instead of silently discarded.
func TestPropertyConfigRejectsMalformedValues(t *testing.T) {
srv, _ := testServerDB(t)
owner, _ := accountClient(t, srv.URL, "props@computer.test")
owner, _ := accountClient(t, srv.URL, "props@superbrain.test")
cid := owner.request("POST", "/api/collections", map[string]any{"name": "Config"}, 201)["id"].(string)
for _, cfg := range []any{"x", []any{}, 5, true} {
owner.request("POST", "/api/collections/"+cid+"/properties", map[string]any{"name": "Bad", "type": "TEXT", "config": cfg}, 400)
@@ -206,8 +206,8 @@ func TestPropertyConfigRejectsMalformedValues(t *testing.T) {
// creating duplicate calendar entries.
func TestSharedDateReshareIsIdempotent(t *testing.T) {
srv, _ := testServerDB(t)
owner, _ := accountClient(t, srv.URL, "dates-owner@computer.test")
_, recipientID := accountClient(t, srv.URL, "dates-recipient@computer.test")
owner, _ := accountClient(t, srv.URL, "dates-owner@superbrain.test")
_, recipientID := accountClient(t, srv.URL, "dates-recipient@superbrain.test")
post := func(note string) []map[string]any {
body, _ := json.Marshal(map[string]any{"date": "2026-11-05", "note": note, "recipientIds": []string{recipientID}})
@@ -258,7 +258,7 @@ func TestSharedDateReshareIsIdempotent(t *testing.T) {
func TestCardDAVRejectsNonStandardPort(t *testing.T) {
srv, _ := testServerDB(t)
t.Setenv("INTEGRATIONS_ALLOW_PRIVATE", "0")
owner, _ := accountClient(t, srv.URL, "carddav@computer.test")
owner, _ := accountClient(t, srv.URL, "carddav@superbrain.test")
v := owner.request("POST", "/api/contacts/sync", map[string]any{
"nextcloudUrl": "https://198.51.100.10:8443",
"username": "user",
@@ -274,7 +274,7 @@ func TestCardDAVRejectsNonStandardPort(t *testing.T) {
// renumbers positions contiguously, so reload order is deterministic.
func TestColumnDeleteNormalizesMovedCardPositions(t *testing.T) {
srv, _ := testServerDB(t)
owner, _ := accountClient(t, srv.URL, "columns@computer.test")
owner, _ := accountClient(t, srv.URL, "columns@superbrain.test")
var columns []map[string]any
res, err := owner.c.Get(srv.URL + "/api/kanban/columns")
if err != nil {
+26 -26
View File
@@ -7,7 +7,7 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"github.com/andrew/go-computer/internal/scripts"
"github.com/andrew/superbrain/internal/scripts"
"net/http"
"net/http/cookiejar"
"os"
@@ -18,18 +18,18 @@ import (
func TestConfiguredAdminCannotBeBypassedDuringBootstrap(t *testing.T) {
srv, d := testServerDB(t)
t.Setenv("ADMIN_EMAILS", "operator@computer.test")
visitor, _ := accountClient(t, srv.URL, "visitor@computer.test")
t.Setenv("ADMIN_EMAILS", "operator@superbrain.test")
visitor, _ := accountClient(t, srv.URL, "visitor@superbrain.test")
if visitor.request("GET", "/api/me", nil, 200)["isAdmin"] != false {
t.Fatal("public signup bypassed reserved administrator bootstrap")
}
visitor.request("GET", "/api/admin/users", nil, 403)
t.Setenv("SEED_EMAIL", "operator@computer.test")
t.Setenv("SEED_EMAIL", "operator@superbrain.test")
t.Setenv("SEED_PASSWORD", "operator-test-password")
if err := scripts.Seed(context.Background(), d); err != nil {
t.Fatal(err)
}
visitor.request("POST", "/api/auth/login", map[string]any{"email": "operator@computer.test", "password": "operator-test-password"}, 200)
visitor.request("POST", "/api/auth/login", map[string]any{"email": "operator@superbrain.test", "password": "operator-test-password"}, 200)
if visitor.request("GET", "/api/me", nil, 200)["isAdmin"] != true {
t.Fatal("operator-provisioned account is not admin")
}
@@ -37,7 +37,7 @@ func TestConfiguredAdminCannotBeBypassedDuringBootstrap(t *testing.T) {
if err := scripts.Seed(context.Background(), d); err != nil {
t.Fatal(err)
}
visitor.request("POST", "/api/auth/login", map[string]any{"email": "operator@computer.test", "password": "operator-test-password"}, 200)
visitor.request("POST", "/api/auth/login", map[string]any{"email": "operator@superbrain.test", "password": "operator-test-password"}, 200)
}
func accountClient(t *testing.T, base, email string) (apiClient, string) {
@@ -54,14 +54,14 @@ func accountClient(t *testing.T, base, email string) (apiClient, string) {
func TestAdminEnrollmentRequiresTrustedIdentity(t *testing.T) {
srv, d := testServerDB(t)
admin, _ := accountClient(t, srv.URL, "admin@computer.test")
user, uid := accountClient(t, srv.URL, "unverified@computer.test")
t.Setenv("ADMIN_EMAILS", "reserved@computer.test,unverified@computer.test")
admin, _ := accountClient(t, srv.URL, "admin@superbrain.test")
user, uid := accountClient(t, srv.URL, "unverified@superbrain.test")
t.Setenv("ADMIN_EMAILS", "reserved@superbrain.test,unverified@superbrain.test")
// Reserved addresses answer exactly like existing accounts (no 403 oracle).
// Review SEC-4/CR-03: operator-reserved addresses return the SAME uniform
// 201 {"ok":true} body as every other accepted registration — no userId
// field, no 409.
reserved := user.request("POST", "/api/signup", map[string]any{"email": "reserved@computer.test", "password": "test-password"}, 201)
reserved := user.request("POST", "/api/signup", map[string]any{"email": "reserved@superbrain.test", "password": "test-password"}, 201)
if len(reserved) != 1 || reserved["ok"] != true {
t.Fatalf("operator-reserved address body is distinguishable: %v", reserved)
}
@@ -80,9 +80,9 @@ func TestAdminEnrollmentRequiresTrustedIdentity(t *testing.T) {
func TestPublicBookmarksDoNotExposePrivateMetadata(t *testing.T) {
srv, d := testServerDB(t)
owner, uid := accountClient(t, srv.URL, "owner@computer.test")
viewer, vid := accountClient(t, srv.URL, "viewer@computer.test")
if _, err := d.Exec(`INSERT INTO "Contact"(id,uid,"displayName",email,phone,"userId") VALUES('contact','vcard','Private','private@computer.test','555-private',$1)`, uid); err != nil {
owner, uid := accountClient(t, srv.URL, "owner@superbrain.test")
viewer, vid := accountClient(t, srv.URL, "viewer@superbrain.test")
if _, err := d.Exec(`INSERT INTO "Contact"(id,uid,"displayName",email,phone,"userId") VALUES('contact','vcard','Private','private@superbrain.test','555-private',$1)`, uid); err != nil {
t.Fatal(err)
}
id := owner.request("POST", "/api/bookmarks", map[string]any{"url": "https://127.0.0.1/test", "isPublic": true, "contactId": "contact", "imapQuery": "private mailbox query", "alertAt": "2026-10-07"}, 201)["id"].(string)
@@ -112,7 +112,7 @@ func TestPublicBookmarksDoNotExposePrivateMetadata(t *testing.T) {
t.Error("shared-reader response lost tags")
}
full := owner.request("GET", "/api/bookmarks/"+id, nil, 200)
if c, _ := full["contact"].(map[string]any); c == nil || c["email"] != "private@computer.test" {
if c, _ := full["contact"].(map[string]any); c == nil || c["email"] != "private@superbrain.test" {
t.Error("owner projection lost the contact record")
}
if s, ok := full["sharedWith"].([]any); !ok || len(s) != 1 {
@@ -146,7 +146,7 @@ func TestPublicBookmarksDoNotExposePrivateMetadata(t *testing.T) {
func TestAdminBootstrapIsOneShot(t *testing.T) {
srv, d := testServerDB(t)
// Fresh installation: the first signup completes bootstrap as admin.
admin, adminID := accountClient(t, srv.URL, "first@computer.test")
admin, adminID := accountClient(t, srv.URL, "first@superbrain.test")
if admin.request("GET", "/api/me", nil, 200)["isAdmin"] != true {
t.Fatal("first signup on a fresh installation was not admin")
}
@@ -155,7 +155,7 @@ func TestAdminBootstrapIsOneShot(t *testing.T) {
if _, err := d.Exec(`UPDATE "User" SET role='USER' WHERE id=$1`, adminID); err != nil {
t.Fatal(err)
}
latecomer, _ := accountClient(t, srv.URL, "late@computer.test")
latecomer, _ := accountClient(t, srv.URL, "late@superbrain.test")
if latecomer.request("GET", "/api/me", nil, 200)["isAdmin"] != false {
t.Fatal("signup re-opened admin bootstrap after the last admin was demoted")
}
@@ -163,7 +163,7 @@ func TestAdminBootstrapIsOneShot(t *testing.T) {
if _, err := d.Exec(`DELETE FROM "User" WHERE id=$1`, adminID); err != nil {
t.Fatal(err)
}
successor, _ := accountClient(t, srv.URL, "successor@computer.test")
successor, _ := accountClient(t, srv.URL, "successor@superbrain.test")
if successor.request("GET", "/api/me", nil, 200)["isAdmin"] != false {
t.Fatal("signup re-opened admin bootstrap after the last admin was removed")
}
@@ -175,7 +175,7 @@ func TestAdminBootstrapIsOneShot(t *testing.T) {
func TestBootstrapSignupCanBeDisabled(t *testing.T) {
srv := testServer(t)
t.Setenv("ALLOW_BOOTSTRAP_SIGNUP", "0")
visitor, _ := accountClient(t, srv.URL, "unclaimed@computer.test")
visitor, _ := accountClient(t, srv.URL, "unclaimed@superbrain.test")
if visitor.request("GET", "/api/me", nil, 200)["isAdmin"] != false {
t.Fatal("first signup became admin despite ALLOW_BOOTSTRAP_SIGNUP=0")
}
@@ -191,7 +191,7 @@ func TestDirectLoginRejectsBrowserForgery(t *testing.T) {
{"text/plain", "https://attacker.invalid", 415},
{"application/json", "https://attacker.invalid", 403},
} {
req, _ := http.NewRequest("POST", srv.URL+"/api/auth/login", bytes.NewBufferString(`{"email":"attacker@computer.test","password":"password"}`))
req, _ := http.NewRequest("POST", srv.URL+"/api/auth/login", bytes.NewBufferString(`{"email":"attacker@superbrain.test","password":"password"}`))
req.Header.Set("Content-Type", tc.contentType)
req.Header.Set("Origin", tc.origin)
res, err := http.DefaultClient.Do(req)
@@ -222,9 +222,9 @@ func TestLoginLockoutHonorsSignedForwardedIdentity(t *testing.T) {
req.Header.Set("Content-Type", "application/json")
if ip != "" {
hip, hts, sig := sign(ip, ts)
req.Header.Set("X-Computer-Client-Ip", hip)
req.Header.Set("X-Computer-Client-Ts", hts)
req.Header.Set("X-Computer-Client-Sig", sig)
req.Header.Set("X-superbrain-Client-Ip", hip)
req.Header.Set("X-superbrain-Client-Ts", hts)
req.Header.Set("X-superbrain-Client-Sig", sig)
}
res, e := http.DefaultClient.Do(req)
if e != nil {
@@ -236,21 +236,21 @@ func TestLoginLockoutHonorsSignedForwardedIdentity(t *testing.T) {
now := time.Now().Unix()
// Browser A: five failures lock out its (IP, email) bucket.
for i := 0; i < 5; i++ { // failureThreshold
if code := post("victim-a@computer.test", "wrong-password", "198.51.100.1", now); code != 401 {
if code := post("victim-a@superbrain.test", "wrong-password", "198.51.100.1", now); code != 401 {
t.Fatalf("browser A attempt %d: %d", i+1, code)
}
}
if code := post("victim-a@computer.test", "wrong-password", "198.51.100.1", now); code != 429 {
if code := post("victim-a@superbrain.test", "wrong-password", "198.51.100.1", now); code != 429 {
t.Fatalf("browser A not locked out: %d", code)
}
// Browser B behind the same proxy peer keeps its own buckets.
if code := post("victim-a@computer.test", "wrong-password", "198.51.100.2", now); code != 401 {
if code := post("victim-a@superbrain.test", "wrong-password", "198.51.100.2", now); code != 401 {
t.Fatalf("browser B locked out by browser A's failures: %d", code)
}
// A stale signature (outside the ~60s window) falls back to the peer, so
// it cannot smuggle a fresh identity: these attempts count against the
// peer bucket and stay 401.
if code := post("victim-b@computer.test", "wrong-password", "198.51.100.9", now-3600); code != 401 {
if code := post("victim-b@superbrain.test", "wrong-password", "198.51.100.9", now-3600); code != 401 {
t.Fatalf("stale signature changed behavior: %d", code)
}
}
+6 -6
View File
@@ -6,12 +6,12 @@ import (
"os"
"time"
"github.com/andrew/go-computer/internal/auth"
"github.com/andrew/go-computer/internal/authguard"
"github.com/andrew/go-computer/internal/config"
"github.com/andrew/go-computer/internal/db"
"github.com/andrew/go-computer/internal/handlers"
"github.com/andrew/go-computer/internal/oidc"
"github.com/andrew/superbrain/internal/auth"
"github.com/andrew/superbrain/internal/authguard"
"github.com/andrew/superbrain/internal/config"
"github.com/andrew/superbrain/internal/db"
"github.com/andrew/superbrain/internal/handlers"
"github.com/andrew/superbrain/internal/oidc"
)
// NewServer builds the HTTP server with all routes registered.
+2 -2
View File
@@ -19,8 +19,8 @@ func TestRevocationAndForeignRelations(t *testing.T) {
// uniform signup body.
return meID(c)
}
account(a, "owner@computer.test")
bid := account(b, "recipient@computer.test")
account(a, "owner@superbrain.test")
bid := account(b, "recipient@superbrain.test")
tag := a.request("POST", "/api/tags", map[string]any{"name": "Shared"}, 201)["id"].(string)
id := a.request("POST", "/api/bookmarks", map[string]any{"url": "https://127.0.0.1/test", "tagIds": []string{tag}, "dueDate": "2026-10-07"}, 201)["id"].(string)
a.request("POST", "/api/bookmarks/"+id+"/share", map[string]any{"userIds": []string{bid}}, 200)
+9 -9
View File
@@ -9,8 +9,8 @@ import (
func TestPageRevisionHistory(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "trust-history@computer.test")
bob := newAPIUser(t, srv, "trust-history-other@computer.test")
alice := newAPIUser(t, srv, "trust-history@superbrain.test")
bob := newAPIUser(t, srv, "trust-history-other@superbrain.test")
page := alice.request("POST", "/api/pages", map[string]any{"title": "History", "content": "version one"}, 201)["id"].(string)
revisions := alice.getJSON("/api/pages/"+page+"/revisions", 200)
@@ -52,8 +52,8 @@ func TestPageRevisionHistory(t *testing.T) {
func TestTrashRestoreNeverResurrectsGrants(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "trust-trash@computer.test")
bob := newAPIUser(t, srv, "trust-trash-other@computer.test")
alice := newAPIUser(t, srv, "trust-trash@superbrain.test")
bob := newAPIUser(t, srv, "trust-trash-other@superbrain.test")
bobID := meID(bob)
tag := alice.request("POST", "/api/tags", map[string]any{"name": "Restored tag"}, 201)["id"].(string)
@@ -162,9 +162,9 @@ func TestTrashRestoreNeverResurrectsGrants(t *testing.T) {
func TestCollectionSharingPermissionBoundary(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "trust-coll-share@computer.test")
bob := newAPIUser(t, srv, "trust-coll-recipient@computer.test")
carol := newAPIUser(t, srv, "trust-coll-third@computer.test")
alice := newAPIUser(t, srv, "trust-coll-share@superbrain.test")
bob := newAPIUser(t, srv, "trust-coll-recipient@superbrain.test")
carol := newAPIUser(t, srv, "trust-coll-third@superbrain.test")
bobID, carolID := meID(bob), meID(carol)
bm := alice.request("POST", "/api/bookmarks", map[string]any{"url": "https://127.0.0.1/collection-share", "title": "Shared via project", "notes": "secret owner notes", "isPublic": true}, 201)
@@ -249,7 +249,7 @@ func TestCollectionSharingPermissionBoundary(t *testing.T) {
func TestStructuredExport(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "trust-export@computer.test")
alice := newAPIUser(t, srv, "trust-export@superbrain.test")
tag := alice.request("POST", "/api/tags", map[string]any{"name": "Export tag"}, 201)["id"].(string)
bm := alice.request("POST", "/api/bookmarks", map[string]any{"url": "https://127.0.0.1/export", "title": "Exported bookmark", "tagIds": []string{tag}}, 201)["id"].(string)
@@ -258,7 +258,7 @@ func TestStructuredExport(t *testing.T) {
alice.request("POST", "/api/collections/"+col+"/items", map[string]any{"bookmarkId": bm}, 201)
v := alice.request("GET", "/api/export", nil, 200)
if v["format"] != "computer-export" || v["version"].(float64) != 1 {
if v["format"] != "superbrain-export" || v["version"].(float64) != 1 {
t.Fatalf("export envelope: %v", v)
}
if len(v["bookmarks"].([]any)) != 1 || len(v["pages"].([]any)) != 1 || len(v["tags"].([]any)) != 1 || len(v["collections"].([]any)) != 1 {