github.com/quay/claircore@v1.5.28/dpkg/scanner_test.go (about)

     1  package dpkg
     2  
     3  import (
     4  	"archive/tar"
     5  	"bufio"
     6  	"context"
     7  	"io"
     8  	"net/textproto"
     9  	"os"
    10  	"slices"
    11  	"testing"
    12  
    13  	"github.com/google/go-cmp/cmp"
    14  	"github.com/quay/zlog"
    15  
    16  	"github.com/quay/claircore"
    17  	"github.com/quay/claircore/test"
    18  )
    19  
    20  func TestScanner(t *testing.T) {
    21  	t.Parallel()
    22  	// TODO(hank) Cook up a manifest format for dpkg ala `test/rpmtest.Manifest`
    23  	want := []*claircore.Package{
    24  		{
    25  			Name:           "fdisk",
    26  			Version:        "2.31.1-0.4ubuntu3.3",
    27  			Kind:           claircore.BINARY,
    28  			Arch:           "amd64",
    29  			Source:         &claircore.Package{Name: "util-linux", Version: "2.31.1-0.4ubuntu3.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
    30  			PackageDB:      "var/lib/dpkg/status",
    31  			RepositoryHint: "9debc95b96eed7df33817e62654b7649",
    32  		},
    33  		{
    34  			Name:           "libpam-runtime",
    35  			Version:        "1.1.8-3.6ubuntu2.18.04.1",
    36  			Kind:           claircore.BINARY,
    37  			Arch:           "all",
    38  			Source:         &claircore.Package{Name: "pam", Version: "1.1.8-3.6ubuntu2.18.04.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
    39  			PackageDB:      "var/lib/dpkg/status",
    40  			RepositoryHint: "f96da69e0bd2f91f257c09522e2e48a9",
    41  		},
    42  		{
    43  			Name:           "libncurses5",
    44  			Version:        "6.1-1ubuntu1.18.04",
    45  			Kind:           claircore.BINARY,
    46  			Arch:           "amd64",
    47  			Source:         &claircore.Package{Name: "ncurses", Version: "6.1-1ubuntu1.18.04", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
    48  			PackageDB:      "var/lib/dpkg/status",
    49  			RepositoryHint: "9d18792b91935a5849328cb368005ec9",
    50  		},
    51  		{
    52  			Name:           "libcom-err2",
    53  			Version:        "1.44.1-1ubuntu1.1",
    54  			Kind:           claircore.BINARY,
    55  			Arch:           "amd64",
    56  			Source:         &claircore.Package{Name: "e2fsprogs", Version: "1.44.1-1ubuntu1.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
    57  			PackageDB:      "var/lib/dpkg/status",
    58  			RepositoryHint: "6ed12cf8b536fa9eca59fd8b0e544111",
    59  		},
    60  		{
    61  			Name:           "libapt-pkg5.0",
    62  			Version:        "1.6.11",
    63  			Kind:           claircore.BINARY,
    64  			Arch:           "amd64",
    65  			Source:         &claircore.Package{Name: "apt", Version: "1.6.11", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
    66  			PackageDB:      "var/lib/dpkg/status",
    67  			RepositoryHint: "b0e3976b91845036e35cbfb01ec6d6eb",
    68  		},
    69  		{
    70  			Name:           "libaudit1",
    71  			Version:        "1:2.8.2-1ubuntu1",
    72  			Kind:           claircore.BINARY,
    73  			Arch:           "amd64",
    74  			Source:         &claircore.Package{Name: "audit", Version: "1:2.8.2-1ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
    75  			PackageDB:      "var/lib/dpkg/status",
    76  			RepositoryHint: "5c0000030cfa810d6c835ab82f517ee6",
    77  		},
    78  		{
    79  			Name:           "libtinfo5",
    80  			Version:        "6.1-1ubuntu1.18.04",
    81  			Kind:           claircore.BINARY,
    82  			Arch:           "amd64",
    83  			Source:         &claircore.Package{Name: "ncurses", Version: "6.1-1ubuntu1.18.04", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
    84  			PackageDB:      "var/lib/dpkg/status",
    85  			RepositoryHint: "33ca525ace7a21d05093465f64207cca",
    86  		},
    87  		{
    88  			Name:           "perl-base",
    89  			Version:        "5.26.1-6ubuntu0.3",
    90  			Kind:           claircore.BINARY,
    91  			Arch:           "amd64",
    92  			Source:         &claircore.Package{Name: "perl", Version: "5.26.1-6ubuntu0.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
    93  			PackageDB:      "var/lib/dpkg/status",
    94  			RepositoryHint: "f17ad9208249962b7a52349494ce75ff",
    95  		},
    96  		{
    97  			Name:           "libudev1",
    98  			Version:        "237-3ubuntu10.25",
    99  			Kind:           claircore.BINARY,
   100  			Arch:           "amd64",
   101  			Source:         &claircore.Package{Name: "systemd", Version: "237-3ubuntu10.25", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   102  			PackageDB:      "var/lib/dpkg/status",
   103  			RepositoryHint: "a6216ccf2388067c734fb7f568f3e0a8",
   104  		},
   105  		{
   106  			Name:           "libunistring2",
   107  			Version:        "0.9.9-0ubuntu2",
   108  			Kind:           claircore.BINARY,
   109  			Arch:           "amd64",
   110  			Source:         &claircore.Package{Name: "libunistring", Version: "0.9.9-0ubuntu2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   111  			PackageDB:      "var/lib/dpkg/status",
   112  			RepositoryHint: "db7af6bc39ecfe032ce4e7a6f858259d",
   113  		},
   114  		{
   115  			Name:           "libnettle6",
   116  			Version:        "3.4-1",
   117  			Kind:           claircore.BINARY,
   118  			Arch:           "amd64",
   119  			Source:         &claircore.Package{Name: "nettle", Version: "3.4-1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   120  			PackageDB:      "var/lib/dpkg/status",
   121  			RepositoryHint: "02bfb40df3039b604a89a846e5daf10c",
   122  		},
   123  		{
   124  			Name:           "libattr1",
   125  			Version:        "1:2.4.47-2build1",
   126  			Kind:           claircore.BINARY,
   127  			Arch:           "amd64",
   128  			Source:         &claircore.Package{Name: "attr", Version: "1:2.4.47-2build1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   129  			PackageDB:      "var/lib/dpkg/status",
   130  			RepositoryHint: "a915a7ea4dd5f10d4d4d385d2c24192d",
   131  		},
   132  		{
   133  			Name:           "libss2",
   134  			Version:        "1.44.1-1ubuntu1.1",
   135  			Kind:           claircore.BINARY,
   136  			Arch:           "amd64",
   137  			Source:         &claircore.Package{Name: "e2fsprogs", Version: "1.44.1-1ubuntu1.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   138  			PackageDB:      "var/lib/dpkg/status",
   139  			RepositoryHint: "06ebd35af75313d7ce587f6d83720209",
   140  		},
   141  		{
   142  			Name:           "liblzma5",
   143  			Version:        "5.2.2-1.3",
   144  			Kind:           claircore.BINARY,
   145  			Arch:           "amd64",
   146  			Source:         &claircore.Package{Name: "xz-utils", Version: "5.2.2-1.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   147  			PackageDB:      "var/lib/dpkg/status",
   148  			RepositoryHint: "16e9fc306ca68a3a7806754784b52d8c",
   149  		},
   150  		{
   151  			Name:           "libidn2-0",
   152  			Version:        "2.0.4-1.1build2",
   153  			Kind:           claircore.BINARY,
   154  			Arch:           "amd64",
   155  			Source:         &claircore.Package{Name: "libidn2", Version: "2.0.4-1.1build2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   156  			PackageDB:      "var/lib/dpkg/status",
   157  			RepositoryHint: "ebecbbce67182ce137f5ca10ed2122e4",
   158  		},
   159  		{
   160  			Name:           "libpam-modules-bin",
   161  			Version:        "1.1.8-3.6ubuntu2.18.04.1",
   162  			Kind:           claircore.BINARY,
   163  			Arch:           "amd64",
   164  			Source:         &claircore.Package{Name: "pam", Version: "1.1.8-3.6ubuntu2.18.04.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   165  			PackageDB:      "var/lib/dpkg/status",
   166  			RepositoryHint: "7b7262bc55945a4b9dfc5bb3a4125974",
   167  		},
   168  		{
   169  			Name:           "grep",
   170  			Version:        "3.1-2",
   171  			Kind:           claircore.BINARY,
   172  			Arch:           "amd64",
   173  			Source:         &claircore.Package{Name: "grep", Version: "3.1-2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   174  			PackageDB:      "var/lib/dpkg/status",
   175  			RepositoryHint: "4455aef7b04af0c9ce1cf2aa6129fed7",
   176  		},
   177  		{
   178  			Name:           "base-passwd",
   179  			Version:        "3.5.44",
   180  			Kind:           claircore.BINARY,
   181  			Arch:           "amd64",
   182  			Source:         &claircore.Package{Name: "base-passwd", Version: "3.5.44", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   183  			PackageDB:      "var/lib/dpkg/status",
   184  			RepositoryHint: "302889f7be244dc6664821cdba719b6e",
   185  		},
   186  		{
   187  			Name:           "liblz4-1",
   188  			Version:        "0.0~r131-2ubuntu3",
   189  			Kind:           claircore.BINARY,
   190  			Arch:           "amd64",
   191  			Source:         &claircore.Package{Name: "lz4", Version: "0.0~r131-2ubuntu3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   192  			PackageDB:      "var/lib/dpkg/status",
   193  			RepositoryHint: "2c4983fb7dd0ba7e990ff7661a3f2379",
   194  		},
   195  		{
   196  			Name:           "debianutils",
   197  			Version:        "4.8.4",
   198  			Kind:           claircore.BINARY,
   199  			Arch:           "amd64",
   200  			Source:         &claircore.Package{Name: "debianutils", Version: "4.8.4", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   201  			PackageDB:      "var/lib/dpkg/status",
   202  			RepositoryHint: "e4235d987575ef2b67b99113b311f5b6",
   203  		},
   204  		{
   205  			Name:           "libgcrypt20",
   206  			Version:        "1.8.1-4ubuntu1.1",
   207  			Kind:           claircore.BINARY,
   208  			Arch:           "amd64",
   209  			Source:         &claircore.Package{Name: "libgcrypt20", Version: "1.8.1-4ubuntu1.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   210  			PackageDB:      "var/lib/dpkg/status",
   211  			RepositoryHint: "217a9e55d627ef5e638296a0ad54a4fd",
   212  		},
   213  		{
   214  			Name:           "libncursesw5",
   215  			Version:        "6.1-1ubuntu1.18.04",
   216  			Kind:           claircore.BINARY,
   217  			Arch:           "amd64",
   218  			Source:         &claircore.Package{Name: "ncurses", Version: "6.1-1ubuntu1.18.04", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   219  			PackageDB:      "var/lib/dpkg/status",
   220  			RepositoryHint: "14164ca584dfc5968d2f00cced8e9dd7",
   221  		},
   222  		{
   223  			Name:           "bash",
   224  			Version:        "4.4.18-2ubuntu1.2",
   225  			Kind:           claircore.BINARY,
   226  			Arch:           "amd64",
   227  			Source:         &claircore.Package{Name: "bash", Version: "4.4.18-2ubuntu1.2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   228  			PackageDB:      "var/lib/dpkg/status",
   229  			RepositoryHint: "bc32b6211b320538050b775f28daa2a1",
   230  		},
   231  		{
   232  			Name:           "libuuid1",
   233  			Version:        "2.31.1-0.4ubuntu3.3",
   234  			Kind:           claircore.BINARY,
   235  			Arch:           "amd64",
   236  			Source:         &claircore.Package{Name: "util-linux", Version: "2.31.1-0.4ubuntu3.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   237  			PackageDB:      "var/lib/dpkg/status",
   238  			RepositoryHint: "056a0822246369948a91cdebbb295225",
   239  		},
   240  		{
   241  			Name:           "libdb5.3",
   242  			Version:        "5.3.28-13.1ubuntu1.1",
   243  			Kind:           claircore.BINARY,
   244  			Arch:           "amd64",
   245  			Source:         &claircore.Package{Name: "db5.3", Version: "5.3.28-13.1ubuntu1.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   246  			PackageDB:      "var/lib/dpkg/status",
   247  			RepositoryHint: "d81a5051ae0295d8ec791e8592849b8e",
   248  		},
   249  		{
   250  			Name:           "debconf",
   251  			Version:        "1.5.66ubuntu1",
   252  			Kind:           claircore.BINARY,
   253  			Arch:           "all",
   254  			Source:         &claircore.Package{Name: "debconf", Version: "1.5.66ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   255  			PackageDB:      "var/lib/dpkg/status",
   256  			RepositoryHint: "f3217960643ae75cc292e59488aabae2",
   257  		},
   258  		{
   259  			Name:           "zlib1g",
   260  			Version:        "1:1.2.11.dfsg-0ubuntu2",
   261  			Kind:           claircore.BINARY,
   262  			Arch:           "amd64",
   263  			Source:         &claircore.Package{Name: "zlib", Version: "1:1.2.11.dfsg-0ubuntu2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   264  			PackageDB:      "var/lib/dpkg/status",
   265  			RepositoryHint: "3270b12c3a9a6ee9f4ae27ffeb407a6c",
   266  		},
   267  		{
   268  			Name:           "hostname",
   269  			Version:        "3.20",
   270  			Kind:           claircore.BINARY,
   271  			Arch:           "amd64",
   272  			Source:         &claircore.Package{Name: "hostname", Version: "3.20", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   273  			PackageDB:      "var/lib/dpkg/status",
   274  			RepositoryHint: "6e0f038548ebd196e0659b06fe81a466",
   275  		},
   276  		{
   277  			Name:           "mawk",
   278  			Version:        "1.3.3-17ubuntu3",
   279  			Kind:           claircore.BINARY,
   280  			Arch:           "amd64",
   281  			Source:         &claircore.Package{Name: "mawk", Version: "1.3.3-17ubuntu3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   282  			PackageDB:      "var/lib/dpkg/status",
   283  			RepositoryHint: "4e377c681d072a697175326a3fcd14da",
   284  		},
   285  		{
   286  			Name:           "gzip",
   287  			Version:        "1.6-5ubuntu1",
   288  			Kind:           claircore.BINARY,
   289  			Arch:           "amd64",
   290  			Source:         &claircore.Package{Name: "gzip", Version: "1.6-5ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   291  			PackageDB:      "var/lib/dpkg/status",
   292  			RepositoryHint: "762f8b7616e78c56ef2c6345361ec179",
   293  		},
   294  		{
   295  			Name:           "gpgv",
   296  			Version:        "2.2.4-1ubuntu1.2",
   297  			Kind:           claircore.BINARY,
   298  			Arch:           "amd64",
   299  			Source:         &claircore.Package{Name: "gnupg2", Version: "2.2.4-1ubuntu1.2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   300  			PackageDB:      "var/lib/dpkg/status",
   301  			RepositoryHint: "4ff938019bf794bd82c6306a04597855",
   302  		},
   303  		{
   304  			Name:           "bsdutils",
   305  			Version:        "1:2.31.1-0.4ubuntu3.3",
   306  			Kind:           claircore.BINARY,
   307  			Arch:           "amd64",
   308  			Source:         &claircore.Package{Name: "util-linux", Version: "2.31.1-0.4ubuntu3.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   309  			PackageDB:      "var/lib/dpkg/status",
   310  			RepositoryHint: "944a8ca185896c4fc8e6d403c44c089f",
   311  		},
   312  		{
   313  			Name:           "dash",
   314  			Version:        "0.5.8-2.10",
   315  			Kind:           claircore.BINARY,
   316  			Arch:           "amd64",
   317  			Source:         &claircore.Package{Name: "dash", Version: "0.5.8-2.10", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   318  			PackageDB:      "var/lib/dpkg/status",
   319  			RepositoryHint: "5267d9451e76c53a4a6dd49a7abf3d0a",
   320  		},
   321  		{
   322  			Name:           "mount",
   323  			Version:        "2.31.1-0.4ubuntu3.3",
   324  			Kind:           claircore.BINARY,
   325  			Arch:           "amd64",
   326  			Source:         &claircore.Package{Name: "util-linux", Version: "2.31.1-0.4ubuntu3.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   327  			PackageDB:      "var/lib/dpkg/status",
   328  			RepositoryHint: "81cd4e0dabde7615af9fbf50c251f034",
   329  		},
   330  		{
   331  			Name:           "libgnutls30",
   332  			Version:        "3.5.18-1ubuntu1.1",
   333  			Kind:           claircore.BINARY,
   334  			Arch:           "amd64",
   335  			Source:         &claircore.Package{Name: "gnutls28", Version: "3.5.18-1ubuntu1.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   336  			PackageDB:      "var/lib/dpkg/status",
   337  			RepositoryHint: "3ded475856db7dde94c0fd8f5300480a",
   338  		},
   339  		{
   340  			Name:           "libsystemd0",
   341  			Version:        "237-3ubuntu10.25",
   342  			Kind:           claircore.BINARY,
   343  			Arch:           "amd64",
   344  			Source:         &claircore.Package{Name: "systemd", Version: "237-3ubuntu10.25", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   345  			PackageDB:      "var/lib/dpkg/status",
   346  			RepositoryHint: "c809acd40a40b37b55491cdb4bd69fb2",
   347  		},
   348  		{
   349  			Name:           "libzstd1",
   350  			Version:        "1.3.3+dfsg-2ubuntu1",
   351  			Kind:           claircore.BINARY,
   352  			Arch:           "amd64",
   353  			Source:         &claircore.Package{Name: "libzstd", Version: "1.3.3+dfsg-2ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   354  			PackageDB:      "var/lib/dpkg/status",
   355  			RepositoryHint: "753d597807e707445ac96a84de2fc62a",
   356  		},
   357  		{
   358  			Name:           "libc6",
   359  			Version:        "2.27-3ubuntu1",
   360  			Kind:           claircore.BINARY,
   361  			Arch:           "amd64",
   362  			Source:         &claircore.Package{Name: "glibc", Version: "2.27-3ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   363  			PackageDB:      "var/lib/dpkg/status",
   364  			RepositoryHint: "69b26e314836bc5fc6364b99b6656f20",
   365  		},
   366  		{
   367  			Name:           "libfdisk1",
   368  			Version:        "2.31.1-0.4ubuntu3.3",
   369  			Kind:           claircore.BINARY,
   370  			Arch:           "amd64",
   371  			Source:         &claircore.Package{Name: "util-linux", Version: "2.31.1-0.4ubuntu3.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   372  			PackageDB:      "var/lib/dpkg/status",
   373  			RepositoryHint: "ba4b64c92f8c2d133390d30a86dd75b7",
   374  		},
   375  		{
   376  			Name:           "libpcre3",
   377  			Version:        "2:8.39-9",
   378  			Kind:           claircore.BINARY,
   379  			Arch:           "amd64",
   380  			Source:         &claircore.Package{Name: "pcre3", Version: "2:8.39-9", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   381  			PackageDB:      "var/lib/dpkg/status",
   382  			RepositoryHint: "56b9cf5dd90f5da6b904b2b90f2a757d",
   383  		},
   384  		{
   385  			Name:           "coreutils",
   386  			Version:        "8.28-1ubuntu1",
   387  			Kind:           claircore.BINARY,
   388  			Arch:           "amd64",
   389  			Source:         &claircore.Package{Name: "coreutils", Version: "8.28-1ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   390  			PackageDB:      "var/lib/dpkg/status",
   391  			RepositoryHint: "c39a8196b07f782ffeea8909a36af21a",
   392  		},
   393  		{
   394  			Name:           "e2fsprogs",
   395  			Version:        "1.44.1-1ubuntu1.1",
   396  			Kind:           claircore.BINARY,
   397  			Arch:           "amd64",
   398  			Source:         &claircore.Package{Name: "e2fsprogs", Version: "1.44.1-1ubuntu1.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   399  			PackageDB:      "var/lib/dpkg/status",
   400  			RepositoryHint: "15e1f965b09cd8b51d75001e7c043ae0",
   401  		},
   402  		{
   403  			Name:           "tar",
   404  			Version:        "1.29b-2ubuntu0.1",
   405  			Kind:           claircore.BINARY,
   406  			Arch:           "amd64",
   407  			Source:         &claircore.Package{Name: "tar", Version: "1.29b-2ubuntu0.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   408  			PackageDB:      "var/lib/dpkg/status",
   409  			RepositoryHint: "e403332f4aee4679e817acaa5d0809eb",
   410  		},
   411  		{
   412  			Name:           "libprocps6",
   413  			Version:        "2:3.3.12-3ubuntu1.1",
   414  			Kind:           claircore.BINARY,
   415  			Arch:           "amd64",
   416  			Source:         &claircore.Package{Name: "procps", Version: "2:3.3.12-3ubuntu1.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   417  			PackageDB:      "var/lib/dpkg/status",
   418  			RepositoryHint: "1dfb5da1f9e5b56b91557cf3d0fadc17",
   419  		},
   420  		{
   421  			Name:           "libbz2-1.0",
   422  			Version:        "1.0.6-8.1ubuntu0.2",
   423  			Kind:           claircore.BINARY,
   424  			Arch:           "amd64",
   425  			Source:         &claircore.Package{Name: "bzip2", Version: "1.0.6-8.1ubuntu0.2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   426  			PackageDB:      "var/lib/dpkg/status",
   427  			RepositoryHint: "4c94d04d3bd207d6c66b0275467a3434",
   428  		},
   429  		{
   430  			Name:           "libblkid1",
   431  			Version:        "2.31.1-0.4ubuntu3.3",
   432  			Kind:           claircore.BINARY,
   433  			Arch:           "amd64",
   434  			Source:         &claircore.Package{Name: "util-linux", Version: "2.31.1-0.4ubuntu3.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   435  			PackageDB:      "var/lib/dpkg/status",
   436  			RepositoryHint: "002355d5a4c210677b484b88ee906711",
   437  		},
   438  		{
   439  			Name:           "libtasn1-6",
   440  			Version:        "4.13-2",
   441  			Kind:           claircore.BINARY,
   442  			Arch:           "amd64",
   443  			Source:         &claircore.Package{Name: "libtasn1-6", Version: "4.13-2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   444  			PackageDB:      "var/lib/dpkg/status",
   445  			RepositoryHint: "40833fb62f189ad0b699085f37fa126b",
   446  		},
   447  		{
   448  			Name:           "bzip2",
   449  			Version:        "1.0.6-8.1ubuntu0.2",
   450  			Kind:           claircore.BINARY,
   451  			Arch:           "amd64",
   452  			Source:         &claircore.Package{Name: "bzip2", Version: "1.0.6-8.1ubuntu0.2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   453  			PackageDB:      "var/lib/dpkg/status",
   454  			RepositoryHint: "7870caea30545bd4fc8470cd7c71cee5",
   455  		},
   456  		{
   457  			Name:           "libhogweed4",
   458  			Version:        "3.4-1",
   459  			Kind:           claircore.BINARY,
   460  			Arch:           "amd64",
   461  			Source:         &claircore.Package{Name: "nettle", Version: "3.4-1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   462  			PackageDB:      "var/lib/dpkg/status",
   463  			RepositoryHint: "7d676949637c18ec15c784d9e0f0d2b7",
   464  		},
   465  		{
   466  			Name:           "lsb-base",
   467  			Version:        "9.20170808ubuntu1",
   468  			Kind:           claircore.BINARY,
   469  			Arch:           "all",
   470  			Source:         &claircore.Package{Name: "lsb", Version: "9.20170808ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   471  			PackageDB:      "var/lib/dpkg/status",
   472  			RepositoryHint: "81f59c0711532f60f4bba8cff2bdc194",
   473  		},
   474  		{
   475  			Name:           "procps",
   476  			Version:        "2:3.3.12-3ubuntu1.1",
   477  			Kind:           claircore.BINARY,
   478  			Arch:           "amd64",
   479  			Source:         &claircore.Package{Name: "procps", Version: "2:3.3.12-3ubuntu1.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   480  			PackageDB:      "var/lib/dpkg/status",
   481  			RepositoryHint: "6226ab16fc27c981a04e5236cd357db4",
   482  		},
   483  		{
   484  			Name:           "libgpg-error0",
   485  			Version:        "1.27-6",
   486  			Kind:           claircore.BINARY,
   487  			Arch:           "amd64",
   488  			Source:         &claircore.Package{Name: "libgpg-error", Version: "1.27-6", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   489  			PackageDB:      "var/lib/dpkg/status",
   490  			RepositoryHint: "9ac0b2bb54b5fca41b5699ab285fd537",
   491  		},
   492  		{
   493  			Name:           "base-files",
   494  			Version:        "10.1ubuntu2.6",
   495  			Kind:           claircore.BINARY,
   496  			Arch:           "amd64",
   497  			Source:         &claircore.Package{Name: "base-files", Version: "10.1ubuntu2.6", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   498  			PackageDB:      "var/lib/dpkg/status",
   499  			RepositoryHint: "b7adc247e1bbd04d0fa877ad976e6999",
   500  		},
   501  		{
   502  			Name:           "libgmp10",
   503  			Version:        "2:6.1.2+dfsg-2",
   504  			Kind:           claircore.BINARY,
   505  			Arch:           "amd64",
   506  			Source:         &claircore.Package{Name: "gmp", Version: "2:6.1.2+dfsg-2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   507  			PackageDB:      "var/lib/dpkg/status",
   508  			RepositoryHint: "0582a99d7e1af42e4e467f8bfb3eefb2",
   509  		},
   510  		{
   511  			Name:           "sensible-utils",
   512  			Version:        "0.0.12",
   513  			Kind:           claircore.BINARY,
   514  			Arch:           "all",
   515  			Source:         &claircore.Package{Name: "sensible-utils", Version: "0.0.12", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   516  			PackageDB:      "var/lib/dpkg/status",
   517  			RepositoryHint: "acacef732b02d7b18bc55fb076129e97",
   518  		},
   519  		{
   520  			Name:           "passwd",
   521  			Version:        "1:4.5-1ubuntu2",
   522  			Kind:           claircore.BINARY,
   523  			Arch:           "amd64",
   524  			Source:         &claircore.Package{Name: "shadow", Version: "1:4.5-1ubuntu2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   525  			PackageDB:      "var/lib/dpkg/status",
   526  			RepositoryHint: "b07c719065496584ffc5d22aad31bd26",
   527  		},
   528  		{
   529  			Name:           "init-system-helpers",
   530  			Version:        "1.51",
   531  			Kind:           claircore.BINARY,
   532  			Arch:           "all",
   533  			Source:         &claircore.Package{Name: "init-system-helpers", Version: "1.51", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   534  			PackageDB:      "var/lib/dpkg/status",
   535  			RepositoryHint: "12ce455753af8d952171bcd97fd9ae46",
   536  		},
   537  		{
   538  			Name:           "ncurses-base",
   539  			Version:        "6.1-1ubuntu1.18.04",
   540  			Kind:           claircore.BINARY,
   541  			Arch:           "all",
   542  			Source:         &claircore.Package{Name: "ncurses", Version: "6.1-1ubuntu1.18.04", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   543  			PackageDB:      "var/lib/dpkg/status",
   544  			RepositoryHint: "82f72407e909caaa18dbc13a5d8dcec4",
   545  		},
   546  		{
   547  			Name:           "libc-bin",
   548  			Version:        "2.27-3ubuntu1",
   549  			Kind:           claircore.BINARY,
   550  			Arch:           "amd64",
   551  			Source:         &claircore.Package{Name: "glibc", Version: "2.27-3ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   552  			PackageDB:      "var/lib/dpkg/status",
   553  			RepositoryHint: "6a8dfc87afeac7c23a876c771153203c",
   554  		},
   555  		{
   556  			Name:           "libsemanage1",
   557  			Version:        "2.7-2build2",
   558  			Kind:           claircore.BINARY,
   559  			Arch:           "amd64",
   560  			Source:         &claircore.Package{Name: "libsemanage", Version: "2.7-2build2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   561  			PackageDB:      "var/lib/dpkg/status",
   562  			RepositoryHint: "2213290d7f16a01ea80c776b161c4d4b",
   563  		},
   564  		{
   565  			Name:           "libseccomp2",
   566  			Version:        "2.4.1-0ubuntu0.18.04.2",
   567  			Kind:           claircore.BINARY,
   568  			Arch:           "amd64",
   569  			Source:         &claircore.Package{Name: "libseccomp", Version: "2.4.1-0ubuntu0.18.04.2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   570  			PackageDB:      "var/lib/dpkg/status",
   571  			RepositoryHint: "6a2c4bd25b02d438edc8b955a190c182",
   572  		},
   573  		{
   574  			Name:           "sysvinit-utils",
   575  			Version:        "2.88dsf-59.10ubuntu1",
   576  			Kind:           claircore.BINARY,
   577  			Arch:           "amd64",
   578  			Source:         &claircore.Package{Name: "sysvinit", Version: "2.88dsf-59.10ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   579  			PackageDB:      "var/lib/dpkg/status",
   580  			RepositoryHint: "4df656cc5c9bf0083c342c8bd294c28e",
   581  		},
   582  		{
   583  			Name:           "libsemanage-common",
   584  			Version:        "2.7-2build2",
   585  			Kind:           claircore.BINARY,
   586  			Arch:           "all",
   587  			Source:         &claircore.Package{Name: "libsemanage", Version: "2.7-2build2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   588  			PackageDB:      "var/lib/dpkg/status",
   589  			RepositoryHint: "d39631bf96b2162fdc3a53291a39df62",
   590  		},
   591  		{
   592  			Name:           "libp11-kit0",
   593  			Version:        "0.23.9-2",
   594  			Kind:           claircore.BINARY,
   595  			Arch:           "amd64",
   596  			Source:         &claircore.Package{Name: "p11-kit", Version: "0.23.9-2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   597  			PackageDB:      "var/lib/dpkg/status",
   598  			RepositoryHint: "61f2a011afb14b04083002d28cb94b9e",
   599  		},
   600  		{
   601  			Name:           "libdebconfclient0",
   602  			Version:        "0.213ubuntu1",
   603  			Kind:           claircore.BINARY,
   604  			Arch:           "amd64",
   605  			Source:         &claircore.Package{Name: "cdebconf", Version: "0.213ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   606  			PackageDB:      "var/lib/dpkg/status",
   607  			RepositoryHint: "8a28204a765d5720cb4af1753f45bed7",
   608  		},
   609  		{
   610  			Name:           "libselinux1",
   611  			Version:        "2.7-2build2",
   612  			Kind:           claircore.BINARY,
   613  			Arch:           "amd64",
   614  			Source:         &claircore.Package{Name: "libselinux", Version: "2.7-2build2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   615  			PackageDB:      "var/lib/dpkg/status",
   616  			RepositoryHint: "a2f847fab267ff4cc6f08351c5d72e16",
   617  		},
   618  		{
   619  			Name:           "dpkg",
   620  			Version:        "1.19.0.5ubuntu2.1",
   621  			Kind:           claircore.BINARY,
   622  			Arch:           "amd64",
   623  			Source:         &claircore.Package{Name: "dpkg", Version: "1.19.0.5ubuntu2.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   624  			PackageDB:      "var/lib/dpkg/status",
   625  			RepositoryHint: "db01a1c0f91bf54aa1126ae814a48760",
   626  		},
   627  		{
   628  			Name:           "gcc-8-base",
   629  			Version:        "8.3.0-6ubuntu1~18.04.1",
   630  			Kind:           claircore.BINARY,
   631  			Arch:           "amd64",
   632  			Source:         &claircore.Package{Name: "gcc-8", Version: "8.3.0-6ubuntu1~18.04.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   633  			PackageDB:      "var/lib/dpkg/status",
   634  			RepositoryHint: "7dac2f53b10d468727cfd34dfe5fdaf7",
   635  		},
   636  		{
   637  			Name:           "apt",
   638  			Version:        "1.6.11",
   639  			Kind:           claircore.BINARY,
   640  			Arch:           "amd64",
   641  			Source:         &claircore.Package{Name: "apt", Version: "1.6.11", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   642  			PackageDB:      "var/lib/dpkg/status",
   643  			RepositoryHint: "bc3018653614f09a74c49875673b4e35",
   644  		},
   645  		{
   646  			Name:           "diffutils",
   647  			Version:        "1:3.6-1",
   648  			Kind:           claircore.BINARY,
   649  			Arch:           "amd64",
   650  			Source:         &claircore.Package{Name: "diffutils", Version: "1:3.6-1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   651  			PackageDB:      "var/lib/dpkg/status",
   652  			RepositoryHint: "49ed959780dcc73b86202dff1614518d",
   653  		},
   654  		{
   655  			Name:           "libpam-modules",
   656  			Version:        "1.1.8-3.6ubuntu2.18.04.1",
   657  			Kind:           claircore.BINARY,
   658  			Arch:           "amd64",
   659  			Source:         &claircore.Package{Name: "pam", Version: "1.1.8-3.6ubuntu2.18.04.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   660  			PackageDB:      "var/lib/dpkg/status",
   661  			RepositoryHint: "d26dab685afef1e59fdf6eea227a764f",
   662  		},
   663  		{
   664  			Name:           "libstdc++6",
   665  			Version:        "8.3.0-6ubuntu1~18.04.1",
   666  			Kind:           claircore.BINARY,
   667  			Arch:           "amd64",
   668  			Source:         &claircore.Package{Name: "gcc-8", Version: "8.3.0-6ubuntu1~18.04.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   669  			PackageDB:      "var/lib/dpkg/status",
   670  			RepositoryHint: "67d777333913485c1776d89fe0be2265",
   671  		},
   672  		{
   673  			Name:           "libffi6",
   674  			Version:        "3.2.1-8",
   675  			Kind:           claircore.BINARY,
   676  			Arch:           "amd64",
   677  			Source:         &claircore.Package{Name: "libffi", Version: "3.2.1-8", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   678  			PackageDB:      "var/lib/dpkg/status",
   679  			RepositoryHint: "c98a2d5689d41ff8c9d7fa0b8053fd35",
   680  		},
   681  		{
   682  			Name:           "libaudit-common",
   683  			Version:        "1:2.8.2-1ubuntu1",
   684  			Kind:           claircore.BINARY,
   685  			Arch:           "all",
   686  			Source:         &claircore.Package{Name: "audit", Version: "1:2.8.2-1ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   687  			PackageDB:      "var/lib/dpkg/status",
   688  			RepositoryHint: "96dff9fbe852eedc8324c4c659c6c9fb",
   689  		},
   690  		{
   691  			Name:           "findutils",
   692  			Version:        "4.6.0+git+20170828-2",
   693  			Kind:           claircore.BINARY,
   694  			Arch:           "amd64",
   695  			Source:         &claircore.Package{Name: "findutils", Version: "4.6.0+git+20170828-2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   696  			PackageDB:      "var/lib/dpkg/status",
   697  			RepositoryHint: "a69359638ce4239976bc4d2902fd422e",
   698  		},
   699  		{
   700  			Name:           "libpam0g",
   701  			Version:        "1.1.8-3.6ubuntu2.18.04.1",
   702  			Kind:           claircore.BINARY,
   703  			Arch:           "amd64",
   704  			Source:         &claircore.Package{Name: "pam", Version: "1.1.8-3.6ubuntu2.18.04.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   705  			PackageDB:      "var/lib/dpkg/status",
   706  			RepositoryHint: "2b70bcd8348ded4048eb05371d206057",
   707  		},
   708  		{
   709  			Name:           "libcap-ng0",
   710  			Version:        "0.7.7-3.1",
   711  			Kind:           claircore.BINARY,
   712  			Arch:           "amd64",
   713  			Source:         &claircore.Package{Name: "libcap-ng", Version: "0.7.7-3.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   714  			PackageDB:      "var/lib/dpkg/status",
   715  			RepositoryHint: "eef5c8b83a5c83ac1d800421013c35d4",
   716  		},
   717  		{
   718  			Name:           "libmount1",
   719  			Version:        "2.31.1-0.4ubuntu3.3",
   720  			Kind:           claircore.BINARY,
   721  			Arch:           "amd64",
   722  			Source:         &claircore.Package{Name: "util-linux", Version: "2.31.1-0.4ubuntu3.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   723  			PackageDB:      "var/lib/dpkg/status",
   724  			RepositoryHint: "54de57abe4e728e553aa9bb3c0a3486b",
   725  		},
   726  		{
   727  			Name:           "login",
   728  			Version:        "1:4.5-1ubuntu2",
   729  			Kind:           claircore.BINARY,
   730  			Arch:           "amd64",
   731  			Source:         &claircore.Package{Name: "shadow", Version: "1:4.5-1ubuntu2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   732  			PackageDB:      "var/lib/dpkg/status",
   733  			RepositoryHint: "fb7eb3beb226312b5fc206b9b68196e4",
   734  		},
   735  		{
   736  			Name:           "adduser",
   737  			Version:        "3.116ubuntu1",
   738  			Kind:           claircore.BINARY,
   739  			Arch:           "all",
   740  			Source:         &claircore.Package{Name: "adduser", Version: "3.116ubuntu1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   741  			PackageDB:      "var/lib/dpkg/status",
   742  			RepositoryHint: "695a46afe8d2418119a6c814272624b2",
   743  		},
   744  		{
   745  			Name:           "libext2fs2",
   746  			Version:        "1.44.1-1ubuntu1.1",
   747  			Kind:           claircore.BINARY,
   748  			Arch:           "amd64",
   749  			Source:         &claircore.Package{Name: "e2fsprogs", Version: "1.44.1-1ubuntu1.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   750  			PackageDB:      "var/lib/dpkg/status",
   751  			RepositoryHint: "b1b278bfc418d3ded83ce0fa811c1b72",
   752  		},
   753  		{
   754  			Name:           "libacl1",
   755  			Version:        "2.2.52-3build1",
   756  			Kind:           claircore.BINARY,
   757  			Arch:           "amd64",
   758  			Source:         &claircore.Package{Name: "acl", Version: "2.2.52-3build1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   759  			PackageDB:      "var/lib/dpkg/status",
   760  			RepositoryHint: "4eb315544d7022817f09883f271f3838",
   761  		},
   762  		{
   763  			Name:           "ncurses-bin",
   764  			Version:        "6.1-1ubuntu1.18.04",
   765  			Kind:           claircore.BINARY,
   766  			Arch:           "amd64",
   767  			Source:         &claircore.Package{Name: "ncurses", Version: "6.1-1ubuntu1.18.04", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   768  			PackageDB:      "var/lib/dpkg/status",
   769  			RepositoryHint: "87fcc071cfb913ef124a557295cfe91f",
   770  		},
   771  		{
   772  			Name:           "libsepol1",
   773  			Version:        "2.7-1",
   774  			Kind:           claircore.BINARY,
   775  			Arch:           "amd64",
   776  			Source:         &claircore.Package{Name: "libsepol", Version: "2.7-1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   777  			PackageDB:      "var/lib/dpkg/status",
   778  			RepositoryHint: "969d98356cf0185d41fcb360b3cc78f0",
   779  		},
   780  		{
   781  			Name:           "ubuntu-keyring",
   782  			Version:        "2018.09.18.1~18.04.0",
   783  			Kind:           claircore.BINARY,
   784  			Arch:           "all",
   785  			Source:         &claircore.Package{Name: "ubuntu-keyring", Version: "2018.09.18.1~18.04.0", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   786  			PackageDB:      "var/lib/dpkg/status",
   787  			RepositoryHint: "6670fc17c7bfbf2f394e994c2324809a",
   788  		},
   789  		{
   790  			Name:           "libgcc1",
   791  			Version:        "1:8.3.0-6ubuntu1~18.04.1",
   792  			Kind:           claircore.BINARY,
   793  			Arch:           "amd64",
   794  			Source:         &claircore.Package{Name: "gcc-8", Version: "8.3.0-6ubuntu1~18.04.1", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   795  			PackageDB:      "var/lib/dpkg/status",
   796  			RepositoryHint: "9bccc3f84c1c9038a55c211f84014a65",
   797  		},
   798  		{
   799  			Name:           "util-linux",
   800  			Version:        "2.31.1-0.4ubuntu3.3",
   801  			Kind:           claircore.BINARY,
   802  			Arch:           "amd64",
   803  			Source:         &claircore.Package{Name: "util-linux", Version: "2.31.1-0.4ubuntu3.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   804  			PackageDB:      "var/lib/dpkg/status",
   805  			RepositoryHint: "4fedd5fb77f729d76705cc545e983730",
   806  		},
   807  		{
   808  			Name:           "sed",
   809  			Version:        "4.4-2",
   810  			Kind:           claircore.BINARY,
   811  			Arch:           "amd64",
   812  			Source:         &claircore.Package{Name: "sed", Version: "4.4-2", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   813  			PackageDB:      "var/lib/dpkg/status",
   814  			RepositoryHint: "bf8c924cef13e42a861f3297ac32ce49",
   815  		},
   816  		{
   817  			Name:           "libsmartcols1",
   818  			Version:        "2.31.1-0.4ubuntu3.3",
   819  			Kind:           claircore.BINARY,
   820  			Arch:           "amd64",
   821  			Source:         &claircore.Package{Name: "util-linux", Version: "2.31.1-0.4ubuntu3.3", Kind: claircore.SOURCE, PackageDB: "var/lib/dpkg/status"},
   822  			PackageDB:      "var/lib/dpkg/status",
   823  			RepositoryHint: "daafc6eba6eae603327bf8fc49645999",
   824  		},
   825  	}
   826  	slices.SortFunc(want, sortpkg)
   827  	ctx := zlog.Test(context.Background(), t)
   828  	l := test.RealizeLayer(ctx, t, test.LayerRef{
   829  		Registry: "docker.io",
   830  		Name:     "library/ubuntu",
   831  		Digest:   "sha256:35c102085707f703de2d9eaad8752d6fe1b8f02b5d2149f1d8357c9cc7fb7d0a",
   832  	})
   833  	var s Scanner
   834  
   835  	got, err := s.Scan(ctx, l)
   836  	if err != nil {
   837  		t.Fatal(err)
   838  	}
   839  	if !cmp.Equal(got, want) {
   840  		t.Fatal(cmp.Diff(got, want))
   841  	}
   842  }
   843  
   844  func TestAbsolutePaths(t *testing.T) {
   845  	t.Parallel()
   846  	ctx := zlog.Test(context.Background(), t)
   847  	l := test.RealizeLayer(ctx, t, test.LayerRef{
   848  		Registry: "gcr.io",
   849  		Name:     "vmwarecloudadvocacy/acmeshop-user",
   850  		Digest:   "sha256:3c9020349340788076971d5ea638b71e35233fd8e149e269d8eebfa17960c03f",
   851  	})
   852  	var s Scanner
   853  	got, err := s.Scan(ctx, l)
   854  	if err != nil {
   855  		t.Fatal(err)
   856  	}
   857  	t.Logf("found %d packages", len(got))
   858  	if len(got) == 0 {
   859  		t.Fail()
   860  	}
   861  }
   862  
   863  func TestExtraMetadata(t *testing.T) {
   864  	t.Parallel()
   865  	mod := test.Modtime(t, "scanner_test.go")
   866  	layerfile := test.GenerateFixture(t, `extrametadata.layer`, mod, extraMetadataSetup)
   867  	ctx := zlog.Test(context.Background(), t)
   868  	var l claircore.Layer
   869  	var s Scanner
   870  
   871  	f, err := os.Open(layerfile)
   872  	if err != nil {
   873  		t.Fatal(err)
   874  	}
   875  	defer f.Close()
   876  	if err := l.Init(ctx, &test.AnyDescription, f); err != nil {
   877  		t.Error(err)
   878  	}
   879  	t.Cleanup(func() {
   880  		if err := l.Close(); err != nil {
   881  			t.Error(err)
   882  		}
   883  	})
   884  
   885  	ps, err := s.Scan(ctx, &l)
   886  	if err != nil {
   887  		t.Error(err)
   888  	}
   889  	if got, want := len(ps), 1; got != want {
   890  		t.Errorf("checking length, got: %d, want: %d", got, want)
   891  	}
   892  }
   893  
   894  // ExtraMetadataSetup is a helper to craft a layer that trips PROJQUAY-1308.
   895  func extraMetadataSetup(t testing.TB, f *os.File) {
   896  	w := tar.NewWriter(f)
   897  	defer func() {
   898  		if err := w.Close(); err != nil {
   899  			t.Error(err)
   900  		}
   901  	}()
   902  	for _, n := range []string{
   903  		"db/",
   904  		"db/available",
   905  		"db/info.md5sums",
   906  		"db/info/",
   907  		"db/info/bogus.md5sums",
   908  		"db/info/extra.md5sums",
   909  	} {
   910  		if err := w.WriteHeader(&tar.Header{
   911  			Name: n,
   912  		}); err != nil {
   913  			t.Error(err)
   914  		}
   915  	}
   916  	const statusfile = `Package: bogus
   917  Status: install ok installed
   918  Priority: important
   919  Section: admin
   920  Installed-Size: 0
   921  Maintainer: Veryreal Developer <email@example.com>
   922  Architecture: all
   923  Version: 1
   924  
   925  `
   926  	if err := w.WriteHeader(&tar.Header{
   927  		Name: "db/status",
   928  		Size: int64(len(statusfile)),
   929  	}); err != nil {
   930  		t.Error(err)
   931  	}
   932  	if _, err := io.WriteString(w, statusfile); err != nil {
   933  		t.Error(err)
   934  	}
   935  }
   936  
   937  // This is a giant status file because texlive was installed.
   938  func TestGiantStatus(t *testing.T) {
   939  	t.Parallel()
   940  	db, err := os.Open(`testdata/texlive.status`)
   941  	if err != nil {
   942  		t.Fatal(err)
   943  	}
   944  
   945  	var found int
   946  	tp := textproto.NewReader(bufio.NewReader(db))
   947  	hdr, err := tp.ReadMIMEHeader()
   948  	for ; err == nil && len(hdr) > 0; hdr, err = tp.ReadMIMEHeader() {
   949  		found++
   950  	}
   951  	t.Logf("found %d installed packages", found)
   952  	if got, want := found, 357; got != want {
   953  		t.Fail()
   954  	}
   955  	if err != nil && err != io.EOF {
   956  		t.Error(err)
   957  	}
   958  }
   959  
   960  // See quay/claircore#297 for more context.
   961  func TestKeyringPackage(t *testing.T) {
   962  	t.Parallel()
   963  	db, err := os.Open(`testdata/debian-only.status`)
   964  	if err != nil {
   965  		t.Fatal(err)
   966  	}
   967  	defer db.Close()
   968  
   969  	tp := textproto.NewReader(bufio.NewReader(db))
   970  	hdr, err := tp.ReadMIMEHeader()
   971  	if err != nil {
   972  		t.Error(err)
   973  	}
   974  	got, want := hdr.Get("Version"), `2019.1`
   975  	t.Logf("got: %q, want: %q", got, want)
   976  	if got != want {
   977  		t.Fail()
   978  	}
   979  }
   980  
   981  // See quay/claircore#1291 for more context.
   982  func TestParsedSource(t *testing.T) {
   983  	t.Parallel()
   984  	const filename = `testdata/postgresql.status`
   985  	ctx := zlog.Test(context.Background(), t)
   986  
   987  	db, err := os.Open(filename)
   988  	if err != nil {
   989  		t.Fatal(err)
   990  	}
   991  	found := newPackages()
   992  	tp := textproto.NewReader(bufio.NewReader(db))
   993  
   994  	if err := parseStatus(ctx, found, filename, tp); err != nil {
   995  		t.Error(err)
   996  	}
   997  
   998  	pkg, ok := found.bin["postgresql-client"]
   999  	if !ok {
  1000  		t.Fatalf("unable to find package %q", "postgresql-client")
  1001  	}
  1002  	src := pkg.Source
  1003  	got, want := src.Name, "postgresql-common"
  1004  	t.Logf("got: %q, want: %q", got, want)
  1005  	if got != want {
  1006  		t.Fail()
  1007  	}
  1008  	got, want = src.Version, "200+deb10u5"
  1009  	t.Logf("got: %q, want: %q", got, want)
  1010  	if got != want {
  1011  		t.Fail()
  1012  	}
  1013  }