| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (test-cve)
|
| 20 | #:use-module (guix cve)
|
| 21 | #:use-module (srfi srfi-1)
|
| 22 | #:use-module (srfi srfi-19)
|
| 23 | #:use-module (srfi srfi-64))
|
| 24 |
|
| 25 | |
| 26 | |
| 27 | (define %sample
|
| 28 | (search-path %load-path "tests/cve-sample.json"))
|
| 29 |
|
| 30 | (define (vulnerability id packages)
|
| 31 | (make-struct/no-tail (@@ (guix cve) <vulnerability>) id packages))
|
| 32 |
|
| 33 | (define %expected-vulnerabilities
|
| 34 | |
| 35 | (list
|
| 36 | (vulnerability "CVE-2019-1010204"
|
| 37 | '(("gnu" "binutils" (and (>= "2.21") (<= "2.31.1")))
|
| 38 | ("gnu" "binutils_gold" (and (>= "1.11") (<= "1.16")))))
|
| 39 | (vulnerability "CVE-2019-1010180"
|
| 40 | '(("gnu" "gdb" (< "9.1"))))
|
| 41 | (vulnerability "CVE-2019-14811"
|
| 42 | '(("artifex" "ghostscript" (< "9.50"))))
|
| 43 | (vulnerability "CVE-2019-17365"
|
| 44 | '(("nixos" "nix" (<= "2.3"))))
|
| 45 | (vulnerability "CVE-2019-18192"
|
| 46 | '(("gnu" "guix" "1.0.1")))
|
| 47 | |
| 48 | |
| 49 | ))
|
| 50 |
|
| 51 |
|
| 52 | (test-begin "cve")
|
| 53 |
|
| 54 | (test-equal "json->cve-items"
|
| 55 | '("CVE-2019-0001"
|
| 56 | "CVE-2019-1010204"
|
| 57 | "CVE-2019-1010180"
|
| 58 | "CVE-2019-14811"
|
| 59 | "CVE-2019-17365"
|
| 60 | "CVE-2019-18192")
|
| 61 | (map cve-item-id
|
| 62 | (call-with-input-file %sample json->cve-items)))
|
| 63 |
|
| 64 | (test-equal "cve-item-published-date"
|
| 65 | '(2019)
|
| 66 | (delete-duplicates
|
| 67 | (map (compose date-year cve-item-published-date)
|
| 68 | (call-with-input-file %sample json->cve-items))))
|
| 69 |
|
| 70 | (test-equal "json->vulnerabilities"
|
| 71 | %expected-vulnerabilities
|
| 72 | (call-with-input-file %sample json->vulnerabilities))
|
| 73 |
|
| 74 | (test-equal "vulnerabilities->lookup-proc"
|
| 75 | (list (list (first %expected-vulnerabilities)) |
| 76 | '()
|
| 77 | (list (first %expected-vulnerabilities))
|
| 78 | '()
|
| 79 |
|
| 80 | (list (second %expected-vulnerabilities)) |
| 81 | (list (second %expected-vulnerabilities))
|
| 82 |
|
| 83 | (list (third %expected-vulnerabilities)) |
| 84 | (list (third %expected-vulnerabilities))
|
| 85 | '()
|
| 86 |
|
| 87 | (list (fourth %expected-vulnerabilities)) |
| 88 | '())
|
| 89 | (let* ((vulns (call-with-input-file %sample json->vulnerabilities))
|
| 90 | (lookup (vulnerabilities->lookup-proc vulns)))
|
| 91 | (list (lookup "binutils" "2.31.1")
|
| 92 | (lookup "binutils" "2.10")
|
| 93 | (lookup "binutils_gold" "1.11")
|
| 94 | (lookup "binutils" "2.32")
|
| 95 | (lookup "gdb")
|
| 96 | (lookup "gdb" "9.0")
|
| 97 | (lookup "ghostscript")
|
| 98 | (lookup "ghostscript" "9.27")
|
| 99 | (lookup "ghostscript" "9.51")
|
| 100 | (lookup "nix")
|
| 101 | (lookup "nix" "2.4"))))
|
| 102 |
|
| 103 | (test-end "cve")
|