You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

374 lines
13 KiB

  1. #include <config.h>
  2. #include <apt-pkg/error.h>
  3. #include <apt-pkg/fileutl.h>
  4. #include <apt-pkg/gpgv.h>
  5. #include <string>
  6. #include <gtest/gtest.h>
  7. #include "file-helpers.h"
  8. /* The test files are created with the 'Joe Sixpack' and 'Marvin Paranoid'
  9. test key included in the integration testing framework */
  10. TEST(OpenMaybeClearSignedFileTest,SimpleSignedFile)
  11. {
  12. std::string tempfile;
  13. FileFd fd;
  14. // Using c++11 raw-strings would be nifty, but travis doesn't support it…
  15. createTemporaryFile("simplesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
  16. "Hash: SHA512\n"
  17. "\n"
  18. "Test\n"
  19. "-----BEGIN PGP SIGNATURE-----\n"
  20. "\n"
  21. "iQFEBAEBCgAuFiEENKjp0Y2zIPNn6OqgWpDRQdusja4FAlhT7+kQHGpvZUBleGFt\n"
  22. "cGxlLm9yZwAKCRBakNFB26yNrjvEB/9/e3jA1l0fvPafx9LEXcH8CLpUFQK7ra9l\n"
  23. "3M4YAH4JKQlTG1be7ixruBRlCTh3YiSs66fKMeJeUYoxA2HPhvbGFEjQFAxunEYg\n"
  24. "X/LBKv1mQWa+Q34P5GBjK8kQdLCN+yJAiUErmWNQG3GPninrxsC9tY5jcWvHeP1k\n"
  25. "V7N3MLnNqzXaCJM24mnKidC5IDadUdQ8qC8c3rjUexQ8vBz0eucH56jbqV5oOcvx\n"
  26. "pjlW965dCPIf3OI8q6J7bIOjyY+u/PTcVlqPq3TUz/ti6RkVbKpLH0D4ll3lUTns\n"
  27. "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
  28. "=TB1F\n"
  29. "-----END PGP SIGNATURE-----\n");
  30. EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
  31. EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
  32. if (tempfile.empty() == false)
  33. unlink(tempfile.c_str());
  34. EXPECT_TRUE(fd.IsOpen());
  35. char buffer[100];
  36. EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
  37. EXPECT_STREQ(buffer, "Test");
  38. EXPECT_TRUE(fd.Eof());
  39. }
  40. TEST(OpenMaybeClearSignedFileTest,WhitespaceSignedFile)
  41. {
  42. std::string tempfile;
  43. FileFd fd;
  44. // no raw-string here to protect the whitespace from cleanup
  45. createTemporaryFile("simplesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE----- \t \n"
  46. "Hash: SHA512 \n"
  47. " \n"
  48. "Test \n"
  49. "-----BEGIN PGP SIGNATURE----- \n"
  50. " \n"
  51. "iQFEBAEBCgAuFiEENKjp0Y2zIPNn6OqgWpDRQdusja4FAlhT7+kQHGpvZUBleGFt \n"
  52. "cGxlLm9yZwAKCRBakNFB26yNrjvEB/9/e3jA1l0fvPafx9LEXcH8CLpUFQK7ra9l \n"
  53. "3M4YAH4JKQlTG1be7ixruBRlCTh3YiSs66fKMeJeUYoxA2HPhvbGFEjQFAxunEYg \n"
  54. "X/LBKv1mQWa+Q34P5GBjK8kQdLCN+yJAiUErmWNQG3GPninrxsC9tY5jcWvHeP1k \n"
  55. "V7N3MLnNqzXaCJM24mnKidC5IDadUdQ8qC8c3rjUexQ8vBz0eucH56jbqV5oOcvx \n"
  56. "pjlW965dCPIf3OI8q6J7bIOjyY+u/PTcVlqPq3TUz/ti6RkVbKpLH0D4ll3lUTns \n"
  57. "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq \n"
  58. "=TB1F \n"
  59. "-----END PGP SIGNATURE-----");
  60. EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
  61. EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
  62. if (tempfile.empty() == false)
  63. unlink(tempfile.c_str());
  64. EXPECT_TRUE(fd.IsOpen());
  65. char buffer[100];
  66. EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
  67. EXPECT_STREQ(buffer, "Test");
  68. EXPECT_TRUE(fd.Eof());
  69. }
  70. TEST(OpenMaybeClearSignedFileTest,SignedFileWithContentHeaders)
  71. {
  72. std::string tempfile;
  73. FileFd fd;
  74. createTemporaryFile("headerssignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
  75. "Version: 0.8.15~exp1\n"
  76. "Hash: SHA512\n"
  77. "Comment: I love you!\n"
  78. "X-Expires: never\n"
  79. "Multilines: no\n"
  80. " yes\n"
  81. " maybe\n"
  82. "\n"
  83. "Test\n"
  84. "-----BEGIN PGP SIGNATURE-----\n"
  85. "\n"
  86. "iQFEBAEBCgAuFiEENKjp0Y2zIPNn6OqgWpDRQdusja4FAlhT7+kQHGpvZUBleGFt\n"
  87. "cGxlLm9yZwAKCRBakNFB26yNrjvEB/9/e3jA1l0fvPafx9LEXcH8CLpUFQK7ra9l\n"
  88. "3M4YAH4JKQlTG1be7ixruBRlCTh3YiSs66fKMeJeUYoxA2HPhvbGFEjQFAxunEYg\n"
  89. "X/LBKv1mQWa+Q34P5GBjK8kQdLCN+yJAiUErmWNQG3GPninrxsC9tY5jcWvHeP1k\n"
  90. "V7N3MLnNqzXaCJM24mnKidC5IDadUdQ8qC8c3rjUexQ8vBz0eucH56jbqV5oOcvx\n"
  91. "pjlW965dCPIf3OI8q6J7bIOjyY+u/PTcVlqPq3TUz/ti6RkVbKpLH0D4ll3lUTns\n"
  92. "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
  93. "=TB1F\n"
  94. "-----END PGP SIGNATURE-----\n");
  95. EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
  96. EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
  97. if (tempfile.empty() == false)
  98. unlink(tempfile.c_str());
  99. EXPECT_TRUE(fd.IsOpen());
  100. char buffer[100];
  101. EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
  102. EXPECT_STREQ(buffer, "Test");
  103. EXPECT_TRUE(fd.Eof());
  104. }
  105. // That isn't how multiple signatures are done
  106. TEST(OpenMaybeClearSignedFileTest,SignedFileWithTwoSignatures)
  107. {
  108. std::string tempfile;
  109. FileFd fd;
  110. createTemporaryFile("doublesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
  111. "Hash: SHA512\n"
  112. "\n"
  113. "Test\n"
  114. "-----BEGIN PGP SIGNATURE-----\n"
  115. "\n"
  116. "iQFEBAEBCgAuFiEENKjp0Y2zIPNn6OqgWpDRQdusja4FAlhT7+kQHGpvZUBleGFt\n"
  117. "cGxlLm9yZwAKCRBakNFB26yNrjvEB/9/e3jA1l0fvPafx9LEXcH8CLpUFQK7ra9l\n"
  118. "3M4YAH4JKQlTG1be7ixruBRlCTh3YiSs66fKMeJeUYoxA2HPhvbGFEjQFAxunEYg\n"
  119. "X/LBKv1mQWa+Q34P5GBjK8kQdLCN+yJAiUErmWNQG3GPninrxsC9tY5jcWvHeP1k\n"
  120. "V7N3MLnNqzXaCJM24mnKidC5IDadUdQ8qC8c3rjUexQ8vBz0eucH56jbqV5oOcvx\n"
  121. "pjlW965dCPIf3OI8q6J7bIOjyY+u/PTcVlqPq3TUz/ti6RkVbKpLH0D4ll3lUTns\n"
  122. "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
  123. "=TB1F\n"
  124. "-----END PGP SIGNATURE-----\n"
  125. "-----BEGIN PGP SIGNATURE-----\n"
  126. "\n"
  127. "iQFHBAEBCgAxFiEE3mauypFRr6GHfsMd6FJdR1KBROIFAlhT/yYTHG1hcnZpbkBl\n"
  128. "eGFtcGxlLm9yZwAKCRDoUl1HUoFE4qq3B/459MSk3xCW30wc5+ul5ZxTSg6eLYPJ\n"
  129. "tfVNYi90/ZxRrYQAN+EWozEIZcxoMYp8Ans3++irkjPbHs4NsesmFKt2W5meFl4V\n"
  130. "oUzYrOh5y5GlDeF7ok5g9atQe8BojjBics+g1IBYcnaMU+ywONmlixa03IPGfxV5\n"
  131. "oTx02Xvlns20i6HRc0WFtft5q1hXo4EIlVc9O0u902SVEEkeuHF3+bCcXrNLPBJA\n"
  132. "+8dxmH5+i89f/kVqURrdHdEuA1tsTNyb2C+lvRONh21H8QRRTU/iUQSzV6vZvof5\n"
  133. "ASc9hsAZRG0xHuRU0F94V/XrkWw8QYAobJ/yxvs4L0EuA4optbSqawDB\n"
  134. "=CP8j\n"
  135. "-----END PGP SIGNATURE-----\n");
  136. EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
  137. EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
  138. if (tempfile.empty() == false)
  139. unlink(tempfile.c_str());
  140. EXPECT_TRUE(fd.IsOpen());
  141. char buffer[100];
  142. EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
  143. EXPECT_STREQ(buffer, "Test");
  144. EXPECT_TRUE(fd.Eof());
  145. }
  146. TEST(OpenMaybeClearSignedFileTest,TwoSimpleSignedFile)
  147. {
  148. std::string tempfile;
  149. FileFd fd;
  150. // read only the first message
  151. createTemporaryFile("twosimplesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
  152. "Hash: SHA512\n"
  153. "\n"
  154. "Test\n"
  155. "-----BEGIN PGP SIGNATURE-----\n"
  156. "\n"
  157. "iQFEBAEBCgAuFiEENKjp0Y2zIPNn6OqgWpDRQdusja4FAlhT7+kQHGpvZUBleGFt\n"
  158. "cGxlLm9yZwAKCRBakNFB26yNrjvEB/9/e3jA1l0fvPafx9LEXcH8CLpUFQK7ra9l\n"
  159. "3M4YAH4JKQlTG1be7ixruBRlCTh3YiSs66fKMeJeUYoxA2HPhvbGFEjQFAxunEYg\n"
  160. "X/LBKv1mQWa+Q34P5GBjK8kQdLCN+yJAiUErmWNQG3GPninrxsC9tY5jcWvHeP1k\n"
  161. "V7N3MLnNqzXaCJM24mnKidC5IDadUdQ8qC8c3rjUexQ8vBz0eucH56jbqV5oOcvx\n"
  162. "pjlW965dCPIf3OI8q6J7bIOjyY+u/PTcVlqPq3TUz/ti6RkVbKpLH0D4ll3lUTns\n"
  163. "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
  164. "=TB1F\n"
  165. "-----END PGP SIGNATURE-----\n"
  166. "-----BEGIN PGP SIGNED MESSAGE-----\n"
  167. "Hash: SHA512\n"
  168. "\n"
  169. "Test\n"
  170. "-----BEGIN PGP SIGNATURE-----\n"
  171. "\n"
  172. "iQFEBAEBCgAuFiEENKjp0Y2zIPNn6OqgWpDRQdusja4FAlhT7+kQHGpvZUBleGFt\n"
  173. "cGxlLm9yZwAKCRBakNFB26yNrjvEB/9/e3jA1l0fvPafx9LEXcH8CLpUFQK7ra9l\n"
  174. "3M4YAH4JKQlTG1be7ixruBRlCTh3YiSs66fKMeJeUYoxA2HPhvbGFEjQFAxunEYg\n"
  175. "X/LBKv1mQWa+Q34P5GBjK8kQdLCN+yJAiUErmWNQG3GPninrxsC9tY5jcWvHeP1k\n"
  176. "V7N3MLnNqzXaCJM24mnKidC5IDadUdQ8qC8c3rjUexQ8vBz0eucH56jbqV5oOcvx\n"
  177. "pjlW965dCPIf3OI8q6J7bIOjyY+u/PTcVlqPq3TUz/ti6RkVbKpLH0D4ll3lUTns\n"
  178. "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
  179. "=TB1F\n"
  180. "-----END PGP SIGNATURE-----");
  181. EXPECT_TRUE(_error->empty());
  182. EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
  183. EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
  184. if (tempfile.empty() == false)
  185. unlink(tempfile.c_str());
  186. EXPECT_FALSE(_error->empty());
  187. EXPECT_TRUE(fd.IsOpen());
  188. char buffer[100];
  189. EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
  190. EXPECT_STREQ(buffer, "Test");
  191. EXPECT_TRUE(fd.Eof());
  192. ASSERT_FALSE(_error->empty());
  193. std::string msg;
  194. _error->PopMessage(msg);
  195. EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unsigned lines.", msg);
  196. }
  197. TEST(OpenMaybeClearSignedFileTest,UnsignedFile)
  198. {
  199. std::string tempfile;
  200. FileFd fd;
  201. createTemporaryFile("unsignedfile", fd, &tempfile, "Test");
  202. EXPECT_FALSE(StartsWithGPGClearTextSignature(tempfile));
  203. EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
  204. if (tempfile.empty() == false)
  205. unlink(tempfile.c_str());
  206. EXPECT_TRUE(fd.IsOpen());
  207. char buffer[100];
  208. EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
  209. EXPECT_STREQ(buffer, "Test");
  210. EXPECT_TRUE(fd.Eof());
  211. }
  212. TEST(OpenMaybeClearSignedFileTest,GarbageTop)
  213. {
  214. std::string tempfile;
  215. FileFd fd;
  216. createTemporaryFile("garbagetop", fd, &tempfile, "Garbage\n"
  217. "-----BEGIN PGP SIGNED MESSAGE-----\n"
  218. "Hash: SHA512\n"
  219. "\n"
  220. "Test\n"
  221. "-----BEGIN PGP SIGNATURE-----\n"
  222. "\n"
  223. "iQFEBAEBCgAuFiEENKjp0Y2zIPNn6OqgWpDRQdusja4FAlhT7+kQHGpvZUBleGFt\n"
  224. "cGxlLm9yZwAKCRBakNFB26yNrjvEB/9/e3jA1l0fvPafx9LEXcH8CLpUFQK7ra9l\n"
  225. "3M4YAH4JKQlTG1be7ixruBRlCTh3YiSs66fKMeJeUYoxA2HPhvbGFEjQFAxunEYg\n"
  226. "X/LBKv1mQWa+Q34P5GBjK8kQdLCN+yJAiUErmWNQG3GPninrxsC9tY5jcWvHeP1k\n"
  227. "V7N3MLnNqzXaCJM24mnKidC5IDadUdQ8qC8c3rjUexQ8vBz0eucH56jbqV5oOcvx\n"
  228. "pjlW965dCPIf3OI8q6J7bIOjyY+u/PTcVlqPq3TUz/ti6RkVbKpLH0D4ll3lUTns\n"
  229. "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
  230. "=TB1F\n"
  231. "-----END PGP SIGNATURE-----\n");
  232. EXPECT_FALSE(StartsWithGPGClearTextSignature(tempfile));
  233. EXPECT_TRUE(_error->empty());
  234. EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
  235. if (tempfile.empty() == false)
  236. unlink(tempfile.c_str());
  237. EXPECT_TRUE(fd.IsOpen());
  238. char buffer[100];
  239. EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
  240. EXPECT_STREQ(buffer, "Test");
  241. EXPECT_TRUE(fd.Eof());
  242. ASSERT_FALSE(_error->empty());
  243. ASSERT_FALSE(_error->PendingError());
  244. std::string msg;
  245. _error->PopMessage(msg);
  246. EXPECT_EQ("Clearsigned file '" + tempfile + "' does not start with a signed message block.", msg);
  247. }
  248. TEST(OpenMaybeClearSignedFileTest,GarbageHeader)
  249. {
  250. std::string tempfile;
  251. FileFd fd;
  252. createTemporaryFile("garbageheader", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE----- Garbage\n"
  253. "Hash: SHA512\n"
  254. "\n"
  255. "Test\n"
  256. "-----BEGIN PGP SIGNATURE-----\n"
  257. "\n"
  258. "iQFEBAEBCgAuFiEENKjp0Y2zIPNn6OqgWpDRQdusja4FAlhT7+kQHGpvZUBleGFt\n"
  259. "cGxlLm9yZwAKCRBakNFB26yNrjvEB/9/e3jA1l0fvPafx9LEXcH8CLpUFQK7ra9l\n"
  260. "3M4YAH4JKQlTG1be7ixruBRlCTh3YiSs66fKMeJeUYoxA2HPhvbGFEjQFAxunEYg\n"
  261. "X/LBKv1mQWa+Q34P5GBjK8kQdLCN+yJAiUErmWNQG3GPninrxsC9tY5jcWvHeP1k\n"
  262. "V7N3MLnNqzXaCJM24mnKidC5IDadUdQ8qC8c3rjUexQ8vBz0eucH56jbqV5oOcvx\n"
  263. "pjlW965dCPIf3OI8q6J7bIOjyY+u/PTcVlqPq3TUz/ti6RkVbKpLH0D4ll3lUTns\n"
  264. "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
  265. "=TB1F\n"
  266. "-----END PGP SIGNATURE-----\n");
  267. EXPECT_FALSE(StartsWithGPGClearTextSignature(tempfile));
  268. // beware: the file will be successfully opened as unsigned file
  269. EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
  270. if (tempfile.empty() == false)
  271. unlink(tempfile.c_str());
  272. EXPECT_TRUE(fd.IsOpen());
  273. char buffer[100];
  274. EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
  275. EXPECT_STREQ(buffer, "-----BEGIN PGP SIGNED MESSAGE----- Garbage\n");
  276. EXPECT_FALSE(fd.Eof());
  277. }
  278. TEST(OpenMaybeClearSignedFileTest,GarbageBottom)
  279. {
  280. std::string tempfile;
  281. FileFd fd;
  282. createTemporaryFile("garbagebottom", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
  283. "Hash: SHA512\n"
  284. "\n"
  285. "Test\n"
  286. "-----BEGIN PGP SIGNATURE-----\n"
  287. "\n"
  288. "iQFEBAEBCgAuFiEENKjp0Y2zIPNn6OqgWpDRQdusja4FAlhT7+kQHGpvZUBleGFt\n"
  289. "cGxlLm9yZwAKCRBakNFB26yNrjvEB/9/e3jA1l0fvPafx9LEXcH8CLpUFQK7ra9l\n"
  290. "3M4YAH4JKQlTG1be7ixruBRlCTh3YiSs66fKMeJeUYoxA2HPhvbGFEjQFAxunEYg\n"
  291. "X/LBKv1mQWa+Q34P5GBjK8kQdLCN+yJAiUErmWNQG3GPninrxsC9tY5jcWvHeP1k\n"
  292. "V7N3MLnNqzXaCJM24mnKidC5IDadUdQ8qC8c3rjUexQ8vBz0eucH56jbqV5oOcvx\n"
  293. "pjlW965dCPIf3OI8q6J7bIOjyY+u/PTcVlqPq3TUz/ti6RkVbKpLH0D4ll3lUTns\n"
  294. "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
  295. "=TB1F\n"
  296. "-----END PGP SIGNATURE-----\n"
  297. "Garbage");
  298. EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
  299. EXPECT_TRUE(_error->empty());
  300. EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
  301. if (tempfile.empty() == false)
  302. unlink(tempfile.c_str());
  303. EXPECT_TRUE(fd.IsOpen());
  304. char buffer[100];
  305. EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
  306. EXPECT_STREQ(buffer, "Test");
  307. EXPECT_TRUE(fd.Eof());
  308. ASSERT_FALSE(_error->empty());
  309. ASSERT_FALSE(_error->PendingError());
  310. std::string msg;
  311. _error->PopMessage(msg);
  312. EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unsigned lines.", msg);
  313. }
  314. TEST(OpenMaybeClearSignedFileTest,BogusNoSig)
  315. {
  316. std::string tempfile;
  317. FileFd fd;
  318. createTemporaryFile("bogusnosig", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
  319. "Hash: SHA512\n"
  320. "\n"
  321. "Test");
  322. EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
  323. EXPECT_TRUE(_error->empty());
  324. EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
  325. if (tempfile.empty() == false)
  326. unlink(tempfile.c_str());
  327. EXPECT_FALSE(_error->empty());
  328. EXPECT_FALSE(fd.IsOpen());
  329. std::string msg;
  330. _error->PopMessage(msg);
  331. EXPECT_EQ("Splitting of file " + tempfile + " failed as it doesn't contain all expected parts 0 1 0", msg);
  332. }
  333. TEST(OpenMaybeClearSignedFileTest,BogusSigStart)
  334. {
  335. std::string tempfile;
  336. FileFd fd;
  337. createTemporaryFile("bogusnosig", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
  338. "Hash: SHA512\n"
  339. "\n"
  340. "Test\n"
  341. "-----BEGIN PGP SIGNATURE-----");
  342. EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
  343. EXPECT_TRUE(_error->empty());
  344. EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
  345. if (tempfile.empty() == false)
  346. unlink(tempfile.c_str());
  347. EXPECT_FALSE(_error->empty());
  348. EXPECT_FALSE(fd.IsOpen());
  349. std::string msg;
  350. _error->PopMessage(msg);
  351. EXPECT_EQ("Signature in file " + tempfile + " wasn't closed", msg);
  352. }