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,103 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDomainWriteBackend(t *testing.T) {
|
||||
for _, b := range []storeSQLBackend{storeSQLite, storePostgreSQL} {
|
||||
t.Run(fmt.Sprint(b), func(t *testing.T) {
|
||||
s, d := accountBackendStore(t, b)
|
||||
ctx := context.Background()
|
||||
if err := s.EnsureFederationSchema(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
original, err := s.GetDomainByUUID(d)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p, err := s.BootstrapOwner(d, "domain-owner", "synthetic domain password", "Owner", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c, err := s.GetCampusByUUID(original.CampusUUID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.UpdateCampus(c.ID, c.Name, c.Title, "ja", "standalone", "home.example.test", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Duplicate semantic host validation must serialize, including different names.
|
||||
ch := make(chan error, 2)
|
||||
for i := 0; i < 2; i++ {
|
||||
go func(i int) {
|
||||
ch <- s.CreateDomain(c.UUID, fmt.Sprint("created-", i), "Created", "child", "local", "", "", true)
|
||||
}(i)
|
||||
}
|
||||
success := 0
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := <-ch; err == nil {
|
||||
success++
|
||||
}
|
||||
}
|
||||
if success != 1 {
|
||||
t.Fatal("host uniqueness race", success)
|
||||
}
|
||||
child, err := s.GetDomainByHost("child.home.example.test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !s.IsBuiltinGroupAdmin(child.UUID, p.UUID, "campus_admin") {
|
||||
t.Fatal("created domain missing inherited admin")
|
||||
}
|
||||
var locale string
|
||||
if err = s.DB.QueryRow(`SELECT value FROM config WHERE domain_uuid=`+s.sqlParam(1)+` AND key='locale'`, child.UUID).Scan(&locale); err != nil || locale != "ja" {
|
||||
t.Fatal(locale, err)
|
||||
}
|
||||
if err = s.CreateCampus("destination", "Destination", "en", "standalone", "destination.example.test", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var dest string
|
||||
if err = s.DB.QueryRow(`SELECT uuid FROM campuses WHERE name='destination'`).Scan(&dest); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.UpdateDomain(child.ID, dest, child.Name, "Moved", child.Domain, "local", "", "", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s.IsBuiltinGroupAdmin(child.UUID, p.UUID, "campus_admin") {
|
||||
t.Fatal("old campus privilege survived move")
|
||||
}
|
||||
if err = s.UpdateDomain(999999, dest, "missing", "Missing", "missing", "local", "", "", true); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("missing update", err)
|
||||
}
|
||||
if err = s.DeleteDomain(child.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.GetDomainByUUID(child.UUID); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("deleted domain survived", err)
|
||||
}
|
||||
destCampus, err := s.GetCampusByUUID(dest)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.DeleteCampus(destCampus.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Default group creation failure must roll back the Domain and locale as well.
|
||||
if _, err = s.DB.Exec(`ALTER TABLE groups RENAME COLUMN inherit_members TO unavailable_inherit_members`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.CreateDomain(c.UUID, "must-rollback", "Rollback", "rollback", "local", "", "", true); err == nil {
|
||||
t.Fatal("group failure ignored")
|
||||
}
|
||||
var n int
|
||||
if err = s.DB.QueryRowContext(ctx, `SELECT count(*) FROM domains WHERE name='must-rollback'`).Scan(&n); err != nil || n != 0 {
|
||||
t.Fatal("partial domain", n, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user