feat: add browser upload queue and trusted sessions with bounded projections
This commit is contained in:
1 parent
84d52390f9
commit
b90aef79d0
79 files changed
+1962
-196
No files matched your search
@@ -23,17 +23,44 @@ import (
|
||||
// The real engine runs against a synthetic Wisp HTTP responder. This test never
|
||||
// dials an article server, production source, DNS name or external calendar.
|
||||
func TestFeedGeckoChromium(t *testing.T) {
|
||||
testFeedGeckoChromium(t, false)
|
||||
}
|
||||
|
||||
func TestFeedGeckoStartupFailureChromium(t *testing.T) {
|
||||
testFeedGeckoChromium(t, true)
|
||||
}
|
||||
|
||||
func testFeedGeckoChromium(t *testing.T, failure bool) {
|
||||
assets := os.Getenv("PAGESWIKI_GECKO_TEST_ASSETS")
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" || assets == "" {
|
||||
t.Skip("opt-in real Gecko assets")
|
||||
}
|
||||
var connections atomic.Int64
|
||||
publicHTTPS := !failure && os.Getenv("PAGESWIKI_GECKO_PUBLIC_HTTPS_TEST") == "1"
|
||||
realRelay, err := geckorelay.New(geckoTestKey, assets)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if publicHTTPS {
|
||||
realRelay.Distribution, err = geckorelay.VerifyDistribution(assets)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if failure && strings.HasSuffix(r.URL.Path, "/NotoSansCJKjp-Regular.otf") {
|
||||
http.Error(w, "synthetic startup failure", 503)
|
||||
return
|
||||
}
|
||||
if publicHTTPS {
|
||||
realRelay.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
if _, err := geckorelay.Verify(geckoTestKey, r.Header.Get(geckorelay.GrantHeader), time.Now()); err != nil {
|
||||
http.Error(w, "bad grant", 403)
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(r.URL.Path, "/assets/") {
|
||||
if strings.HasPrefix(r.URL.Path, "/assets/") || strings.HasPrefix(r.URL.Path, geckorelay.DistributionPrefix) {
|
||||
http.ServeFile(w, r, filepath.Join(assets, filepath.Base(r.URL.Path)))
|
||||
return
|
||||
}
|
||||
@@ -67,7 +94,7 @@ func TestFeedGeckoChromium(t *testing.T) {
|
||||
if !strings.Contains(requests[id], "\r\n\r\n") {
|
||||
continue
|
||||
}
|
||||
body := `<!doctype html><body style="margin:0;background:rgb(255,0,0)"><a style="display:block;width:300px;height:100px;background:blue;color:white" href="http://fixture.invalid/next">Synthetic next page</a><h1>Private fixture</h1>`
|
||||
body := `<!doctype html><meta charset="utf-8"><body style="margin:0;background:rgb(255,0,0)"><a style="display:block;width:300px;height:100px;background:blue;color:white" href="http://fixture.invalid/next">Synthetic next page</a><h1>日本語の記事:学舎の園</h1>`
|
||||
if strings.HasPrefix(requests[id], "GET /next ") {
|
||||
body = `<!doctype html><body style="margin:0;background:rgb(0,255,0)"><h1>Second synthetic page</h1>`
|
||||
}
|
||||
@@ -96,11 +123,26 @@ func TestFeedGeckoChromium(t *testing.T) {
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.store.CompleteFeed(context.Background(), claim, []store.FeedItem{{ID: "synthetic", Title: "Gecko synthetic fixture", URL: "http://fixture.invalid/first", Body: "No external network access."}}, "", "", "", false); e != nil {
|
||||
articleURL := "http://fixture.invalid/first"
|
||||
if publicHTTPS {
|
||||
articleURL = "https://example.com/"
|
||||
}
|
||||
if e = s.store.CompleteFeed(context.Background(), claim, []store.FeedItem{{ID: "synthetic", Title: "Gecko synthetic fixture", URL: articleURL, Body: "Synthetic test fixture."}}, "", "", "", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
handler := s.handler()
|
||||
web := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if publicHTTPS && r.URL.Path == "/static/js/feed-gecko.js" {
|
||||
js, err := os.ReadFile("static/js/feed-gecko.js")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
http.Error(w, "fixture missing", 500)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/javascript")
|
||||
io.WriteString(w, strings.Replace(string(js), "engine=new Gecko(", "globalThis.fixtureEngine=engine=new Gecko(", 1))
|
||||
return
|
||||
}
|
||||
if r.Header.Get("Origin") == "http://"+r.Host {
|
||||
r.Header.Set("Origin", "http://localhost")
|
||||
}
|
||||
@@ -111,7 +153,14 @@ func TestFeedGeckoChromium(t *testing.T) {
|
||||
defer web.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second)
|
||||
defer cancel()
|
||||
out, e := exec.CommandContext(ctx, "node", "internal/server/testdata/feed-gecko-browser.mjs", web.URL+"/v/feeds", t.TempDir(), "/tmp/pageswiki-feed-gecko.png").CombinedOutput()
|
||||
mode := "synthetic"
|
||||
if failure {
|
||||
mode = "startup-failure"
|
||||
}
|
||||
if publicHTTPS {
|
||||
mode = "public-https"
|
||||
}
|
||||
out, e := exec.CommandContext(ctx, "node", "internal/server/testdata/feed-gecko-browser.mjs", web.URL+"/v/feeds", t.TempDir(), "/tmp/pageswiki-feed-gecko.png", mode).CombinedOutput()
|
||||
if e != nil {
|
||||
t.Fatalf("browser: %v\n%s", e, out)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user