]> git.notmuchmail.org Git - notmuch/blob - test/T357-index-decryption.sh
cli/insert: add --try-decrypt=(true|false)
[notmuch] / test / T357-index-decryption.sh
1 #!/usr/bin/env bash
2
3 # TODO: test index.decryption=failed
4
5 test_description='indexing decrypted mail'
6 . $(dirname "$0")/test-lib.sh || exit 1
7
8 ##################################################
9
10 add_gnupg_home
11 # get key fingerprint
12 FINGERPRINT=$(gpg --no-tty --list-secret-keys --with-colons --fingerprint | grep '^fpr:' | cut -d: -f10)
13
14 # create a test encrypted message
15 test_begin_subtest 'emacs delivery of encrypted message'
16 test_expect_success \
17 'emacs_fcc_message \
18     "test encrypted message for cleartext index 001" \
19     "This is a test encrypted message with a wumpus.\n" \
20     "(mml-secure-message-encrypt)"'
21
22 test_begin_subtest "search for unindexed cleartext"
23 output=$(notmuch search wumpus)
24 expected=''
25 test_expect_equal \
26     "$output" \
27     "$expected"
28
29 # create a test encrypted message that is indexed in the clear
30 test_begin_subtest 'emacs delivery of encrypted message'
31 test_expect_success \
32 'emacs_fcc_message --try-decrypt=true \
33     "test encrypted message for cleartext index 002" \
34     "This is a test encrypted message with a wumpus.\n" \
35     "(mml-secure-message-encrypt)"'
36
37 test_begin_subtest "emacs delivery of encrypted message, indexed cleartext"
38 output=$(notmuch search wumpus)
39 expected='thread:0000000000000002   2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (encrypted inbox)'
40 test_expect_equal \
41     "$output" \
42     "$expected"
43
44 # and the same search, but by property ($expected is untouched):
45 test_begin_subtest "emacs search by property for one message"
46 output=$(notmuch search property:index.decryption=success)
47 test_expect_equal \
48     "$output" \
49     "$expected"
50
51
52 test_begin_subtest "message should go away after deletion"
53 # cache the message in an env var and remove it:
54 fname=$(notmuch search --output=files wumpus)
55 contents="$(notmuch show --format=raw wumpus)"
56 rm -f "$fname"
57 notmuch new
58 output=$(notmuch search wumpus)
59 expected=''
60 test_expect_equal \
61     "$output" \
62     "$expected"
63
64 # try reinserting it without decryption, should stay the same:
65 test_begin_subtest "message cleartext not present after insert"
66 notmuch insert --folder=sent <<<"$contents"
67 output=$(notmuch search wumpus)
68 test_expect_equal \
69     "$output" \
70     "$expected"
71
72 # try reinserting it with decryption, should appear again, but now we
73 # have two copies of the message:
74 test_begin_subtest "message cleartext is present after reinserting with --try-decrypt"
75 notmuch insert --folder=sent --try-decrypt <<<"$contents"
76 output=$(notmuch search wumpus)
77 expected='thread:0000000000000003   2000-01-01 [1/1(2)] Notmuch Test Suite; test encrypted message for cleartext index 002 (encrypted inbox unread)'
78 test_expect_equal \
79     "$output" \
80     "$expected"
81
82 # remove all copies
83 test_begin_subtest "delete all copies of the message"
84 mid="$(notmuch search --output=messages wumpus)"
85 rm -f $(notmuch search --output=files wumpus)
86 notmuch new
87 output=$(notmuch search "id:$mid")
88 expected=''
89 test_expect_equal \
90     "$output" \
91     "$expected"
92
93 # try inserting it with decryption, should appear as a single copy
94 # (note: i think thread id skips 4 because of duplicate message-id
95 # insertion, above)
96 test_begin_subtest "message cleartext is present with insert --try-decrypt"
97 notmuch insert --folder=sent --try-decrypt <<<"$contents"
98 output=$(notmuch search wumpus)
99 expected='thread:0000000000000005   2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (encrypted inbox unread)'
100 test_expect_equal \
101     "$output" \
102     "$expected"
103
104
105
106
107 test_done