From 13a7d2a538b00aa0a8cf9b999f1a4ff3e5959af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 31 Jan 2021 16:14:59 +0100 Subject: database: Validate #:nar-size and #:time when registering store items. * guix/store/database.scm (assert-integer): New procedure. (update-or-insert): Use it to validate NAR-SIZE and TIME. * tests/store-database.scm ("sqlite-register with incorrect size"): New test. --- tests/store-database.scm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tests/store-database.scm') diff --git a/tests/store-database.scm b/tests/store-database.scm index 17eea38c63..d8f3ce8070 100644 --- a/tests/store-database.scm +++ b/tests/store-database.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2017, 2018, 2020 Ludovic Courtès +;;; Copyright © 2017, 2018, 2020, 2021 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -123,4 +123,21 @@ (pk 'welcome-exception! args) #t))))) +(test-equal "sqlite-register with incorrect size" + 'out-of-range + (call-with-temporary-output-file + (lambda (db-file port) + (delete-file db-file) + (catch #t + (lambda () + (with-database db-file db + (sqlite-register db #:path "/gnu/foo" + #:references '("/gnu/bar") + #:deriver "/gnu/foo.drv" + #:hash (string-append "sha256:" (make-string 64 #\e)) + #:nar-size -1234)) + #f) + (lambda (key . _) + key))))) + (test-end "store-database") -- cgit v1.2.3