public void MediaServicesV3ServiceCreateLocatorTestWithOpenIdSettings()
        {
            var settingsProvider = Mock.Of <ISettingsProvider>();

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmOpenIdConnectDiscoveryDocument"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmOpenIdConnectDiscoveryDocument);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayPfxPassword"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayPfxPassword);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayAskHex"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayAskHex);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayCertificateB64"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayCertAsSecretStringStatic);

            // Act
            var polService = new MediaServicesV3ContentKeyPolicyService(settingsProvider, LogKey);

            // Assert
            Xunit.Assert.NotNull(polService);
        }
Exemplo n.º 2
0
        public void MediaServicesV3ContentKeyPolicyServiceWithDRMSettings(string openId, string fairPlayPassword, string fairPlayAsk, string fairPlayCertSecretAsString, bool expectedValue, Type typeException)
        {
            Mock.Get(SettingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmOpenIdConnectDiscoveryDocument"))
            .Returns(openId);

            Mock.Get(SettingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayPfxPassword"))
            .Returns(fairPlayPassword);

            Mock.Get(SettingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayAskHex"))
            .Returns(fairPlayAsk);

            Mock.Get(SettingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayCertificateB64"))
            .Returns(fairPlayCertSecretAsString);

            if (expectedValue)
            {
                // Act
                var polService = new MediaServicesV3ContentKeyPolicyService(SettingsProvider, LogKey);

                // Assert
                Xunit.Assert.NotNull(polService);
            }
            else
            {
                _ = Xunit.Assert.Throws(typeException, () => new MediaServicesV3ContentKeyPolicyService(SettingsProvider, LogKey));
            }
        }
Exemplo n.º 3
0
        public void MediaServicesV3ContentKeyPolicyServiceWithDRMSettingsGetContentKeyPolicyAsync(string openId, string fairPlayPassword, string fairPlayAsk, string fairPlayCertSecretAsString, string polName, bool expectedValue, Type typeResult, Type typeException)
        {
            Mock.Get(SettingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmOpenIdConnectDiscoveryDocument"))
            .Returns(openId);

            Mock.Get(SettingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayPfxPassword"))
            .Returns(fairPlayPassword);

            Mock.Get(SettingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayAskHex"))
            .Returns(fairPlayAsk);

            Mock.Get(SettingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayCertificateB64"))
            .Returns(fairPlayCertSecretAsString);

            // Act
            var polService = new MediaServicesV3ContentKeyPolicyService(SettingsProvider, LogKey);

            if (expectedValue)
            {
                var keyPol = polService.GetContentKeyPolicyFromMemory(polName);
                if (typeResult != null)
                {
                    Xunit.Assert.NotNull(keyPol);
                    Xunit.Assert.IsType(typeResult, keyPol);
                }
                else
                {
                    Xunit.Assert.Null(keyPol);
                }
            }
            else
            {
                _ = Xunit.Assert.Throws(typeException, () => polService.GetContentKeyPolicyFromMemory(polName));
            }
        }
        public async void MediaServicesV3ServiceCreateLocatorTestWithPolicyUpdate(RequestMediaServicesLocatorCreateDTO locatorCreateDTO, string updatePolicy, ContentKeyPolicy contentKeyPolicy)
        {
            var amsV3SdkWrapper  = Mock.Of <IMediaServicesV3SdkWrapper>();
            var storageService   = Mock.Of <IStorageService>();
            var settingsProvider = Mock.Of <ISettingsProvider>();

            // Arrange
            string assetName  = "myassetname";
            var    amsAccount = new MediaService(storageAccounts: new List <StorageAccount>()
            {
                new StorageAccount()
                {
                    Id = MediaServicesV3PublicationTestData.DefaultStorageId
                }
            });

            // Arrange Mocks
            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.AssetCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <Asset>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new Asset(name: assetName));

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.MediaservicesGetAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(amsAccount);

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.StreamingEndpointsListAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(MockPageSe);

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.StreamingLocatorListPathsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Paths);

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.StreamingLocatorCreateAsync(It.IsAny <string>(), It.IsAny <StreamingLocator>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new StreamingLocator(assetName: "asset45", streamingPolicyName: locatorCreateDTO.StreamingPolicyName, defaultContentKeyPolicyName: locatorCreateDTO.ContentKeyPolicyName, contentKeys: new List <StreamingLocatorContentKey>()
            {
                new StreamingLocatorContentKey(Guid.NewGuid(), StreamingLocatorContentKeyType.CommonEncryptionCenc), new StreamingLocatorContentKey(Guid.NewGuid(), StreamingLocatorContentKeyType.CommonEncryptionCbcs)
            }));

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.ContentKeyPolicyGetAsync(locatorCreateDTO.ContentKeyPolicyName, It.IsAny <CancellationToken>()))
            .ReturnsAsync(contentKeyPolicy);

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.StreamingPolicyGetAsync(MediaServicesV3PublicationTestData.GoodDRMStreamingPolicy, It.IsAny <CancellationToken>()))
            .ReturnsAsync(new StreamingPolicy());

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.ContentKeyPolicyCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <IEnumerable <ContentKeyPolicyOption> >(), It.IsAny <string>(), It.IsAny <CancellationToken>()));

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmOpenIdConnectDiscoveryDocument"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmOpenIdConnectDiscoveryDocument);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayPfxPassword"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayPfxPassword);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayAskHex"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayAskHex);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayCertificateB64"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayCertAsSecretStringStatic);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmEnableContentKeyPolicyUpdate"))
            .Returns(updatePolicy);

            IMediaServicesV3ContentKeyPolicyService      amsContentKeyPolService2 = new MediaServicesV3ContentKeyPolicyService(settingsProvider, LogKey);
            IMediaServicesV3CustomStreamingPolicyService amsStreamingPolService2  = new MediaServicesV3CustomStreamingPolicyService();

            // Act
            var amsV3PubServices = new MediaServicesV3PublicationService(amsContentKeyPolService2, amsStreamingPolService2, amsV3SdkWrapper, storageService, settingsProvider, Log);

            // Assert
            var result = await amsV3PubServices.LocatorCreateAsync(
                locatorCreateDTO.ContainerUri,
                locatorCreateDTO.StreamingPolicyName,
                locatorCreateDTO.ContentKeyPolicyName,
                locatorCreateDTO.TimeBasedFilter,
                locatorCreateDTO.OperationContext,
                locatorCreateDTO.GenerateAudioFilters).ConfigureAwait(false);

            result.ShouldBeOfType <ServiceOperationResultMediaServicesV3LocatorCreate>();
            result.LocatorName.ShouldBeOfType <string>();
        }
        public async void MediaServicesV3ServiceCreateLocatorTest(RequestMediaServicesLocatorCreateDTO locatorCreateDTO, bool expectedValue, Type typeException, string environmentType)
        {
            // Arrange
            var storageService   = Mock.Of <IStorageService>();
            var amsV3SdkWrapper  = Mock.Of <IMediaServicesV3SdkWrapper>();
            var settingsProvider = Mock.Of <ISettingsProvider>();

            string assetName  = "myassetname";
            var    amsAccount = new MediaService(storageAccounts: new List <StorageAccount>()
            {
                new StorageAccount()
                {
                    Id = MediaServicesV3PublicationTestData.DefaultStorageId
                }
            });

            // Arrange Mocks
            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.AssetCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <Asset>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new Asset(name: assetName));

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.AssetFiltersCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>(), TimingIsWrong(), It.IsAny <CancellationToken>()))
            .ThrowsAsync(new Exception());

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.MediaservicesGetAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(amsAccount);

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.StreamingEndpointsListAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(MockPageSe);

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.StreamingLocatorListPathsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Paths);

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.StreamingLocatorCreateAsync(It.IsAny <string>(), It.IsAny <StreamingLocator>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new StreamingLocator(assetName: "asset45", streamingPolicyName: locatorCreateDTO.StreamingPolicyName, defaultContentKeyPolicyName: locatorCreateDTO.ContentKeyPolicyName, contentKeys: new List <StreamingLocatorContentKey>()));

            if (locatorCreateDTO.ContentKeyPolicyName == MediaServicesV3PublicationTestData.GoodContentKeyPolicyDrm)
            {
                // let's add a CENC and CBCS keys
                Mock.Get(amsV3SdkWrapper)
                .Setup(x => x.StreamingLocatorCreateAsync(It.IsAny <string>(), It.IsAny <StreamingLocator>(), It.IsAny <CancellationToken>()))
                .ReturnsAsync(new StreamingLocator(assetName: "asset45", streamingPolicyName: locatorCreateDTO.StreamingPolicyName, defaultContentKeyPolicyName: locatorCreateDTO.ContentKeyPolicyName, contentKeys: new List <StreamingLocatorContentKey>()
                {
                    new StreamingLocatorContentKey(Guid.NewGuid(), StreamingLocatorContentKeyType.CommonEncryptionCenc), new StreamingLocatorContentKey(Guid.NewGuid(), StreamingLocatorContentKeyType.CommonEncryptionCbcs)
                }));
            }
            else
            {
                Mock.Get(amsV3SdkWrapper)
                .Setup(x => x.StreamingLocatorCreateAsync(It.IsAny <string>(), It.IsAny <StreamingLocator>(), It.IsAny <CancellationToken>()))
                .ReturnsAsync(new StreamingLocator(assetName: "asset45", streamingPolicyName: locatorCreateDTO.StreamingPolicyName, defaultContentKeyPolicyName: locatorCreateDTO.ContentKeyPolicyName, contentKeys: new List <StreamingLocatorContentKey>()));
            }

            Mock.Get(amsV3SdkWrapper)
            .Setup(x => x.AssetFiltersCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <AssetFilter>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new AssetFilter());

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue(EnvironmentTypeConstants.EnvironmentTypeSettingName))
            .Returns(environmentType);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmOpenIdConnectDiscoveryDocument"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmOpenIdConnectDiscoveryDocument);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayPfxPassword"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayPfxPassword);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayAskHex"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayAskHex);

            Mock.Get(settingsProvider)
            .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayCertificateB64"))
            .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayCertAsSecretStringStatic);

            Mock.Get(storageService)
            .Setup(x => x.ListBlobsAsync(It.IsAny <Uri>(), It.IsAny <StorageClientProviderContext>()))
            .ReturnsAsync(MediaServicesV3PublicationTestData.GoodBlobItemListWithIsmFile);

            Mock.Get(storageService)
            .Setup(x => x.DownloadHttpRangeAsync(It.IsAny <Uri>(), It.IsAny <StorageClientProviderContext>(), default))
            .ReturnsAsync(MediaServicesV3PublicationTestData.GoodIsmFileBlobDownloadInfo);

            IMediaServicesV3ContentKeyPolicyService      amsContentKeyPolService2 = new MediaServicesV3ContentKeyPolicyService(settingsProvider, LogKey);
            IMediaServicesV3CustomStreamingPolicyService amsStreamingPolService2  = new MediaServicesV3CustomStreamingPolicyService();

            // Act
            var amsV3PubServices = new MediaServicesV3PublicationService(amsContentKeyPolService2, amsStreamingPolService2, amsV3SdkWrapper, storageService, settingsProvider, Log);

            // Assert
            if (expectedValue == false)
            {
                _ = await Xunit.Assert.ThrowsAsync(typeException, async() =>
                                                   await amsV3PubServices.LocatorCreateAsync(
                                                       locatorCreateDTO.ContainerUri,
                                                       locatorCreateDTO.StreamingPolicyName,
                                                       locatorCreateDTO.ContentKeyPolicyName,
                                                       locatorCreateDTO.TimeBasedFilter,
                                                       locatorCreateDTO.OperationContext,
                                                       locatorCreateDTO.GenerateAudioFilters).ConfigureAwait(false)).ConfigureAwait(false);
            }
            else
            {
                var result = await amsV3PubServices.LocatorCreateAsync(
                    locatorCreateDTO.ContainerUri,
                    locatorCreateDTO.StreamingPolicyName,
                    locatorCreateDTO.ContentKeyPolicyName,
                    locatorCreateDTO.TimeBasedFilter,
                    locatorCreateDTO.OperationContext,
                    locatorCreateDTO.GenerateAudioFilters).ConfigureAwait(false);

                result.ShouldBeOfType <ServiceOperationResultMediaServicesV3LocatorCreate>();
                result.LocatorName.ShouldBeOfType <string>();
            }
        }