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,196 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPostgreSQLMetadataSearch(t *testing.T) {
|
||||
f := newPublicationBackend(t, storePostgreSQL)
|
||||
s := f.s
|
||||
for range 2 {
|
||||
if err := s.EnsureSearchIndexSchema(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for i, entry := range []struct{ path, mime, filename, category string }{
|
||||
{"/files/literal_%", "application/octet-stream", "code.py", "code"},
|
||||
{"/files/pdf", "application/pdf; x=y", "report.txt", "pdf"},
|
||||
{"/files/json", "application/ld+json", "", "json"},
|
||||
{"/files/office", "application/vnd.ms-word.document.macroenabled.12", "", "office"},
|
||||
{"/files/image", "image/png", "", "image"},
|
||||
{"/files/archive", "application/octet-stream", "bundle.tar.gz", "archive"},
|
||||
{"/files/audio", "audio/flac", "", "audio"},
|
||||
{"/files/video", "video/mp4", "", "video"},
|
||||
{"/files/text", "text/markdown", "", "text"},
|
||||
{"/files/csv", "text/csv", "", "csv"},
|
||||
{"/files/other", "application/unrecognized", "pretend.pdf", "other"},
|
||||
{"/files/html", "text/html", "", "html"},
|
||||
} {
|
||||
id := fmt.Sprint(i)
|
||||
f.page(id, entry.path, "r"+id, 2000)
|
||||
f.exec(`UPDATE revisions SET content_type=$1,filename=$2,body='body-only-needle' WHERE uuid=$3`, entry.mime, entry.filename, "r"+id)
|
||||
results, err := s.SearchPathsInDomainWithOptions(context.Background(), f.domain, "/files", "", 100, func(string) bool { return true }, SearchOptions{FileType: entry.category})
|
||||
if err != nil || len(results) != 1 || results[0].Path != entry.path {
|
||||
t.Fatalf("category %s: %+v %v", entry.category, results, err)
|
||||
}
|
||||
}
|
||||
f.page("sibling", "/files-sibling/literal_%", "rs", 2000)
|
||||
s.DB.SetMaxOpenConns(1)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
allowed := func(p string) bool {
|
||||
var n int
|
||||
if err := s.DB.QueryRowContext(ctx, `SELECT 1`).Scan(&n); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return p != "/files/pdf"
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
scope, q string
|
||||
n int
|
||||
}{
|
||||
{"/files", "_%", 1}, {"/files", "code.py", 1}, {"/files", "body-only-needle", 0}, {"/files", "report", 0}, {"/files", "' OR true --", 0},
|
||||
} {
|
||||
results, err := s.SearchPathsInDomainFiltered(ctx, f.domain, tc.scope, tc.q, 100, allowed)
|
||||
if err != nil || len(results) != tc.n {
|
||||
t.Fatalf("%+v: %+v %v", tc, results, err)
|
||||
}
|
||||
for _, r := range results {
|
||||
if r.BodyMatch || r.Excerpt != "" {
|
||||
t.Fatal("unexpected body hydration", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
if results, err := s.SearchPathsInDomainFiltered(ctx, "outside", "/", "literal", 100, allowed); err != nil || len(results) != 0 {
|
||||
t.Fatal(results, err)
|
||||
}
|
||||
from, before := int64(2000), int64(2001)
|
||||
results, err := s.SearchPathsInDomainWithOptions(ctx, f.domain, "/files", "", 100, allowed, SearchOptions{Extension: "tar.gz", FromMS: &from, BeforeMS: &before})
|
||||
if err != nil || len(results) != 1 || results[0].Filename != "bundle.tar.gz" {
|
||||
t.Fatal(results, err)
|
||||
}
|
||||
before = 2000
|
||||
if _, err = s.SearchPathsInDomainWithOptions(ctx, f.domain, "/files", "", 100, allowed, SearchOptions{FromMS: &from, BeforeMS: &before}); !errors.Is(err, ErrInvalidSearchOptions) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.SearchPathsInDomainFiltered(ctx, f.domain, "/", strings.Repeat("x", 513), 100, allowed); err == nil {
|
||||
t.Fatal("unbounded query")
|
||||
}
|
||||
suggestions, err := s.SearchPathSuggestionsInDomain(ctx, f.domain, "/files", "_%", 8, allowed)
|
||||
if err != nil || len(suggestions) != 1 {
|
||||
t.Fatal(suggestions, err)
|
||||
}
|
||||
canceled, stop := context.WithCancel(ctx)
|
||||
stop()
|
||||
if _, err = s.SearchPathsInDomainFiltered(canceled, f.domain, "/", "files", 100, allowed); !errors.Is(err, context.Canceled) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCitySearchBackend(t *testing.T) {
|
||||
for _, backend := range []storeSQLBackend{storeSQLite, storePostgreSQL} {
|
||||
t.Run(fmt.Sprint(backend), func(t *testing.T) {
|
||||
f := newPublicationBackend(t, backend)
|
||||
s := f.s
|
||||
f.page("page", "/news_%/st/sp", "rev", 1000)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
s.DB.SetMaxOpenConns(1)
|
||||
blocked := ""
|
||||
allowed := func(p string) bool {
|
||||
var n int
|
||||
if err := s.DB.QueryRowContext(ctx, `SELECT 1`).Scan(&n); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return p != blocked
|
||||
}
|
||||
results, err := s.SearchCityInDomain(ctx, f.domain, "/", "_%", 30, allowed, SearchOptions{})
|
||||
if err != nil || len(results) != 3 || results[0].Kind != "quartier" || results[2].Kind != "spot" || !results[2].HasPage {
|
||||
t.Fatal(results, err)
|
||||
}
|
||||
blocked = "/news_%"
|
||||
results, err = s.SearchCityInDomain(ctx, f.domain, "/", "sp", 30, allowed, SearchOptions{})
|
||||
if err != nil || len(results) != 0 {
|
||||
t.Fatal("parent ACL", results, err)
|
||||
}
|
||||
blocked = ""
|
||||
from, before := int64(1), int64(2)
|
||||
results, err = s.SearchCityInDomain(ctx, f.domain, "/news_%/st", "", 30, allowed, SearchOptions{FromMS: &from, BeforeMS: &before, DateField: "created"})
|
||||
if err != nil || len(results) != 2 {
|
||||
t.Fatal("dates/scope", results, err)
|
||||
}
|
||||
results, err = s.SearchCityInDomain(ctx, "outside", "/", "_%", 30, allowed, SearchOptions{})
|
||||
if err != nil || len(results) != 0 {
|
||||
t.Fatal("domain", results, err)
|
||||
}
|
||||
f.exec(`UPDATE spots SET path_prefix='/news_%/st/_undefined' WHERE uuid='sp'`)
|
||||
results, err = s.SearchCityInDomain(ctx, f.domain, "/", "_undefined", 30, allowed, SearchOptions{})
|
||||
if err != nil || len(results) != 1 || results[0].NavigationPath != "/news_%/st" {
|
||||
t.Fatal(results, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostgreSQLHostedEditorGate(t *testing.T) {
|
||||
s := testNamespaceStore(t, storePostgreSQL)
|
||||
for range 2 {
|
||||
if err := s.EnsureAdapterSessionsSchema(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := s.DB.Exec(`INSERT INTO adapter_sessions(ticket_hash,domain_uuid,plugin_id,object_uuid,base_revision_uuid,ticket_expires_at_ms,created_at_ms) VALUES('retained','d','code','o','r',1,1)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, e1 := s.IssueAdapterTicket("d", "code", "o", "r", "/")
|
||||
_, _, e2 := s.ExchangeAdapterTicket("retained")
|
||||
_, e3 := s.GetAdapterSession("retained")
|
||||
_, e4 := s.SaveHostedRevision(nil, nil, "")
|
||||
_, e5 := s.SaveHostedRevisionAt(nil, "", "", nil, "")
|
||||
for _, err := range []error{e1, e2, e3, e4, e5} {
|
||||
if !errors.Is(err, ErrBackendFeatureUnavailable) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var count int
|
||||
if err := s.DB.QueryRow(`SELECT count(*) FROM adapter_sessions WHERE ticket_hash='retained' AND exchanged_at_ms=0`).Scan(&count); err != nil || count != 1 {
|
||||
t.Fatal(count, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostgreSQLSearchFiltersBeforeCandidateLimit(t *testing.T) {
|
||||
f := newPublicationBackend(t, storePostgreSQL)
|
||||
s := f.s
|
||||
if err := s.EnsureSearchIndexSchema(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.exec(`INSERT INTO objects(uuid,kind,created_at) SELECT 'bulk-'||i,'page',1 FROM generate_series(1,1100) i`)
|
||||
f.exec(`INSERT INTO paths(domain_uuid,path,object_uuid,created_at) SELECT $1,'/bulk/'||lpad(i::text,4,'0'),'bulk-'||i,1 FROM generate_series(1,1100) i`, f.domain)
|
||||
f.exec(`INSERT INTO revisions(uuid,object_uuid,document_hash,lang,content_type,filename,created_at_ms,created_at) SELECT 'bulk-rev-'||i,'bulk-'||i,repeat('a',64),'ja','text/plain','',1000,1 FROM generate_series(1,1100) i`)
|
||||
f.exec(`UPDATE revisions SET content_type='application/pdf',created_at_ms=2000,filename='target.pdf' WHERE uuid='bulk-rev-1100'`)
|
||||
ctx := context.Background()
|
||||
allow := func(string) bool { return true }
|
||||
from := int64(2000)
|
||||
for _, options := range []SearchOptions{{FileType: "pdf"}, {Extension: "pdf"}, {FromMS: &from}} {
|
||||
results, err := s.SearchPathsInDomainWithOptions(ctx, f.domain, "/bulk", "", 100, allow, options)
|
||||
if err != nil || len(results) != 1 || results[0].Path != "/bulk/1100" {
|
||||
t.Fatal(options, results, err)
|
||||
}
|
||||
}
|
||||
// Only the latest revision contributes file/date predicates.
|
||||
f.revision("bulk-1100", "newer", 3000)
|
||||
results, err := s.SearchPathsInDomainWithOptions(ctx, f.domain, "/bulk", "", 100, allow, SearchOptions{FileType: "pdf"})
|
||||
if err != nil || len(results) != 0 {
|
||||
t.Fatal("historical metadata leaked", results, err)
|
||||
}
|
||||
checked := 0
|
||||
results, err = s.SearchPathsInDomainFiltered(ctx, f.domain, "/bulk", "bulk", 100, func(string) bool { checked++; return false })
|
||||
if err != nil || len(results) != 0 || checked != SearchCandidateLimit {
|
||||
t.Fatal("candidate cap", checked, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user