Before, a binary in a folder magpie may not write to, on a system that
can't ask for the administrator's password (Windows; Linux without
pkexec), was left with no exe to replace and shown only "{v} is out";
Download opened GitHub. The reporter found the cause themselves: the exe
was at C:\. updater.placeExe now marks it stuck "not-writable" with the
folder, and updateStuck says to move it to a folder the user can write
to; zh, zh-TW, ja and de strings added.
Verified:
- TestUpdateNotWritableSaysWhy (internal/gui) fails without the fix:
"a binary in a folder magpie can't write to: {State:available ...
Stuck: StuckDir: ...}"; passes with it.
- update-stuck.test.cjs, Chromium and WebKit, en/zh/ja/de at 1000px and
440px: 18/18 pass; without the app.js change it fails (the reason text
never appears, waitForFunction timeout).
- gui-ja, gui-de, gui-zh-tw, i18n-keys, update-*.test.cjs, cli-path:
136/136 pass in both engines.
- go vet ./internal/gui, go build, GOOS=linux/windows go vet -tags nogui
./internal/gui, GOOS=windows go build; sandbox HOME go test -tags nogui
./... all ok.
- On the Windows box, update.Writable (a windows/amd64 build, over ssh)
is false for a folder whose ACL denies the user write. Over ssh the
token is High integrity, so C:\ itself reads writable there; a
standard user's C:\ and the GUI on Windows weren't tried.
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/update"
|
|
)
|
|
|
|
// #1277: a magpie.exe kept at C:\ may not write there, so it can't replace
|
|
// itself. It still says a new version is out, and says why it opens the
|
|
// release page instead of updating, naming the folder.
|
|
func TestUpdateNotWritableSaysWhy(t *testing.T) {
|
|
if runtime.GOOS == "windows" || os.Geteuid() == 0 {
|
|
t.Skip("needs a folder this user may not write to")
|
|
}
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
json.NewEncoder(w).Encode(update.Release{Version: "0.1.11", Assets: map[string]update.Asset{
|
|
update.BinaryAsset(): {URL: "http://" + r.Host + "/asset"},
|
|
}})
|
|
}))
|
|
defer srv.Close()
|
|
t.Setenv("MAGPIE_UPDATE_FEED", srv.URL)
|
|
old := Version
|
|
Version = "0.1.10"
|
|
defer func() { Version = old }()
|
|
was := canElevate
|
|
defer func() { canElevate = was }()
|
|
|
|
dir := t.TempDir()
|
|
exe := filepath.Join(dir, "magpie.exe")
|
|
if err := os.WriteFile(exe, []byte("magpie"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Chmod(dir, 0o555); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.Chmod(dir, 0o755)
|
|
|
|
canElevate = func() bool { return false }
|
|
u := &updater{}
|
|
u.placeExe(exe)
|
|
u.check()
|
|
j := u.json()
|
|
if j.State != "available" || j.Stuck != "not-writable" || j.StuckDir != dir {
|
|
t.Fatalf("a binary in a folder magpie can't write to: %+v", j)
|
|
}
|
|
|
|
// where the system can ask for the password, it updates as before
|
|
canElevate = func() bool { return true }
|
|
u = &updater{}
|
|
u.placeExe(exe)
|
|
if u.stuck != "" || u.exe != exe {
|
|
t.Fatalf("stuck %q, exe %q", u.stuck, u.exe)
|
|
}
|
|
// and a folder it may write to is never stuck
|
|
canElevate = func() bool { return false }
|
|
os.Chmod(dir, 0o755)
|
|
u = &updater{}
|
|
u.placeExe(exe)
|
|
if u.stuck != "" || u.exe != exe {
|
|
t.Fatalf("a writable folder: stuck %q, exe %q", u.stuck, u.exe)
|
|
}
|
|
}
|