File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,12 @@ def _scope_to_resource(scope): # This is an experimental reasonable-effort appr
32
32
if scope .startswith (a ):
33
33
return a
34
34
u = urlparse (scope )
35
+ if not u .scheme and not u .netloc : # Typically the "GUID/scope" case
36
+ return u .path .split ("/" )[0 ]
35
37
if u .scheme :
36
- return "{}://{}" .format (u .scheme , u .netloc )
38
+ trailer = ( # https://learn.microsoft.com/en-us/entra/identity-platform/scopes-oidc#trailing-slash-and-default
39
+ "/" if u .path .startswith ("//" ) else "" )
40
+ return "{}://{}{}" .format (u .scheme , u .netloc , trailer )
37
41
return scope # There is no much else we can do here
38
42
39
43
Original file line number Diff line number Diff line change
1
+ import unittest
2
+ from msal .cloudshell import _scope_to_resource
3
+
4
+ class TestScopeToResource (unittest .TestCase ):
5
+
6
+ def test_expected_behaviors (self ):
7
+ for scope , expected_resource in {
8
+ "https://analysis.windows.net/powerbi/api/foo" :
9
+ "https://analysis.windows.net/powerbi/api" , # A special case
10
+ "https://pas.windows.net/CheckMyAccess/Linux/.default" :
11
+ "https://pas.windows.net/CheckMyAccess/Linux/.default" , # Special case
12
+ "https://double-slash.com//scope" : "https://double-slash.com/" ,
13
+ "https://single-slash.com/scope" : "https://single-slash.com" ,
14
+ "guid/some/scope" : "guid" ,
15
+ "797f4846-ba00-4fd7-ba43-dac1f8f63013/.default" : # Realistic GUID
16
+ "797f4846-ba00-4fd7-ba43-dac1f8f63013"
17
+ }.items ():
18
+ self .assertEqual (_scope_to_resource (scope ), expected_resource )
19
+
20
+ if __name__ == '__main__' :
21
+ unittest .main ()
You can’t perform that action at this time.
0 commit comments