Skip to content

Commit

Permalink
fix issue Azure#11658 for is_valid_resource_id (Azure#11709)
Browse files Browse the repository at this point in the history
* fix issue Azure#11658

* use regex

* add tests

* revert print
  • Loading branch information
changlong-liu authored and rakshith91 committed Sep 4, 2020
1 parent bf75632 commit aacbd60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions sdk/core/azure-mgmt-core/azure/mgmt/core/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@

_LOGGER = logging.getLogger(__name__)
_ARMID_RE = re.compile(
"(?i)/subscriptions/(?P<subscription>[^/]*)(/resourceGroups/(?P<resource_group>[^/]*))?"
"(/providers/(?P<namespace>[^/]*)/(?P<type>[^/]*)/(?P<name>[^/]*)(?P<children>.*))?"
"(?i)/subscriptions/(?P<subscription>[^/]+)(/resourceGroups/(?P<resource_group>[^/]+))?"
"(/providers/(?P<namespace>[^/]+)/(?P<type>[^/]*)/(?P<name>[^/]+)(?P<children>.*))?"
)

_CHILDREN_RE = re.compile(
"(?i)(/providers/(?P<child_namespace>[^/]*))?/"
"(?P<child_type>[^/]*)/(?P<child_name>[^/]*)"
"(?i)(/providers/(?P<child_namespace>[^/]+))?/"
"(?P<child_type>[^/]*)/(?P<child_name>[^/]+)"
)

_ARMNAME_RE = re.compile("^[^<>%&:\\?/]{1,260}$")
Expand Down
4 changes: 3 additions & 1 deletion sdk/core/azure-mgmt-core/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ def test_resource_parse(self):
invalid_ids = [
'/subscriptions/fakesub/resourceGroups/myRg/type1/name1',
'/subscriptions/fakesub/resourceGroups/myRg/providers/Microsoft.Provider/foo',
'/subscriptions/fakesub/resourceGroups/myRg/providers/namespace/type/name/type1'
'/subscriptions/fakesub/resourceGroups/myRg/providers/namespace/type/name/type1',
'/subscriptions/fakesub/resourceGroups/',
'/subscriptions//resourceGroups/'
]
for invalid_id in invalid_ids:
self.assertFalse(is_valid_resource_id(invalid_id))
Expand Down

0 comments on commit aacbd60

Please sign in to comment.