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);
            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");
            }
        }
Exemple #2
0
        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 ShouldThrowKeyNotFoundExceptionDuringEncryptIfKeyIsMissing()
        {
            var sourcePath = DeploymentFolder1;

            Assert.IsTrue(Directory.Exists(sourcePath));
            List <string> files = Directory.EnumerateFiles(sourcePath, "*.txt").ToList();

            //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;

            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);

            var path = @".\Resources\TestFiles\" + Guid.NewGuid();

            Directory.CreateDirectory(path);
            try
            {
                ingestManifestCreated.EncryptFiles(path);
            }
            catch (AggregateException ex)
            {
                Assert.AreEqual(1, ex.InnerExceptions.Count);
                throw ex.InnerExceptions[0];
            }
        }