示例#1
0
        public void TestGetEncryptionState()
        {
            IAsset asset = JobTests.CreateSmoothAsset(_mediaContext, _filePaths, AssetCreationOptions.None);
            AssetDeliveryProtocol protocolsToSet = AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.Dash;
            Dictionary <AssetDeliveryPolicyConfigurationKey, string> configuration = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>()
            {
                { AssetDeliveryPolicyConfigurationKey.EnvelopeBaseKeyAcquisitionUrl, "https://www.test.com/" },
                { AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIVAsBase64, Convert.ToBase64String(ContentKeyTests.GetRandomBuffer(16)) }
            };
            IAssetDeliveryPolicy policy = _mediaContext.AssetDeliveryPolicies.Create("Test Policy", AssetDeliveryPolicyType.DynamicEnvelopeEncryption, protocolsToSet, configuration);
            IContentKey          key    = _mediaContext.ContentKeys.Create(Guid.NewGuid(), ContentKeyTests.GetRandomBuffer(16), "Test key", ContentKeyType.EnvelopeEncryption);

            asset.ContentKeys.Add(key);
            asset.DeliveryPolicies.Add(policy);

            AssetEncryptionState state = asset.GetEncryptionState(protocolsToSet);

            Assert.AreEqual(AssetEncryptionState.DynamicEnvelopeEncryption, state);

            state = asset.GetEncryptionState(AssetDeliveryProtocol.Dash | AssetDeliveryProtocol.Hds);
            Assert.AreEqual(AssetEncryptionState.NoSinglePolicyApplies, state);

            state = asset.GetEncryptionState(AssetDeliveryProtocol.Hds);
            Assert.AreEqual(AssetEncryptionState.BlockedByPolicy, state);

            CleanupAsset(asset);
        }
        public void RunAllGetEffectiveDeliveryPolicyTestCases()
        {
            string testCaseDataFilePath = WindowsAzureMediaServicesTestConfiguration.GetVideoSampleFilePath(TestContext, c_TestCaseDataFile);

            string[] testCases = File.ReadAllLines(testCaseDataFilePath);
            Assert.IsNotNull(testCases);
            Assert.AreEqual(401, testCases.Length); // ensure we have the expected number of cases

            int failureCount = 0;

            StringBuilder builder = new StringBuilder();

            builder.Append(testCases[0]);
            builder.Append(",ActualAssetType,ActualIsStreamable,ActualEffectiveEncryptionState");
            builder.AppendLine();

            for (int i = 1; i < testCases.Length; i++)
            {
                string[]                parameters              = testCases[i].Split(',');
                AssetCreationOptions    options                 = (AssetCreationOptions)Enum.Parse(typeof(AssetCreationOptions), parameters[0]);
                AssetType               assetType               = (AssetType)Enum.Parse(typeof(AssetType), parameters[1]);
                AssetDeliveryProtocol   assetDeliveryProtocol   = (AssetDeliveryProtocol)Enum.Parse(typeof(AssetDeliveryProtocol), parameters[2]);
                AssetDeliveryPolicyType assetDeliveryPolicyType = (AssetDeliveryPolicyType)Enum.Parse(typeof(AssetDeliveryPolicyType), parameters[3]);
                AssetEncryptionState    expectedEncryptionState = (AssetEncryptionState)Enum.Parse(typeof(AssetEncryptionState), parameters[4]);
                bool      expectedIsStreamable = bool.Parse(parameters[5]);
                AssetType expectedAssetType    = (AssetType)Enum.Parse(typeof(AssetType), parameters[6]);

                IAsset asset = GetTestAsset(options, assetType, assetDeliveryProtocol, assetDeliveryPolicyType);

                AssetEncryptionState actualEncryptionState = asset.GetEncryptionState(assetDeliveryProtocol);

                if (false == ((expectedAssetType == asset.AssetType) &&
                              (expectedIsStreamable == asset.IsStreamable) &&
                              (expectedEncryptionState == actualEncryptionState)
                              )
                    )
                {
                    // We had a failure so increase our failed count and then save the details of the test case and where it failed
                    failureCount++;

                    builder.Append(testCases[i]);
                    builder.Append(",");
                    builder.Append(asset.AssetType.ToString());
                    builder.Append(",");
                    builder.Append(asset.IsStreamable.ToString());
                    builder.Append(",");
                    builder.Append(actualEncryptionState.ToString());
                    builder.AppendLine();
                }
            }

            if (failureCount > 0)
            {
                Assert.Fail("Some RunAllGetEffectiveDeliveryPolicyTestCases failed");

                // If there are a lot of failures the best way to debug then is to dump
                // failed test case input and output data to a csv file for more detailed
                // analysis
                //File.WriteAllText("output.csv", builder.ToString());
            }
        }
示例#3
0
        AssetEncryptionState IAsset.GetEncryptionState(AssetDeliveryProtocol protocolsToCheck)
        {
            IAsset asset = (IAsset)this;

            AssetEncryptionState returnValue = AssetEncryptionState.Unsupported;

            if (asset.IsStreamable)
            {
                if (asset.DeliveryPolicies.Count == 0)
                {
                    if ((asset.Options == AssetCreationOptions.EnvelopeEncryptionProtected) &&
                        (asset.AssetType == AssetType.MediaServicesHLS))
                    {
                        returnValue = AssetEncryptionState.StaticEnvelopeEncryption;
                    }
                    else if (asset.Options == AssetCreationOptions.CommonEncryptionProtected &&
                             (asset.AssetType == AssetType.MediaServicesHLS || asset.AssetType == AssetType.SmoothStreaming))
                    {
                        returnValue = AssetEncryptionState.StaticCommonEncryption;
                    }
                    else if (asset.Options == AssetCreationOptions.None)
                    {
                        returnValue = AssetEncryptionState.ClearOutput;
                    }
                    else if (asset.Options == AssetCreationOptions.StorageEncrypted)
                    {
                        returnValue = AssetEncryptionState.StorageEncryptedWithNoDeliveryPolicy;
                    }
                }
                else
                {
                    IAssetDeliveryPolicy policy = asset.DeliveryPolicies.Where(p => p.AssetDeliveryProtocol.HasFlag(protocolsToCheck)).FirstOrDefault();

                    if (policy == null)
                    {
                        if (asset.DeliveryPolicies.Any(p => ((p.AssetDeliveryProtocol & protocolsToCheck) != 0)))
                        {
                            returnValue = AssetEncryptionState.NoSinglePolicyApplies;
                        }
                        else
                        {
                            returnValue = AssetEncryptionState.BlockedByPolicy;
                        }
                    }
                    else
                    {
                        if (policy.AssetDeliveryPolicyType == AssetDeliveryPolicyType.Blocked)
                        {
                            returnValue = AssetEncryptionState.BlockedByPolicy;
                        }
                        else if (policy.AssetDeliveryPolicyType == AssetDeliveryPolicyType.NoDynamicEncryption)
                        {
                            returnValue = AssetEncryptionState.NoDynamicEncryption;
                        }
                        else if (policy.AssetDeliveryPolicyType == AssetDeliveryPolicyType.DynamicCommonEncryption)
                        {
                            if (((asset.AssetType == AssetType.SmoothStreaming) || (asset.AssetType == AssetType.MultiBitrateMP4)) &&
                                ((asset.Options == AssetCreationOptions.StorageEncrypted) || (asset.Options == AssetCreationOptions.None)))
                            {
                                returnValue = AssetEncryptionState.DynamicCommonEncryption;
                            }
                        }
                        else if (policy.AssetDeliveryPolicyType == AssetDeliveryPolicyType.DynamicEnvelopeEncryption)
                        {
                            if (((asset.AssetType == AssetType.SmoothStreaming) || (asset.AssetType == AssetType.MultiBitrateMP4)) &&
                                ((asset.Options == AssetCreationOptions.StorageEncrypted) || (asset.Options == AssetCreationOptions.None)))
                            {
                                returnValue = AssetEncryptionState.DynamicEnvelopeEncryption;
                            }
                        }
                    }
                }
            }

            return(returnValue);
        }
 public TestCase(AssetDeliveryProtocol protocolsToTest, AssetEncryptionState expectedState)
 {
     ProtocolsToTest = protocolsToTest;
     ExpectedState = expectedState;
 }
        private void ValidateAssetEncryptionState(IAsset asset, AssetDeliveryProtocol protocolsToTest, AssetEncryptionState expectedState)
        {
            AssetEncryptionState actualState = asset.GetEncryptionState(protocolsToTest);

            Assert.AreEqual(expectedState, actualState);
        }
        private List<TestCase> GetTestsCasesForProtocolCombination(AssetDeliveryProtocol protocols, AssetEncryptionState expectedState)
        {
            List<TestCase> testCases = new List<TestCase>();

            List<AssetDeliveryProtocol> combinationList = GetAllCombinationsOfDeliveryProtocol(protocols);

            foreach(AssetDeliveryProtocol combination in combinationList)
            {
                testCases.Add(new TestCase(combination, expectedState));
            }

            return testCases;
        }
示例#7
0
        private List <TestCase> GetTestsCasesForProtocolCombination(AssetDeliveryProtocol protocols, AssetEncryptionState expectedState)
        {
            List <TestCase> testCases = new List <TestCase>();

            List <AssetDeliveryProtocol> combinationList = GetAllCombinationsOfDeliveryProtocol(protocols);

            foreach (AssetDeliveryProtocol combination in combinationList)
            {
                testCases.Add(new TestCase(combination, expectedState));
            }

            return(testCases);
        }
示例#8
0
 public TestCase(AssetDeliveryProtocol protocolsToTest, AssetEncryptionState expectedState)
 {
     ProtocolsToTest = protocolsToTest;
     ExpectedState   = expectedState;
 }
示例#9
0
        private void ValidateAssetEncryptionState(IAsset asset, AssetDeliveryProtocol protocolsToTest, AssetEncryptionState expectedState)
        {
            AssetEncryptionState actualState = asset.GetEncryptionState(protocolsToTest);

            Assert.AreEqual(expectedState, actualState);
        }