Beispiel #1
0
		public void TestReEncryptNullResponseAttachments()
		{
			using (ContentEncryptionManager manager = new ContentEncryptionManager())
			{
				bool val;
				manager.ReencryptResponseAttachments(null, out val);
			}
		}
Beispiel #2
0
		public void ExecuteEncryptionTestScript(string scriptName, bool shouldSucceed)
		{
			try
			{
                ContentEncryptionManager.ClearPasswordCache();

				string scriptPath = Path.Combine(TestFileDirectory, shouldSucceed ? "succeed" : "fail", scriptName);

				var passwordInfo = ParsePasswordInfo(scriptPath);
				using (RequestCreator rc = new RequestCreator())
				{
					// Create a request based on the script file
					using (Request request = rc.CreateRequest(scriptPath))
					{
						// Check attachments read into request correctly
						Assert.IsTrue(CheckAttachments(scriptPath, request), "CheckAttachments failed after initial request creation, script:" + scriptPath);
						IContentEncryptionUi ui = new MockContentEncryptionUi(passwordInfo, DecryptResult.Ok, DecryptionErrorAction.Cancel);

						using (var app = new WsApplication(new MSOutlook.Application(), false))
						{
							using (Workshare.PolicyMarshaller.MailAttachmentTransform mat = new MailAttachmentTransform(Interop.Options.OptionApi.GetInt("LevelOfProcessingEmbeddedMessages"), app))
							using (ContentEncryptionManager manager = new ContentEncryptionManager(mat.ExpandMSG, mat.PackMSG))
							{
								// Check decryption
								Assert.AreEqual(shouldSucceed, manager.DecryptRequestAttachments(request, ui), "DecryptRequestAttachments response incorrect, script:" + scriptPath);

								if (shouldSucceed)// No point proceeding if we were expecting failure
								{
									EnforceResponse spoofResponse = new EnforceResponse();
									spoofResponse.ModifiedRequest = request;

									// Now ensure we can re-encrypt it
									bool cancelSend = true;
									Assert.IsTrue(manager.ReencryptResponseAttachments(spoofResponse, out cancelSend), "ReencryptResponseAttachments failed, script:" + scriptPath);
									Assert.IsFalse(cancelSend, "cancelSend true, should be false, script:" + scriptPath);
									Assert.IsTrue(CheckAttachments(scriptPath, request), "CheckAttachments failed after re-encryption, script:" + scriptPath);

									// Ensure the encryption went OK
									CheckFilesEncrypted(passwordInfo, manager, spoofResponse);
								}
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				Assert.Fail(string.Format("Caught exception while executing: {0}. Exception: {1}", Path.GetFileName(scriptName), ex.Message));
				throw;
			}
			finally
			{
				// Occasionally seeing a COM error when re-running tests, suspect its down to the Request writer not having cleaned up fully.
				GC.Collect();
				GC.WaitForPendingFinalizers();
			}

		}