cve.scm 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-cve)
  19. #:use-module (guix cve)
  20. #:use-module (srfi srfi-1)
  21. #:use-module (srfi srfi-64))
  22. (define %sample
  23. (search-path %load-path "tests/cve-sample.xml"))
  24. (define (vulnerability id packages)
  25. (make-struct (@@ (guix cve) <vulnerability>) 0 id packages))
  26. (define %expected-vulnerabilities
  27. ;; What we should get when reading %SAMPLE.
  28. (list
  29. ;; CVE-2003-0001 has no "/a" in its product list so it is omitted.
  30. ;; CVE-2004-0230 lists "tcp" as an application, but lacks a version number.
  31. (vulnerability "CVE-2008-2335" '(("phpvid" "1.2" "1.1")))
  32. (vulnerability "CVE-2008-3522" '(("enterprise_virtualization" "3.5")
  33. ("jasper" "1.900.1")))
  34. (vulnerability "CVE-2009-3301" '(("openoffice.org" "2.3.0" "2.2.1" "2.1.0")))
  35. ;; CVE-2015-8330 has no software list.
  36. ))
  37. (test-begin "cve")
  38. (test-equal "xml->vulnerabilities"
  39. %expected-vulnerabilities
  40. (call-with-input-file %sample xml->vulnerabilities))
  41. (test-equal "vulnerabilities->lookup-proc"
  42. (list (list (first %expected-vulnerabilities))
  43. '()
  44. '()
  45. (list (second %expected-vulnerabilities))
  46. (list (third %expected-vulnerabilities)))
  47. (let* ((vulns (call-with-input-file %sample xml->vulnerabilities))
  48. (lookup (vulnerabilities->lookup-proc vulns)))
  49. (list (lookup "phpvid")
  50. (lookup "jasper" "2.0")
  51. (lookup "foobar")
  52. (lookup "jasper" "1.900.1")
  53. (lookup "openoffice.org" "2.3.0"))))
  54. (test-end "cve")