public void EncryptManifestTestDisableOverwriteExistingFile() { CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext(); var sourcePath = DeploymentFolder1; Assert.IsTrue(Directory.Exists(sourcePath)); List <string> files = Directory.EnumerateFiles(sourcePath, "*.txt").ToList(); const string manifestName = "Manifest 1"; IIngestManifest ingestManifestCreated = context.IngestManifests.Create(manifestName); //Adding manifest asset info with multiple file IAsset emptyAsset = context.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted); IIngestManifestAsset ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.Create(emptyAsset, files.ToArray()); var path = @".\Resources\TestFiles\" + Guid.NewGuid(); try { Directory.CreateDirectory(path); string dupFileName = Path.Combine(path, Path.GetFileName(files[0])); File.WriteAllText(dupFileName, ""); ingestManifestCreated.EncryptFiles(path, false); } catch (AggregateException ax) { var expectedExcpetion = ax.GetBaseException() as IOException; throw expectedExcpetion; } finally { AssetFilesTests.CleanDirectory(path); } }
public void EncryptManifestFilesAndVerifyThemAfterDecryption() { List <IIngestManifestFile> files; IIngestManifest ingestManifestCreated; string path = null; try { path = CreateManifestEncryptFiles(out files, out ingestManifestCreated); IIngestManifestAsset ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.ToList().Where(c => c.Asset.Options == AssetCreationOptions.StorageEncrypted).FirstOrDefault(); IIngestManifestFile mFile = ingestManifestAsset.IngestManifestFiles.Where(c => c.Name == "File0.txt").FirstOrDefault(); Dictionary <string, string> filePaths = new Dictionary <string, string>(); foreach (var filePath in new[] { TestFile1, TestFile2 }) { FileInfo fileInfo = new FileInfo(filePath); filePaths.Add(fileInfo.Name, filePath); } var encryptedPath = Path.Combine(path, mFile.Name); Assert.IsTrue(File.Exists(encryptedPath)); var decryptedPath = DecryptedFile(mFile, encryptedPath, _mediaContext); Assert.IsTrue(AssetTests.CompareFiles(decryptedPath, filePaths[mFile.Name]), "Original file and Decrypted are not same"); } finally { AssetFilesTests.CleanDirectory(path); } }
public void CheckIfOnlyStorageEncryptedFilesExistsInEncryptionFolderAnfterEncrypt() { List <IIngestManifestFile> files; IIngestManifest ingestManifestCreated; string path = null; try { path = CreateManifestEncryptFiles(out files, out ingestManifestCreated); foreach (var manifestAssetFile in files) { if (manifestAssetFile.EncryptionScheme == CommonEncryption.SchemeName) { Assert.IsFalse(File.Exists(Path.Combine(path, manifestAssetFile.Name))); } if (manifestAssetFile.EncryptionScheme == FileEncryption.SchemeName) { Assert.IsTrue(File.Exists(Path.Combine(path, manifestAssetFile.Name))); } } } finally { AssetFilesTests.CleanDirectory(path); } }
public void ShouldThrowAggregateExceptionWithMultipleKetNotFoundExceptionDuringEncryptIfKeyIsMissing() { var sourcePath = @".\Resources\TestFiles\"; var path = @".\Resources\TestFiles\" + Guid.NewGuid(); Assert.IsTrue(Directory.Exists(sourcePath)); List <string> files = Directory.EnumerateFiles(sourcePath, "File0.txt").ToList(); //Creating empty manifest const string manifestName = "Manifest 1"; IIngestManifest ingestManifestCreated = _mediaContext.IngestManifests.Create(manifestName); //Adding manifest asset info with multiple file IAsset emptyAsset = _mediaContext.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted); IIngestManifestAsset ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.CreateAsync(emptyAsset, files.ToArray(), CancellationToken.None).Result; Assert.IsNotNull(ingestManifestAsset); emptyAsset.ContentKeys.RemoveAt(0); files = Directory.EnumerateFiles(sourcePath, "File1.txt").ToList(); emptyAsset = _mediaContext.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted); ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.CreateAsync(emptyAsset, files.ToArray(), CancellationToken.None).Result; Assert.IsNotNull(ingestManifestAsset); //According to last REST implementation breaking a link //also deleting a key on server side if no other links are found emptyAsset.ContentKeys.RemoveAt(0); Directory.CreateDirectory(path); try { ingestManifestCreated.EncryptFiles(path); } catch (AggregateException ex) { Assert.AreEqual(2, ex.InnerExceptions.Count); Assert.IsTrue(ex.InnerExceptions[0] is InvalidOperationException); Assert.IsTrue(ex.InnerExceptions[1] is InvalidOperationException); } finally { AssetFilesTests.CleanDirectory(path); } }
private static void EncryptFilesDecryptAndCompare(List <string> files) { CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext(); //Creating empty manifest const string manifestName = "Manifest 1"; IIngestManifest ingestManifestCreated = context.IngestManifests.Create(manifestName); //Adding manifest asset info with multiple file IAsset emptyAsset = context.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted); IIngestManifestAsset ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.CreateAsync(emptyAsset, files.ToArray(), CancellationToken.None).Result; var path = @".\Resources\TestFiles\" + Guid.NewGuid(); Directory.CreateDirectory(path); try { ingestManifestCreated.EncryptFiles(path); Dictionary <string, string> filePaths = new Dictionary <string, string>(); foreach (var filePath in files) { FileInfo fileInfo = new FileInfo(filePath); filePaths.Add(fileInfo.Name, filePath); } foreach (var assetFile in ingestManifestAsset.IngestManifestFiles) { var encryptedPath = Path.Combine(path, assetFile.Name); Assert.IsTrue(File.Exists(encryptedPath)); var decryptedPath = DecryptedFile(assetFile, encryptedPath, context); Assert.IsTrue(AssetTests.CompareFiles(decryptedPath, filePaths[assetFile.Name]), "Original file and Decrypted are not same"); } } finally { AssetFilesTests.CleanDirectory(path); } }