mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
The host checked that each package a first build of base recorded is the archive's, but root in the recording build VM chose which signed lists to hand back: it could return only the release pocket's and record an older version than -updates or -security have. Now: - a recording must hand back resolute-updates' and resolute-security's signed InRelease files with lists for the architectures whose lists have the recorded packages (another archive's InRelease, such as archive.ubuntu.com's on arm64, doesn't count), and every non-empty list each InRelease it hands back gives for those architectures, in every component (packages_lists_missing); - a recorded package that the release pocket, -updates or -security lists a newer version of, for its architecture, is refused, naming the package, both versions and the suite (packages_not_newest); -backports doesn't count, as apt installs from it only when asked; - a list's SHA-256 is checked against the verified InRelease files before it's read, so only signed lists are parsed; - apt.sh's recording takes phased updates (APT::Get::Always-Include-Phased-Updates), so apt installs the newest version the lists have. - internal/ubuntu: CompareVersions, dpkg --compare-versions in Go (epoch, upstream, revision, ~ and letters' order; ErrVersion for one that isn't a version); Release.Lists gives the matching lists with their paths, ListsFor, List.Arch, Backports, RequiredSuites. - internal/build: signedEntries returns a signed (entries, each package's architectures, the newest version by architecture and name and its suite); verified, complete, checkNewest, newer; readArchiveList returns an archiveList. - Messages: packages_lists_missing, packages_not_newest. - Tests: CompareVersions' table (Debian policy's ordering and dpkg's cases, invalid versions); ListsFor and Backports on Ubuntu's real InRelease; a recording refused for an older version than -updates has, for a missing -updates or -security InRelease, a missing list, another archive's -security, a missing backports list; kept for the newer version, a newer one in backports, an older one in -security; checkNewest's table. The gpg-made fixtures are signed again by a new test key, with Packages-newer, Packages-security and InRelease-newer, -security, -security-amd64 and -backports added. - Docs: images.md's Base's packages, design.md's trust note (the pocket choice closed; what root in the recording VM still chooses). Co-Authored-By: Claude Opus 5.5 <[email protected]>
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package ubuntu
|
|
|
|
import "testing"
|
|
|
|
// CompareVersions orders versions as dpkg --compare-versions does: Debian
|
|
// policy's examples (5.6.12), and the cases dpkg's own tests check.
|
|
func TestCompareVersions(t *testing.T) {
|
|
for _, c := range []struct {
|
|
a, b string
|
|
want int
|
|
}{
|
|
{"1.0", "1.0", 0},
|
|
{"0:1.0", "1.0", 0},
|
|
{"1.0-0", "1.0", 0},
|
|
{"1.0-1", "1.0-01", 0},
|
|
{"1.0", "1.0-1", -1},
|
|
{"1.0-1", "1.0-2", -1},
|
|
{"1.0-1ubuntu1", "1.0-1ubuntu2", -1},
|
|
{"1.0-1ubuntu1", "1.0-1ubuntu1.1", -1},
|
|
{"1.0-1ubuntu1.1", "1.0-1ubuntu2", -1},
|
|
{"2.39-0ubuntu8", "2.39-0ubuntu8.3", -1},
|
|
{"1.9", "1.10", -1},
|
|
{"1.0", "1.0.1", -1},
|
|
{"1.0", "1.0a", -1},
|
|
{"1.0a", "1.0b", -1},
|
|
{"1.0a", "1.0+", -1}, // letters sort before everything else but ~
|
|
{"1.0+", "1.0.", -1}, // then by ASCII
|
|
{"1.0", "1.0+b1", -1}, // a binary rebuild is newer
|
|
{"1.0~rc1", "1.0", -1},
|
|
{"1.0~rc1", "1.0~rc2", -1},
|
|
{"1.0~~", "1.0~~a", -1}, // policy: ~~ < ~~a < ~ < (nothing) < a
|
|
{"1.0~~a", "1.0~", -1},
|
|
{"1.0~", "1.0", -1},
|
|
{"1.0", "1.0a", -1},
|
|
{"1.0-1~bpo1", "1.0-1", -1},
|
|
{"2.0", "1:0.1", -1}, // the epoch first
|
|
{"1:2.0", "2:0.1", -1},
|
|
{"10:1.0", "9:1.0", 1},
|
|
{"1.0-1-1", "1.0-1-2", -1}, // the revision is after the last hyphen
|
|
{"1.0-a", "1.0-1", 1},
|
|
{"1:1.0:1-1", "1:1.0:2-1", -1}, // colons after the epoch's are upstream's
|
|
{"001.000", "1.0", 0},
|
|
{"1.0.0", "1.0", 1},
|
|
{"a", "b", -1},
|
|
{"1.2.3", "1.2.3", 0},
|
|
{"7.88.1-10+deb12u5", "7.88.1-10+deb12u12", -1},
|
|
} {
|
|
got, err := CompareVersions(c.a, c.b)
|
|
if err != nil || got != c.want {
|
|
t.Errorf("CompareVersions(%q, %q) = %d, %v; want %d", c.a, c.b, got, err, c.want)
|
|
}
|
|
if back, _ := CompareVersions(c.b, c.a); back != -c.want {
|
|
t.Errorf("CompareVersions(%q, %q) = %d; want %d", c.b, c.a, back, -c.want)
|
|
}
|
|
}
|
|
for _, bad := range []string{"", ":1.0", "x:1.0", "-1:1.0", "1:", "1.0-", "-1", "1.0 2", "1.0_1", "1.0-1:2", "1.0-é", "99999999999999999999:1"} {
|
|
if _, err := CompareVersions(bad, "1.0"); err == nil {
|
|
t.Errorf("CompareVersions(%q): no error", bad)
|
|
}
|
|
if _, err := CompareVersions("1.0", bad); err == nil {
|
|
t.Errorf("CompareVersions(1.0, %q): no error", bad)
|
|
}
|
|
}
|
|
}
|