Skip to content

Commit b1d8cd7

Browse files
committed
Use lowercase environment value during searching
1 parent d49296c commit b1d8cd7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

msal/token_cache.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ def _get(self, credential_type, key, default=None): # O(1)
126126

127127
@staticmethod
128128
def _is_matching(entry: dict, query: dict, target_set: set = None) -> bool:
129-
return is_subdict_of(query or {}, entry) and (
129+
query_with_lowercase_environment = {
130+
# __add() canonicalized entry's environment value to lower case,
131+
# so we do the same here.
132+
k: v.lower() if k == "environment" and isinstance(v, str) else v
133+
for k, v in query.items()
134+
} if query else {}
135+
return is_subdict_of(query_with_lowercase_environment, entry) and (
130136
target_set <= set(entry.get("target", "").split())
131137
if target_set else True)
132138

tests/test_mi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ def test_happy_path_of_vm(self):
190190
headers={'Metadata': 'true'},
191191
)
192192

193+
@patch("msal.managed_identity.socket.getfqdn", new=lambda: "MixedCaseHostName")
194+
def test_happy_path_of_windows_vm(self):
195+
self.test_happy_path_of_vm()
196+
193197
@patch.dict(os.environ, {"AZURE_POD_IDENTITY_AUTHORITY_HOST": "http://localhost:1234//"})
194198
def test_happy_path_of_pod_identity(self):
195199
self._test_happy_path().assert_called_with(

0 commit comments

Comments
 (0)