Skip to content

Commit 67bb6a9

Browse files
author
Hovsep
committed
Merge pull request #1106 from markcowl/release-0.9.8.1
Add back AddUserAgent methods to ClientFactory
2 parents daecb2d + a2a9e7d commit 67bb6a9

File tree

165 files changed

+289
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+289
-176
lines changed

src/Common/Commands.Common.Storage/Commands.Common.Storage.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</Reference>
5959
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6060
<SpecificVersion>False</SpecificVersion>
61-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.1.3-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
61+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.1.6-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6262
</Reference>
6363
<Reference Include="Microsoft.Azure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6464
<SpecificVersion>False</SpecificVersion>

src/Common/Commands.Common.Storage/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
5-
<package id="Microsoft.Azure.Common.Authentication" version="1.1.3-preview" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.1.6-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
88
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

src/Common/Commands.Common.Test/Commands.Common.Test.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
44
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
@@ -58,7 +58,7 @@
5858
</Reference>
5959
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6060
<SpecificVersion>False</SpecificVersion>
61-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.1.3-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
61+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.1.6-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6262
</Reference>
6363
<Reference Include="Microsoft.Azure.Common.NetFramework">
6464
<HintPath>..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
@@ -166,7 +166,9 @@
166166
</ItemGroup>
167167
<ItemGroup>
168168
<Compile Include="Common\AuthenticationFactoryTests.cs" />
169+
<Compile Include="Common\ClientFactoryTests.cs" />
169170
<Compile Include="Common\MockSubsciptionFactory.cs" />
171+
<Compile Include="Common\NullClient.cs" />
170172
<Compile Include="Common\ServicePrincipalStoreTests.cs" />
171173
<Compile Include="Common\GeneralUtilitiesTests.cs" />
172174
<Compile Include="Common\Data.cs" />
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using Xunit;
17+
using System;
18+
using System.Net.Http.Headers;
19+
using Hyak.Common;
20+
using Microsoft.Azure;
21+
using Microsoft.Azure.Common.Authentication.Factories;
22+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
23+
using Microsoft.Azure.Common.Authentication;
24+
using Microsoft.Azure.Common.Authentication.Models;
25+
using Microsoft.Rest.TransientFaultHandling;
26+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
27+
28+
namespace Microsoft.WindowsAzure.Commands.Common.Test.Common
29+
{
30+
public class ClientFactoryTests
31+
{
32+
[Fact]
33+
[Trait(Category.AcceptanceType, Category.CheckIn)]
34+
public void VerifyUserAgentValuesAreTransmitted()
35+
{
36+
var storedClientFactory = AzureSession.ClientFactory;
37+
var storedAuthFactory = AzureSession.AuthenticationFactory;
38+
try
39+
{
40+
var authFactory = new AuthenticationFactory();
41+
authFactory.TokenProvider = new MockAccessTokenProvider(Guid.NewGuid().ToString(), "[email protected]");
42+
AzureSession.AuthenticationFactory = authFactory;
43+
var factory = new ClientFactory();
44+
AzureSession.ClientFactory = factory;
45+
factory.UserAgents.Clear();
46+
factory.AddUserAgent("agent1");
47+
factory.AddUserAgent("agent1", "1.0.0");
48+
factory.AddUserAgent("agent1", "1.0.0");
49+
factory.AddUserAgent("agent1", "1.9.8");
50+
factory.AddUserAgent("agent2");
51+
Assert.Equal(4, factory.UserAgents.Count);
52+
var client = factory.CreateClient<NullClient>(new AzureContext(
53+
new AzureSubscription
54+
{
55+
Id = Guid.NewGuid(),
56+
Properties = new Dictionary<AzureSubscription.Property, string>
57+
{
58+
{AzureSubscription.Property.Tenants, "123"}
59+
}
60+
},
61+
new AzureAccount
62+
{
63+
64+
Type = AzureAccount.AccountType.User,
65+
Properties = new Dictionary<AzureAccount.Property, string>
66+
{
67+
{AzureAccount.Property.Tenants, "123"}
68+
}
69+
},
70+
AzureEnvironment.PublicEnvironments["AzureCloud"]
71+
72+
), AzureEnvironment.Endpoint.ResourceManager);
73+
Assert.Equal(5, client.HttpClient.DefaultRequestHeaders.UserAgent.Count);
74+
Assert.True(client.HttpClient.DefaultRequestHeaders.UserAgent.Contains(new ProductInfoHeaderValue("agent1", "")));
75+
Assert.True(client.HttpClient.DefaultRequestHeaders.UserAgent.Contains(new ProductInfoHeaderValue("agent1", "1.0.0")));
76+
Assert.True(client.HttpClient.DefaultRequestHeaders.UserAgent.Contains(new ProductInfoHeaderValue("agent1", "1.9.8")));
77+
Assert.True(client.HttpClient.DefaultRequestHeaders.UserAgent.Contains(new ProductInfoHeaderValue("agent2", "")));
78+
}
79+
finally
80+
{
81+
AzureSession.ClientFactory = storedClientFactory;
82+
AzureSession.AuthenticationFactory = storedAuthFactory;
83+
}
84+
}
85+
}
86+
}

src/Common/Commands.Common.Test/Common/MockSubsciptionFactory.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,16 @@ public void RemoveAction(Type actionType)
6666
throw new NotImplementedException();
6767
}
6868

69-
public void AddUserAgent(string productName, string productVersion)
69+
void IClientFactory.AddUserAgent(string productName, string productVersion)
7070
{
7171
throw new NotImplementedException();
7272
}
7373

74-
public void AddUserAgent(string productName)
74+
void IClientFactory.AddUserAgent(string productName)
7575
{
7676
throw new NotImplementedException();
7777
}
7878

79-
public HashSet<ProductInfoHeaderValue> UserAgents
80-
{
81-
get { throw new NotImplementedException(); }
82-
}
83-
84-
8579
public TClient CreateArmClient<TClient>(Azure.Common.Authentication.Models.AzureContext context, Azure.Common.Authentication.Models.AzureEnvironment.Endpoint endpoint) where TClient : Microsoft.Rest.ServiceClient<TClient>
8680
{
8781
throw new NotImplementedException();
@@ -92,7 +86,7 @@ public TClient CreateCustomArmClient<TClient>(params object[] parameters) where
9286
throw new NotImplementedException();
9387
}
9488

95-
List<ProductInfoHeaderValue> IClientFactory.UserAgents
89+
HashSet<ProductInfoHeaderValue> IClientFactory.UserAgents
9690
{
9791
get
9892
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
16+
using System;
17+
using Hyak.Common;
18+
using Microsoft.Azure;
19+
20+
namespace Microsoft.WindowsAzure.Commands.Common.Test.Common
21+
{
22+
23+
public class NullClient : ServiceClient<NullClient>
24+
{
25+
public NullClient(SubscriptionCloudCredentials credentials) : base()
26+
{
27+
28+
}
29+
public NullClient(SubscriptionCloudCredentials credentials, Uri baseUri) : base()
30+
{
31+
32+
}
33+
}
34+
}

src/Common/Commands.Common.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
5-
<package id="Microsoft.Azure.Common.Authentication" version="1.1.3-preview" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.1.6-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5715.36130-prerelease" targetFramework="net45" />

src/Common/Commands.Common/Commands.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</Reference>
6666
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6767
<SpecificVersion>False</SpecificVersion>
68-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.1.3-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
68+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.1.6-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6969
</Reference>
7070
<Reference Include="Microsoft.Azure.Common.NetFramework">
7171
<SpecificVersion>False</SpecificVersion>

src/Common/Commands.Common/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<package id="Microsoft.ApplicationInsights" version="1.1.1-beta" targetFramework="net45" />
55
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Common.Authentication" version="1.1.3-preview" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Common.Authentication" version="1.1.6-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
1010
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

src/Common/Commands.Profile/Commands.Profile.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<HintPath>..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5555
</Reference>
5656
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.1.3-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
57+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.1.6-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
5858
<Private>True</Private>
5959
</Reference>
6060
<Reference Include="Microsoft.Azure.Common.NetFramework">

0 commit comments

Comments
 (0)