]> git.notmuchmail.org Git - notmuch/blob - test/T357-index-decryption.sh
22e716c6536c2ad7dd6fad6bfb644056d8434ca4
[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 # add a tag to all messages to ensure that it stays after reindexing
106 test_begin_subtest 'tagging all messages'
107 test_expect_success 'notmuch tag +blarney "encrypted message"'
108 test_begin_subtest "verify that tags have not changed"
109 output=$(notmuch search tag:blarney)
110 expected='thread:0000000000000001   2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 001 (blarney encrypted inbox)
111 thread:0000000000000005   2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (blarney encrypted inbox unread)'
112 test_expect_equal \
113     "$output" \
114     "$expected"
115
116 # see if first message shows up after reindexing with --try-decrypt=true (same $expected, untouched):
117 test_begin_subtest 'reindex old messages'
118 test_expect_success 'notmuch reindex --try-decrypt=true tag:encrypted and not property:index.decryption=success'
119 test_begin_subtest "reindexed encrypted message, including cleartext"
120 output=$(notmuch search wumpus)
121 test_expect_equal \
122     "$output" \
123     "$expected"
124
125 # and the same search, but by property ($expected is untouched):
126 test_begin_subtest "emacs search by property for both messages"
127 output=$(notmuch search property:index.decryption=success)
128 test_expect_equal \
129     "$output" \
130     "$expected"
131
132
133 # try to remove cleartext indexing
134 test_begin_subtest 'reindex without cleartext'
135 test_expect_success 'notmuch reindex tag:encrypted and property:index.decryption=success'
136 test_begin_subtest "reindexed encrypted messages, without cleartext"
137 output=$(notmuch search wumpus)
138 expected=''
139 test_expect_equal \
140     "$output" \
141     "$expected"
142
143 # and the same search, but by property ($expected is untouched):
144 test_begin_subtest "emacs search by property with both messages unindexed"
145 output=$(notmuch search property:index.decryption=success)
146 test_expect_equal \
147     "$output" \
148     "$expected"
149
150 # ensure that the tags remain even when we are dropping the cleartext.
151 test_begin_subtest "verify that tags remain without cleartext"
152 output=$(notmuch search tag:blarney)
153 expected='thread:0000000000000001   2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 001 (blarney encrypted inbox)
154 thread:0000000000000005   2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (blarney encrypted inbox unread)'
155 test_expect_equal \
156     "$output" \
157     "$expected"
158
159
160 # TODO: test removal of a message from the message store between
161 # indexing and reindexing.
162
163 # TODO: insert the same message into the message store twice, index,
164 # remove one of them from the message store, and then reindex.
165 # reindexing should return a failure but the message should still be
166 # present? -- or what should the semantics be if you ask to reindex a
167 # message whose underlying files have been renamed or moved or
168 # removed?
169
170 test_done