Skip to content

Commit 8b37d4a

Browse files
authored
fix: TT-339 skip users with azureioet.onmicrosoft.com extension from user search (#322)
1 parent 0e9f8f6 commit 8b37d4a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

tests/utils/azure_users_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ def test_users_functions_should_returns_all_users(
253253
first_response.status_code = 200
254254
first_response._content = (
255255
b'{"odata.nextLink":"nomatter&$skiptoken=X12872","value":[{"displayName":"Fake1",'
256-
b'"otherMails":["[email protected]"],"objectId":"1"}]} '
256+
b'"otherMails":["[email protected]"], "mail":"[email protected]","objectId":"1"}]} '
257257
)
258258

259259
second_response = copy.copy(first_response)
260-
second_response._content = b'{"value":[{"displayName":"Fake2","otherMails":["[email protected]"],"objectId":"1"}]}'
260+
second_response._content = b'{"value":[{"displayName":"Fake2","otherMails":["[email protected]"], "mail":"[email protected]","objectId":"1"}]}'
261261

262262
get_mock.side_effect = [first_response, second_response]
263263
get_groups_and_users_mock.return_value = []
264264

265265
users = AzureConnection().users()
266266

267-
assert len(users) == 2
267+
assert len(users) == 0

utils/azure_users.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ def users(self) -> List[AzureUser]:
9696
role_fields_params = ','.join(
9797
[field_name for field_name, _ in ROLE_FIELD_VALUES.values()]
9898
)
99-
endpoint = "{endpoint}/users?api-version=1.6&$select=displayName,otherMails,objectId,{role_fields_params}".format(
99+
endpoint = "{endpoint}/users?api-version=1.6&$select=displayName,otherMails,mail,objectId,{role_fields_params}".format(
100100
endpoint=self.config.ENDPOINT,
101101
role_fields_params=role_fields_params,
102102
)
103103

104104
exists_users = True
105105
users = []
106+
valid_users = []
106107
skip_token_attribute = '&$skiptoken='
107108

108109
while exists_users:
@@ -124,8 +125,12 @@ def users(self) -> List[AzureUser]:
124125
skip_token_attribute
125126
)[1]
126127
endpoint = endpoint + skip_token_attribute + request_token
127-
128-
return [self.to_azure_user(user) for user in users]
128+
129+
for i in range(len(users)):
130+
if users[i]['mail'] is None:
131+
valid_users.append(users[i])
132+
133+
return [self.to_azure_user(user) for user in valid_users]
129134

130135
def to_azure_user(self, item) -> AzureUser:
131136
there_is_email = len(item['otherMails']) > 0

0 commit comments

Comments
 (0)