Setting sync up on a second computer meant typing the server, user, password (or S3 keys, or GitHub token) and every tick again. Settings › Sync's form, with sync on, now has Copy setup. It copies one line, `magpie-sync:…`, to paste into the same form on the other computer. - The line is not base64 of the settings. It is the setup (server, password or token, endpoint, region, path style, branch, the ticks) sealed with the sync passphrase by backup.SealData, the AES-GCM and PBKDF2 envelope the server's file already uses. The passphrase is never in it. Whoever has the line and not the passphrase has nothing. The copied note says what it holds and that the same passphrase opens it. - Pasted into any field of the form, the line is not typed in; the form asks for the passphrase, opens it (POST /api/davsync/setup-open), picks WebDAV, S3 or GitHub from its address and fills every field and tick. Nothing is saved until Turn on, and Turn on opens a pasted line first. A wrong passphrase, or text that isn't a setup, is said in the reader's language. A line a chat wrapped, or text around it, still opens. - Not built: GitLab or MySQL sync backends. Run (mica): - At the pushed tree (run as 8fadc2ef8, the same tree before these bodies): go test ./internal/gui ./internal/davsync ok; sync-setup-text, i18n-keys and i18n-en-no-cjk in the 110 of 110 the commit before names. At the base5b25d7e9e: ./internal/backup ok too. New TestSetupTextOpensWithItsPassphrase (WebDAV, S3, GitHub; no secret readable in the text or its decoded bytes; wrapped line; wrong passphrase), TestSetupTextNeedsSyncAndItsOwnText and TestDavsyncSetupTextRoutes (through the page's routes: off, copy, open on a computer with sync off, wrong passphrase, nothing saved). - New sync-setup-text.test.cjs, Chromium and WebKit, en, zh, zh-TW, ja, de at 900px and en, zh at 440px: 42 of 42. The sync GUI files and i18n-keys / i18n-en-no-cjk: green but s3-sync webkit en, red the same alone on origin/maine4ea31321(#3413). - GOOS=linux go vet -tags nogui, GOOS=windows go vet: clean. gofmt clean. - Broken by hand: SetupText unsealed (base64 of the JSON) made TestSetupTextOpensWithItsPassphrase red ("dav-app-password-9z is readable"); Turn on without opening the pasted line made all seven "pasted setup fills" GUI tests red. Both restored green. Not tried: a real WebDAV, S3 or GitHub server between two computers, a paste in the real app, WebKitGTK.
56 lines
2.1 KiB
Go
56 lines
2.1 KiB
Go
package gui
|
||
|
||
import (
|
||
"encoding/json"
|
||
"net/http"
|
||
"net/http/httptest"
|
||
"strings"
|
||
"testing"
|
||
|
||
"github.com/yetone/magpie/internal/davsync"
|
||
)
|
||
|
||
// Settings › Sync's Copy setup and its paste on another computer
|
||
// (WJaunita45604 on X), through the routes the page calls: the text comes
|
||
// sealed, opens with the passphrase into the setup the form fills, says a
|
||
// wrong passphrase as such, and saves nothing on the computer it opens on.
|
||
func TestDavsyncSetupTextRoutes(t *testing.T) {
|
||
sandboxHome(t)
|
||
mux := http.NewServeMux()
|
||
backupRoutes(mux, folderOnly{})
|
||
post := func(action, body string) (int, map[string]any) {
|
||
t.Helper()
|
||
w := httptest.NewRecorder()
|
||
mux.ServeHTTP(w, httptest.NewRequest("POST", "/api/davsync/"+action, strings.NewReader(body)))
|
||
var v map[string]any
|
||
json.Unmarshal(w.Body.Bytes(), &v)
|
||
return w.Code, v
|
||
}
|
||
if code, v := post("setup-text", "{}"); code != 400 || v["error"] != davsync.ErrSetupOff.Error() {
|
||
t.Fatalf("sync off: %d %v", code, v)
|
||
}
|
||
if err := davsync.Configure(davsync.Config{URL: "https://dav.jianguoyun.com/dav/", User: "me@example.com", Password: "app-password-9z", Passphrase: "correct horse", Keys: true}); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
code, v := post("setup-text", "{}")
|
||
text, _ := v["text"].(string)
|
||
if code != 200 || !strings.HasPrefix(text, davsync.SetupPrefix) || strings.Contains(text, "app-password") {
|
||
t.Fatalf("copy: %d %v", code, v)
|
||
}
|
||
if err := davsync.Off(); err != nil { // the other computer: sync off there
|
||
t.Fatal(err)
|
||
}
|
||
in, _ := json.Marshal(map[string]string{"text": text, "passphrase": "wrong horse"})
|
||
if code, v := post("setup-open", string(in)); code != 400 || v["error"] != davsync.ErrSetupPassphrase.Error() {
|
||
t.Fatalf("wrong passphrase: %d %v", code, v)
|
||
}
|
||
in, _ = json.Marshal(map[string]string{"text": text, "passphrase": "correct horse"})
|
||
code, v = post("setup-open", string(in))
|
||
if code != 200 || v["url"] != "https://dav.jianguoyun.com/dav/" || v["user"] != "me@example.com" || v["password"] != "app-password-9z" || v["keys"] != true {
|
||
t.Fatalf("open: %d %v", code, v)
|
||
}
|
||
if _, on := davsync.Load(); on {
|
||
t.Fatal("opening a pasted setup turned sync on")
|
||
}
|
||
}
|