github.com/quay/claircore@v1.5.28/alpine/secdb_test.go (about)

     1  package alpine
     2  
     3  import (
     4  	"encoding/json"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/google/go-cmp/cmp"
    10  )
    11  
    12  var v3_10CommunityTruncatedSecDB = SecurityDB{
    13  	Distroversion: "v3.10",
    14  	Reponame:      "community",
    15  	Urlprefix:     "http://dl-cdn.alpinelinux.org/alpine",
    16  	Apkurl:        "{{urlprefix}}/{{distroversion}}/{{reponame}}/{{arch}}/{{pkg.name}}-{{pkg.ver}}.apk",
    17  	Packages: []Package{
    18  		{
    19  			Pkg: Details{
    20  				Name: "botan",
    21  				Secfixes: map[string][]string{
    22  					"2.9.0-r0": {"CVE-2018-20187"},
    23  					"2.7.0-r0": {"CVE-2018-12435"},
    24  					"2.6.0-r0": {"CVE-2018-9860"},
    25  					"2.5.0-r0": {"CVE-2018-9127"},
    26  				},
    27  			},
    28  		},
    29  		{
    30  			Pkg: Details{
    31  				Name: "cfengine",
    32  				Secfixes: map[string][]string{
    33  					"3.12.2-r0": {"CVE-2019-9929"},
    34  				},
    35  			},
    36  		},
    37  		{
    38  			Pkg: Details{
    39  				Name: "chicken",
    40  				Secfixes: map[string][]string{
    41  					"4.12.0-r3": {"CVE-2017-6949"},
    42  					"4.12.0-r2": {"CVE-2017-9334"},
    43  					"4.11.1-r0": {"CVE-2016-6830", "CVE-2016-6831"},
    44  				},
    45  			},
    46  		},
    47  	},
    48  }
    49  
    50  func TestSecDBParse(t *testing.T) {
    51  	var table = []struct {
    52  		testFile string
    53  		expected SecurityDB
    54  	}{
    55  		{
    56  			testFile: "fetch/v3.10/community.json",
    57  			expected: v3_10CommunityTruncatedSecDB,
    58  		},
    59  	}
    60  
    61  	for _, test := range table {
    62  		path := filepath.Join("testdata", test.testFile)
    63  		want := test.expected
    64  		t.Run(test.testFile, func(t *testing.T) {
    65  			t.Parallel()
    66  
    67  			f, err := os.Open(path)
    68  			if err != nil {
    69  				t.Fatalf("failed to open test data: %v", path)
    70  			}
    71  
    72  			var got SecurityDB
    73  			if err := json.NewDecoder(f).Decode(&got); err != nil {
    74  				t.Fatalf("failed to parse file contents into sec db: %v", err)
    75  			}
    76  			if !cmp.Equal(got, want) {
    77  				t.Log("security databases were not equal:")
    78  				t.Error(cmp.Diff(got, want))
    79  			}
    80  		})
    81  	}
    82  }