github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/deb/parse_dpkg_info_files_test.go (about)

     1  package deb
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  	"github.com/stretchr/testify/require"
     9  
    10  	"github.com/anchore/syft/syft/file"
    11  	"github.com/anchore/syft/syft/pkg"
    12  )
    13  
    14  func TestMD5SumInfoParsing(t *testing.T) {
    15  	tests := []struct {
    16  		fixture  string
    17  		expected []pkg.DpkgFileRecord
    18  	}{
    19  		{
    20  			fixture: "test-fixtures/info/zlib1g.md5sums",
    21  			expected: []pkg.DpkgFileRecord{
    22  				{Path: "/lib/x86_64-linux-gnu/libz.so.1.2.11", Digest: &file.Digest{
    23  					Algorithm: "md5",
    24  					Value:     "55f905631797551d4d936a34c7e73474",
    25  				}},
    26  				{Path: "/usr/share/doc/zlib1g/changelog.Debian.gz", Digest: &file.Digest{
    27  					Algorithm: "md5",
    28  					Value:     "cede84bda30d2380217f97753c8ccf3a",
    29  				}},
    30  				{Path: "/usr/share/doc/zlib1g/changelog.gz", Digest: &file.Digest{
    31  					Algorithm: "md5",
    32  					Value:     "f3c9dafa6da7992c47328b4464f6d122",
    33  				}},
    34  				{Path: "/usr/share/doc/zlib1g/copyright", Digest: &file.Digest{
    35  					Algorithm: "md5",
    36  					Value:     "a4fae96070439a5209a62ae5b8017ab2",
    37  				}},
    38  			},
    39  		},
    40  	}
    41  
    42  	for _, test := range tests {
    43  		t.Run(test.fixture, func(t *testing.T) {
    44  			f, err := os.Open(test.fixture)
    45  			require.NoError(t, err)
    46  			t.Cleanup(func() { require.NoError(t, f.Close()) })
    47  
    48  			actual := parseDpkgMD5Info(f)
    49  
    50  			if diff := cmp.Diff(test.expected, actual); diff != "" {
    51  				t.Errorf("unexpected md5 files (-want +got):\n%s", diff)
    52  			}
    53  
    54  		})
    55  	}
    56  }
    57  
    58  func TestConffileInfoParsing(t *testing.T) {
    59  	tests := []struct {
    60  		fixture  string
    61  		expected []pkg.DpkgFileRecord
    62  	}{
    63  		{
    64  			fixture: "test-fixtures/info/util-linux.conffiles",
    65  			expected: []pkg.DpkgFileRecord{
    66  				{Path: "/etc/default/hwclock", IsConfigFile: true},
    67  				{Path: "/etc/init.d/hwclock.sh", IsConfigFile: true},
    68  				{Path: "/etc/pam.d/runuser", IsConfigFile: true},
    69  				{Path: "/etc/pam.d/runuser-l", IsConfigFile: true},
    70  				{Path: "/etc/pam.d/su", IsConfigFile: true},
    71  				{Path: "/etc/pam.d/su-l", IsConfigFile: true},
    72  			},
    73  		},
    74  	}
    75  
    76  	for _, test := range tests {
    77  		t.Run(test.fixture, func(t *testing.T) {
    78  			f, err := os.Open(test.fixture)
    79  			require.NoError(t, err)
    80  			t.Cleanup(func() { require.NoError(t, f.Close()) })
    81  
    82  			actual := parseDpkgConffileInfo(f)
    83  
    84  			if diff := cmp.Diff(test.expected, actual); diff != "" {
    85  				t.Errorf("unexpected md5 files (-want +got):\n%s", diff)
    86  			}
    87  
    88  		})
    89  	}
    90  }