aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015, 2016, 2019 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-cve)
  #:use-module (guix cve)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-19)
  #:use-module (srfi srfi-64))

(define %sample
  (search-path %load-path "tests/cve-sample.json"))

(define (vulnerability id packages)
  (make-struct/no-tail (@@ (guix cve) <vulnerability>) id packages))

(define %expected-vulnerabilities
  ;; What we should get when reading %SAMPLE.
  (list
   (vulnerability "CVE-2019-0001"
                  ;; Only the "a" CPE configurations are kept; the "o"
                  ;; configurations are discarded.
                  '(("junos" (or "18.21-s4" (or "18.21-s3" "18.2")))))
   (vulnerability "CVE-2019-0005"
                  '(("junos" (or "18.11" "18.1"))))
   ;; CVE-2019-0005 has no "a" configurations.
   (vulnerability "CVE-2019-14811"
                  '(("ghostscript" (< "9.28"))))
   (vulnerability "CVE-2019-17365"
                  '(("nix" (<= "2.3"))))
   (vulnerability "CVE-2019-1010180"
                  '(("gdb" _)))                   ;any version
   (vulnerability "CVE-2019-1010204"
                  '(("binutils" (and (>= "2.21") (<= "2.31.1")))
                    ("binutils_gold" (and (>= "1.11") (<= "1.16")))))
   ;; CVE-2019-18192 has no associated configurations.
   ))


(test-begin "cve")

(test-equal "json->cve-items"
  '("CVE-2019-0001"
    "CVE-2019-0005"
    "CVE-2019-14811"
    "CVE-2019-17365"
    "CVE-2019-1010180"
    "CVE-2019-1010204"
    "CVE-2019-18192")
  (map (compose cve-id cve-item-cve)
       (call-with-input-file %sample json->cve-items)))

(test-equal "cve-item-published-date"
  '(2019)
  (delete-duplicates
   (map (compose date-year cve-item-published-date)
        (call-with-input-file %sample json->cve-items))))

(test-equal "json->vulnerabilities"
  %expected-vulnerabilities
  (call-with-input-file %sample json->vulnerabilities))

(test-equal "vulnerabilities->lookup-proc"
  (list (list (third %expected-vulnerabilities))  ;ghostscript
        (list (third %expected-vulnerabilities))
        '()

        (list (fifth %expected-vulnerabilities))  ;gdb
        (list (fifth %expected-vulnerabilities))

        (list (fourth %expected-vulnerabilities)) ;nix
        '()

        (list (sixth %expected-vulnerabilities))  ;binutils
        '()
        (list (sixth %expected-vulnerabilities))
        '())
  (let* ((vulns  (call-with-input-file %sample json->vulnerabilities))
         (lookup (vulnerabilities->lookup-proc vulns)))
    (list (lookup "ghostscript")
          (lookup "ghostscript" "9.27")
          (lookup "ghostscript" "9.28")
          (lookup "gdb")
          (lookup "gdb" "42.0")
          (lookup "nix")
          (lookup "nix" "2.4")
          (lookup "binutils" "2.31.1")
          (lookup "binutils" "2.10")
          (lookup "binutils_gold" "1.11")
          (lookup "binutils" "2.32"))))

(test-end "cve")
-avail'>...Marius Bakke 2019-12-11gnu: atk: Update to 2.34.1....Marius Bakke 2019-12-11gnu: gtk+: Update to 3.24.13....Marius Bakke 2019-12-04gnu: girara: Fetch sources from git....Tobias Geerinckx-Rice 2019-12-04Merge branch 'staging'Marius Bakke 2019-12-03gnu: girara: Update to 0.3.3....Tobias Geerinckx-Rice 2019-11-28Merge branch 'master' into stagingMarius Bakke 2019-11-28gnu: Use the test-only Xorg variant for tests....Marius Bakke 2019-11-23gnu: perl-cairo: Update to 1.107....Tobias Geerinckx-Rice 2019-11-15Merge branch 'master' into stagingMarius Bakke 2019-11-01gnu: yad: Update to 5.0....Tobias Geerinckx-Rice 2019-10-30Merge branch 'master' into stagingMarius Bakke 2019-10-28gnu: gtkmm: Update to 3.24.2....Tobias Geerinckx-Rice 2019-10-18Merge branch 'master' into stagingMarius Bakke 2019-10-16gnu: perl-gtk2: Update to 1.24993....Tobias Geerinckx-Rice 2019-10-14gnu: gtkmm: Update to 3.24.1....Ludovic Courtès 2019-10-09gnu: gtk+: Add libxrandr input....Ingo Ruhnke 2019-10-08gnu: gtk+: Update to 3.24.12....Marius Bakke 2019-10-08gnu: gdk-pixbuf: Update to 2.40.0....Marius Bakke 2019-08-29Merge branch 'master' into core-updatesMark H Weaver 2019-08-28gnu: gtkspell3: Install Vala bindings....Giacomo Leidi 2019-08-13Merge branch 'master' into core-updatesMarius Bakke 2019-08-04gnu: gtk+: Update to 3.24.10....Marius Bakke 2019-07-12gnu: gtksourceview: Update to 4.2.0....Marius Bakke 2019-07-11gnu: harfbuzz: Create hb-gobject-enums.h....Marius Bakke 2019-07-03gnu: ganv: Remove GCC5 workaround....Marius Bakke 2019-07-02gnu: gtkmm: Remove GCC5 workaround....Marius Bakke 2019-07-02Merge branch 'staging' into core-updatesMarius Bakke 2019-07-02Merge branch 'master' into stagingMarius Bakke 2019-06-30gnu: gtksourceviewmm: Build against gtksourceview@3....Marius Bakke 2019-06-30gnu: harfbuzz: Update to 2.5.3....Marius Bakke 2019-06-29gnu: gtk+: Update to 3.24.9....Marius Bakke 2019-06-27Merge branch 'master' into core-updatesLudovic Courtès 2019-06-24gnu: Add volumeicon....Tobias Geerinckx-Rice 2019-06-23gnu: spread-sheet-widget: Don't use NAME in source URI....Tobias Geerinckx-Rice 2019-06-21gnu: harfbuzz: Update to 2.5.2....Marius Bakke