3 # TODO: test index.decryption=failed
5 test_description='indexing decrypted mail'
6 . $(dirname "$0")/test-lib.sh || exit 1
8 ##################################################
12 FINGERPRINT=$(gpg --no-tty --list-secret-keys --with-colons --fingerprint | grep '^fpr:' | cut -d: -f10)
14 # create a test encrypted message
15 test_begin_subtest 'emacs delivery of encrypted 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)"'
22 test_begin_subtest "search for unindexed cleartext"
23 output=$(notmuch search wumpus)
29 # create a test encrypted message that is indexed in the clear
30 test_begin_subtest 'emacs delivery of encrypted message'
32 'emacs_fcc_message --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)"'
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)'
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)
51 test_begin_subtest "show the message body of the encrypted message"
53 output=$(notmuch show wumpus | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }')
54 expected='This is a test encrypted message with a wumpus.'
55 if [ $NOTMUCH_HAVE_GMIME_SESSION_KEYS -eq 0 ]; then
56 test_subtest_known_broken
63 test_begin_subtest "message should go away after deletion"
64 # cache the message in an env var and remove it:
65 fname=$(notmuch search --output=files wumpus)
66 contents="$(notmuch show --format=raw wumpus)"
69 output=$(notmuch search wumpus)
75 # try reinserting it without decryption, should stay the same:
76 test_begin_subtest "message cleartext not present after insert"
77 notmuch insert --folder=sent <<<"$contents"
78 output=$(notmuch search wumpus)
83 # try reinserting it with decryption, should appear again, but now we
84 # have two copies of the message:
85 test_begin_subtest "message cleartext is present after reinserting with --decrypt=true"
86 notmuch insert --folder=sent --decrypt=true <<<"$contents"
87 output=$(notmuch search wumpus)
88 expected='thread:0000000000000003 2000-01-01 [1/1(2)] Notmuch Test Suite; test encrypted message for cleartext index 002 (encrypted inbox unread)'
94 test_begin_subtest "delete all copies of the message"
95 mid="$(notmuch search --output=messages wumpus)"
96 rm -f $(notmuch search --output=files wumpus)
98 output=$(notmuch search "id:$mid")
104 # try inserting it with decryption, should appear as a single copy
105 # (note: i think thread id skips 4 because of duplicate message-id
107 test_begin_subtest "message cleartext is present with insert --decrypt=true"
108 notmuch insert --folder=sent --decrypt=true <<<"$contents"
109 output=$(notmuch search wumpus)
110 expected='thread:0000000000000005 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (encrypted inbox unread)'
116 # add a tag to all messages to ensure that it stays after reindexing
117 test_begin_subtest 'tagging all messages'
118 test_expect_success 'notmuch tag +blarney "encrypted message"'
119 test_begin_subtest "verify that tags have not changed"
120 output=$(notmuch search tag:blarney)
121 expected='thread:0000000000000001 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 001 (blarney encrypted inbox)
122 thread:0000000000000005 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (blarney encrypted inbox unread)'
127 # see if first message shows up after reindexing with --decrypt=true (same $expected, untouched):
128 test_begin_subtest 'reindex old messages'
129 test_expect_success 'notmuch reindex --decrypt=true tag:encrypted and not property:index.decryption=success'
130 test_begin_subtest "reindexed encrypted message, including cleartext"
131 output=$(notmuch search wumpus)
136 # and the same search, but by property ($expected is untouched):
137 test_begin_subtest "emacs search by property for both messages"
138 output=$(notmuch search property:index.decryption=success)
143 # try a simple reindex
144 test_begin_subtest 'reindex in auto mode'
145 test_expect_success 'notmuch reindex tag:encrypted and property:index.decryption=success'
146 test_begin_subtest "reindexed encrypted messages, should not have changed"
147 output=$(notmuch search wumpus)
148 if [ $NOTMUCH_HAVE_GMIME_SESSION_KEYS -eq 0 ]; then
149 test_subtest_known_broken
155 # try to remove cleartext indexing
156 test_begin_subtest 'reindex without cleartext'
157 test_expect_success 'notmuch reindex --decrypt=false tag:encrypted and property:index.decryption=success'
158 test_begin_subtest "reindexed encrypted messages, without cleartext"
159 output=$(notmuch search wumpus)
165 # ensure no session keys are present:
166 test_begin_subtest 'reindex using only session keys'
167 test_expect_success 'notmuch reindex tag:encrypted and property:index.decryption=success'
168 test_begin_subtest "reindexed encrypted messages, decrypting only with session keys"
169 output=$(notmuch search wumpus)
175 # and the same search, but by property ($expected is untouched):
176 test_begin_subtest "emacs search by property with both messages unindexed"
177 output=$(notmuch search property:index.decryption=success)
182 # ensure that the tags remain even when we are dropping the cleartext.
183 test_begin_subtest "verify that tags remain without cleartext"
184 output=$(notmuch search tag:blarney)
185 expected='thread:0000000000000001 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 001 (blarney encrypted inbox)
186 thread:0000000000000005 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (blarney encrypted inbox unread)'
191 test_begin_subtest "index cleartext without keeping session keys"
192 test_expect_success "notmuch reindex --decrypt=nostash tag:blarney"
194 test_begin_subtest "Ensure that the indexed terms are present"
195 output=$(notmuch search wumpus)
200 test_begin_subtest "show one of the messages with --decrypt"
201 output=$(notmuch show --decrypt thread:0000000000000001 | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }')
202 expected='This is a test encrypted message with a wumpus.'
207 test_begin_subtest "Ensure that we cannot show the message without --decrypt"
208 output=$(notmuch show thread:0000000000000001 | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }')
209 expected='Non-text part: application/octet-stream'
214 add_email_corpus crypto
216 test_begin_subtest "indexing message fails when secret key not available"
217 notmuch reindex --decrypt=true id:simple-encrypted@crypto.notmuchmail.org
218 output=$(notmuch dump )
219 expected='#notmuch-dump batch-tag:3 config,properties,tags
220 +encrypted +inbox +unread -- id:simple-encrypted@crypto.notmuchmail.org
221 #= simple-encrypted@crypto.notmuchmail.org index.decryption=failure'
226 test_begin_subtest "cannot find cleartext index"
227 output=$(notmuch search sekrit)
233 test_begin_subtest "cleartext index recovery on reindexing with stashed session keys"
234 notmuch restore <<EOF
235 #notmuch-dump batch-tag:3 config,properties,tags
236 #= simple-encrypted@crypto.notmuchmail.org session-key=9%3AFC09987F5F927CC0CC0EE80A96E4C5BBF4A499818FB591207705DFDDD6112CF9
238 notmuch reindex id:simple-encrypted@crypto.notmuchmail.org
239 output=$(notmuch search sekrit)
240 expected='thread:0000000000000001 2016-12-22 [1/1] Daniel Kahn Gillmor; encrypted message (encrypted inbox unread)'
241 if [ $NOTMUCH_HAVE_GMIME_SESSION_KEYS -eq 0 ]; then
242 test_subtest_known_broken
248 test_begin_subtest "notmuch reply should show cleartext if session key is present"
249 output=$(notmuch reply id:simple-encrypted@crypto.notmuchmail.org | grep '^>')
250 expected='> This is a top sekrit message.'
251 if [ $NOTMUCH_HAVE_GMIME_SESSION_KEYS -eq 0 ]; then
252 test_subtest_known_broken
258 test_begin_subtest "notmuch show should show cleartext if session key is present"
259 output=$(notmuch show id:simple-encrypted@crypto.notmuchmail.org | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }')
260 expected='This is a top sekrit message.'
261 if [ $NOTMUCH_HAVE_GMIME_SESSION_KEYS -eq 0 ]; then
262 test_subtest_known_broken
268 test_begin_subtest "notmuch show should show nothing if decryption is explicitly disallowed"
269 output=$(notmuch show --decrypt=false id:simple-encrypted@crypto.notmuchmail.org | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }')
270 expected='Non-text part: application/octet-stream'
275 test_begin_subtest "purging stashed session keys should lose access to the cleartext"
276 notmuch reindex --decrypt=false id:simple-encrypted@crypto.notmuchmail.org
277 output=$(notmuch search sekrit)
283 test_begin_subtest "and cleartext should be unrecoverable now that there are no stashed session keys"
285 notmuch reindex --decrypt=true id:simple-encrypted@crypto.notmuchmail.org
286 output=$(notmuch search sekrit)
293 # TODO: test removal of a message from the message store between
294 # indexing and reindexing.
296 # TODO: insert the same message into the message store twice, index,
297 # remove one of them from the message store, and then reindex.
298 # reindexing should return a failure but the message should still be
299 # present? -- or what should the semantics be if you ask to reindex a
300 # message whose underlying files have been renamed or moved or