Debian Codegraph @

debian/tests/emacs-epg-message-mode

raw
1 #!/bin/sh
2 set -e
3
4 # Author: Daniel Kahn Gillmor <[email protected]>
5
6 # Emacs has epg mode, which expects a certain behavior from GnuPG.
7 #
8 # GnuPG upstream doesn't think that it is a bug to break those
9 # expectations (see https://dev.gnupg.org/T6481) but we want to avoid
10 # having those problems in debian. (see
11 # https://bugs.debian.org/1071552)
12
13 # This test ensures that a simple attempt to send signed, encrypted
14 # PGP/MIME mail with emacs doesn't break with the current version of
15 # GnuPG.
16
17 WORKDIR="$(mktemp -d)"
18 mkdir -m 0700 "$WORKDIR/a" "$WORKDIR/b" "$WORKDIR/out"
19 OUTDIR="${AUTOPKGTEST_ARTIFACTS:-$WORKDIR/out}"
20
21 cleanup() {
22 find "$WORKDIR/out" -type f -print0 | xargs --null --no-run-if-empty -- head -v -n100
23 printf "Cleaning up working directory '%s'\n" "$WORKDIR"
24 rm -rf "$WORKDIR"
25 }
26
27 trap cleanup EXIT
28
29 GPG() {
30 home=$1
31 shift
32 gpg --quiet --homedir "$WORKDIR/$home" --batch --pinentry-mode=loopback --passphrase='' --no-tty --status-file="$WORKDIR/status" "$@"
33 }
34
35 GPG a --quick-gen-key "Alice <[email protected]>"
36 ALICE_FPR=$(grep KEY_CREATED "$WORKDIR/status" | cut -f4 -d\ )
37 GPG b --quick-gen-key "Bob <[email protected]>"
38 BOB_FPR=$(grep KEY_CREATED "$WORKDIR/status" | cut -f4 -d\ )
39 GPG b --export "Bob <[email protected]>" | GPG a --import
40 # Alice certifies Bob's certificate locally so that her GnuPG installation knows it is valid:
41 GPG a --quick-lsign-key "$BOB_FPR" "Bob <[email protected]>"
42
43 cat > "$WORKDIR/mailscript.el" <<EOF
44 (let ((user-mail-address "[email protected]")
45 (user-full-name "Alice")
46 (mail-host-address "example.com"))
47 (message-mail "Bob <[email protected]>" "this is a test")
48 (message-goto-body)
49 (insert "we need to see whether easypg can handle encryption (see https://dev.gnupg.org/T6481)")
50 (mml-secure-message-sign-encrypt)
51 (let ((mml-secure-openpgp-sign-with-sender t)
52 (message-send-mail-function (lambda () (write-region nil nil "sample.eml"))))
53 (message-send-and-exit))
54 )
55 EOF
56
57 # emacs message mode is chatty to stderr even on success, so we store it to keep autopkgtest happy.
58 (cd "$WORKDIR" && TERM=dumb GNUPGHOME="$WORKDIR/a" timeout 10s emacs --quick --no-window-system --script mailscript.el 2> "$OUTDIR/stderr")
59
60 head -v -n 100 "$OUTDIR/stderr"
61
62 cp "$WORKDIR/sample.eml" "$OUTDIR/"
63
64 GPG a --output "$OUTDIR/alice.key" --armor --export-secret-key "$ALICE_FPR"
65 GPG b --output "$OUTDIR/bob.key" --armor --export-secret-key "$BOB_FPR"