summaryrefslogtreecommitdiffstats
path: root/tests/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@g10code.com>2017-02-15 14:50:44 +0100
committerJustus Winter <justus@g10code.com>2017-02-15 14:53:07 +0100
commit127e1e532da4083ccd3c307555b6177fab16f408 (patch)
tree2255164a0803595333b032626725a6717eac14c7 /tests/openpgp
parentscd: Fix RESET command handling. (diff)
downloadgnupg2-127e1e532da4083ccd3c307555b6177fab16f408.tar.xz
gnupg2-127e1e532da4083ccd3c307555b6177fab16f408.zip
tests: Check expiration times of created keys.
* tests/gpgscm/ffi.c (do_get_time): New function. (ffi_init): Expose new function. * tests/gpgscm/ffi.scm (get-time): Document new function. * tests/gpgscm/time.scm: New file. * tests/openpgp/quick-key-manipulation.scm: Use the new facilities to check the expiration times of created keys. * tests/openpgp/tofu.scm: Use the new module. Signed-off-by: Justus Winter <justus@g10code.com>
Diffstat (limited to '')
-rwxr-xr-xtests/openpgp/quick-key-manipulation.scm24
-rwxr-xr-xtests/openpgp/tofu.scm3
2 files changed, 18 insertions, 9 deletions
diff --git a/tests/openpgp/quick-key-manipulation.scm b/tests/openpgp/quick-key-manipulation.scm
index d43f7b53a..c0007d414 100755
--- a/tests/openpgp/quick-key-manipulation.scm
+++ b/tests/openpgp/quick-key-manipulation.scm
@@ -1,6 +1,6 @@
#!/usr/bin/env gpgscm
-;; Copyright (C) 2016 g10 Code GmbH
+;; Copyright (C) 2016-2017 g10 Code GmbH
;;
;; This file is part of GnuPG.
;;
@@ -18,6 +18,7 @@
;; along with this program; if not, see <http://www.gnu.org/licenses/>.
(load (with-path "defs.scm"))
+(load (with-path "time.scm"))
(setup-environment)
;; XXX because of --always-trust, the trustdb is not created.
@@ -91,8 +92,9 @@
;; Make the key expire in one year.
(call-check `(,@gpg --quick-set-expire ,fpr "1y"))
-;; XXX It'd be nice to check that the value is right.
-(assert (not (equal? "" (expiration-time fpr))))
+(assert (time-matches? (+ (get-time) (years->seconds 1))
+ (string->number (expiration-time fpr))
+ (minutes->seconds 5)))
;;
@@ -134,21 +136,29 @@
(lambda (subkey)
(assert (= 1 (:alg subkey)))
(assert (string-contains? (:cap subkey) "s"))
- (assert (not (equal? "" (:expire subkey)))))
+ (assert (time-matches? (+ (get-time) (days->seconds 2))
+ (string->number (:expire subkey))
+ (minutes->seconds 5))))
(lambda (subkey)
(assert (= 1 (:alg subkey)))
(assert (= 1024 (:length subkey)))
(assert (string-contains? (:cap subkey) "s"))
- (assert (not (equal? "" (:expire subkey)))))
+ (assert (time-matches? (+ (get-time) (weeks->seconds 2))
+ (string->number (:expire subkey))
+ (minutes->seconds 5))))
(lambda (subkey)
(assert (= 1 (:alg subkey)))
(assert (= 2048 (:length subkey)))
(assert (string-contains? (:cap subkey) "e"))
- (assert (not (equal? "" (:expire subkey)))))
+ (assert (time-matches? (+ (get-time) (months->seconds 2))
+ (string->number (:expire subkey))
+ (minutes->seconds 5))))
(lambda (subkey)
(assert (= 1 (:alg subkey)))
(assert (= 4096 (:length subkey)))
(assert (string-contains? (:cap subkey) "s"))
(assert (string-contains? (:cap subkey) "a"))
- (assert (not (equal? "" (:expire subkey)))))
+ (assert (time-matches? (+ (get-time) (years->seconds 2))
+ (string->number (:expire subkey))
+ (minutes->seconds 5))))
#f))
diff --git a/tests/openpgp/tofu.scm b/tests/openpgp/tofu.scm
index ca5786b4e..2e32765e8 100755
--- a/tests/openpgp/tofu.scm
+++ b/tests/openpgp/tofu.scm
@@ -18,6 +18,7 @@
;; along with this program; if not, see <http://www.gnu.org/licenses/>.
(load (with-path "defs.scm"))
+(load (with-path "time.scm"))
(setup-environment)
(define GPGTIME 1480943782)
@@ -25,8 +26,6 @@
;; Generate a --faked-system-time parameter for a particular offset.
(define (faketime delta)
(string-append "--faked-system-time=" (number->string (+ GPGTIME delta))))
-;; A convenience function for the above.
-(define (days->seconds days) (* days 24 60 60))
;; Redefine GPG without --always-trust and a fixed time.
(define GPG `(,(tool 'gpg) --no-permission-warning ,(faketime 0)))