s/user_id/user/g for consistency

This commit is contained in:
Daniel Wagner-Hall 2015-09-01 12:41:16 +01:00
parent 81450fded8
commit e255c2c32f
6 changed files with 25 additions and 25 deletions

View File

@ -367,7 +367,7 @@ class Auth(object):
pass # normal users won't have the user_id query parameter set. pass # normal users won't have the user_id query parameter set.
user_info = yield self._get_user_by_access_token(access_token) user_info = yield self._get_user_by_access_token(access_token)
user_id = user_info["user_id"] user = user_info["user"]
token_id = user_info["token_id"] token_id = user_info["token_id"]
ip_addr = self.hs.get_ip_from_request(request) ip_addr = self.hs.get_ip_from_request(request)
@ -375,17 +375,17 @@ class Auth(object):
"User-Agent", "User-Agent",
default=[""] default=[""]
)[0] )[0]
if user_id and access_token and ip_addr: if user and access_token and ip_addr:
self.store.insert_client_ip( self.store.insert_client_ip(
user=user_id, user=user,
access_token=access_token, access_token=access_token,
ip=ip_addr, ip=ip_addr,
user_agent=user_agent user_agent=user_agent
) )
request.authenticated_entity = user_id.to_string() request.authenticated_entity = user.to_string()
defer.returnValue((user_id, token_id,)) defer.returnValue((user, token_id,))
except KeyError: except KeyError:
raise AuthError( raise AuthError(
self.TOKEN_NOT_FOUND_HTTP_STATUS, "Missing access token.", self.TOKEN_NOT_FOUND_HTTP_STATUS, "Missing access token.",
@ -420,18 +420,18 @@ class Auth(object):
user_prefix = "user_id = " user_prefix = "user_id = "
for caveat in macaroon.caveats: for caveat in macaroon.caveats:
if caveat.caveat_id.startswith(user_prefix): if caveat.caveat_id.startswith(user_prefix):
user_id = UserID.from_string(caveat.caveat_id[len(user_prefix):]) user = UserID.from_string(caveat.caveat_id[len(user_prefix):])
# This codepath exists so that we can actually return a # This codepath exists so that we can actually return a
# token ID, because we use token IDs in place of device # token ID, because we use token IDs in place of device
# identifiers throughout the codebase. # identifiers throughout the codebase.
# TODO(daniel): Remove this fallback when device IDs are # TODO(daniel): Remove this fallback when device IDs are
# properly implemented. # properly implemented.
ret = yield self._look_up_user_by_access_token(macaroon_str) ret = yield self._look_up_user_by_access_token(macaroon_str)
if ret["user_id"] != user_id: if ret["user"] != user:
logger.error( logger.error(
"Macaroon user (%s) != DB user (%s)", "Macaroon user (%s) != DB user (%s)",
user_id, user,
ret["user_id"] ret["user"]
) )
raise AuthError( raise AuthError(
self.TOKEN_NOT_FOUND_HTTP_STATUS, self.TOKEN_NOT_FOUND_HTTP_STATUS,
@ -490,7 +490,7 @@ class Auth(object):
errcode=Codes.UNKNOWN_TOKEN errcode=Codes.UNKNOWN_TOKEN
) )
user_info = { user_info = {
"user_id": UserID.from_string(ret.get("name")), "user": UserID.from_string(ret.get("name")),
"token_id": ret.get("token_id", None), "token_id": ret.get("token_id", None),
} }
defer.returnValue(user_info) defer.returnValue(user_info)

View File

@ -146,17 +146,17 @@ class AuthTestCase(unittest.TestCase):
return_value={"name": "@baldrick:matrix.org"} return_value={"name": "@baldrick:matrix.org"}
) )
user = "@baldrick:matrix.org" user_id = "@baldrick:matrix.org"
macaroon = pymacaroons.Macaroon( macaroon = pymacaroons.Macaroon(
location=self.hs.config.server_name, location=self.hs.config.server_name,
identifier="key", identifier="key",
key=self.hs.config.macaroon_secret_key) key=self.hs.config.macaroon_secret_key)
macaroon.add_first_party_caveat("gen = 1") macaroon.add_first_party_caveat("gen = 1")
macaroon.add_first_party_caveat("type = access") macaroon.add_first_party_caveat("type = access")
macaroon.add_first_party_caveat("user_id = %s" % (user,)) macaroon.add_first_party_caveat("user_id = %s" % (user_id,))
user_info = yield self.auth._get_user_from_macaroon(macaroon.serialize()) user_info = yield self.auth._get_user_from_macaroon(macaroon.serialize())
user_id = user_info["user_id"] user = user_info["user"]
self.assertEqual(UserID.from_string(user), user_id) self.assertEqual(UserID.from_string(user_id), user)
@defer.inlineCallbacks @defer.inlineCallbacks
def test_get_user_from_macaroon_user_db_mismatch(self): def test_get_user_from_macaroon_user_db_mismatch(self):

View File

@ -72,7 +72,7 @@ class PresenceStateTestCase(unittest.TestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(myid), "user": UserID.from_string(myid),
"token_id": 1, "token_id": 1,
} }
@ -159,7 +159,7 @@ class PresenceListTestCase(unittest.TestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(myid), "user": UserID.from_string(myid),
"token_id": 1, "token_id": 1,
} }

View File

@ -56,7 +56,7 @@ class RoomPermissionsTestCase(RestTestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(self.auth_user_id), "user": UserID.from_string(self.auth_user_id),
"token_id": 1, "token_id": 1,
} }
hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token
@ -441,7 +441,7 @@ class RoomsMemberListTestCase(RestTestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(self.auth_user_id), "user": UserID.from_string(self.auth_user_id),
"token_id": 1, "token_id": 1,
} }
hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token
@ -519,7 +519,7 @@ class RoomsCreateTestCase(RestTestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(self.auth_user_id), "user": UserID.from_string(self.auth_user_id),
"token_id": 1, "token_id": 1,
} }
hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token
@ -610,7 +610,7 @@ class RoomTopicTestCase(RestTestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(self.auth_user_id), "user": UserID.from_string(self.auth_user_id),
"token_id": 1, "token_id": 1,
} }
@ -715,7 +715,7 @@ class RoomMemberStateTestCase(RestTestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(self.auth_user_id), "user": UserID.from_string(self.auth_user_id),
"token_id": 1, "token_id": 1,
} }
hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token
@ -840,7 +840,7 @@ class RoomMessagesTestCase(RestTestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(self.auth_user_id), "user": UserID.from_string(self.auth_user_id),
"token_id": 1, "token_id": 1,
} }
hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token
@ -935,7 +935,7 @@ class RoomInitialSyncTestCase(RestTestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(self.auth_user_id), "user": UserID.from_string(self.auth_user_id),
"token_id": 1, "token_id": 1,
} }
hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token

View File

@ -63,7 +63,7 @@ class RoomTypingTestCase(RestTestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(self.auth_user_id), "user": UserID.from_string(self.auth_user_id),
"token_id": 1, "token_id": 1,
} }

View File

@ -45,7 +45,7 @@ class V2AlphaRestTestCase(unittest.TestCase):
def _get_user_by_access_token(token=None): def _get_user_by_access_token(token=None):
return { return {
"user_id": UserID.from_string(self.USER_ID), "user": UserID.from_string(self.USER_ID),
"token_id": 1, "token_id": 1,
} }
hs.get_auth()._get_user_by_access_token = _get_user_by_access_token hs.get_auth()._get_user_by_access_token = _get_user_by_access_token