diff --git a/.nuget/windowsazure.mediaservices.nuspec b/.nuget/windowsazure.mediaservices.nuspec index 88628712..6fde89a6 100644 --- a/.nuget/windowsazure.mediaservices.nuspec +++ b/.nuget/windowsazure.mediaservices.nuspec @@ -2,7 +2,7 @@ windowsazure.mediaservices - 3.2.0.0 + 3.3.0.0 Windows Azure Media Services .NET SDK Microsoft Corporation Microsoft Corporation @@ -10,7 +10,7 @@ http://aka.ms/wamsmsdn http://nimbuspmteam.blob.core.windows.net/nuget/Media Services 150.png true - This package contains Windows Azure Media Service library 3.2.0.0 for .NET. + This package contains Windows Azure Media Service library 3.3.0.0 for .NET. For more information, please check our forum: http://social.msdn.microsoft.com/Forums/en-US/MediaServices/threads For MSDN documentation please visit http://aka.ms/wamsmsdn @@ -20,13 +20,14 @@ Source in GitHub at https://github.com/WindowsAzure/azure-sdk-for-media-services en-US windowsazureofficial, WindowsAzure, MediaServices, Microsoft, - - - - + + + + - + + diff --git a/Readme.md b/Readme.md index 332e1533..943810dd 100644 --- a/Readme.md +++ b/Readme.md @@ -1,53 +1,54 @@ # Windows Azure Media Services SDK .NET 4.5 - -Windows Azure Media Services allows you to build a media distribution solution that can stream audio and video to Windows, iOS, Android, and other devices and platforms.To learn more, visit our [Developer Center](http://www.windowsazure.com/en-us/develop/media-services/). - + + +Windows Azure Media Services allows you to build a media distribution solution that can stream audio and video to Windows, iOS, Android, and other devices and platforms.To learn more, visit our [Developer Center](http://www.windowsazure.com/en-us/develop/media-services/). + ## Release Notes Please read the latest note here: https://github.com/Azure/azure-sdk-for-media-services/releases. -## Getting Started - -If you are new to Media Services, you can get started by following our [tutorials](http://www.windowsazure.com/en-us/develop/media-services/tutorials/get-started/). You could be able to bring media into Azure, encoded it, package it into stream-able format and make it available for streaming. - -## Download Source Code - -To get the source code of our SDKs and samples via **git** just type: - - git clone https://github.com/WindowsAzure/azure-sdk-for-media-services.git - cd ./azure-sdk-for-media-services/ - -## .NET SDK - -### Prerequisites - -1. A Media Services account in a new or existing Windows Azure subscription. See the topic [How to Create a Media Services Account](http://www.windowsazure.com/en-us/manage/services/media-services/how-to-create-a-media-services-account/). -2. Operating Systems: Windows 7, Windows 2008 R2, or Windows 8. -3. .NET Framework 4.5. -4. Visual Studio 2012 or Visual Studio 2010 SP1 (Professional, Premium, Ultimate, or Express). - -### Building and Referencing the SDK - -To build sdk sources and tests type following commands: - - cd ./azure-sdk-for-media-services/ - msbuild ./SDK.Client.sln - - -### Running the Tests - -This set of test allows you to verify Windows Azure Media Services .Net SDK functionality using your existing Windows Azure Media Services account. Please check out [Test instruction](https://github.com/WindowsAzure/azure-sdk-for-media-services/tree/master/test) on how to use it. - - -## Need Help? - -Be sure to check out the Mobile Services [Developer Forum](http://social.msdn.microsoft.com/Forums/en-US/MediaServices/threads) if you are having trouble. The Media Services product team actively monitors the forum and will be more than happy to assist you. - -## Contribute Code or Provide Feedback - -If you would like to become an active contributor to this project please follow the instructions provided in [Windows Azure Projects Contribution Guidelines](http://windowsazure.github.com/guidelines.html). - -If you encounter any bugs with the library please file an issue in the [Issues](https://github.com/WindowsAzure/azure-media-services/issues) section of the project. - -## Learn More -[Windows Azure Media Services Developer Center](http://www.windowsazure.com/en-us/develop/media-services/) +## Getting Started + +If you are new to Media Services, you can get started by following our [tutorials](http://www.windowsazure.com/en-us/develop/media-services/tutorials/get-started/). You could be able to bring media into Azure, encoded it, package it into stream-able format and make it available for streaming. + +## Download Source Code + +To get the source code of our SDKs and samples via **git** just type: + + git clone https://github.com/WindowsAzure/azure-sdk-for-media-services.git + cd ./azure-sdk-for-media-services/ + +## .NET SDK + +### Prerequisites + +1. A Media Services account in a new or existing Windows Azure subscription. See the topic [How to Create a Media Services Account](http://www.windowsazure.com/en-us/manage/services/media-services/how-to-create-a-media-services-account/). +2. Operating Systems: Windows 7, Windows 2008 R2, or Windows 8. +3. .NET Framework 4.5. +4. Visual Studio 2012 or Visual Studio 2010 SP1 (Professional, Premium, Ultimate, or Express). + +### Building and Referencing the SDK + +To build sdk sources and tests type following commands: + + cd ./azure-sdk-for-media-services/ + msbuild ./SDK.Client.sln + + +### Running the Tests + +This set of test allows you to verify Windows Azure Media Services .Net SDK functionality using your existing Windows Azure Media Services account. Please check out [Test instruction](https://github.com/WindowsAzure/azure-sdk-for-media-services/tree/master/test) on how to use it. + + +## Need Help? + +Be sure to check out the Mobile Services [Developer Forum](http://social.msdn.microsoft.com/Forums/en-US/MediaServices/threads) if you are having trouble. The Media Services product team actively monitors the forum and will be more than happy to assist you. + +## Contribute Code or Provide Feedback + +If you would like to become an active contributor to this project please follow the instructions provided in [Windows Azure Projects Contribution Guidelines](http://windowsazure.github.com/guidelines.html). + +If you encounter any bugs with the library please file an issue in the [Issues](https://github.com/WindowsAzure/azure-media-services/issues) section of the project. + +## Learn More +[Windows Azure Media Services Developer Center](http://www.windowsazure.com/en-us/develop/media-services/) diff --git a/SDK.Client.sln b/SDK.Client.sln index 809688f0..4e76b643 100644 --- a/SDK.Client.sln +++ b/SDK.Client.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDK.Client", "src\net\Client\SDK.Client.csproj", "{E194B46E-9063-4CFA-85FC-51E5AAD55586}" EndProject @@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{ECC37A .nuget\NuGet.Config = .nuget\NuGet.Config .nuget\NuGet.exe = .nuget\NuGet.exe .nuget\NuGet.targets = .nuget\NuGet.targets + .nuget\windowsazure.mediaservices.nuspec = .nuget\windowsazure.mediaservices.nuspec EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDK.Client.Tests.Unit", "test\net\unit\SDK.Client.Tests.Unit.csproj", "{19DA48B7-6C3C-4B2C-8789-1CC9CCBDA4C7}" diff --git a/ci/AssemblyInfo.cs b/ci/AssemblyInfo.cs index 3d150b6d..d7042d39 100644 --- a/ci/AssemblyInfo.cs +++ b/ci/AssemblyInfo.cs @@ -47,8 +47,8 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("3.2.0.0")] -[assembly: AssemblyFileVersion("3.2.0.0")] +[assembly: AssemblyVersion("3.3.0.0")] +[assembly: AssemblyFileVersion("3.3.0.0")] [assembly: NeutralResourcesLanguage("en-US")] //For delay signing specify PublicKey for each friendly assembly diff --git a/ci/SignMedia.bat b/ci/SignMedia.bat index 3ae70278..379fd169 100644 --- a/ci/SignMedia.bat +++ b/ci/SignMedia.bat @@ -1,6 +1,24 @@ @echo off +echo Cleaning signed and packages directories +del /q c:\signing\signed\*.* +del /q c:\packages\*.* +echo Copying managed desktop library DLLs to signing source directory +copy /y .\Publish\Build\Release\Microsoft.WindowsAzure.MediaServices.Client.dll c:\signing\tosign\ +copy /y .\Publish\Build\Release\Microsoft.WindowsAzure.MediaServices.Client.Common.FileEncryption.dll c:\signing\tosign\ +copy /y .\Publish\Build\Release\Microsoft.WindowsAzure.MediaServices.Client.Common.BlobTransfer.dll c:\signing\tosign\ +if %ERRORLEVEL% neq 0 goto copyfailed +echo OK + +echo Signing managed desktop library DLLs... +%CI_SIGNING%\CodeSignUtility\csu.exe /c1=72 /c2=10006 "/d=.NET SDK" "/kw=MediaServices" +if %ERRORLEVEL% neq 0 goto signfailed +echo OK + +echo Removing all unsigned files from \\adksdksign\unsigned... +del /q c:\signing\tosign\*.* +echo OK echo Copying Media SDK signed managed DLLs and the pdbs to the final drop location... echo Creating \drop\WAMSSDK\lib\net45 diff --git a/src/net/Client/App.config b/src/net/Client/App.config index 567eabde..a9afbaae 100644 --- a/src/net/Client/App.config +++ b/src/net/Client/App.config @@ -10,23 +10,27 @@ + + + + - + - + - + diff --git a/src/net/Client/Common/Common.BlobTransfer/Properties/AssemblyInfo.cs b/src/net/Client/Common/Common.BlobTransfer/Properties/AssemblyInfo.cs index 00090e26..b0a5ce3a 100644 --- a/src/net/Client/Common/Common.BlobTransfer/Properties/AssemblyInfo.cs +++ b/src/net/Client/Common/Common.BlobTransfer/Properties/AssemblyInfo.cs @@ -49,8 +49,8 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.2.0.0")] -[assembly: AssemblyFileVersion("3.2.0.0")] +[assembly: AssemblyVersion("3.3.0.0")] +[assembly: AssemblyFileVersion("3.3.0.0")] [assembly: InternalsVisibleTo("Microsoft.WindowsAzure.MediaServices.Client.Tests.Scenario")] [assembly: InternalsVisibleTo("Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit")] [assembly: InternalsVisibleTo("Microsoft.WindowsAzure.MediaServices.Client.Tests.Common")] \ No newline at end of file diff --git a/src/net/Client/Common/Common.BlobTransfer/Properties/DelaySign_AssemblyInfo.cs b/src/net/Client/Common/Common.BlobTransfer/Properties/DelaySign_AssemblyInfo.cs index 582e7708..2e47ccd8 100644 --- a/src/net/Client/Common/Common.BlobTransfer/Properties/DelaySign_AssemblyInfo.cs +++ b/src/net/Client/Common/Common.BlobTransfer/Properties/DelaySign_AssemblyInfo.cs @@ -49,8 +49,8 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.2.0.0")] -[assembly: AssemblyFileVersion("3.2.0.0")] +[assembly: AssemblyVersion("3.3.0.0")] +[assembly: AssemblyFileVersion("3.3.0.0")] //For delay signing specify PublicKey for each friendly assembly [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.WindowsAzure.MediaServices.Client.Tests.Scenario, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] diff --git a/src/net/Client/Common/Common.BlobTransfer/SDK.Client.Common.BlobTransfer.csproj b/src/net/Client/Common/Common.BlobTransfer/SDK.Client.Common.BlobTransfer.csproj index a4222232..5c5cfd40 100644 --- a/src/net/Client/Common/Common.BlobTransfer/SDK.Client.Common.BlobTransfer.csproj +++ b/src/net/Client/Common/Common.BlobTransfer/SDK.Client.Common.BlobTransfer.csproj @@ -12,7 +12,9 @@ v4.0 512 - NOTSIGNED + NOTSIGNED + ..\..\..\..\..\ + true true @@ -39,19 +41,30 @@ true ..\..\..\..\..\MSSharedLibSN1024.snk - + + False + ..\..\..\..\..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll + + + False + ..\..\..\..\..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll + + + False + ..\..\..\..\..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll + + + False + ..\..\..\..\..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll + - - False - ..\..\..\..\..\packages\Microsoft.Data.Services.Client.5.6.3\lib\net40\Microsoft.Data.Services.Client.dll - False ..\..\..\..\..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll @@ -74,8 +87,8 @@ - - + + @@ -90,7 +103,20 @@ SDK.Client.Common.FileEncryption + + + Designer + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + + + + + + + diff --git a/test/net/Scenario/DynamicEncryption/GetKeyDeliveryUrlTests.cs b/test/net/Scenario/DynamicEncryption/GetKeyDeliveryUrlTests.cs index 828868f8..17635a45 100644 --- a/test/net/Scenario/DynamicEncryption/GetKeyDeliveryUrlTests.cs +++ b/test/net/Scenario/DynamicEncryption/GetKeyDeliveryUrlTests.cs @@ -16,16 +16,21 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Data.Services.Client; +using System.Globalization; using System.IdentityModel.Tokens; using System.Runtime.Serialization; +using System.Linq; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; +using Microsoft.IdentityModel.Clients.ActiveDirectory; using Microsoft.Practices.TransientFaultHandling; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.WindowsAzure.MediaServices.Client.ContentKeyAuthorization; using Microsoft.WindowsAzure.MediaServices.Client.Tests.Common; using Microsoft.WindowsAzure.MediaServices.Client.Tests.DynamicEncryption; +using AuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext; namespace Microsoft.WindowsAzure.MediaServices.Client.Tests { @@ -207,6 +212,113 @@ private void FetchKeyWithJWTAuth(string audience, string issuer) } } + [TestMethod] + public void GetHlsKeyDeliveryUrlAndFetchKeyWithADJWTAuthUsingADOpenConnectDiscovery() + { + // + // The Client ID is used by the application to uniquely identify itself to Azure AD. + // The App Key is a credential used by the application to authenticate to Azure AD. + // The Tenant is the name of the Azure AD tenant in which this application is registered. + // The AAD Instance is the instance of Azure, for example public Azure or Azure China. + // The Authority is the sign-in URL of the tenant. + // + string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"]; + string tenant = ConfigurationManager.AppSettings["ida:Tenant"]; + string clientId = ConfigurationManager.AppSettings["ida:ClientId"]; + string appKey = ConfigurationManager.AppSettings["ida:AppKey"]; + + string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant); + + // + // To authenticate to the To Do list service, the client needs to know the service's App ID URI. + // To contact the To Do list service we need it's URL as well. + // + string appResourceId = ConfigurationManager.AppSettings["app:AppResourceId"]; + + IContentKey contentKey = null; + IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = null; + IContentKeyAuthorizationPolicyOption policyOption = null; + + var authContext = new AuthenticationContext(authority); + var clientCredential = new ClientCredential(clientId, appKey); + + try + { + byte[] expectedKey = null; + contentKey = CreateTestKey(_mediaContext, ContentKeyType.EnvelopeEncryption, out expectedKey, "GetHlsKeyDeliveryUrlAndFetchKeyWithADJWTAuthUsingADOpenConnectDiscovery"+Guid.NewGuid().ToString()); + + TokenRestrictionTemplate tokenRestrictionTemplate = new TokenRestrictionTemplate(TokenType.JWT); + tokenRestrictionTemplate.OpenIdConnectDiscoveryDocument = new OpenIdConnectDiscoveryDocument("https://login.windows.net/common/.well-known/openid-configuration"); + var result = authContext.AcquireToken(appResourceId, clientCredential); + string jwtTokenString = result.AccessToken; + + JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler(); + Assert.IsTrue(handler.CanReadToken(jwtTokenString)); + JwtSecurityToken token = handler.ReadToken(jwtTokenString) as JwtSecurityToken; + Assert.IsNotNull(token); + + tokenRestrictionTemplate.Audience = token.Audiences.First(); + tokenRestrictionTemplate.Issuer = token.Issuer; + + string optionName = "GetHlsKeyDeliveryUrlAndFetchKeyWithJWTAuthentication"; + string requirements = TokenRestrictionTemplateSerializer.Serialize(tokenRestrictionTemplate); + policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, optionName, ContentKeyDeliveryType.BaselineHttp, requirements, null, ContentKeyRestrictionType.TokenRestricted); + + List options = new List + { + policyOption + }; + + contentKeyAuthorizationPolicy = CreateTestPolicy(_mediaContext, String.Empty, options, ref contentKey); + + Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp); + Assert.IsNotNull(keyDeliveryServiceUri); + + // Enable once all accounts are enabled for per customer Key Delivery Urls + //Assert.IsTrue(keyDeliveryServiceUri.Host.StartsWith(_mediaContext.Credentials.ClientId)); + + KeyDeliveryServiceClient keyClient = new KeyDeliveryServiceClient(RetryPolicy.DefaultFixed); + byte[] key = keyClient.AcquireHlsKeyWithBearerHeader(keyDeliveryServiceUri, jwtTokenString); + + string expectedString = GetString(expectedKey); + string fetchedString = GetString(key); + Assert.AreEqual(expectedString, fetchedString); + } + finally + { + CleanupKeyAndPolicy(contentKey, contentKeyAuthorizationPolicy, policyOption); + } + } + + [TestMethod] + public void FetchKeyWithRSATokenValidationKeyAsPrimaryVerificationKey() + { + + //Create a new RSACryptoServiceProvider object. + using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) + { + //Export the key information to an RSAParameters object. + //Pass false to export the public key information or pass + //true to export public and private key information. + RSAParameters RSAParams = RSA.ExportParameters(true); + + TokenRestrictionTemplate tokenRestrictionTemplate = new TokenRestrictionTemplate(TokenType.JWT); + + var tokenVerificationKey = new RsaTokenVerificationKey(); + tokenVerificationKey.InitFromRsaParameters(RSAParams); + tokenRestrictionTemplate.PrimaryVerificationKey = tokenVerificationKey; + + tokenRestrictionTemplate.Audience = "http://sampleIssuerUrl"; + tokenRestrictionTemplate.Issuer = "http://sampleAudience"; + string requirements = TokenRestrictionTemplateSerializer.Serialize(tokenRestrictionTemplate); + } + + + + + } + + [TestMethod] [TestCategory("ClientSDK")] [Owner("ClientSDK")] diff --git a/test/net/Scenario/Live/LiveE2ETests.cs b/test/net/Scenario/Live/LiveE2ETests.cs index 176b6807..edc6604b 100644 --- a/test/net/Scenario/Live/LiveE2ETests.cs +++ b/test/net/Scenario/Live/LiveE2ETests.cs @@ -88,23 +88,23 @@ public void StreamingEndpointCrossDomain() var clientPolicy = @" - - - - - - - - - - - - "; + + + + + + + + + + + + "; var xdomainPolicy = @" - - - "; + + + "; streamingEndpoint.CrossSiteAccessPolicies.ClientAccessPolicy = clientPolicy; streamingEndpoint.CrossSiteAccessPolicies.CrossDomainPolicy = xdomainPolicy; @@ -127,24 +127,24 @@ public void ChannelCrossDomain() string clientPolicy = @" - - - - - - - - - - - - "; + + + + + + + + + + + + "; string xdomainPolicy = @" - - - "; + + + "; channel.CrossSiteAccessPolicies = new CrossSiteAccessPolicies { diff --git a/test/net/Scenario/Live/LiveTranscodingTest.cs b/test/net/Scenario/Live/LiveTranscodingTest.cs index dec7f349..d54789d5 100644 --- a/test/net/Scenario/Live/LiveTranscodingTest.cs +++ b/test/net/Scenario/Live/LiveTranscodingTest.cs @@ -58,10 +58,10 @@ public void LiveEncodingChannelShowSlateTest() channel.HideSlate(); channel.StartAdvertisement(TimeSpan.FromMinutes(10), 1000); - channel.EndAdvertisement(); + channel.EndAdvertisement(1000); - channel.StartAdvertisement(TimeSpan.FromMinutes(10), 1000, false); - channel.EndAdvertisement(); + channel.StartAdvertisement(TimeSpan.FromMinutes(10), 1001, false); + channel.EndAdvertisement(1001); } finally { diff --git a/test/net/Scenario/OpenIDConnectDiscoveryDocumentTest.cs b/test/net/Scenario/OpenIDConnectDiscoveryDocumentTest.cs new file mode 100644 index 00000000..3804d021 --- /dev/null +++ b/test/net/Scenario/OpenIDConnectDiscoveryDocumentTest.cs @@ -0,0 +1,66 @@ +//----------------------------------------------------------------------- +// Copyright 2012 Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.MediaServices.Client.ContentKeyAuthorization; +using Microsoft.IdentityModel.Protocols; +using System.IdentityModel.Tokens; +using System.Collections.Generic; + +namespace Microsoft.WindowsAzure.MediaServices.Client.Tests +{ + [TestClass] + public class OpenIDConnectDiscoveryDocumentTest + { + private const string googleOpenConectDiscoveryUri = "https://accounts.google.com/.well-known/openid-configuration"; + private const string adOpenConectDiscoveryUri = "https://login.windows.net/common/.well-known/openid-configuration"; + + [TestMethod] + public void FetchGooleJWKKeysAndUseIdentityExtensions() + { + + GetAndVerifyJsonWebKeys(googleOpenConectDiscoveryUri); + + + } + [TestMethod] + public void FetchMicrosoftJWKKeysAndUseIdentityExtensions() + { + GetAndVerifyJsonWebKeys(adOpenConectDiscoveryUri); + + } + + private static IList GetAndVerifyJsonWebKeys(string uri) + { + Microsoft.IdentityModel.Protocols.JsonWebKey key = new IdentityModel.Protocols.JsonWebKey(); + Microsoft.IdentityModel.Protocols.OpenIdConnectConfiguration config; + System.Threading.CancellationTokenSource src = new System.Threading.CancellationTokenSource(); + config = Microsoft.IdentityModel.Protocols.OpenIdConnectConfigurationRetriever.GetAsync(uri, src.Token).Result; + JsonWebKeySet keyset = config.JsonWebKeySet; + Assert.IsNotNull(keyset); + Assert.IsNotNull(keyset.GetSigningTokens()); + return keyset.GetSigningTokens(); + } + + + + + + + } +} \ No newline at end of file diff --git a/test/net/Scenario/Properties/AssemblyInfo.cs b/test/net/Scenario/Properties/AssemblyInfo.cs index f7d561a6..133e1135 100644 --- a/test/net/Scenario/Properties/AssemblyInfo.cs +++ b/test/net/Scenario/Properties/AssemblyInfo.cs @@ -30,5 +30,5 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("3.2.0.0")] -[assembly: AssemblyFileVersion("3.2.0.0")] +[assembly: AssemblyVersion("3.3.0.0")] +[assembly: AssemblyFileVersion("3.3.0.0")] diff --git a/test/net/Scenario/Properties/SlowCheetah/SlowCheetah.Transforms.targets b/test/net/Scenario/Properties/SlowCheetah/SlowCheetah.Transforms.targets index 462c8fc7..c5ab154d 100644 --- a/test/net/Scenario/Properties/SlowCheetah/SlowCheetah.Transforms.targets +++ b/test/net/Scenario/Properties/SlowCheetah/SlowCheetah.Transforms.targets @@ -16,13 +16,13 @@ Copyright (C) Sayed Ibrahim Hashimi, Chuck England 2011-2013. All rights reserve $(LocalAppData)\Microsoft\MSBuild\SlowCheetah\v2.5.11\ - + $(MSBuildThisFileDirectory) - + $(sc-MSBuildLibPathLocal) - + $(SlowCheetahToolsPath) @@ -57,7 +57,7 @@ Copyright (C) Sayed Ibrahim Hashimi, Chuck England 2011-2013. All rights reserve - @@ -146,13 +146,26 @@ Copyright (C) Sayed Ibrahim Hashimi, Chuck England 2011-2013. All rights reserve <_Sc_HasAppConfigTransform>false - <_Sc_HasAppConfigTransform Condition=" Exists( '@(_AppConfigToTransform->'%(RelativeDir)%(Filename).$(Configuration)%(Extension)')' ) ">true + <_Sc_HasAppConfigConfigurationTransform Condition=" Exists( '@(_AppConfigToTransform->'%(RelativeDir)%(Filename).$(Configuration)%(Extension)')' ) ">true + <_Sc_HasAppConfigPublishProfileTransform Condition=" Exists( '@(_AppConfigToTransform->'%(RelativeDir)%(Filename).$(PublishProfile)%(Extension)')' ) ">true + <_Sc_HasAppConfigPublishProfileTransform Condition=" '$(Configuration)'=='$(PublishProfile)' ">false + <_Sc_HasAppConfigTransform Condition=" '$(_Sc_HasAppConfigConfigurationTransform)'=='true' ">true + <_Sc_HasAppConfigTransform Condition=" '$(_Sc_HasAppConfigPublishProfileTransform)'=='true' ">true - + + + + Condition=" '$(_Sc_HasAppConfigConfigurationTransform)'=='true' " /> + + $(__SC_IntermediateAppConfig) diff --git a/test/net/Scenario/SDK.Client.Tests.Scenario.csproj b/test/net/Scenario/SDK.Client.Tests.Scenario.csproj index 8520c1fe..87bf35d9 100644 --- a/test/net/Scenario/SDK.Client.Tests.Scenario.csproj +++ b/test/net/Scenario/SDK.Client.Tests.Scenario.csproj @@ -92,12 +92,6 @@ true ..\..\..\MSSharedLibSN1024.snk - - $([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\..\..\..\packages\SlowCheetah.2.5.12\tools\)) - true - $([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\Properties\SlowCheetah\SlowCheetah.Transforms.targets )) - $(SlowCheetah_NuGetImportPath) - bin\LKG\ false @@ -140,7 +134,12 @@ \Build\NimbusFXCopRules.ruleset false - + + $([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\..\..\..\packages\SlowCheetah.2.5.14\tools\)) + true + $([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\Properties\SlowCheetah\SlowCheetah.Transforms.targets )) + $(SlowCheetah_NuGetImportPath) + False @@ -165,16 +164,14 @@ - - - + @@ -298,17 +295,29 @@ - + + False + ..\..\..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll + + False - ..\..\..\packages\Microsoft.Data.Edm.5.6.3\lib\net40\Microsoft.Data.Edm.dll + ..\..\..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll - + False - ..\..\..\packages\Microsoft.Data.OData.5.6.3\lib\net40\Microsoft.Data.OData.dll + ..\..\..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll - + False - ..\..\..\packages\Microsoft.Data.Services.Client.5.6.3\lib\net40\Microsoft.Data.Services.Client.dll + ..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.16.204221202\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + + False + ..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.16.204221202\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll + + + ..\..\..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.205111437\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll + True ..\..\..\packages\TransientFaultHandling.Core.5.1.1209.1\lib\NET4\Microsoft.Practices.TransientFaultHandling.Core.dll @@ -320,23 +329,26 @@ False ..\..\..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll - - ..\..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll + + False + ..\..\..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll - + False - ..\..\..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll + ..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll + - - ..\..\..\packages\System.IdentityModel.Tokens.Jwt.4.0.1\lib\net45\System.IdentityModel.Tokens.Jwt.dll + + ..\..\..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.205111437\lib\net45\System.IdentityModel.Tokens.Jwt.dll + True - + False - ..\..\..\packages\System.Spatial.5.6.3\lib\net40\System.Spatial.dll + ..\..\..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll diff --git a/test/net/Scenario/packages.config b/test/net/Scenario/packages.config index 3b878d5c..49948a19 100644 --- a/test/net/Scenario/packages.config +++ b/test/net/Scenario/packages.config @@ -1,14 +1,15 @@  - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/test/net/common/Properties/AssemblyInfo.cs b/test/net/common/Properties/AssemblyInfo.cs index 88a6d3e5..6a95c204 100644 --- a/test/net/common/Properties/AssemblyInfo.cs +++ b/test/net/common/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("3.3.0.0")] +[assembly: AssemblyFileVersion("3.3.0.0")] diff --git a/test/net/common/SDK.Client.Tests.Common.csproj b/test/net/common/SDK.Client.Tests.Common.csproj index af0d6463..92c66872 100644 --- a/test/net/common/SDK.Client.Tests.Common.csproj +++ b/test/net/common/SDK.Client.Tests.Common.csproj @@ -56,17 +56,17 @@ false - + False - ..\..\..\packages\Microsoft.Data.Edm.5.6.3\lib\net40\Microsoft.Data.Edm.dll + ..\..\..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll - + False - ..\..\..\packages\Microsoft.Data.OData.5.6.3\lib\net40\Microsoft.Data.OData.dll + ..\..\..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll - + False - ..\..\..\packages\Microsoft.Data.Services.Client.5.6.3\lib\net40\Microsoft.Data.Services.Client.dll + ..\..\..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll ..\..\..\packages\TransientFaultHandling.Core.5.1.1209.1\lib\NET4\Microsoft.Practices.TransientFaultHandling.Core.dll @@ -76,19 +76,20 @@ False ..\..\..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll - - ..\..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll + + False + ..\..\..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll - + False - ..\..\..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll + ..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll - + False - ..\..\..\packages\System.Spatial.5.6.3\lib\net40\System.Spatial.dll + ..\..\..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll @@ -120,6 +121,7 @@ + diff --git a/test/net/common/TestMediaServicesClassFactory.cs b/test/net/common/TestMediaServicesClassFactory.cs index 2bbf79b6..745121f6 100644 --- a/test/net/common/TestMediaServicesClassFactory.cs +++ b/test/net/common/TestMediaServicesClassFactory.cs @@ -102,22 +102,22 @@ public static Mock CreateLoadPropertyMockConnectionClo public override BlobTransferClient GetBlobTransferClient() { Mock mock = new Mock(default(TimeSpan)); - mock.Setup(c => c.UploadBlob( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny>())) - .Returns((Uri url, - string localFile, - string contentType, - FileEncryption fileEncryption, - CancellationToken cancellationToken, - IRetryPolicy retryPolicy, - Func sharedAccessSignature - ) => Task.Factory.StartNew(() => + mock.Setup(c => c.UploadBlob( + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny>())) + .Returns((Uri url, + string localFile, + string contentType, + FileEncryption fileEncryption, + CancellationToken cancellationToken, + IRetryPolicy retryPolicy, + Func sharedAccessSignature + ) => Task.Factory.StartNew(() => { FileInfo info = new FileInfo(localFile); if (fileEncryption != null) @@ -132,27 +132,27 @@ Func sharedAccessSignature } })); mock.Setup(c => c.DownloadBlob( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny>() - )).Returns(() => Task.Factory.StartNew(() => { })); + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny>() + )).Returns(() => Task.Factory.StartNew(() => { })); mock.Setup(c => c.DownloadBlob( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny>(), - It.IsAny(), - It.IsAny() - )).Returns(() => Task.Factory.StartNew(() => { })); + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny>(), + It.IsAny(), + It.IsAny() + )).Returns(() => Task.Factory.StartNew(() => { })); return mock.Object; } diff --git a/test/net/common/app.config b/test/net/common/app.config new file mode 100644 index 00000000..cac0a55e --- /dev/null +++ b/test/net/common/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/net/common/packages.config b/test/net/common/packages.config index 101798c9..fff39d21 100644 --- a/test/net/common/packages.config +++ b/test/net/common/packages.config @@ -1,11 +1,11 @@  - - - - - - + + + + + + \ No newline at end of file diff --git a/test/net/stress/SDK.Client.Tests.Stress.csproj b/test/net/stress/SDK.Client.Tests.Stress.csproj index b4f083d3..5b917be9 100644 --- a/test/net/stress/SDK.Client.Tests.Stress.csproj +++ b/test/net/stress/SDK.Client.Tests.Stress.csproj @@ -55,17 +55,17 @@ MinimumRecommendedRules.ruleset - + False - ..\..\..\packages\Microsoft.Data.Edm.5.6.3\lib\net40\Microsoft.Data.Edm.dll + ..\..\..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll - + False - ..\..\..\packages\Microsoft.Data.OData.5.6.3\lib\net40\Microsoft.Data.OData.dll + ..\..\..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll - + False - ..\..\..\packages\Microsoft.Data.Services.Client.5.6.3\lib\net40\Microsoft.Data.Services.Client.dll + ..\..\..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll @@ -146,9 +146,9 @@ - + False - ..\..\..\packages\System.Spatial.5.6.3\lib\net40\System.Spatial.dll + ..\..\..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll diff --git a/test/net/stress/app.config b/test/net/stress/app.config index 993d8bb5..b93ed96d 100644 --- a/test/net/stress/app.config +++ b/test/net/stress/app.config @@ -10,23 +10,27 @@ + + + + - + - + - + diff --git a/test/net/stress/packages.config b/test/net/stress/packages.config index 9a39241c..978a3974 100644 --- a/test/net/stress/packages.config +++ b/test/net/stress/packages.config @@ -1,5 +1,9 @@  + + + + \ No newline at end of file diff --git a/test/net/unit/AssetEncryptionStateUnitTests.cs b/test/net/unit/AssetEncryptionStateUnitTests.cs index 415a77ca..9f36fd06 100644 --- a/test/net/unit/AssetEncryptionStateUnitTests.cs +++ b/test/net/unit/AssetEncryptionStateUnitTests.cs @@ -12,22 +12,15 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -// - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.WindowsAzure.MediaServices.Client.DynamicEncryption; -using Microsoft.WindowsAzure.MediaServices.Client.Tests.Common; -using Moq; - +// + +using System; +using System.IO; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.MediaServices.Client.DynamicEncryption; +using Microsoft.WindowsAzure.MediaServices.Client.Tests.Common; + namespace Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit { [TestClass] diff --git a/test/net/unit/CacheTest.cs b/test/net/unit/CacheTest.cs index e44bd53b..452a259d 100644 --- a/test/net/unit/CacheTest.cs +++ b/test/net/unit/CacheTest.cs @@ -15,6 +15,7 @@ // using System; +using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit @@ -44,7 +45,7 @@ public void CacheAfterExpiration() { var target = new Cache(); target.GetOrAdd("k", () => "v1", () => DateTime.UtcNow.AddMilliseconds(100)); - System.Threading.Thread.Sleep(1000); + Thread.Sleep(1000); var actual = target.GetOrAdd("k", () => "v2", () => DateTime.UtcNow.AddMilliseconds(100)); Assert.AreEqual("v2", actual); } diff --git a/test/net/unit/Live/ChannelDataTest.cs b/test/net/unit/Live/ChannelDataTest.cs index 5cc276f2..6d826b12 100644 --- a/test/net/unit/Live/ChannelDataTest.cs +++ b/test/net/unit/Live/ChannelDataTest.cs @@ -20,7 +20,7 @@ using System.Net; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace Microsoft.WindowsAzure.MediaServices.Client.Live.UnitTests +namespace Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit.Live { [TestClass] public class ChannelDataTest @@ -83,7 +83,7 @@ public void LiveEncodingUrlTest() target.ShowSlateAsync(TimeSpan.FromMinutes(5), Guid.NewGuid().ToString()); target.HideSlateAsync(); target.StartAdvertisementAsync(TimeSpan.FromMinutes(10), 100, false); - target.EndAdvertisementAsync(); + target.EndAdvertisementAsync(100); } /// diff --git a/test/net/Scenario/Live/OperationTests.cs b/test/net/unit/Live/OperationTests.cs similarity index 94% rename from test/net/Scenario/Live/OperationTests.cs rename to test/net/unit/Live/OperationTests.cs index 5cb6832f..8053b916 100644 --- a/test/net/Scenario/Live/OperationTests.cs +++ b/test/net/unit/Live/OperationTests.cs @@ -20,7 +20,7 @@ using Microsoft.WindowsAzure.MediaServices.Client.Tests.Common; using Moq; -namespace Microsoft.WindowsAzure.MediaServices.Client.Tests +namespace Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit.Live { @@ -35,7 +35,7 @@ public class OperationTests [TestInitialize] public void SetupTest() { - _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext(); + _mediaContext = Helper.GetMediaDataServiceContextForUnitTests(); } /// diff --git a/test/net/Scenario/Live/ProgramTests.cs b/test/net/unit/Live/ProgramTests.cs similarity index 60% rename from test/net/Scenario/Live/ProgramTests.cs rename to test/net/unit/Live/ProgramTests.cs index f604e1b5..6ddc3612 100644 --- a/test/net/Scenario/Live/ProgramTests.cs +++ b/test/net/unit/Live/ProgramTests.cs @@ -16,20 +16,22 @@ using System; using System.Net; +using System.Web.UI.WebControls; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.WindowsAzure.MediaServices.Client.Tests.Common; using Moq; -namespace Microsoft.WindowsAzure.MediaServices.Client.Tests +namespace Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit.Live { [TestClass] public class ProgramTests { private CloudMediaContext _mediaContext; + [TestInitialize] public void SetupTest() { - _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext(); + _mediaContext = Helper.GetMediaDataServiceContextForUnitTests(); } #region Retry Logic tests @@ -37,6 +39,7 @@ public void SetupTest() [TestCategory("ClientSDK")] [Owner("ClientSDK")] [Priority(0)] + [TestMethod()] public void TestProgramCreateRetryAsyn() { var expected = new ProgramData { Name = "testData" }; @@ -57,6 +60,36 @@ public void TestProgramCreateRetryAsyn() dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny()), Times.Exactly(2)); } + [TestCategory("ClientSDK")] + [Owner("ClientSDK")] + [Priority(0)] + [TestMethod()] + [ExpectedException(typeof(AggregateException))] + public void TestProgramCreateRetryAsyncAndFailed() + { + var expected = new ProgramData { Name = "testData" }; + var fakeException = new WebException("test", WebExceptionStatus.Timeout); + var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 100, expected); + + dataContextMock.Setup((ctxt) => ctxt.AddObject("Channels", It.IsAny())); + + _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object); + + IChannel channel = new ChannelData(); + ProgramBaseCollection programs = new ProgramBaseCollection(_mediaContext, channel); + + try + { + var actual = programs.CreateAsync(expected.Name, TimeSpan.FromHours(1), Guid.NewGuid().ToString()).Result; + + } + catch (AggregateException) + { + dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny()), Times.AtLeast(2)); + throw; + } + } + #endregion Retry Logic tests } } \ No newline at end of file diff --git a/test/net/Scenario/Live/RestEntityTests.cs b/test/net/unit/Live/RestEntityTests.cs similarity index 88% rename from test/net/Scenario/Live/RestEntityTests.cs rename to test/net/unit/Live/RestEntityTests.cs index 6aeaaeac..ec7489a3 100644 --- a/test/net/Scenario/Live/RestEntityTests.cs +++ b/test/net/unit/Live/RestEntityTests.cs @@ -20,45 +20,17 @@ using Microsoft.WindowsAzure.MediaServices.Client.Tests.Common; using Moq; -namespace Microsoft.WindowsAzure.MediaServices.Client.Tests +namespace Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit.Live { - class TestRestEntity : RestEntity - { - public TestRestEntity(MediaContextBase context) - { - SetMediaContext(context); - } - - public void ExecuteActionAsyncTest() - { - ExecuteActionAsync(new Uri("http://whatever"), TimeSpan.FromMilliseconds(1)).Wait(); - } - - public void RefreshTest() - { - Refresh(); - } - - public IOperation SendOperationTest() - { - return SendOperation(new Uri("http://whatever")); - } - - protected override string EntitySetName - { - get { return "StreamingEndpoints"; } - } - } - [TestClass] - [Ignore] //TODO: enable when the streaming endpoint is deployed in the test environment + public class RestEntityTests { private CloudMediaContext _mediaContext; [TestInitialize] public void SetupTest() { - _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext(); + _mediaContext = Helper.GetMediaDataServiceContextForUnitTests(); } #region Retry Logic tests diff --git a/test/net/unit/Live/TestRestEntity.cs b/test/net/unit/Live/TestRestEntity.cs new file mode 100644 index 00000000..dfae3c4f --- /dev/null +++ b/test/net/unit/Live/TestRestEntity.cs @@ -0,0 +1,32 @@ +using System; + +namespace Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit.Live +{ + class TestRestEntity : RestEntity + { + public TestRestEntity(MediaContextBase context) + { + SetMediaContext(context); + } + + public void ExecuteActionAsyncTest() + { + ExecuteActionAsync(new Uri("http://whatever"), TimeSpan.FromMilliseconds(1)).Wait(); + } + + public void RefreshTest() + { + Refresh(); + } + + public IOperation SendOperationTest() + { + return SendOperation(new Uri("http://whatever")); + } + + protected override string EntitySetName + { + get { return "StreamingEndpoints"; } + } + } +} \ No newline at end of file diff --git a/test/net/unit/OpenIDConnectDiscoveryDocumentTest.cs b/test/net/unit/OpenIDConnectDiscoveryDocumentTest.cs new file mode 100644 index 00000000..370a2490 --- /dev/null +++ b/test/net/unit/OpenIDConnectDiscoveryDocumentTest.cs @@ -0,0 +1,183 @@ +//----------------------------------------------------------------------- +// Copyright 2012 Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +using System; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Cryptography; +using System.Security.Cryptography.X509Certificates; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.MediaServices.Client.ContentKeyAuthorization; +using Moq; +using Microsoft.IdentityModel.Protocols; +using System.Threading; +using System.Threading.Tasks; +using System.IO; + +namespace Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit +{ + [TestClass] + public class OpenIDConnectDiscoveryDocumentTest + { + + [TestMethod] + public void FetchJWKKeyAsRSATokenVerificationKey() + { + string keysResponse = @"{ + ""keys"": [ + { + ""kty"": ""RSA"", + ""alg"": ""RS256"", + ""use"": ""sig"", + ""kid"": ""d83ad1bbaac388a4dcb4957e53282a0e7d0bf98a"", + ""n"": ""temCVy5oxWCEUwHUqGXxvHnySlaZtT_JmHm0zICxsanboYss-b3nOqIXN45L5TyTiNbOBgE6vge2TfIjo_NqXBiKjRNl_g7F4iwl07p2abn3KQ6mgYDlFMhJJOXG4-0dMORBgi3hQi8VajLHJ04FoorZsf__FDb1gvvnPObUQwM="", + ""e"": ""AQAB"" + } + ] + }"; + + JsonWebKey jsonWebKey = FetchAndValidateJsonWebKeyWithCommonProperties(keysResponse); + Assert.AreEqual(0,jsonWebKey.X5c.Count, "x5c should not contain elements "); + Assert.IsNull(jsonWebKey.X5t, "x5t field should be null"); + + RsaTokenVerificationKey tokenVerificationKey = jsonWebKey.AsTokenVerificationKey() as RsaTokenVerificationKey; + Assert.IsNotNull(tokenVerificationKey); + RSAParameters parameters = tokenVerificationKey.GetRsaParameters(); + Assert.IsNotNull(parameters); + Assert.IsNotNull(parameters.Modulus); + Assert.IsNotNull(parameters.Exponent); + } + + [TestMethod] + public void FetchAsTokenVerificationKey() + { + string keysResponse = @"{ + ""keys"": [ + { + ""kty"": ""RSA"", + ""alg"": ""RS256"", + ""use"": ""sig"", + ""kid"": ""d83ad1bbaac388a4dcb4957e53282a0e7d0bf98a"", + ""n"": ""temCVy5oxWCEUwHUqGXxvHnySlaZtT_JmHm0zICxsanboYss-b3nOqIXN45L5TyTiNbOBgE6vge2TfIjo_NqXBiKjRNl_g7F4iwl07p2abn3KQ6mgYDlFMhJJOXG4-0dMORBgi3hQi8VajLHJ04FoorZsf__FDb1gvvnPObUQwM="", + ""e"": ""AQAB"" + } + ] + }"; + + Assert.IsNotNull(FetchAndValidateJsonWebKeyWithCommonProperties(keysResponse).AsTokenVerificationKey()); + + + } + + private static JsonWebKey FetchAndValidateJsonWebKeyWithCommonProperties(string keysResponse) + { + + + Microsoft.IdentityModel.Protocols.OpenIdConnectConfiguration config; + System.Threading.CancellationTokenSource src = new System.Threading.CancellationTokenSource(); + TestDocumentRetriever retriver = new TestDocumentRetriever("{\"jwks_uri\": \"secondary\"}", keysResponse); + + config = OpenIdConnectConfigurationRetriever.GetAsync("primary",retriver as IDocumentRetriever, src.Token).Result; + + Assert.IsNotNull(config.JsonWebKeySet); + Assert.IsNotNull(config.JsonWebKeySet.Keys); + Assert.AreEqual(1, config.JsonWebKeySet.Keys.Count); + JsonWebKey jsonWebKey = config.JsonWebKeySet.Keys.ToList()[0]; + ValidateCommonJWKProperties(jsonWebKey); + return jsonWebKey; + } + + private static void ValidateCommonJWKProperties(JsonWebKey jsonWebKey) + { + Assert.IsNotNull(jsonWebKey.Kid); + Assert.IsNotNull(jsonWebKey.Kty); + Assert.IsNotNull(jsonWebKey.E); + Assert.IsNotNull(jsonWebKey.N); + Assert.AreEqual("sig", jsonWebKey.Use); + } + + + + [TestMethod] + public void FetchJWKKeyAsX509TokenVerificationKey() + { + string keysResponse = @" + { + ""keys"": + [ + { + ""kty"":""RSA"", + ""use"":""sig"", + ""kid"":""kriMPdmBvx68skT8-mPAB3BseeA"", + ""x5t"":""kriMPdmBvx68skT8-mPAB3BseeA"", + ""n"":""kSCWg6q9iYxvJE2NIhSyOiKvqoWCO2GFipgH0sTSAs5FalHQosk9ZNTztX0ywS/AHsBeQPqYygfYVJL6/EgzVuwRk5txr9e3n1uml94fLyq/AXbwo9yAduf4dCHTP8CWR1dnDR+Qnz/4PYlWVEuuHHONOw/blbfdMjhY+C/BYM2E3pRxbohBb3x//CfueV7ddz2LYiH3wjz0QS/7kjPiNCsXcNyKQEOTkbHFi3mu0u13SQwNddhcynd/GTgWN8A+6SN1r4hzpjFKFLbZnBt77ACSiYx+IHK4Mp+NaVEi5wQtSsjQtI++XsokxRDqYLwus1I1SihgbV/STTg5enufuw=="", + ""e"":""AQAB"", + ""x5c"":[""MIIDPjCCAiqgAwIBAgIQsRiM0jheFZhKk49YD0SK1TAJBgUrDgMCHQUAMC0xKzApBgNVBAMTImFjY291bnRzLmFjY2Vzc2NvbnRyb2wud2luZG93cy5uZXQwHhcNMTQwMTAxMDcwMDAwWhcNMTYwMTAxMDcwMDAwWjAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3MubmV0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkSCWg6q9iYxvJE2NIhSyOiKvqoWCO2GFipgH0sTSAs5FalHQosk9ZNTztX0ywS/AHsBeQPqYygfYVJL6/EgzVuwRk5txr9e3n1uml94fLyq/AXbwo9yAduf4dCHTP8CWR1dnDR+Qnz/4PYlWVEuuHHONOw/blbfdMjhY+C/BYM2E3pRxbohBb3x//CfueV7ddz2LYiH3wjz0QS/7kjPiNCsXcNyKQEOTkbHFi3mu0u13SQwNddhcynd/GTgWN8A+6SN1r4hzpjFKFLbZnBt77ACSiYx+IHK4Mp+NaVEi5wQtSsjQtI++XsokxRDqYLwus1I1SihgbV/STTg5enufuwIDAQABo2IwYDBeBgNVHQEEVzBVgBDLebM6bK3BjWGqIBrBNFeNoS8wLTErMCkGA1UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldIIQsRiM0jheFZhKk49YD0SK1TAJBgUrDgMCHQUAA4IBAQCJ4JApryF77EKC4zF5bUaBLQHQ1PNtA1uMDbdNVGKCmSf8M65b8h0NwlIjGGGy/unK8P6jWFdm5IlZ0YPTOgzcRZguXDPj7ajyvlVEQ2K2ICvTYiRQqrOhEhZMSSZsTKXFVwNfW6ADDkN3bvVOVbtpty+nBY5UqnI7xbcoHLZ4wYD251uj5+lo13YLnsVrmQ16NCBYq2nQFNPuNJw6t3XUbwBHXpF46aLT1/eGf/7Xx6iy8yPJX4DyrpFTutDz882RWofGEO5t4Cw+zZg70dJ/hH/ODYRMorfXEW+8uKmXMKmX2wyxMKvfiPbTy5LmAU8Jvjs2tLg4rOBcXWLAIarZ""] + } + ] + }"; + + JsonWebKey jsonWebKey = FetchAndValidateJsonWebKeyWithCommonProperties(keysResponse); + + X509CertTokenVerificationKey tokenVerificationKey = jsonWebKey.AsTokenVerificationKey() as X509CertTokenVerificationKey; + Assert.IsNotNull(tokenVerificationKey); + Assert.IsNotNull(jsonWebKey.X5c); + Assert.IsNotNull(jsonWebKey.X5t); + X509Certificate2 cert = tokenVerificationKey.X509Certificate2; + Assert.IsNotNull(cert); + + } + + private class TestDocumentRetriever : IDocumentRetriever + { + private string _primaryDocument; + private string _secondaryDocument; + private IDocumentRetriever _fallback; + + public TestDocumentRetriever(string primaryDocument, string secondaryDocument) + { + _primaryDocument = primaryDocument; + _secondaryDocument = secondaryDocument; + } + + public TestDocumentRetriever(string primaryDocument, IDocumentRetriever fallback) + { + _primaryDocument = primaryDocument; + _fallback = fallback; + } + + public Task GetDocumentAsync(string address, CancellationToken cancel) + { + if (string.Equals("primary", address)) + { + return Task.FromResult(_primaryDocument); + } + if (string.Equals("secondary", address) && !string.IsNullOrWhiteSpace(_secondaryDocument)) + { + return Task.FromResult(_secondaryDocument); + } + if (_fallback != null) + { + return _fallback.GetDocumentAsync(address, cancel); + } + throw new IOException("Document not found: " + address); + } + } + } + +} \ No newline at end of file diff --git a/test/net/unit/Properties/AssemblyInfo.cs b/test/net/unit/Properties/AssemblyInfo.cs index 62ba18b9..a7bb88a8 100644 --- a/test/net/unit/Properties/AssemblyInfo.cs +++ b/test/net/unit/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.2.0.0")] -[assembly: AssemblyFileVersion("3.2.0.0")] +[assembly: AssemblyVersion("3.3.0.0")] +[assembly: AssemblyFileVersion("3.3.0.0")] diff --git a/test/net/unit/SDK.Client.Tests.Unit.csproj b/test/net/unit/SDK.Client.Tests.Unit.csproj index 8f70a523..d5f8af29 100644 --- a/test/net/unit/SDK.Client.Tests.Unit.csproj +++ b/test/net/unit/SDK.Client.Tests.Unit.csproj @@ -61,17 +61,21 @@ false - - ..\..\..\packages\Microsoft.Data.Edm.5.6.3\lib\net40\Microsoft.Data.Edm.dll - True + + False + ..\..\..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll - - ..\..\..\packages\Microsoft.Data.OData.5.6.3\lib\net40\Microsoft.Data.OData.dll - True + + False + ..\..\..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll - + False - ..\..\..\packages\Microsoft.Data.Services.Client.5.6.3\lib\net40\Microsoft.Data.Services.Client.dll + ..\..\..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll + + + ..\..\..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.205111437\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll + True False @@ -82,20 +86,24 @@ True - ..\..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll - True + ..\..\..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll - False - ..\..\..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll + ..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll - - - ..\..\..\packages\System.Spatial.5.6.3\lib\net40\System.Spatial.dll + + ..\..\..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.205111437\lib\net45\System.IdentityModel.Tokens.Jwt.dll True + + + + + False + ..\..\..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll + @@ -114,11 +122,16 @@ + + + + + @@ -173,11 +186,11 @@ - \ No newline at end of file diff --git a/test/net/unit/TokenRestrictionTemplateSerializerTests.cs b/test/net/unit/TokenRestrictionTemplateSerializerTests.cs index 8a46ebf4..d84bc8ff 100644 --- a/test/net/unit/TokenRestrictionTemplateSerializerTests.cs +++ b/test/net/unit/TokenRestrictionTemplateSerializerTests.cs @@ -20,6 +20,7 @@ using System.Runtime.Serialization; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.WindowsAzure.MediaServices.Client.ContentKeyAuthorization; +using System.Security.Cryptography; namespace Microsoft.WindowsAzure.MediaServices.Client.Tests.Unit { @@ -117,6 +118,7 @@ public void InputMissingAudienceShouldThrow() } [TestMethod] + [ExpectedException(typeof(InvalidDataContractException))] public void InputMissingPrimaryKeyShouldThrow() { string tokenTemplate = "GG07fDPZ+HMD2vcoknMqYjEJMb7LSq8zUmdCYMvRCevnQK//ilbhODO/FydMrHiwZGmI6XywvOOU7SSzRPlI3Q==http://sampleaudience/http://sampleissuerurl/urn:microsoft:azure:mediaservices:contentkeyidentifierurn:myservice:claims:rentaltrue"; @@ -126,9 +128,10 @@ public void InputMissingPrimaryKeyShouldThrow() TokenRestrictionTemplate template = TokenRestrictionTemplateSerializer.Deserialize(tokenTemplate); Assert.Fail("Should throw"); } - catch (SerializationException e) - { - Assert.IsTrue(e.Message.Contains("Expecting element 'PrimaryVerificationKey'.")); + catch (InvalidDataContractException e) + { + Assert.IsTrue(e.Message.Contains("Both PrimaryVerificationKey and OpenIdConnectDiscoveryDocument are null")); + throw; } } @@ -140,6 +143,166 @@ public void InputMissingRequiredClaimsOkay() TokenRestrictionTemplate template = TokenRestrictionTemplateSerializer.Deserialize(tokenTemplate); Assert.IsNotNull(template); Assert.AreEqual(TokenType.SWT, template.TokenType); + } + + [TestMethod] + [ExpectedException(typeof(InvalidDataContractException))] + public void TokenRestrictionTemplateDeserializeNilOpenConnectIdDocumentNoPrimaryKey() + { + string body = + @"http://sampleissuerurl/http://sampleaudience/"; + + try + { + var template = TokenRestrictionTemplateSerializer.Deserialize(body); + } + catch (Exception ex) + { + Assert.AreEqual("Both PrimaryVerificationKey and OpenIdConnectDiscoveryDocument are null", ex.Message); + throw; + } + + } + + [TestMethod] + [ExpectedException(typeof(InvalidDataContractException))] + public void TokenRestrictionTemplateDeserializeNilOpenConnectIdDocumentUriNoPrimaryKey() + { + string body = + @"http://sampleissuerurl/http://sampleaudience/"; + try + { + var template = TokenRestrictionTemplateSerializer.Deserialize(body); + } + catch (Exception ex) + { + Assert.AreEqual("OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri string value is null or empty", ex.Message); + throw; + } + + + } + + [TestMethod] + [ExpectedException(typeof(InvalidDataContractException))] + public void TokenRestrictionTemplateDeserializeNotAbsoluteDiscoveryUri() + { + string body = + @"http://sampleissuerurl/http://sampleaudience/RelativeUri"; + + try + { + var template = TokenRestrictionTemplateSerializer.Deserialize(body); + } + catch (Exception ex) + { + Assert.AreEqual("String representation of OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri is not valid absolute Uri.", ex.Message); + throw; + } + + } + + [TestMethod] + [ExpectedException(typeof(InvalidDataContractException))] + public void TokenRestrictionTemplateSerializeNotPrimaryKeyAndNoOpenConnectIdDocument() + { + TokenRestrictionTemplate template = new TokenRestrictionTemplate(TokenType.JWT); + template.Audience = _sampleAudience; + template.Issuer = _sampleIssuer; + try + { + TokenRestrictionTemplateSerializer.Serialize(template); + } + catch (Exception ex) + { + Assert.AreEqual("Both PrimaryVerificationKey and OpenIdConnectDiscoveryDocument are null", ex.Message); + throw; + } + + + } + + + [TestMethod] + [ExpectedException(typeof(InvalidDataContractException), "Both PrimaryVerificationKey and OpenIdConnectDiscoveryDocument are null")] + public void InputMissingPrimaryKeyShouldNotThrow() + { + string tokenTemplate = "GG07fDPZ+HMD2vcoknMqYjEJMb7LSq8zUmdCYMvRCevnQK//ilbhODO/FydMrHiwZGmI6XywvOOU7SSzRPlI3Q==http://sampleaudience/http://sampleissuerurl/urn:microsoft:azure:mediaservices:contentkeyidentifierurn:myservice:claims:rentaltrue"; + TokenRestrictionTemplate template = TokenRestrictionTemplateSerializer.Deserialize(tokenTemplate); + + } + + [TestMethod] + public void RSATokenVerificationKeySerializeShouldIncudePrpoperTypeAttribbute() + { + TokenRestrictionTemplate template = new TokenRestrictionTemplate(TokenType.JWT); + RsaTokenVerificationKey tokenVerificationKey = new RsaTokenVerificationKey(); + template.PrimaryVerificationKey = tokenVerificationKey; + var templateAsString = TokenRestrictionTemplateSerializer.Serialize(template); + Assert.IsTrue(templateAsString.Contains("")); + } + + [TestMethod] + public void RSATokenVerificationKeyRoundTrip() + { + TokenRestrictionTemplate template = new TokenRestrictionTemplate(TokenType.JWT); + RsaTokenVerificationKey tokenVerificationKey = new RsaTokenVerificationKey(); + RSAParameters inputRsaParameters; + using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider()) + { + inputRsaParameters = provider.ExportParameters(true); + + tokenVerificationKey.InitFromRsaParameters(inputRsaParameters); + } + Assert.IsNotNull(tokenVerificationKey.RawBody); + template.Audience = _sampleAudience; + template.Issuer = _sampleIssuer; + template.PrimaryVerificationKey = tokenVerificationKey; + var templateAsString = TokenRestrictionTemplateSerializer.Serialize(template); + Assert.IsTrue(templateAsString.Contains("")); + TokenRestrictionTemplate output = TokenRestrictionTemplateSerializer.Deserialize(templateAsString); + Assert.AreEqual(TokenType.JWT, output.TokenType); + Assert.IsNotNull(output.PrimaryVerificationKey); + Assert.IsNotNull(output.PrimaryVerificationKey as RsaTokenVerificationKey); + RsaTokenVerificationKey key = output.PrimaryVerificationKey as RsaTokenVerificationKey; + Assert.IsNotNull(key.RawBody); + RSAParameters outputRsaParametersutParameters = key.GetRsaParameters(); + Assert.IsNotNull(outputRsaParametersutParameters); + Assert.IsNotNull(outputRsaParametersutParameters.Exponent); + Assert.IsNotNull(outputRsaParametersutParameters.Modulus); + //Check that we are storing only public signing key + Assert.IsNull(outputRsaParametersutParameters.P); + Assert.IsNull(outputRsaParametersutParameters.Q); + Assert.IsNull(outputRsaParametersutParameters.D); + Assert.IsNull(outputRsaParametersutParameters.DP); + Assert.IsNull(outputRsaParametersutParameters.DQ); + //Checking that public key matching + Assert.IsTrue(inputRsaParameters.Exponent.SequenceEqual(outputRsaParametersutParameters.Exponent), "Exponent value mismatch"); + Assert.IsTrue(inputRsaParameters.Modulus.SequenceEqual(outputRsaParametersutParameters.Modulus), "Modulus value mismatch"); + + } + + [TestMethod] + public void OpenIdDocumentAsVerificationKeyRoundTrip() + { + string openConnectId = "https://openconnectIddiscoveryUri"; + string expectedElement = + "https://openconnectIddiscoveryUri"; + + TokenRestrictionTemplate template = new TokenRestrictionTemplate(TokenType.JWT); + template.Audience = _sampleAudience; + template.Issuer = _sampleIssuer; + template.OpenIdConnectDiscoveryDocument = new OpenIdConnectDiscoveryDocument(openConnectId); + var templateAsString = TokenRestrictionTemplateSerializer.Serialize(template); + Assert.IsTrue(templateAsString.Contains("")); + Assert.IsTrue(templateAsString.Contains(expectedElement)); + TokenRestrictionTemplate output = TokenRestrictionTemplateSerializer.Deserialize(templateAsString); + Assert.IsNotNull(output); + Assert.IsNotNull(output.OpenIdConnectDiscoveryDocument); + Assert.IsNull(output.PrimaryVerificationKey); + Assert.AreEqual(0, output.AlternateVerificationKeys.Count); + Assert.AreEqual(output.OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri, openConnectId); + } } } diff --git a/test/net/unit/app.config b/test/net/unit/app.config index d23d60f2..0bbfe793 100644 --- a/test/net/unit/app.config +++ b/test/net/unit/app.config @@ -3,24 +3,40 @@ - - + + - - + + - - + + + + + + + + + + + + + + + + + + - + diff --git a/test/net/unit/packages.config b/test/net/unit/packages.config index e36562a4..7aab512b 100644 --- a/test/net/unit/packages.config +++ b/test/net/unit/packages.config @@ -1,11 +1,15 @@  - - - - - - + + + + + + + + + + \ No newline at end of file