tests: Deduplicate and simplify code.

* tests/gpgme/gpgme-defs.scm (create-file): Move...
* tests/gpgsm/gpgsm-defs.scm (create-file): ... likewise...
* tests/openpgp/defs.scm (create-file): Here.
(create-gpghome): Use 'create-file'.
* tests/openpgp/gpg-agent.conf.tmpl: Delete file.
* tests/openpgp/gpg.conf.tmpl: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2017-04-20 17:35:15 +02:00
parent 9ae63b9cae
commit 06a177ceea
No known key found for this signature in database
GPG Key ID: DD1A52F9DA8C9020
5 changed files with 24 additions and 33 deletions

View File

@ -45,11 +45,6 @@
;; The tests expect the pinentry to return the passphrase "abc". ;; The tests expect the pinentry to return the passphrase "abc".
(setenv "PINENTRY_USER_DATA" "abc" #t) (setenv "PINENTRY_USER_DATA" "abc" #t)
(define (create-file name . lines)
(letfd ((fd (open name (logior O_WRONLY O_CREAT O_BINARY) #o600)))
(let ((port (fdopen fd "wb")))
(for-each (lambda (line) (display line port) (newline port)) lines))))
(define (create-gpgmehome . path) (define (create-gpgmehome . path)
;; Support for various environments. ;; Support for various environments.
(define mode (define mode

View File

@ -61,12 +61,6 @@
(equal? key::fpr (:fpr l)))) (equal? key::fpr (:fpr l))))
(gpgsm-with-colons `(--list-secret-keys ,key::fpr)))))) (gpgsm-with-colons `(--list-secret-keys ,key::fpr))))))
(define (create-file name . lines)
(letfd ((fd (open name (logior O_WRONLY O_CREAT O_BINARY) #o600)))
(let ((port (fdopen fd "wb")))
(for-each (lambda (line) (display line port) (newline port))
lines))))
(define (create-gpgsmhome) (define (create-gpgsmhome)
(create-file "gpgsm.conf" (create-file "gpgsm.conf"
"disable-crl-checks" "disable-crl-checks"

View File

@ -309,6 +309,12 @@
(lambda (port) (lambda (port)
(display (make-random-string size) port)))) (display (make-random-string size) port))))
(define (create-file name . lines)
(letfd ((fd (open name (logior O_WRONLY O_CREAT O_BINARY) #o600)))
(let ((port (fdopen fd "wb")))
(for-each (lambda (line) (display line port) (newline port))
lines))))
(define (create-gpghome) (define (create-gpghome)
(log "Creating test environment...") (log "Creating test environment...")
@ -316,21 +322,24 @@
(make-test-data "random_seed" 600) (make-test-data "random_seed" 600)
(log "Creating configuration files") (log "Creating configuration files")
(for-each (create-file "gpg.conf"
(lambda (name) "no-greeting"
(file-copy (in-srcdir "tests" "openpgp" (string-append name ".tmpl")) name) "no-secmem-warning"
(let ((p (open-input-output-file name))) "no-permission-warning"
(cond "batch"
((string=? "gpg.conf" name) "allow-weak-digest-algos"
(if have-opt-always-trust (if have-opt-always-trust
(display "no-auto-check-trustdb\n" p)) "no-auto-check-trustdb" "#no-auto-check-trustdb")
(display (string-append "agent-program " (string-append "agent-program "
(tool 'gpg-agent) (tool 'gpg-agent)
"|--debug-quick-random\n") p) "|--debug-quick-random\n")
(display "allow-weak-digest-algos\n" p)) )
((string=? "gpg-agent.conf" name) (create-file "gpg-agent.conf"
(display (string-append "pinentry-program " PINENTRY "\n") p))))) "allow-preset-passphrase"
'("gpg.conf" "gpg-agent.conf"))) "no-grab"
"enable-ssh-support"
(string-append "pinentry-program " (tool 'pinentry))
))
;; Initialize the test environment, install appropriate configuration ;; Initialize the test environment, install appropriate configuration
;; and start the agent, without any keys. ;; and start the agent, without any keys.

View File

@ -1,3 +0,0 @@
allow-preset-passphrase
no-grab
enable-ssh-support

View File

@ -1,4 +0,0 @@
no-greeting
no-secmem-warning
no-permission-warning
batch