@@ -10,6 +10,7 @@ import (
1010 "io"
1111 "os"
1212 "path/filepath"
13+ "regexp"
1314 "slices"
1415 "strings"
1516 "testing"
@@ -67,7 +68,17 @@ func tree(t *testing.T) (root, out string) {
6768 "kernel/patches/0001-k.patch" , "image/rootfs.qcow2" , "licenses.txt" } {
6869 put (t , filepath .Join (out , f ), f , 0o644 )
6970 }
70- put (t , filepath .Join (out , "packages.txt" ), "bash 5.2-1 amd64\n libc6 2.39-1 amd64\n " , 0o644 )
71+ // Docker's packages, as dpkg records them: an epoch and Docker's suffix around the pinned version.
72+ // First, so that the first line of the list is one of them.
73+ var list string
74+ for _ , e := range pins (t ).Entries {
75+ if file := filepath .Base (e .URL ()); strings .HasSuffix (file , ".deb" ) {
76+ // The .deb's name is <package>_<version>_<arch>.deb.
77+ f := strings .Split (strings .TrimSuffix (file , ".deb" ), "_" )
78+ list += f [0 ] + " 5:" + f [1 ] + " " + f [2 ] + "\n "
79+ }
80+ }
81+ put (t , filepath .Join (out , "packages.txt" ), list + "bash 5.2-1 amd64\n libc6 2.39-1 amd64\n " , 0o644 )
7182 put (t , filepath .Join (out , "sbom/qemu.apk" ), apkDB ("glib-static,pcre2-static,libffi-dev,pixman-static,zlib-static,libseccomp-static,libcap-ng-static,liburing-dev,libaio-dev,gettext-static,musl-dev,gcc" ), 0o644 )
7283 put (t , filepath .Join (out , "sbom/e2fsprogs.apk" ), apkDB ("libarchive-static,acl-static,zlib-static,xz-static,zstd-static,bzip2-static,lz4-static,expat-static,openssl-libs-static,musl-dev,gcc" ), 0o644 )
7384 return root , out
@@ -180,12 +191,20 @@ func TestAReleaseShipsEveryPartAndSaysWhatItIs(t *testing.T) {
180191 if err != nil || inner .Metadata .Component .Name != "spin-machine" {
181192 t .Fatalf ("the machine's SBOM: %v" , err )
182193 }
183- text , _ := io .ReadAll (mustOpen (t , filepath .Join (out , "release" , name , share , "sbom" , "machine.cdx.json" )))
184- for _ , c := range []string {"pkg:apk/alpine/glib-static@1.0-r0" , "pkg:deb/ubuntu/bash@5.2-1" , `"name": "qboot.bin"` , `"name": "rootfs.qcow2"` , "0001-k.patch" , "mtrr.patch" } {
185- if ! strings .Contains (string (text ), c ) {
194+ raw , _ := io .ReadAll (mustOpen (t , filepath .Join (out , "release" , name , share , "sbom" , "machine.cdx.json" )))
195+ // encoding/json writes a purl's & as \u0026.
196+ text := strings .ReplaceAll (string (raw ), `\u0026` , "&" )
197+ docker , _ := pins (t ).Get ("docker-ce" )
198+ for _ , c := range []string {"pkg:apk/alpine/glib-static@1.0-r0" , "pkg:deb/ubuntu/bash@5.2-1" , `"name": "qboot.bin"` , `"name": "rootfs.qcow2"` , "0001-k.patch" , "mtrr.patch" ,
199+ "pkg:deb/docker/docker-ce@5:" + docker .Version + "-1~ubuntu.26.04~resolute?arch=amd64&repository_url=https://download.docker.com/linux/ubuntu" , docker .Pin , docker .URL (),
200+ "pkg:deb/docker/containerd.io@" } {
201+ if ! strings .Contains (text , c ) {
186202 t .Errorf ("the machine's SBOM does not name %s" , c )
187203 }
188204 }
205+ if strings .Contains (text , "pkg:deb/ubuntu/docker-ce" ) {
206+ t .Error ("the machine's SBOM names Docker's docker-ce as Ubuntu's" )
207+ }
189208}
190209
191210func maps (a , b map [string ]string ) bool {
@@ -242,8 +261,38 @@ func TestAReleaseMissingAnythingIsRefused(t *testing.T) {
242261 }
243262 })
244263 }
264+ // A Docker package the image did not record, or recorded at a version versions.yaml does not
265+ // pin, is an image that did not install what the release would say it did.
266+ for name , edit := range map [string ]func (string ) string {
267+ "without docker-ce" : func (list string ) string {
268+ return regexp .MustCompile (`(?m)^docker-ce .*\n` ).ReplaceAllString (list , "" )
269+ },
270+ "another docker-ce" : func (list string ) string {
271+ return regexp .MustCompile (`(?m)^docker-ce .*` ).ReplaceAllString (list , "docker-ce 5:1.0.0-1~ubuntu.26.04~resolute amd64" )
272+ },
273+ "a docker-ce whose version only starts with the pin's" : func (list string ) string {
274+ return regexp .MustCompile (`(?m)^docker-ce 5:([^-]*)-` ).ReplaceAllString (list , "docker-ce 5:${1}1-" )
275+ },
276+ } {
277+ root , out := tree (t )
278+ put (t , filepath .Join (out , "packages.txt" ), edit (read (t , filepath .Join (out , "packages.txt" ))), 0o644 )
279+ if _ , err := Pack (context .Background (), options (t , root , out )); err == nil || ! strings .Contains (err .Error (), "docker-ce" ) {
280+ t .Errorf ("an image %s: Pack = %v" , name , err )
281+ }
282+ }
283+ // A .deb pinned from a repository the SBOM has no vendor for would be named as Ubuntu's again.
245284 root , out := tree (t )
246285 o := options (t , root , out )
286+ for i , e := range o .Pins .Entries {
287+ if e .Name == "docker-ce" {
288+ o .Pins .Entries [i ].Source = strings .Replace (e .Source , "download.docker.com" , "example.org" , 1 )
289+ }
290+ }
291+ if _ , err := Pack (context .Background (), o ); err == nil || ! strings .Contains (err .Error (), "example.org" ) {
292+ t .Errorf ("a .deb from an unknown repository: Pack = %v" , err )
293+ }
294+ root , out = tree (t )
295+ o = options (t , root , out )
247296 o .Pins = & versions.Versions {}
248297 if _ , err := Pack (context .Background (), o ); err == nil {
249298 t .Error ("a release with no pins packed" )
0 commit comments