diff --git a/rocky/rocky.go b/rocky/rocky.go index f0ca00f8..8fd264d4 100644 --- a/rocky/rocky.go +++ b/rocky/rocky.go @@ -10,9 +10,7 @@ import ( "os" "path" "path/filepath" - "strconv" "strings" - "time" "github.com/aquasecurity/vuln-list-update/utils" "github.com/cheggaaa/pb/v3" @@ -149,7 +147,7 @@ func (c Config) Update() error { for _, release := range c.releases { for _, repo := range c.repos { for _, arch := range c.arches { - log.Printf("Fetching Rocky Linux %s %s %s data...\n", release, repo, arch) + log.Printf("Fetching Rocky Linux %s %s %s data...", release, repo, arch) if err := c.update(release, repo, arch); err != nil { return xerrors.Errorf("failed to update security advisories of Rocky Linux %s %s %s: %w", release, repo, arch, err) } @@ -161,7 +159,7 @@ func (c Config) Update() error { func (c Config) update(release, repo, arch string) error { dirPath := filepath.Join(c.dir, release, repo, arch) - log.Printf("Remove Rocky Linux %s %s %s directory %s\n", release, repo, arch, dirPath) + log.Printf("Remove Rocky Linux %s %s %s directory %s", release, repo, arch, dirPath) if err := os.RemoveAll(dirPath); err != nil { return xerrors.Errorf("failed to remove Rocky Linux %s %s %s directory: %w", release, repo, arch, err) } @@ -190,17 +188,12 @@ func (c Config) update(release, repo, arch string) error { if !strings.HasPrefix(rlsa.ID, "RLSA-") { continue } - - issuedDate, err := time.Parse("2006-01-02 15:04:05", rlsa.Issued.Date) - if err != nil { - return xerrors.Errorf("failed to parse issued date: %w", err) - } - y := strconv.Itoa(issuedDate.Year()) + y := strings.Split(strings.TrimPrefix(rlsa.ID, "RLSA-"), ":")[0] secErrata[y] = append(secErrata[y], rlsa) } for year, errata := range secErrata { - log.Printf("Write Errata for Rocky Linux %s %s %s %s\n", release, repo, arch, year) + log.Printf("Write Errata for Rocky Linux %s %s %s %s", release, repo, arch, year) if err := os.MkdirAll(filepath.Join(dirPath, year), os.ModePerm); err != nil { return xerrors.Errorf("failed to mkdir: %w", err) @@ -208,8 +201,8 @@ func (c Config) update(release, repo, arch string) error { bar := pb.StartNew(len(errata)) for _, erratum := range errata { - filepath := filepath.Join(dirPath, year, fmt.Sprintf("%s.json", erratum.ID)) - if err := utils.Write(filepath, erratum); err != nil { + jsonPath := filepath.Join(dirPath, year, fmt.Sprintf("%s.json", erratum.ID)) + if err := utils.Write(jsonPath, erratum); err != nil { return xerrors.Errorf("failed to write Rocky Linux CVE details: %w", err) } bar.Increment() @@ -238,7 +231,7 @@ func fetchUpdateInfoPath(repomdURL string) (updateInfoPath string, err error) { } } if updateInfoPath == "" { - return "", xerrors.New("No updateinfo field in the repomd") + return "", xerrors.New("no updateinfo field in the repomd") } return updateInfoPath, nil } diff --git a/rocky/rocky_test.go b/rocky/rocky_test.go index 992ffbb9..12d16c26 100644 --- a/rocky/rocky_test.go +++ b/rocky/rocky_test.go @@ -24,34 +24,35 @@ func Test_Update(t *testing.T) { }{ { name: "happy path", - repomdFileName: "testdata/fixtures/repomd_valid.xml", - updateInfoFileName: "testdata/fixtures/updateinfo_valid.xml.gz", + repomdFileName: "repomd_valid.xml", + updateInfoFileName: "updateinfo_valid.xml.gz", expectedError: nil, }, { name: "bad repomd response", - repomdFileName: "testdata/fixtures/repomd_invalid.xml", + repomdFileName: "repomd_invalid.xml", expectedError: xerrors.Errorf("failed to update security advisories of Rocky Linux 8 BaseOS x86_64: %w", errors.New("failed to fetch updateInfo path from repomd.xml")), }, { name: "bad updateInfo response", - repomdFileName: "testdata/fixtures/repomd_valid.xml", - updateInfoFileName: "testdata/fixtures/updateinfo_invalid.xml.gz", + repomdFileName: "repomd_valid.xml", + updateInfoFileName: "updateinfo_invalid.xml.gz", expectedError: xerrors.Errorf("failed to update security advisories of Rocky Linux 8 BaseOS x86_64: %w", errors.New("failed to fetch updateInfo")), }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tsUpdateInfoURL := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch { - case strings.HasSuffix(r.URL.Path, "repomd.xml"): - repomd, _ := os.ReadFile(tt.repomdFileName) - _, _ = w.Write(repomd) - case strings.HasSuffix(r.URL.Path, "updateinfo.xml.gz"): - buf, _ := os.ReadFile(tt.updateInfoFileName) - _, _ = w.Write(buf) - default: - assert.Fail(t, "bad URL requested: ", r.URL.Path, tt.name) + if strings.HasPrefix(r.URL.Path, "/pub/rocky/8/BaseOS/x86_64/os/repodata/") { + switch { + case strings.HasSuffix(r.URL.Path, "repomd.xml"): + r.URL.Path = filepath.Join(filepath.Dir(r.URL.Path), tt.repomdFileName) + case strings.HasSuffix(r.URL.Path, "updateinfo.xml.gz"): + r.URL.Path = filepath.Join(filepath.Dir(r.URL.Path), tt.updateInfoFileName) + } + http.StripPrefix("/pub/rocky/8/BaseOS/x86_64/os/repodata/", http.FileServer(http.Dir("testdata/fixtures"))) + } else { + http.NotFound(w, r) } })) defer tsUpdateInfoURL.Close() @@ -65,6 +66,9 @@ func Test_Update(t *testing.T) { } err := filepath.Walk(dir, func(path string, info os.FileInfo, errfp error) error { + if errfp != nil { + return errfp + } if info.IsDir() { return nil } @@ -76,7 +80,7 @@ func Test_Update(t *testing.T) { got, err := os.ReadFile(path) assert.NoError(t, err, "failed to open the result file") - assert.Equal(t, string(want), string(got)) + assert.JSONEq(t, string(want), string(got)) return nil }) diff --git a/updateinfo_valid.xml b/updateinfo_valid.xml deleted file mode 100644 index 7394af8b..00000000 --- a/updateinfo_valid.xml +++ /dev/null @@ -1,172 +0,0 @@ - - - RLBA-2021:2580 - firewalld bug fix and enhancement update - - - Copyright (C) 2021 Rocky Enterprise Software Foundation - Rocky Linux 8 - 1 - None - An update for firewalld is now available for Rocky Linux 8. - For more information visit https://errata.rockylinux.org/RLBA-2021:2580 - - - - - - Rocky Linux 8 - - firewalld-filesystem-0.8.2-7.el8_4.noarch.rpm - a35c21fbb221611e6c309d319210f00b5f4978a7eb64fd3a8f563ad79b23abfb - - - firewalld-0.8.2-7.el8_4.noarch.rpm - df084b00f05c91c50e048ee20ce31705f8bc9b87b80fa2e352d53784acb672ff - - - python3-firewall-0.8.2-7.el8_4.noarch.rpm - 313f800ac556b3a2d52ef5ef94a0b63c42f463805bfb8547d084d563a5e39bd6 - - - - - - RLSA-2021:2575 - Moderate: lz4 security update - - - Copyright (C) 2021 Rocky Enterprise Software Foundation - Rocky Linux 8 - 1 - Moderate - An update for lz4 is now available for Rocky Linux 8. Rocky Linux Product Security has rated this update as having a security impact of Moderate. A Common Vulnerability Scoring System (CVSS) base score, which gives a detailed severity rating, is available for each vulnerability from the CVE link(s) in the References section. - For more information visit https://errata.rockylinux.org/RLSA-2021:2575 - - - - - - Rocky Linux 8 - - lz4-libs-1.8.3-3.el8_4.i686.rpm - 08d9574547cf3b7e8c097033eed070118a61658d2b6611bb07c3e5c23e3417a5 - - - lz4-libs-1.8.3-3.el8_4.x86_64.rpm - cf76cb56e26c49ceed4d164973aaf69406111ecb9f93e15c4ee700522a0a9757 - - - lz4-devel-1.8.3-3.el8_4.x86_64.rpm - 15e64b28e17640ad880eae7dcac02406ffb01ef9691d8f8de44f232717bc94e7 - - - lz4-devel-1.8.3-3.el8_4.i686.rpm - 2fe40661f80759c875e8fbc171d58f64b6b068157d9c447d3adaa21eb65e9fde - - - lz4-1.8.3-3.el8_4.x86_64.rpm - e74ca5fb78b28ff0c60bfdee2afdc2f3a23aac1da30dbf52c28f92e576542278 - - - - - - RLSA-2021:3057 - Important: kernel security, bug fix, and enhancement update - - - Copyright (C) 2021 Rocky Enterprise Software Foundation - Rocky Linux 8 - 1 - Important - An update for kernel is now available for Rocky Linux 8. Rocky Linux Product Security has rated this update as having a security impact of Important. A Common Vulnerability Scoring System (CVSS) base score, which gives a detailed severity rating, is available for each vulnerability from the CVE link(s) in the References section. - For more information visit https://errata.rockylinux.org/RLSA-2021:3057 - - - - - - - - Rocky Linux 8 - - kernel-tools-4.18.0-305.12.1.el8_4.x86_64.rpm - 18fb471e45be0eb64fd5671a9f316358780f24feb7069b6844833abfb1edd3e0 - - - kernel-4.18.0-305.12.1.el8_4.x86_64.rpm - 6469e68392625e029cb663f746a6cdc340db8e3d8590f073584bbc777d005189 - - - kernel-debug-modules-4.18.0-305.12.1.el8_4.x86_64.rpm - d44ca2668ebf528dc89e7eb0efc49a656f22cd1559b464b8f59be499ab2b8a21 - - - bpftool-4.18.0-305.12.1.el8_4.x86_64.rpm - c44042a776f4c91d3071970d99dbac005dade9a41c3b976b68e02b51c3fbacb6 - - - kernel-debug-core-4.18.0-305.12.1.el8_4.x86_64.rpm - d8f28b742401bb35482f3bb503301250a62acaeb6e591aa07e7a05baf19e12b0 - - - kernel-abi-stablelists-4.18.0-305.12.1.el8_4.noarch.rpm - 6d89489545e3fce41e85ba1bc652842e24c844230022570180a10795c189b8b7 - - - kernel-debug-4.18.0-305.12.1.el8_4.x86_64.rpm - fb72c03b5153dc08dc5f077dfa15cc6e679033899e242e169e5b2d9ae79de138 - - - kernel-headers-4.18.0-305.12.1.el8_4.x86_64.rpm - 7366c06807d09bf9fdfb899df79bad843b12410143c389fcd01fe68e258c7389 - - - kernel-debug-modules-extra-4.18.0-305.12.1.el8_4.x86_64.rpm - 6324c0ab4f8a2eeddd5378b98587b6b2f18d16a3746fabfde283efa586b931b4 - - - kernel-core-4.18.0-305.12.1.el8_4.x86_64.rpm - 6b7b42c0682ad843c02a75d7d96d90ce9934ea8d582ef21a127ebcf216b8d834 - - - kernel-debug-devel-4.18.0-305.12.1.el8_4.x86_64.rpm - db1b78ea2abd3d932a45bacfc75e86769b7953b0fb7daea00a612804a301d5dc - - - kernel-modules-4.18.0-305.12.1.el8_4.x86_64.rpm - ce003598fb79c7632870b965335688fbd518c10acd127dc1816fb988ea265614 - - - perf-4.18.0-305.12.1.el8_4.x86_64.rpm - 973c676ae20cd9a9f09a1880c5474d148439f4628555597af47af4080bcd99df - - - kernel-tools-libs-4.18.0-305.12.1.el8_4.x86_64.rpm - a7efc5b178006cdc8a73b25e759b1accbb537d2f077e908366b20ba91472809f - - - kernel-cross-headers-4.18.0-305.12.1.el8_4.x86_64.rpm - 657604ad64559c1a2dfd0b1d124d963debcbbf86479e7fd9d719595d3d2cf3ee - - - kernel-modules-extra-4.18.0-305.12.1.el8_4.x86_64.rpm - 0874b15963a3ba1763a6de97f240a3902ffc92579e617f5af0454a3c13dc8cc6 - - - kernel-devel-4.18.0-305.12.1.el8_4.x86_64.rpm - dad7a172c28be86836ab362442445449eae552e88e5a0308c27e9165bc9a45cc - - - python3-perf-4.18.0-305.12.1.el8_4.x86_64.rpm - d89f3f888ece07cb81abb65e98e8d9f66f156c15aa2f5ea694813be780d1499a - - - kernel-doc-4.18.0-305.12.1.el8_4.noarch.rpm - e5a88969b329d2977549e45ce459ca9ac28e98e3aa2015ad3010f03694891a7f - - - - - \ No newline at end of file