JasonLeeForOnly's WebDAV sync failed with only "not a magpie backup" for
several versions, and nothing on the page got past it. A WebDAV GET of the
backup can come back as a body that isn't the file in several ways; each is
now reproduced with an httptest server that answers the way the real one
does:
Unpacked (WebDAV and S3): gzip with or without Content-Encoding (a proxy
that drops the header), x-gzip, zstd with or without the header, deflate
(zlib or raw), and a header that says gzip over a plain body. Bodies are
told by magic number; a backup is JSON, so either magic is never the file.
Brotli (br) can't be unpacked and is said as itself, with what to turn off.
Said, with no upload offered: an HTML page answered with 200 (Nextcloud
login after a redirect, Cloudflare Access, an AList/OpenList web app, an
rclone directory listing, a captive portal), with its <title> and the
host/path a redirect ended at (query, fragment and user dropped), and
where the WebDAV address is for 坚果云 and Nextcloud; an XML answer, by its
root element.
Said, with Upload as the way out: an empty (0-byte) file, a backup cut
short or damaged (the automatic rebuild is unchanged and still goes first
when its rules allow), another app's file ("format": "…"), other JSON,
and any other file by its content type. Messages carry the size, kind and a
page title only, never the file's contents.
backup.Open now tells ErrNotBackup (doesn't begin like a backup) from
ErrCorrupt (begins like one, cut short). The status carries the kind as
serverFile; Settings › Sync and backup says it in the reader's language,
wraps it whole, and shows "Upload this computer's setup" only when the file
may be replaced. davsync.Upload (POST /api/davsync/upload, `magpie webdav
upload`, `magpie s3 upload`) asks first in the GUI, re-reads the file,
refuses a backup this computer opens, one sealed with another passphrase,
a newer magpie's, a page and an XML answer, keeps the server's copy in the
sync folder (0600, newest 5) and writes nothing if that fails, then writes
with If-Match on the version read. New strings in en, zh, zh-TW, ja, de.
Verified: internal/davsync/not_backup_test.go (TestReadCompressedBackup,
TestReadBrotliSaid, TestServerAnswerSaid, TestCutBackupSaidAndUploaded,
TestS3ReadCompressedObject; Upload-only parts stripped to compile) fails
on e4a90aa6 for every compressed case but "gzip said", Brotli, every
server-answer case, the cut case and S3 gzip, and passes here. Dropping
the Replace check in Upload turns the page/XML cases red ("Upload wrote
over a page"). gofmt -l clean; go vet darwin, GOOS=linux and GOOS=windows
-tags nogui on ., davsync, backup, gui; full go test -tags nogui ./... ok;
-race on davsync and backup ok. GUI: sync-not-backup.test.cjs (en, zh,
zh-TW, ja, de; 900 and 440px), sync-*, s3-sync, gui-de, gui-ja, gui-zh-tw,
click-scroll in Chromium and WebKit, 81 pass. Not tried against a real
WebDAV server or on the Windows box; the reporter's server is unknown.
76 lines
2.7 KiB
Go
76 lines
2.7 KiB
Go
//go:build linux && cgo && gtk3 && !nogui
|
|
|
|
package gui
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestFontDPIUnset builds testdata/fontdpi_probe.c with the guard the app
|
|
// runs (fontdpi_gtk3.h) and opens a real WebKitGTK page with GDK's font
|
|
// DPI unset, as on #1371's NixOS/Niri desktop. Without the guard WebKitGTK
|
|
// 2.54.1 lays it out at viewport -40320 and font 9000000px. A positive DPI
|
|
// is the user's own and is kept. It needs a display (Xvfb will do).
|
|
func TestFontDPIUnset(t *testing.T) {
|
|
if os.Getenv("DISPLAY") == "" && os.Getenv("WAYLAND_DISPLAY") == "" {
|
|
t.Skip("needs a display")
|
|
}
|
|
flags, err := exec.Command("pkg-config", "--cflags", "--libs", "gtk+-3.0", "webkit2gtk-4.1").Output()
|
|
if err != nil {
|
|
t.Skip("no GTK 3 / WebKitGTK 4.1 headers:", err)
|
|
}
|
|
here, _ := filepath.Abs(".")
|
|
bin := filepath.Join(t.TempDir(), "probe")
|
|
args := append([]string{"testdata/fontdpi_probe.c", "-DMAGPIE_FONT_DPI", "-I" + here, "-o", bin}, strings.Fields(string(flags))...)
|
|
if out, err := exec.Command("cc", args...).CombinedOutput(); err != nil {
|
|
t.Fatalf("build probe: %v\n%s", err, out)
|
|
}
|
|
home := t.TempDir()
|
|
for _, c := range []struct {
|
|
name, dpi, scale string
|
|
want float64
|
|
}{
|
|
{"unset", "-1", "", 96},
|
|
{"unset, font scale", "-1", "1.25", 120},
|
|
{"unset, bad font scale", "-1", "nan", 96},
|
|
{"the user's own", "144", "", 144},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
|
|
defer cancel()
|
|
cmd := exec.CommandContext(ctx, bin, c.dpi)
|
|
cmd.Env = append(os.Environ(), "HOME="+home, "XDG_CONFIG_HOME="+filepath.Join(home, ".config"),
|
|
"XDG_CACHE_HOME="+filepath.Join(home, ".cache"), "XDG_DATA_HOME="+filepath.Join(home, ".local/share"),
|
|
"GSETTINGS_BACKEND=memory", "GDK_DPI_SCALE="+c.scale, "WEBKIT_DISABLE_COMPOSITING_MODE=1")
|
|
out, err := cmd.Output()
|
|
if err != nil {
|
|
t.Fatalf("probe: %v\n%s", err, out)
|
|
}
|
|
var dpi, viewport, font float64
|
|
var allocated int
|
|
for _, l := range strings.Split(string(out), "\n") {
|
|
if strings.HasPrefix(l, "layout ") {
|
|
fmt.Sscanf(l, "layout dpi=%g allocated=%d viewport=%g font=%g", &dpi, &allocated, &viewport, &font)
|
|
}
|
|
}
|
|
t.Logf("%s", out)
|
|
if dpi != c.want {
|
|
t.Errorf("font DPI %g, want %g", dpi, c.want)
|
|
}
|
|
if viewport <= 0 || font != 16 {
|
|
t.Errorf("page laid out at viewport %g, body font %gpx; want a positive viewport and 16px", viewport, font)
|
|
}
|
|
if want := float64(allocated) * 96 / c.want; viewport < want-2 || viewport > want+2 {
|
|
t.Errorf("viewport %g, want %g for %dpx at %g DPI", viewport, want, allocated, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|