Skip to content

Commit 42edbcb

Browse files
committed
Merge pull request #1101 from shuagarw/release-0.9.8.1
Authorization RBAC commands changes for GA to Release 0.9.8.1 branch
2 parents 67bb6a9 + 98ed97f commit 42edbcb

File tree

100 files changed

+11212
-9550
lines changed

Some content is hidden

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

100 files changed

+11212
-9550
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
<Compile Include="Mocks\MockClientFactory.cs" />
133133
<Compile Include="Mocks\MockTokenAuthenticationFactory.cs" />
134134
<Compile Include="PermissiveRecordMatcher.cs" />
135+
<Compile Include="PermissiveRecordMatcherWithApiExclusion.cs" />
135136
<Compile Include="PowerShellExtensions.cs" />
136137
<Compile Include="Properties\AssemblyInfo.cs" />
137138
</ItemGroup>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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;
16+
using System.Collections.Generic;
17+
using System.Text;
18+
using System.Text.RegularExpressions;
19+
using Microsoft.Azure.Test.HttpRecorder;
20+
21+
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
22+
{
23+
public class PermissiveRecordMatcherWithApiExclusion : IRecordMatcher
24+
{
25+
private bool _ignoreGenericResource;
26+
private Dictionary<string, string> _providersToIgnore;
27+
28+
public PermissiveRecordMatcherWithApiExclusion(bool ignoreResourcesClient, Dictionary<string, string> providers)
29+
{
30+
_ignoreGenericResource = ignoreResourcesClient;
31+
_providersToIgnore = providers;
32+
}
33+
34+
public string GetMatchingKey(System.Net.Http.HttpRequestMessage request)
35+
{
36+
var path = request.RequestUri.PathAndQuery;
37+
if (path.Contains("?&"))
38+
{
39+
path = path.Replace("?&", "?");
40+
}
41+
42+
string version;
43+
if (ContainsIgnoredProvider(path, out version))
44+
{
45+
path = RemoveApiVersion(path, version);
46+
}
47+
48+
var encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(path));
49+
return string.Format("{0} {1}", request.Method, encodedPath);
50+
}
51+
52+
public string GetMatchingKey(RecordEntry recordEntry)
53+
{
54+
var encodedPath = recordEntry.EncodedRequestUri;
55+
if (recordEntry.RequestUri.Contains("?&"))
56+
{
57+
var updatedPath = recordEntry.RequestUri.Replace("?&", "?");
58+
59+
string version;
60+
if (ContainsIgnoredProvider(updatedPath, out version))
61+
{
62+
updatedPath = RemoveApiVersion(updatedPath, version);
63+
}
64+
65+
encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(updatedPath));
66+
}
67+
68+
return string.Format("{0} {1}", recordEntry.RequestMethod, encodedPath);
69+
}
70+
71+
private bool ContainsIgnoredProvider(string requestUri, out string version)
72+
{
73+
if (_ignoreGenericResource && !requestUri.Contains("providers"))
74+
{
75+
version = String.Empty;
76+
return true;
77+
}
78+
79+
foreach (var provider in _providersToIgnore)
80+
{
81+
var providerString = string.Format("providers/{0}", provider.Key);
82+
if (requestUri.Contains(providerString))
83+
{
84+
version = provider.Value;
85+
return true;
86+
}
87+
}
88+
89+
version = string.Empty;
90+
return false;
91+
}
92+
93+
private string RemoveApiVersion(string requestUri, string version)
94+
{
95+
return Regex.Replace(requestUri, @"\?api-version=[^&]+", string.Format("?api-version={0}", version));
96+
}
97+
}
98+
}

src/ResourceManager/ApiManagement/Commands.ApiManagement.Test/ScenarioTests/ApiManagementTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.Test.ScenarioTests
2525
using Microsoft.WindowsAzure.Management;
2626
using Microsoft.WindowsAzure.Management.Storage;
2727
using Xunit;
28+
using System.Collections.Generic;
2829

2930
public class ApiManagementTests
3031
{
@@ -146,6 +147,9 @@ private void RunPowerShellTest(params string[] scripts)
146147
// "TEST_ORGID_AUTHENTICATION",
147148
// "SubscriptionId=;Environment=");
148149
#endif
150+
Dictionary<string, string> d = new Dictionary<string, string>();
151+
d.Add("Microsoft.Authorization", "2014-07-01-preview");
152+
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);
149153

150154
using (var context = UndoContext.Current)
151155
{

src/ResourceManager/AzureBatch/Commands.Batch.Test/Commands.Batch.Test.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
<Reference Include="Microsoft.Azure.Gallery">
6161
<HintPath>..\..\..\packages\Microsoft.Azure.Gallery.2.6.2-preview\lib\net40\Microsoft.Azure.Gallery.dll</HintPath>
6262
</Reference>
63-
<Reference Include="Microsoft.Azure.Management.Authorization, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
64-
<SpecificVersion>False</SpecificVersion>
65-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.0.19.2-preview\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
63+
<Reference Include="Microsoft.Azure.Management.Authorization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
64+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
65+
<Private>True</Private>
6666
</Reference>
6767
<Reference Include="Microsoft.Azure.Management.Batch">
6868
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Batch.1.4.0\lib\net40\Microsoft.Azure.Management.Batch.dll</HintPath>

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/BatchController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Microsoft.Azure.Test.HttpRecorder;
2222
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2323
using System;
24+
using System.Collections.Generic;
2425
using System.Linq;
2526

2627
namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
@@ -73,7 +74,11 @@ public void RunPsTestWorkflow(
7374
string callingClassType,
7475
string mockName)
7576
{
76-
HttpMockServer.Matcher = new PermissiveRecordMatcher();
77+
78+
Dictionary<string, string> d = new Dictionary<string, string>();
79+
d.Add("Microsoft.Authorization", "2014-07-01-preview");
80+
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);
81+
7782
using (UndoContext context = UndoContext.Current)
7883
{
7984
context.Start(callingClassType, mockName);

src/ResourceManager/AzureBatch/Commands.Batch.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<package id="Microsoft.Azure.Common.Authentication" version="1.1.6-preview" targetFramework="net45" />
77
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
88
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
9-
<package id="Microsoft.Azure.Management.Authorization" version="0.19.2-preview" targetFramework="net45" />
9+
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Batch" version="1.4.0" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Test.Framework" version="1.0.5715.36130-prerelease" targetFramework="net45" />

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
<SpecificVersion>False</SpecificVersion>
6363
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
6464
</Reference>
65-
<Reference Include="Microsoft.Azure.Management.Authorization, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66-
<SpecificVersion>False</SpecificVersion>
67-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.0.19.2-preview\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
65+
<Reference Include="Microsoft.Azure.Management.Authorization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
67+
<Private>True</Private>
6868
</Reference>
6969
<Reference Include="Microsoft.Azure.Management.Compute, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7070
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.8.2.0\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>

src/ResourceManager/Compute/Commands.Compute.Test/Common/ComputeTestController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using System;
2828
using System.Linq;
2929
using Microsoft.Azure.Common.Authentication;
30+
using System.Collections.Generic;
3031

3132
namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
3233
{
@@ -95,6 +96,10 @@ public void RunPsTestWorkflow(
9596
string callingClassType,
9697
string mockName)
9798
{
99+
Dictionary<string, string> d = new Dictionary<string, string>();
100+
d.Add("Microsoft.Authorization", "2014-07-01-preview");
101+
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);
102+
98103
using (UndoContext context = UndoContext.Current)
99104
{
100105
context.Start(callingClassType, mockName);

src/ResourceManager/Compute/Commands.Compute.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.0-preview" targetFramework="net45" />
9-
<package id="Microsoft.Azure.Management.Authorization" version="0.19.2-preview" targetFramework="net45" />
9+
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Compute" version="8.2.0" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Network" version="2.0.9-preview" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<SpecificVersion>False</SpecificVersion>
7474
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
7575
</Reference>
76-
<Reference Include="Microsoft.Azure.Management.Authorization, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
77-
<SpecificVersion>False</SpecificVersion>
78-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.0.19.2-preview\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
76+
<Reference Include="Microsoft.Azure.Management.Authorization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
77+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
78+
<Private>True</Private>
7979
</Reference>
8080
<Reference Include="Microsoft.Azure.Management.Compute, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8181
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.8.2.0\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>

0 commit comments

Comments
 (0)