Exemple #1
0
        public void ShouldSubmitJobWhereOutPutInDefaultStorage()
        {
            IAsset          asset          = AssetTests.CreateAsset(_dataContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor = GetMediaProcessor(_dataContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName, WindowsAzureMediaServicesTestConfiguration.MpEncoderVersion);
            string          name           = GenerateName("Job 1");
            IJob            job            = _dataContext.Jobs.Create(name);
            ITask           task           = job.Tasks.AddNew("Task1", mediaProcessor, GetWamePreset(mediaProcessor), TaskOptions.None);

            task.InputAssets.Add(asset);
            task.OutputAssets.AddNew("Output asset", _dataContext.DefaultStorageAccount.Name, AssetCreationOptions.None);
            job.Submit();
            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);
        }
        public void ShouldReceiveNotificationsForCompeletedJob()
        {
            string           endPointAddress = Guid.NewGuid().ToString();
            CloudQueueClient client          = CloudStorageAccount.Parse(WindowsAzureMediaServicesTestConfiguration.ClientStorageConnectionString).CreateCloudQueueClient();
            CloudQueue       queue           = client.GetQueueReference(endPointAddress);

            queue.CreateIfNotExists();
            string endPointName = Guid.NewGuid().ToString();
            INotificationEndPoint notificationEndPoint = _mediaContext.NotificationEndPoints.Create(endPointName, NotificationEndPointType.AzureQueue, endPointAddress);

            Assert.IsNotNull(notificationEndPoint);

            string          configuration  = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.DefaultMp4ToSmoothConfig);
            IAsset          asset          = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallMp41, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpPackagerName);

            IJob  job  = _mediaContext.Jobs.Create("CreateJobWithNotificationSubscription");
            ITask task = job.Tasks.AddNew("Task1", mediaProcessor, configuration, TaskOptions.None);

            task.InputAssets.Add(asset);
            task.OutputAssets.AddNew("Output", AssetCreationOptions.None);

            job.JobNotificationSubscriptions.AddNew(NotificationJobState.All, notificationEndPoint);

            job.Submit();

            Assert.IsTrue(job.JobNotificationSubscriptions.Count > 0);

            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);
            Thread.Sleep((int)TimeSpan.FromMinutes(5).TotalMilliseconds);

            Assert.IsNotNull(queue);
            Assert.IsTrue(queue.Exists());
            IEnumerable <CloudQueueMessage> messages = queue.GetMessages(10);

            Assert.IsTrue(messages.Any());
            Assert.AreEqual(4, messages.Count(), "Expecting to have 4 notifications messages");

            IJob lastJob = _mediaContext.Jobs.Where(j => j.Id == job.Id).FirstOrDefault();

            Assert.IsNotNull(lastJob);
            Assert.IsTrue(lastJob.JobNotificationSubscriptions.Count > 0);
            IJobNotificationSubscription lastJobNotificationSubscription = lastJob.JobNotificationSubscriptions.Where(n => n.NotificationEndPoint.Id == notificationEndPoint.Id).FirstOrDefault();

            Assert.IsNotNull(lastJobNotificationSubscription);
            INotificationEndPoint lastNotificationEndPoint = lastJobNotificationSubscription.NotificationEndPoint;

            Assert.IsNotNull(lastNotificationEndPoint);
            Assert.AreEqual(endPointName, lastNotificationEndPoint.Name);
            Assert.AreEqual(endPointAddress, lastNotificationEndPoint.EndPointAddress);
        }
        public void ShouldFinishJobWithSuccessWhenPresetISUTF8()
        {
            IAsset          asset          = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            string          presetXml      = @"<?xml version=""1.0"" encoding=""utf-8""?>
                <Thumbnail Size=""80,60"" Type=""Jpeg"" Filename=""{OriginalFilename}_{ThumbnailTime}.{DefaultExtension}"">
                  <Time Value=""0:0:0""/>
                  <Time Value=""0:0:3"" Step=""0:0:0.25"" Stop=""0:0:10""/>
                </Thumbnail>";
            string          name           = GenerateName("ShouldFinishJobWithSuccessWhenPresetISUTF8");
            IJob            job            = CreateAndSubmitOneTaskJob(_mediaContext, name, mediaProcessor, presetXml, asset, TaskOptions.None);

            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);
        }
        public void ShouldQueryJobByStartTime()
        {
            DateTime        startDateTime  = DateTime.UtcNow;
            IAsset          asset          = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            string          name           = GenerateName("Job 1");
            IJob            job            = CreateAndSubmitOneTaskJob(_mediaContext, name, mediaProcessor, GetWamePreset(mediaProcessor), asset, TaskOptions.None);
            Task            task           = job.GetExecutionProgressTask(CancellationToken.None);

            task.Wait();
            List <IJob> jobs = _mediaContext.Jobs.Where(j => j.StartTime > startDateTime && j.StartTime < DateTime.UtcNow).ToList();

            Assert.IsTrue(jobs.Count > 0);
        }
        public void ShouldContainTaskHistoryEventsOnceJobFinished()
        {
            IAsset          asset          = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            string          name           = GenerateName("ShouldContainTaskHistoryEventsOnceJobFinished");
            string          preset         = GetWamePreset(mediaProcessor);
            IJob            job            = CreateAndSubmitOneTaskJob(_mediaContext, name, mediaProcessor, preset, asset, TaskOptions.None);
            ITask           task           = job.Tasks.FirstOrDefault();

            Assert.IsNotNull(task);
            Assert.IsNotNull(task.HistoricalEvents, "HistoricalEvents should not be null for submitted job");
            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);
            Assert.IsTrue(task.HistoricalEvents.Count > 0, "HistoricalEvents should not be empty after job has been finished");
        }
Exemple #6
0
        public void ShouldDownloadToFileFromStorageEncryptedAsset()
        {
            string fileUploaded = _smallWmv;

            IAsset asset = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(fileUploaded),
                                                  AssetCreationOptions.StorageEncrypted);
            IAssetFile assetFile = asset.AssetFiles.First();

            Assert.AreEqual(AssetCreationOptions.StorageEncrypted, asset.Options);
            Assert.AreEqual(assetFile.Asset.Id, asset.Id);
            Assert.AreEqual(1, asset.Locators.Count);

            VerifyAndDownloadAssetFile(assetFile, asset, fileUploaded);
        }
        public void ShouldCreateOriginLocator()
        {
            IAsset        asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);
            IAccessPolicy accessPolicy = _mediaContext.AccessPolicies.Create("Read", TimeSpan.FromMinutes(5), AccessPermissions.Read);

            ILocator locator = _mediaContext.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset, accessPolicy);

            Assert.IsNotNull(locator);

            string locatorIdWithoutPrefix = locator.Id.Remove(0, LocatorData.LocatorIdentifierPrefix.Length);

            Assert.AreEqual(locator.ContentAccessComponent, locatorIdWithoutPrefix, true);
            Assert.IsTrue(locator.Path.TrimEnd('/').EndsWith(locatorIdWithoutPrefix, StringComparison.OrdinalIgnoreCase));
        }
        public void ShouldSubmitAndFinishMp4ToSmoothJobWithStorageProtectedInputsAndOutputs()
        {
            string          configuration  = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.DefaultMp4ToSmoothConfig);
            IAsset          asset          = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallMp41, AssetCreationOptions.StorageEncrypted);
            IJob            job            = _mediaContext.Jobs.Create("MP4 to Smooth with protected input and output assets");
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpPackagerName);
            ITask           task           = job.Tasks.AddNew(MediaPackager, mediaProcessor, configuration, TaskOptions.None);

            task.InputAssets.Add(asset);
            task.OutputAssets.AddNew("Output encrypted", AssetCreationOptions.StorageEncrypted);
            job.Submit();
            Assert.IsNotNull(task.InputAssets);
            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);
        }
Exemple #9
0
        public void ShouldDownloadToFileFromCommonEncryptionProtectedAsset()
        {
            string fileUploaded    = _smallWmv;
            string outputDirectory = "Download" + Guid.NewGuid();

            IAsset asset = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(fileUploaded),
                                                  AssetCreationOptions.CommonEncryptionProtected);
            IAssetFile assetFile = asset.AssetFiles.First();

            Assert.AreEqual(AssetCreationOptions.CommonEncryptionProtected, asset.Options);
            Assert.AreEqual(assetFile.Asset.Id, asset.Id);
            Assert.AreEqual(1, asset.Locators.Count);

            VerifyAndDownloadAssetFile(assetFile, asset, fileUploaded);
        }
        public void ShouldGenerateMetadataFile()
        {
            IAsset          asset          = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            string          name           = GenerateName("ShouldSplitMetadataLost");

            IJob job = CreateAndSubmitOneTaskJob(_mediaContext, name, mediaProcessor, "H264 Smooth Streaming 720p", asset, TaskOptions.None);

            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);

            IJob refreshedJob = _mediaContext.Jobs.Where(c => c.Id == job.Id).Single();
            bool ok           = refreshedJob.Tasks.Single().OutputAssets.Single().AssetFiles.AsEnumerable().Select(f => f.Name).Contains("SmallWmv_manifest.xml");

            Assert.IsTrue(ok);
        }
        public void ShouldDeleteLocatorWhenDeleteLocatorCalled()
        {
            // Arrange

            var accessPolicy = _mediaContext.AccessPolicies.Create("TestPolicy", TimeSpan.FromMinutes(10), AccessPermissions.List | AccessPermissions.Read);
            var asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);
            var locator      = _mediaContext.Locators.CreateSasLocator(asset, accessPolicy);

            // Act
            locator.Delete();

            var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var actual   = context2.Locators.Where(x => x.Id == locator.Id).FirstOrDefault();

            // Assert
            Assert.IsNull(actual);
        }
        public void ShouldRecreateLocatorWithSameLocatorId()
        {
            IAsset        asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);
            IAccessPolicy accessPolicy = _mediaContext.AccessPolicies.Create("Read", TimeSpan.FromMinutes(5), AccessPermissions.Read);


            ILocator locator = _mediaContext.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset, accessPolicy);

            Assert.IsNotNull(locator);
            string id = locator.Id;

            locator.Delete();
            Assert.IsNull(_mediaContext.Locators.Where(c => c.Id == id).FirstOrDefault());

            locator = _mediaContext.Locators.CreateLocator(id, LocatorType.OnDemandOrigin, asset, accessPolicy, null);
            Assert.IsNotNull(locator);
        }
Exemple #13
0
        public void ShouldDownloadToFileFromStorageEncryptedAsset()
        {
            string fileUploaded     = _smallWmv;
            string outputDirectory  = "Download" + Guid.NewGuid();
            string fileDownloaded   = Path.Combine(outputDirectory, Path.GetFileName(fileUploaded));
            var    fileUploadedInfo = new FileInfo(fileUploaded);

            IAsset     asset     = AssetTests.CreateAsset(_dataContext, Path.GetFullPath(fileUploaded), AssetCreationOptions.StorageEncrypted);
            IAssetFile assetFile = asset.AssetFiles.First();

            Assert.AreEqual(AssetCreationOptions.StorageEncrypted, asset.Options);
            Assert.AreEqual(assetFile.Asset.Id, asset.Id);
            Assert.AreEqual(1, asset.Locators.Count);

            CleanDirectory(outputDirectory);

            Assert.IsFalse(File.Exists(fileDownloaded));

            double downloadProgress = 0;
            long   bytesDownloaded  = 0;

            assetFile.DownloadProgressChanged += (s, e) =>
            {
                Assert.AreSame(assetFile, s);

                Assert.IsNotNull(e);
                Assert.AreEqual(fileUploadedInfo.Length, e.TotalBytes);
                Assert.IsTrue(e.BytesDownloaded <= e.TotalBytes);

                downloadProgress = e.Progress;
                bytesDownloaded  = e.BytesDownloaded;
            };

            assetFile.Download(fileDownloaded);

            Assert.IsTrue(File.Exists(fileDownloaded));
            Assert.AreEqual(100, downloadProgress);

            var fileDownloadedInfo = new FileInfo(fileDownloaded);

            Assert.AreEqual(fileUploadedInfo.Length, fileDownloadedInfo.Length);
            Assert.AreEqual(fileDownloadedInfo.Length, bytesDownloaded);

            asset = _dataContext.Assets.Where(a => a.Id == asset.Id).Single();
            Assert.AreEqual(1, asset.Locators.Count);
        }
        public void ShouldUpdateJobPriorityWhenJobIsQueued()
        {
            const int newPriority = 3;

            IMediaProcessor processor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            IAsset          asset     = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            //Create temp job to simuate queue when no reserved unit are allocated
            IJob tempJob = CreateAndSubmitOneTaskJob(_mediaContext, GenerateName("SubmitJobToCreateQueue"), processor, GetWamePreset(processor), asset, TaskOptions.None);
            IJob job     = CreateAndSubmitOneTaskJob(_mediaContext, GenerateName("ShouldSubmitJobAndUpdatePriorityWhenJobIsQueued"), processor, GetWamePreset(processor), asset, TaskOptions.None);

            WaitForJobStateAndUpdatePriority(job, JobState.Queued, newPriority);
            WaitForJob(job.Id, JobState.Finished, (string id) =>
            {
                var finished = _mediaContext.Jobs.Where(c => c.Id == job.Id && c.Priority == newPriority).FirstOrDefault();
                Assert.IsNotNull(finished);
            });
        }
        public void ShouldSubmitAndFinishChainedTasksUsingParentOverload()
        {
            IAsset asset = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);

            IJob            job            = _mediaContext.Jobs.Create("Test");
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            ITask           task           = job.Tasks.AddNew("Task1", mediaProcessor, GetWamePreset(mediaProcessor), TaskOptions.None);

            task.InputAssets.Add(asset);
            IAsset asset1 = task.OutputAssets.AddNew("output asset");

            string xmlPreset = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.ThumbnailXml);
            ITask  task2     = job.Tasks.AddNew("Task2", mediaProcessor, xmlPreset, TaskOptions.None, task);

            task2.OutputAssets.AddNew("JobOutput", options: AssetCreationOptions.None);
            job.Submit();
            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);
        }
Exemple #16
0
        public void ShouldThrowForbiddenExceptionWhenExpired()
        {
            string fileUploaded = _smallWmv;
            IAsset asset        = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(fileUploaded),
                                                         AssetCreationOptions.StorageEncrypted);
            IAssetFile assetFile = asset.AssetFiles.First();

            Assert.AreEqual(assetFile.Asset.Id, asset.Id);
            try
            {
                VerifyAndDownloadAssetFileNTimes(assetFile, asset, 1, 1, true, true);
            }
            catch (AggregateException exception)
            {
                Assert.IsTrue(exception.InnerException.Message.Contains("The remote server returned an error: (403) Forbidden."));
                throw exception.InnerException;
            }
        }
        public void ShouldThrowTryingUpdateJobPriorityWhenJobIsFinished()
        {
            const int newPriority = 3;

            IMediaProcessor processor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            IAsset          asset     = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IJob            job       = CreateAndSubmitOneTaskJob(_mediaContext, GenerateName("ShouldSubmitJobAndUpdatePriorityWhenJobIsQueued"), processor, GetWamePreset(processor), asset, TaskOptions.None);

            try
            {
                WaitForJobStateAndUpdatePriority(job, JobState.Finished, newPriority);
            }
            catch (DataServiceRequestException ex)
            {
                Assert.IsTrue(ex.InnerException.Message.Contains("Job's priority can only be changed if the job is in Queued state"));
                throw ex;
            }
        }
        public void ShouldCreateAssetFileWithEncryption()
        {
            var    filePaths = new[] { WindowsAzureMediaServicesTestConfiguration.SmallWmv };
            IAsset asset     = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(WindowsAzureMediaServicesTestConfiguration.SmallWmv), AssetCreationOptions.StorageEncrypted);

            // Associate an access policy with the asset so we can download the files associated with it
            IAccessPolicy policy = _mediaContext.AccessPolicies.Create("Test", TimeSpan.FromMinutes(10), AccessPermissions.Read);

            _mediaContext.Locators.CreateSasLocator(asset, policy);

            Assert.IsNotNull(asset, "Asset should be non null");
            Assert.AreNotEqual(Guid.Empty, asset.Id, "Asset ID should not be null");
            Assert.AreEqual(1, asset.AssetFiles.Count(), "Child files count wrong");
            Assert.IsTrue(asset.Options == AssetCreationOptions.StorageEncrypted, "AssetCreationOptions did not have the expected value");

            VerifyFileAndContentKeyMetadataForStorageEncryption(asset, _mediaContext);
            VerifyStorageEncryptionOnFiles(asset, filePaths);
        }
        public void ShouldSubmitAndFinishEETaskWithStorageProtectedInputAndClearOutput()
        {
            //
            //  This test uses the same preset as the EE DRM tests but does not apply
            //  common encryption.  This preset gets split into multiple subtasks by EE.
            //

            IAsset asset = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);

            // Load the EE preset to create a smooth streaming presentation with PlayReady protection
            string xmlPreset = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.EncodePlusEncryptWithEeXml);

            // Remove the DRM Section to produce clear content
            var doc = new XmlDocument();

            doc.LoadXml(xmlPreset);

            XmlNodeList drmNodes = doc.GetElementsByTagName("Drm");

            Assert.AreEqual(1, drmNodes.Count);

            XmlNode drmNode = drmNodes[0];

            drmNode.ParentNode.RemoveChild(drmNode);

            xmlPreset = doc.OuterXml;
            IMediaProcessor processor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            IJob            job       = CreateAndSubmitOneTaskJob(_mediaContext, GenerateName("ShouldSubmitAndFinishEETaskWithStorageProtectedInputAndClearOutput"), processor, xmlPreset, asset, TaskOptions.None);

            Assert.AreEqual(1, job.Tasks.Count);
            Assert.AreEqual(TaskOptions.None, job.Tasks[0].Options);
            Assert.IsNull(job.Tasks[0].InitializationVector);
            Assert.IsTrue(String.IsNullOrEmpty(job.Tasks[0].EncryptionKeyId));
            Assert.IsNull(job.Tasks[0].EncryptionScheme);
            Assert.IsNull(job.Tasks[0].EncryptionVersion);

            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);

            CloudMediaContext context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IJob job2 = context2.Jobs.Where(c => c.Id == job.Id).Single();

            Assert.AreEqual(1, job2.Tasks.Count);
            Assert.AreEqual(1, job2.Tasks[0].OutputAssets.Count);
        }
Exemple #20
0
        public void ValidateEffectiveEncryptionStatusOfStorageEncryptedWmv()
        {
            IAsset asset = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallWmv, AssetCreationOptions.StorageEncrypted);

            Assert.AreEqual(false, asset.IsStreamable);
            Assert.AreEqual(AssetType.Unknown, asset.AssetType);
            Assert.AreEqual(AssetCreationOptions.StorageEncrypted, asset.Options);

            AssetDeliveryProtocol protocolsToTest = AssetDeliveryProtocol.SmoothStreaming |
                                                    AssetDeliveryProtocol.Dash |
                                                    AssetDeliveryProtocol.HLS |
                                                    AssetDeliveryProtocol.Hds;

            List <TestCase> testCases = GetTestsCasesForProtocolCombination(protocolsToTest, AssetEncryptionState.Unsupported);

            ValidateAssetEncryptionState(asset, testCases);

            CleanupAsset(asset);
        }
 public void ShouldThrowSubmittingJobWhenNonexistingStorageSpecifiedForOutPut()
 {
     try
     {
         IAsset          asset          = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
         IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
         string          name           = GenerateName("Job 1");
         IJob            job            = _mediaContext.Jobs.Create(name);
         ITask           task           = job.Tasks.AddNew("Task1", mediaProcessor, GetWamePreset(mediaProcessor), TaskOptions.None);
         task.InputAssets.Add(asset);
         task.OutputAssets.AddNew("Output asset", Guid.NewGuid().ToString(), AssetCreationOptions.None);
         job.Submit();
     }
     catch (DataServiceRequestException ex)
     {
         Assert.IsTrue(ex.Response.First().Error.Message.Contains("Cannot find the storage account"));
         throw;
     }
 }
        public void ShouldFinishJobWithErrorWithInvalidPreset()
        {
            IAsset          asset     = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor processor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            IJob            job       = CreateAndSubmitOneTaskJob(_mediaContext, GenerateName("ShouldFinishJobWithErrorWithInvalidPreset"), processor, "Some wrong Preset", asset, TaskOptions.None);
            Action <string> verify    = id =>
            {
                IJob job2 = _mediaContext.Jobs.Where(c => c.Id == id).SingleOrDefault();
                Assert.IsNotNull(job2);
                Assert.IsNotNull(job2.Tasks);
                Assert.AreEqual(1, job2.Tasks.Count);
                Assert.IsNotNull(job2.Tasks[0].ErrorDetails);
                Assert.AreEqual(1, job2.Tasks[0].ErrorDetails.Count);
                Assert.IsNotNull(job2.Tasks[0].ErrorDetails[0]);
                Assert.AreEqual("ErrorParsingConfiguration", job2.Tasks[0].ErrorDetails[0].Code);
            };

            WaitForJob(job.Id, JobState.Error, verify);
        }
        public void ShouldReturnLocatorWhenCreateSasLocatorCalled()
        {
            // Arrange

            var accessPolicy = _mediaContext.AccessPolicies.Create("TestPolicy", TimeSpan.FromMinutes(10), AccessPermissions.List | AccessPermissions.Read);
            var asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);

            // Act
            var actual = _mediaContext.Locators.CreateSasLocator(asset, accessPolicy);

            // Assert
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Id);
            Assert.IsNotNull(actual.Path);
            Assert.IsTrue(actual.ExpirationDateTime < DateTime.UtcNow.AddMinutes(11));
            Assert.AreEqual(asset.Id, actual.Asset.Id);
            Assert.AreEqual(asset.Name, actual.Asset.Name);
            Assert.AreEqual(accessPolicy.Id, actual.AccessPolicy.Id);
        }
        public void ShouldUpdateExpiryTimeWhenUpdateLocatorCalledWithExpiryTime()
        {
            // Arrange
            var accessPolicyDuration = TimeSpan.FromHours(2);
            var expectedExpiryTime   = DateTime.UtcNow.Date.AddDays(2);

            var accessPolicy = _mediaContext.AccessPolicies.Create("TestPolicy", accessPolicyDuration, AccessPermissions.Read);
            var asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);
            var locator      = _mediaContext.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset, accessPolicy);

            // Act
            locator.Update(expectedExpiryTime);

            var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var actual   = context2.Locators.Where(x => x.Id == locator.Id).FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedExpiryTime, locator.ExpirationDateTime);
            Assert.AreEqual(expectedExpiryTime, actual.ExpirationDateTime);
        }
Exemple #25
0
        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);
            }
        }
        public void ShouldCreateAssetFileWithPlayReadyEncryption()
        {
            // Note that this file is not really PlayReady encrypted.  For the purposes of this test that is okay.
            IAsset asset = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(WindowsAzureMediaServicesTestConfiguration.SmallWmv), AssetCreationOptions.CommonEncryptionProtected);

            Guid keyId = Guid.NewGuid();

            byte[] contentKey = GetRandomBuffer(16);

            IContentKey key = _mediaContext.ContentKeys.Create(keyId, contentKey);

            asset.ContentKeys.Add(key);

            Assert.IsNotNull(asset, "Asset should be non null");
            Assert.AreNotEqual(Guid.Empty, asset.Id, "Asset ID should not be null");
            Assert.AreEqual(1, asset.AssetFiles.Count(), "Child files count wrong");
            Assert.IsTrue(asset.Options == AssetCreationOptions.CommonEncryptionProtected, "AssetCreationOptions did not have the expected value");

            VerifyFileAndContentKeyMetadataForCommonEncryption(asset);
            VerifyContentKeyVersusExpectedValue2(asset, contentKey, keyId);
        }
        public void ShouldCreateTaskUsingStorageEncryptedAsset()
        {
            var             filePaths = new[] { WindowsAzureMediaServicesTestConfiguration.SmallWmv };
            IAsset          asset     = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(WindowsAzureMediaServicesTestConfiguration.SmallWmv), AssetCreationOptions.StorageEncrypted);
            IMediaProcessor processor = JobTests.GetEncoderMediaProcessor(_mediaContext);
            IJob            job       = _mediaContext.Jobs.Create("Encode Job with encrypted asset");
            ITask           task      = job.Tasks.AddNew("Task 1", processor, JobTests.GetWamePreset(processor), TaskOptions.None);

            task.InputAssets.Add(asset);
            task.OutputAssets.AddNew("Encrypted Output", AssetCreationOptions.StorageEncrypted);
            job.Submit();
            JobTests.WaitForJob(job.Id, JobState.Finished, JobTests.VerifyAllTasksFinished);

            CloudMediaContext context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IJob job2 = context2.Jobs.Where(c => c.Id == job.Id).Single();

            foreach (IAsset outputAsset in job2.Tasks[0].OutputAssets)
            {
                VerifyFileAndContentKeyMetadataForStorageEncryption(outputAsset, _mediaContext);
            }
        }
        public void ShouldDeleteAssetWithStorageEncryptionContentKey()
        {
            // Use two contexts to cover the case where the content key needs to be internally attached to
            // the data context.  This simulates deleting a content key that we haven't just created.
            var dataContext2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();

            IAsset asset = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(WindowsAzureMediaServicesTestConfiguration.SmallWmv), AssetCreationOptions.StorageEncrypted);

            Assert.AreEqual(1, asset.ContentKeys.Count, "Expected 1 content key associated with the asset for storage encryption");
            Assert.AreEqual(ContentKeyType.StorageEncryption, asset.ContentKeys[0].ContentKeyType);

            // Get the ids to make sure they are no longer in the system after deleting the asset
            string assetId = asset.Id;
            string fileId  = asset.AssetFiles.ToList()[0].Id;
            string keyId   = asset.ContentKeys[0].Id;

            foreach (ILocator locator in asset.Locators)
            {
                locator.Delete();
            }

            // Now delete the asset and ensure that the content key and file are also deleted
            asset.Delete();

            foreach (IAsset assetFromRest in dataContext2.Assets)
            {
                Assert.IsFalse(assetFromRest.Id == assetId, "Asset was deleted we should not be able to query it by identifier.");
            }

            foreach (IAssetFile fileFromRest in dataContext2.Files)
            {
                Assert.IsFalse(fileFromRest.Id == fileId, "Asset was deleted we should not be able to query its associated File by identifier.");
            }

            foreach (IContentKey keyFromRest in dataContext2.ContentKeys)
            {
                Assert.IsFalse(keyFromRest.Id == keyId, "Asset was deleted we should not be able to query its associated storage encryption key by identifier.");
            }
        }
        public void ShouldCreateLocatorWhenCreateSasLocatorCalled()
        {
            // Arrange

            var accessPolicy = _mediaContext.AccessPolicies.Create("TestPolicy", TimeSpan.FromMinutes(10), AccessPermissions.List | AccessPermissions.Read);
            var asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);

            // Act
            var locator = _mediaContext.Locators.CreateSasLocator(asset, accessPolicy);

            var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var actual   = context2.Locators.Where(x => x.Id == locator.Id).FirstOrDefault();

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(locator.Id, actual.Id);
            Assert.IsNotNull(actual.Path);
            Assert.IsTrue(actual.ExpirationDateTime < DateTime.UtcNow.AddMinutes(11));
            Assert.AreEqual(asset.Id, actual.Asset.Id);
            Assert.AreEqual(asset.Name, actual.Asset.Name);
            Assert.AreEqual(accessPolicy.Id, actual.AccessPolicy.Id);
        }
        public void EncryptManifestFilesAndVerifyThemAfterDeencryption()
        {
            List <IIngestManifestFile> files;
            IIngestManifest            ingestManifestCreated;
            var 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, _context);

            Assert.IsTrue(AssetTests.CompareFiles(decryptedPath, filePaths[mFile.Name]), "Original file and Decrypted are not same");
        }