forked from microsoft/AzureTRE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabling +20 users/groups on batch endpoint payload (microsoft#3759)
- Loading branch information
1 parent
68e8312
commit 6d589c4
Showing
4 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.15.17" | ||
__version__ = "0.15.18" |
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import pytest | ||
from mock import patch | ||
from mock import call, patch | ||
|
||
from models.domain.authentication import User, RoleAssignment | ||
from models.domain.workspace import Workspace, WorkspaceRole | ||
|
@@ -554,6 +554,66 @@ def test_get_workspace_role_assignment_details_with_groups_and_users_assigned_re | |
assert "[email protected]" in role_assignment_details["WorkspaceOwner"] | ||
|
||
|
||
@patch("services.aad_authentication.AzureADAuthorization._get_auth_header") | ||
@patch("services.aad_authentication.AzureADAuthorization._get_batch_users_by_role_assignments_body") | ||
@patch("requests.post") | ||
def test_get_user_emails_with_batch_of_more_than_20_requests(mock_graph_post, mock_get_batch_users_by_role_assignments_body, mock_headers): | ||
# Arrange | ||
access_service = AzureADAuthorization() | ||
roles_graph_data = [{"id": "role1"}, {"id": "role2"}] | ||
msgraph_token = "token" | ||
batch_endpoint = access_service._get_batch_endpoint() | ||
|
||
# mock the response of _get_auth_header | ||
headers = {"Authorization": f"Bearer {msgraph_token}"} | ||
mock_headers.return_value = headers | ||
headers["Content-type"] = "application/json" | ||
|
||
# mock the response of the get batch request for 30 users | ||
batch_request_body_first_20 = { | ||
"requests": [ | ||
{"id": f"{i}", "method": "GET", "url": f"/users/{i}"} for i in range(20) | ||
] | ||
} | ||
|
||
batch_request_body_last_10 = { | ||
"requests": [ | ||
{"id": f"{i}", "method": "GET", "url": f"/users/{i}"} for i in range(20, 30) | ||
] | ||
} | ||
|
||
batch_request_body = { | ||
"requests": [ | ||
{"id": f"{i}", "method": "GET", "url": f"/users/{i}"} for i in range(30) | ||
] | ||
} | ||
|
||
mock_get_batch_users_by_role_assignments_body.return_value = batch_request_body | ||
|
||
# Mock the response of the post request | ||
mock_graph_post_response = {"responses": [{"id": "user1"}, {"id": "user2"}]} | ||
mock_graph_post.return_value.json.return_value = mock_graph_post_response | ||
|
||
# Act | ||
users_graph_data = access_service._get_user_emails(roles_graph_data, msgraph_token) | ||
|
||
# Assert | ||
assert len(users_graph_data["responses"]) == 4 | ||
calls = [ | ||
call( | ||
f"{batch_endpoint}", | ||
json=batch_request_body_first_20, | ||
headers=headers | ||
), | ||
call( | ||
f"{batch_endpoint}", | ||
json=batch_request_body_last_10, | ||
headers=headers | ||
) | ||
] | ||
mock_graph_post.assert_has_calls(calls, any_order=True) | ||
|
||
|
||
def get_mock_batch_response(user_principals, group_principals): | ||
response_body = {"responses": []} | ||
for user_principal in user_principals: | ||
|