Skip to content

Commit 855b4c6

Browse files
Merge pull request #617 from ddybvig-perf/dale-sign-bugfix
Sign post-sync bug fix - email casing difference between umapi and sign users
2 parents 125fe5d + 75e51bf commit 855b4c6

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

tests/test_post_sync.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
import json
2+
from unittest import mock
3+
14
import pytest
5+
from requests import Response
6+
7+
from user_sync.post_sync import PostSyncConnector
8+
from user_sync.post_sync.connectors.sign_sync import SignClient, SignConnector
29
from user_sync.post_sync.manager import PostSyncData
310

411

@@ -51,3 +58,41 @@ def test_add_remove_groups(example_user):
5158
delta_groups = example_user['groups'] | set(groups_add)
5259
delta_groups -= set(groups_remove)
5360
assert post_sync_data.umapi_data[None][email_id]['groups'] == delta_groups
61+
62+
63+
@mock.patch('requests.get')
64+
@mock.patch('user_sync.post_sync.connectors.sign_sync.client.SignClient._init')
65+
def test_update_sign_users(mock_client, mock_get, example_user):
66+
def mock_response(data):
67+
r = Response()
68+
r.status_code = 200
69+
r._content = json.dumps(data).encode()
70+
return r
71+
user_list = mock_response({'userInfoList': [{"userId": "123"}]})
72+
user_one = mock_response({'userStatus': 'ACTIVE', 'email': '[email protected]'})
73+
mock_get.side_effect = [user_list, user_one]
74+
client_config = {
75+
'console_org': None,
76+
'host': 'api.na2.echosignstage.com',
77+
'key': 'allsortsofgibberish1234567890',
78+
'admin_email': '[email protected]'
79+
}
80+
sign_client = SignClient(client_config)
81+
sign_client.api_url = "whatever"
82+
connector_config = {
83+
'sign_orgs': [client_config],
84+
'entitlement_groups': ['group1']
85+
}
86+
sign_connector = SignConnector(connector_config)
87+
# set the email from the fixture example user to use an uppercase letter
88+
example_user['email'] = '[email protected]'
89+
# make a new dict indexed by the uppercase email to pass in to the update method from the sign connector
90+
umapi_users = {example_user['email']: example_user}
91+
92+
def should_sync_replacement(umapi_user, sign_user, org_name):
93+
assert sign_user is not None
94+
# going to exit the update method early because this bug fix is only concerned with the email mismatch
95+
# looking up the sign user from the umapi_users dict should return a sign user even if there is a casing mismatch
96+
sign_connector.should_sync = should_sync_replacement
97+
sign_connector.update_sign_users(umapi_users, sign_client, 'testOrg')
98+

user_sync/post_sync/connectors/sign_sync/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def run(self, post_sync_data):
5555
def update_sign_users(self, umapi_users, sign_client, org_name):
5656
sign_users = sign_client.get_users()
5757
for _, umapi_user in umapi_users.items():
58-
sign_user = sign_users.get(umapi_user['email'])
58+
sign_user = sign_users.get(umapi_user['email'].lower())
5959
if not self.should_sync(umapi_user, sign_user, org_name):
6060
continue
6161

0 commit comments

Comments
 (0)