Hardcode the repository releases come from
routerUpdate.repository (a module option beside the update keys, not a router.* setting) defaults to the project's repository; the Updates page names it but no longer has a field for it. Forks and tests set it in a module. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,9 +9,13 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
const testRepository = "https://git.example.org/me/nixos-router"
|
||||
|
||||
func TestUpdatesFromGit(t *testing.T) {
|
||||
a, sys := newTestApp(t)
|
||||
sys.ReleaseFile = filepath.Join(t.TempDir(), "router-release")
|
||||
dir := t.TempDir()
|
||||
sys.ReleaseFile = filepath.Join(dir, "router-release")
|
||||
sys.RepositoryFile = filepath.Join(dir, "router-update-repository")
|
||||
os.WriteFile(sys.ReleaseFile, []byte(`{"version":"1.0.0","serial":1000}`), 0o600)
|
||||
a.sys = sys
|
||||
orig := startUnit
|
||||
@@ -26,26 +30,24 @@ func TestUpdatesFromGit(t *testing.T) {
|
||||
return do(h, "POST", path, form, cookie).Header().Get("Location")
|
||||
}
|
||||
|
||||
// The repository: an address of a public repository, nothing else.
|
||||
for _, bad := range []string{"git@git.example.org:me/r.git", "https://user:pw@git.example.org/r", "https://git.example.org/r?x=1", "file:///etc", "https://git.example.org/a b"} {
|
||||
if loc := post("/update/repository", url.Values{"repository": {bad}}); !strings.Contains(loc, "Not+saved") {
|
||||
t.Errorf("%q was accepted: %s", bad, loc)
|
||||
}
|
||||
}
|
||||
if loc := post("/update/gitcheck", url.Values{}); !strings.Contains(loc, "Set+the+repository") || len(started) != 0 {
|
||||
// A router without a repository has nothing to look at.
|
||||
if loc := post("/update/gitcheck", url.Values{}); !strings.Contains(loc, "no+repository") || len(started) != 0 {
|
||||
t.Fatalf("a check without a repository: %q %v", loc, started)
|
||||
}
|
||||
if loc := post("/update/gitinstall", url.Values{"tag": {"v1.1.0"}}); !strings.Contains(loc, "Set+the+repository") {
|
||||
if loc := post("/update/gitinstall", url.Values{"tag": {"v1.1.0"}}); !strings.Contains(loc, "no+repository") {
|
||||
t.Fatalf("an install without a repository: %q", loc)
|
||||
}
|
||||
post("/update/repository", url.Values{"repository": {"https://git.example.org/me/nixos-router/"}})
|
||||
s, _ := loadSettings(sys.settingsPath())
|
||||
if got := s.repository(); got != "https://git.example.org/me/nixos-router" {
|
||||
t.Fatalf("repository: %q", got)
|
||||
if rec := do(h, "POST", "/update/repository", url.Values{"csrf": {token}, "repository": {"https://evil.example.org/r"}}, cookie); rec.Code != 404 && rec.Code != 405 {
|
||||
t.Fatalf("the repository can be set from the page: %d", rec.Code)
|
||||
}
|
||||
// It takes effect when updating, so it is no unapplied change.
|
||||
if c, err := loadSettings(sys.confirmedPath()); err == nil && c.repository() != "" {
|
||||
t.Logf("confirmed settings carry it: %q", c.repository())
|
||||
if body := do(h, "GET", "/update", nil, cookie).Body.String(); strings.Contains(body, `name="repository"`) {
|
||||
t.Fatalf("the page has a field for the repository:\n%s", body)
|
||||
}
|
||||
|
||||
// The repository is the installed version's; the page names it.
|
||||
os.WriteFile(sys.RepositoryFile, []byte(testRepository+"\n"), 0o644)
|
||||
if body := do(h, "GET", "/update", nil, cookie).Body.String(); !strings.Contains(body, testRepository) || !strings.Contains(body, "Not looked yet") {
|
||||
t.Fatalf("the page does not say which repository:\n%s", body)
|
||||
}
|
||||
|
||||
// Looking starts the unit; what it found is shown while it is about this repository and version.
|
||||
@@ -53,9 +55,6 @@ func TestUpdatesFromGit(t *testing.T) {
|
||||
if len(started) != 1 || started[0] != "router-update-check.service" {
|
||||
t.Fatalf("started %v", started)
|
||||
}
|
||||
if body := do(h, "GET", "/update", nil, cookie).Body.String(); !strings.Contains(body, "Not looked yet") {
|
||||
t.Fatalf("a result before any look:\n%s", body)
|
||||
}
|
||||
write := func(repo, installed string, newer bool) {
|
||||
os.MkdirAll(sys.updateDir(), 0o755)
|
||||
data, _ := json.Marshal(map[string]any{"repository": repo, "time": "2026-11-26T08:00:00Z", "installed": installed,
|
||||
@@ -66,17 +65,17 @@ func TestUpdatesFromGit(t *testing.T) {
|
||||
if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "is out") {
|
||||
t.Fatalf("a notice from another repository:\n%s", body)
|
||||
}
|
||||
write("https://git.example.org/me/nixos-router", "0.9.0", true)
|
||||
write(testRepository, "0.9.0", true)
|
||||
if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "is out") {
|
||||
t.Fatalf("a notice from before the last update:\n%s", body)
|
||||
}
|
||||
write("https://git.example.org/me/nixos-router", "1.0.0", true)
|
||||
write(testRepository, "1.0.0", true)
|
||||
for _, path := range []string{"/", "/update"} {
|
||||
if body := do(h, "GET", path, nil, cookie).Body.String(); !strings.Contains(body, "1.1.0") || (path == "/" && !strings.Contains(body, "nixos-router 1.1.0 is out")) {
|
||||
t.Fatalf("%s lacks the release:\n%s", path, body)
|
||||
}
|
||||
}
|
||||
write("https://git.example.org/me/nixos-router", "1.0.0", false)
|
||||
write(testRepository, "1.0.0", false)
|
||||
if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "nixos-router 1.1.0 is out") {
|
||||
t.Fatalf("a notice when up to date")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user