feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
@@ -0,0 +1,118 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUserSpaceBackend(t *testing.T) {
|
||||
for _, b := range []storeSQLBackend{storeSQLite, storePostgreSQL} {
|
||||
t.Run(fmt.Sprint(b), func(t *testing.T) {
|
||||
f := newPublicationBackend(t, b)
|
||||
s := f.s
|
||||
ctx := context.Background()
|
||||
if err := s.EnsureUserSpaceSchema(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.EnsureUserSpaceSchema(); err != nil {
|
||||
t.Fatal("repeat migration", err)
|
||||
}
|
||||
f.page("user-page", "/u/owner/notes_%/日本語", "user-rev", 10)
|
||||
f.page("private-page", "/u/owner/private", "private-rev", 10)
|
||||
p, err := s.UserSpacePolicy(ctx, f.domain, f.actor)
|
||||
if err != nil || p.Version != 0 || !p.DomainAllowsPublic {
|
||||
t.Fatal(p, err)
|
||||
}
|
||||
p.RootVisibility = "public"
|
||||
p.DescendantVisibility = "public"
|
||||
p.ProfileVisibility = "public"
|
||||
p.Overrides = []UserSpacePathPolicy{{Path: "/u/owner/private", Visibility: "private"}}
|
||||
p, err = s.SaveUserSpacePolicy(ctx, f.domain, f.actor, p)
|
||||
if err != nil || p.Version != 1 {
|
||||
t.Fatal(p, err)
|
||||
}
|
||||
if err = s.ensureSchemaComponent("profile-contacts"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
contact := ProfileContact{PhoneDisplay: "+81 90 1234 5678", Visibility: "public"}
|
||||
if err = s.SaveProfileContact(ctx, f.domain, f.actor, contact, false); !errors.Is(err, ErrGovernanceInvalid) {
|
||||
t.Fatal("public contact without confirmation", err)
|
||||
}
|
||||
if err = s.SaveProfileContact(ctx, f.domain, f.actor, contact, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
visible, err := s.ProfileContactForViewer(ctx, f.domain, f.actor, "")
|
||||
if err != nil || visible.PhoneNumber != "+819012345678" {
|
||||
t.Fatal(visible, err)
|
||||
}
|
||||
if err = s.SaveProfileContact(ctx, f.domain, f.actor, contact, true); !errors.Is(err, ErrGovernanceConflict) {
|
||||
t.Fatal("stale contact update", err)
|
||||
}
|
||||
visible.Visibility = "private"
|
||||
if err = s.SaveProfileContact(ctx, f.domain, f.actor, visible, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
private, err := s.ProfileContactForViewer(ctx, f.domain, f.actor, "")
|
||||
if err != nil || private.PhoneNumber != "" || private.PhoneDisplay != "" || private.Version != 0 {
|
||||
t.Fatal("contact leak", private, err)
|
||||
}
|
||||
rev, err := s.PublicUserSpaceRevision(ctx, f.domain, "owner", "/u/owner/notes_%/日本語", []string{"ja"})
|
||||
if err != nil || rev.UUID != "user-rev" {
|
||||
t.Fatal(rev, err)
|
||||
}
|
||||
if _, err = s.PublicUserSpaceRevision(ctx, f.domain, "owner", "/u/owner/private", nil); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("private read", err)
|
||||
}
|
||||
nav, err := s.PublicUserSpaceNavigation(ctx, f.domain, "owner")
|
||||
if err != nil || len(nav) != 1 || nav[0].Path != "/u/owner/notes_%/日本語" {
|
||||
t.Fatal(nav, err)
|
||||
}
|
||||
stale := p
|
||||
stale.Version = 0
|
||||
if _, err = s.SaveUserSpacePolicy(ctx, f.domain, f.actor, stale); !errors.Is(err, ErrGovernanceConflict) {
|
||||
t.Fatal("stale policy", err)
|
||||
}
|
||||
// Domain boundary and alias protection are evaluated against live metadata.
|
||||
if _, err = s.PublicUserSpaceRevision(ctx, "other-domain", "owner", "/u/owner/notes_%/日本語", nil); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("cross domain", err)
|
||||
}
|
||||
f.exec(`INSERT INTO paths(domain_uuid,path,object_uuid,created_at) VALUES(`+s.sqlValues(4)+`)`, f.domain, "/alias", "user-page", 1)
|
||||
if _, err = s.PublicUserSpaceRevision(ctx, f.domain, "owner", "/u/owner/notes_%/日本語", nil); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("aliased public page", err)
|
||||
}
|
||||
f.exec(`DELETE FROM paths WHERE path='/alias'`)
|
||||
f.exec(`UPDATE principals SET state='suspended' WHERE uuid=`+s.sqlParam(1), f.actor)
|
||||
if _, err = s.PublicUserSpaceRevision(ctx, f.domain, "owner", "/u/owner/notes_%/日本語", nil); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("suspended owner", err)
|
||||
}
|
||||
f.exec(`UPDATE principals SET state='active' WHERE uuid=`+s.sqlParam(1), f.actor)
|
||||
// Path guards preserve private overrides and reject moves out of the user's namespace.
|
||||
if _, err = s.DB.Exec(`UPDATE paths SET path='/elsewhere' WHERE path='/u/owner/private'`); err == nil {
|
||||
t.Fatal("private override escaped")
|
||||
}
|
||||
f.exec(`UPDATE paths SET path='/u/owner/renamed' WHERE path='/u/owner/private'`)
|
||||
p, err = s.UserSpacePolicy(ctx, f.domain, f.actor)
|
||||
if err != nil || len(p.Overrides) != 1 || p.Overrides[0].Path != "/u/owner/renamed" {
|
||||
t.Fatal(p, err)
|
||||
}
|
||||
f.exec(`DELETE FROM paths WHERE path='/u/owner/renamed'`)
|
||||
p, err = s.UserSpacePolicy(ctx, f.domain, f.actor)
|
||||
if err != nil || len(p.Overrides) != 0 {
|
||||
t.Fatal(p, err)
|
||||
}
|
||||
// Atomic policy+audit update: no successful policy mutation without its record.
|
||||
f.exec(`ALTER TABLE user_space_policy_events RENAME COLUMN after_json TO unavailable_after_json`)
|
||||
p.DescendantVisibility = "private"
|
||||
if _, err = s.SaveUserSpacePolicy(ctx, f.domain, f.actor, p); err == nil {
|
||||
t.Fatal("audit failure ignored")
|
||||
}
|
||||
current, err := s.UserSpacePolicy(ctx, f.domain, f.actor)
|
||||
if err != nil || current.Version != p.Version || current.DescendantVisibility != "public" {
|
||||
t.Fatal("partial policy", current, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user