-
Notifications
You must be signed in to change notification settings - Fork 4k
Authorization: Changes to the Get-AzureRoleAssignment commandlet to also display classic admins and perform group expansion for users #846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
eb0a088
Authorization:Changes to Get-AzureroleAssignment commandlet to expand…
namratab 43cec70
Update with official Authorization 'nuget package
namratab 2f0d532
Fix packages.config changes that were missed
namratab cf14a21
Revert other RPs to use the older version of the Authorization packag…
namratab 24b042e
Use latest Authorization package for Network and Keyvalut projects du…
namratab dae6fda
[Test:do not merge]Attempt to fix SQl tests by using Record matcher t…
namratab 5f2f930
Merge changes with upstream dev
namratab aa1e830
Fix build error
namratab ffa2ac1
Merge branch 'dev' of github.com:Azure/azure-powershell into roleassi…
namratab 7766973
Fix break
namratab 3aba220
Re-record certain Resources tests
namratab f24dff3
Merge branch 'dev' of github.com:Azure/azure-powershell into roleassi…
namratab 27791a5
Merge branch 'dev' of github.com:Azure/azure-powershell into roleassi…
namratab eca4e40
Fix Compute and Dns tests to exclude api version for permissions
namratab 2ece092
Update api version for remaining test projects and add exclusion for …
namratab 8090605
Merge branch 'dev' of github.com:Azure/azure-powershell into roleassi…
namratab cd74631
Re-record operation insight tests
namratab eca9f59
Fix api management test
namratab af617d6
Refactor recordmatcher code
namratab c4e0d6a
Address review feedback for authorization commands
namratab b39bd6d
Merge branch 'dev' of github.com:Azure/azure-powershell into roleassi…
namratab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/Common/Commands.ScenarioTests.Common/PermissiveRecordMatcherWithApiExclusion.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright 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.Collections.Generic; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using Microsoft.Azure.Test.HttpRecorder; | ||
|
||
namespace Microsoft.WindowsAzure.Commands.ScenarioTest | ||
{ | ||
public class PermissiveRecordMatcherWithApiExclusion : IRecordMatcher | ||
{ | ||
private bool _ignoreGenericResource; | ||
private Dictionary<string, string> _providersToIgnore; | ||
|
||
public PermissiveRecordMatcherWithApiExclusion(bool ignoreResourcesClient, Dictionary<string, string> providers) | ||
{ | ||
_ignoreGenericResource = ignoreResourcesClient; | ||
_providersToIgnore = providers; | ||
} | ||
|
||
public string GetMatchingKey(System.Net.Http.HttpRequestMessage request) | ||
{ | ||
var path = request.RequestUri.PathAndQuery; | ||
if (path.Contains("?&")) | ||
{ | ||
path = path.Replace("?&", "?"); | ||
} | ||
|
||
string version; | ||
if (ContainsIgnoredProvider(path, out version)) | ||
{ | ||
path = RemoveApiVersion(path, version); | ||
} | ||
|
||
var encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(path)); | ||
return string.Format("{0} {1}", request.Method, encodedPath); | ||
} | ||
|
||
public string GetMatchingKey(RecordEntry recordEntry) | ||
{ | ||
var encodedPath = recordEntry.EncodedRequestUri; | ||
if (recordEntry.RequestUri.Contains("?&")) | ||
{ | ||
var updatedPath = recordEntry.RequestUri.Replace("?&", "?"); | ||
|
||
string version; | ||
if (ContainsIgnoredProvider(updatedPath, out version)) | ||
{ | ||
updatedPath = RemoveApiVersion(updatedPath, version); | ||
} | ||
|
||
encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(updatedPath)); | ||
} | ||
|
||
return string.Format("{0} {1}", recordEntry.RequestMethod, encodedPath); | ||
} | ||
|
||
private bool ContainsIgnoredProvider(string requestUri, out string version) | ||
{ | ||
if (_ignoreGenericResource && !requestUri.Contains("providers")) | ||
{ | ||
version = String.Empty; | ||
return true; | ||
} | ||
|
||
foreach (var provider in _providersToIgnore) | ||
{ | ||
var providerString = string.Format("providers/{0}", provider.Key); | ||
if (requestUri.Contains(providerString)) | ||
{ | ||
version = provider.Value; | ||
return true; | ||
} | ||
} | ||
|
||
version = string.Empty; | ||
return false; | ||
} | ||
|
||
private string RemoveApiVersion(string requestUri, string version) | ||
{ | ||
return Regex.Replace(requestUri, @"\?api-version=[^&]+", string.Format("?api-version={0}", version)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
.../Commands.ScenarioTests.ResourceManager.Common/PermissiveRecordMatcherWithApiExclusion.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright 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.Collections.Generic; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using Microsoft.Azure.Test.HttpRecorder; | ||
|
||
namespace Microsoft.WindowsAzure.Commands.ScenarioTest | ||
{ | ||
// Excludes api version when matching mocked records. | ||
// If alternate api version is provided, uses that to match records else removes the api-version matching. | ||
public class PermissiveRecordMatcherWithApiExclusion : IRecordMatcher | ||
{ | ||
private bool _ignoreGenericResource; | ||
private Dictionary<string, string> _providersToIgnore; | ||
|
||
public PermissiveRecordMatcherWithApiExclusion(bool ignoreResourcesClient, Dictionary<string, string> providers) | ||
{ | ||
_ignoreGenericResource = ignoreResourcesClient; | ||
_providersToIgnore = providers; | ||
} | ||
|
||
public string GetMatchingKey(System.Net.Http.HttpRequestMessage request) | ||
{ | ||
var path = request.RequestUri.PathAndQuery; | ||
if (path.Contains("?&")) | ||
{ | ||
path = path.Replace("?&", "?"); | ||
} | ||
|
||
string version; | ||
if (ContainsIgnoredProvider(path, out version)) | ||
{ | ||
path = RemoveOrReplaceApiVersion(path, version); | ||
} | ||
|
||
var encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(path)); | ||
return string.Format("{0} {1}", request.Method, encodedPath); | ||
} | ||
|
||
public string GetMatchingKey(RecordEntry recordEntry) | ||
{ | ||
var encodedPath = recordEntry.EncodedRequestUri; | ||
if (recordEntry.RequestUri.Contains("?&")) | ||
{ | ||
var updatedPath = recordEntry.RequestUri.Replace("?&", "?"); | ||
|
||
|
||
string version; | ||
if (ContainsIgnoredProvider(updatedPath, out version)) | ||
{ | ||
updatedPath = RemoveOrReplaceApiVersion(updatedPath, version); | ||
} | ||
|
||
encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(updatedPath)); | ||
} | ||
|
||
return string.Format("{0} {1}", recordEntry.RequestMethod, encodedPath); | ||
} | ||
|
||
private bool ContainsIgnoredProvider(string requestUri, out string version) | ||
{ | ||
if (_ignoreGenericResource && !requestUri.Contains("providers")) | ||
{ | ||
version = String.Empty; | ||
return true; | ||
} | ||
|
||
foreach (var provider in _providersToIgnore) | ||
{ | ||
var providerString = string.Format("providers/{0}", provider.Key); | ||
if (requestUri.Contains(providerString)) | ||
{ | ||
version = provider.Value; | ||
return true; | ||
} | ||
} | ||
|
||
|
||
version = string.Empty; | ||
return false; | ||
} | ||
|
||
private string RemoveOrReplaceApiVersion(string requestUri, string version) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(version)) | ||
{ | ||
return Regex.Replace(requestUri, @"\?api-version=[^&]+", string.Format("?api-version={0}", version)); | ||
} | ||
else | ||
{ | ||
return Regex.Replace(requestUri, @"\?api-version=[^&]+", string.Empty); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could u move this code to
RMTestBase
instead of duplicating it everywhere in the code?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used only for a few of the test projects which depend on authorization RP. Not needed for all tests. Is there benefit in moving it there? Keeping it here also makes it explicit that en exclusion is added for particular test projects only.