Skip to content

Commit 70c8aac

Browse files
authored
[FDS-2386] Add owner id to the credentials to be used later on (#1130)
* Add owner id to the credentials to be used later on
1 parent ed886ae commit 70c8aac

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

synapseclient/core/credentials/cred_data.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def username(self) -> None:
2020
def secret(self) -> None:
2121
"""The secret associated with these credentials."""
2222

23+
@property
24+
@abc.abstractmethod
25+
def owner_id(self) -> None:
26+
"""The owner id, or profile id, associated with these credentials."""
27+
2328

2429
class SynapseAuthTokenCredentials(SynapseCredentials):
2530
@classmethod
@@ -69,6 +74,7 @@ def __init__(
6974
self._token = token
7075
self.username = username
7176
self.displayname = displayname
77+
self.owner_id = None
7278

7379
@property
7480
def username(self) -> str:
@@ -88,6 +94,15 @@ def displayname(self) -> str:
8894
def displayname(self, displayname: str) -> None:
8995
self._displayname = displayname
9096

97+
@property
98+
def owner_id(self) -> str:
99+
"""The owner id associated with this token."""
100+
return self._owner_id
101+
102+
@owner_id.setter
103+
def owner_id(self, owner_id: str) -> None:
104+
self._owner_id = owner_id
105+
91106
@property
92107
def secret(self) -> str:
93108
"""The bearer token."""
@@ -102,7 +117,8 @@ def __repr__(self):
102117
f"SynapseAuthTokenCredentials("
103118
f"username='{self.username}', "
104119
f"displayname='{self.displayname}', "
105-
f"token='{self.secret}')"
120+
f"token='{self.secret}', "
121+
f"owner_id='{self.owner_id}')"
106122
)
107123

108124

synapseclient/core/credentials/credential_provider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def _create_synapse_credential(
9191
)
9292
credentials.username = profile_username
9393
credentials.displayname = profile_displayname
94+
credentials.owner_id = profile.get("ownerId", None)
9495

9596
return credentials
9697

tests/unit/synapseclient/core/credentials/unit_test_cred_data.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ def setup_method(self):
1313
self.username = "ahhhhhhhhhhhhhh"
1414
self.auth_token = "opensesame"
1515
self.displayname = "hhhhhaaaa"
16+
self.owner_id = 123
1617
self.credentials = SynapseAuthTokenCredentials(
1718
self.auth_token, username=self.username, displayname=self.displayname
1819
)
20+
self.credentials.owner_id = self.owner_id
1921
self.KEYRING_NAME = "SYNAPSE.ORG_CLIENT_AUTH_TOKEN"
2022

2123
def test_username(self):
@@ -57,8 +59,9 @@ def test_repr(self):
5759
f"SynapseAuthTokenCredentials("
5860
f"username='{self.username}', "
5961
f"displayname='{self.displayname}', "
60-
f"token='{self.auth_token}')" == repr(self.credentials)
61-
)
62+
f"token='{self.auth_token}', "
63+
f"owner_id='{self.owner_id}')"
64+
) == repr(self.credentials)
6265

6366
def test_tokens_validated(self, mocker):
6467
"""Validate that tokens are validated when a credentials object is created"""

tests/unit/synapseclient/core/credentials/unit_test_cred_provider.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def init_syn(self, syn: Synapse) -> None:
9898
def setup_method(self) -> None:
9999
self.username = "username"
100100
self.auth_token = "auth_token"
101+
self.owner_id = 1234567890
101102
self.user_login_args = UserLoginArgs(
102103
self.username,
103104
self.auth_token,
@@ -149,6 +150,7 @@ def test_create_synapse_credential_username_is_None_auth_provided(
149150
mock_init_auth_creds.return_value = mock_creds
150151
mock_creds.secret = self.auth_token
151152
mock_creds.username = self.username
153+
mock_creds.owner_id = self.owner_id
152154
mock_rest_get.return_value = {"userName": self.username}
153155
creds = self.provider._create_synapse_credential(
154156
syn=self.syn, username=None, auth_token=self.auth_token
@@ -175,14 +177,15 @@ def test_create_synapse_credential_username_not_None_auth_token_is_not_None(
175177
assert creds is mock_creds
176178

177179
@pytest.mark.parametrize(
178-
"login_username,profile_username,profile_emails,profile_displayname",
180+
"login_username,profile_username,profile_emails,profile_displayname,profile_owner_id",
179181
(
180-
("foo", "foo", ["[email protected]"], "foo"), # username matches
182+
("foo", "foo", ["[email protected]"], "foo", 123), # username matches
181183
(
182184
183185
"foo",
184186
185187
"foo",
188+
456,
186189
), # email matches
187190
),
188191
)
@@ -193,6 +196,7 @@ def test_create_synapse_credential__username_auth_token_match(
193196
profile_username,
194197
profile_emails,
195198
profile_displayname,
199+
profile_owner_id,
196200
) -> None:
197201
"""Verify that if both a username/email and a auth token are provided, the login is successful
198202
if the token matches either the username or a profile email address."""
@@ -202,6 +206,7 @@ def test_create_synapse_credential__username_auth_token_match(
202206
"userName": profile_username,
203207
"emails": profile_emails,
204208
"displayName": profile_displayname,
209+
"ownerId": profile_owner_id,
205210
}
206211

207212
cred = self.provider._create_synapse_credential(
@@ -210,6 +215,7 @@ def test_create_synapse_credential__username_auth_token_match(
210215
assert cred.secret == self.auth_token
211216
assert cred.username == profile_username
212217
assert cred.displayname == profile_displayname
218+
assert cred.owner_id == profile_owner_id
213219

214220
def test_create_synapse_credential__username_auth_token_mismatch(
215221
self, mocker

0 commit comments

Comments
 (0)