chiark / gitweb /
asshelp.c: add a lot of debug logging
[gnupg2.git] / tests / openpgp / gpgtar.scm
1 #!/usr/bin/env gpgscm
2
3 ;; Copyright (C) 2016 g10 Code GmbH
4 ;;
5 ;; This file is part of GnuPG.
6 ;;
7 ;; GnuPG is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3 of the License, or
10 ;; (at your option) any later version.
11 ;;
12 ;; GnuPG is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; if not, see <http://www.gnu.org/licenses/>.
19
20 (load (with-path "defs.scm"))
21 (setup-legacy-environment)
22
23 (catch (skip "gpgtar not built")
24        (call-check `(,(tool 'gpgtar) --help)))
25
26 (define testfiles (append plain-files data-files))
27 (define gpgargs
28   (if have-opt-always-trust
29       "--no-permission-warning --always-trust"
30       "--no-permission-warning"))
31
32 (define (do-test create-flags inspect-flags extract-flags)
33   (lettmp (archive)
34     (call-check `(,(tool 'gpgtar) --gpg ,(tool 'gpg) --gpg-args ,gpgargs
35                   ,@create-flags
36                   --output ,archive
37                   ,@testfiles))
38     (tr:do
39      (tr:pipe-do
40       (pipe:spawn `(,(tool 'gpgtar) --gpg ,(tool 'gpg) --gpg-args ,gpgargs
41                     --list-archive ,@inspect-flags
42                     ,archive)))
43      (tr:call-with-content
44       (lambda (c)
45         (unless (all (lambda (f) (string-contains? c f)) testfiles)
46                 (fail "some file(s) are missing from archive")))))
47
48     (with-temporary-working-directory
49      (call-check `(,(tool 'gpgtar) --gpg ,(tool 'gpg) --gpg-args ,gpgargs
50                    --tar-args --directory=.
51                    ,@extract-flags
52                    ,archive))
53
54      (for-each
55       (lambda (f) (unless (call-with-input-file f (lambda (x) #t))
56                           (fail (string-append "missing file: " f))))
57       testfiles))))
58
59 (info "Checking gpgtar without encryption")
60 (do-test '(--skip-crypto --encrypt) '(--skip-crypto)
61          '(--skip-crypto --decrypt))
62
63 (info "Checking gpgtar without encryption with nicer actions")
64 (do-test '(--create) '(--skip-crypto) '(--extract))
65
66 (info "Checking gpgtar with asymmetric encryption")
67 (do-test `(--encrypt --recipient ,usrname2) '() '(--decrypt))
68
69 (info "Checking gpgtar with asymmetric encryption and signature")
70 (do-test `(--encrypt --recipient ,usrname2 --sign --local-user ,usrname3)
71          '() '(--decrypt))
72
73 (info "Checking gpgtar with signature")
74 (do-test `(--sign --local-user ,usrname3) '() '(--decrypt))
75
76 (lettmp (passphrasefile)
77   (letfd ((fd (open passphrasefile (logior O_WRONLY O_CREAT O_BINARY) #o600)))
78     (display "streng geheimes hupsipupsi" (fdopen fd "wb")))
79
80   (let ((ppflags `(--gpg-args ,(string-append "--passphrase-file="
81                                               passphrasefile))))
82     (info "Checking gpgtar with symmetric encryption")
83     (do-test `(,@ppflags --symmetric) ppflags (cons '--decrypt ppflags))
84
85     (info "Checking gpgtar with symmetric encryption and chosen cipher")
86     (do-test `(,@ppflags --symmetric --gpg-args
87                          ,(string-append "--cipher="
88                                          (car (force all-cipher-algos))))
89              ppflags (cons '--decrypt ppflags))
90
91     (info "Checking gpgtar with both symmetric and asymmetric encryption")
92     (do-test `(,@ppflags --symmetric --encrypt --recipient ,usrname2
93                          --sign --local-user ,usrname3)
94              ppflags (cons '--decrypt ppflags))))