Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Name the type of token in "Invalid token" messages (#10815)
Browse files Browse the repository at this point in the history
I had one of these error messages yesterday and assumed it was an
invalid auth token (because that was an HTTP query parameter in the
test) I was working on. In fact, it was an invalid next batch token for
syncing.
  • Loading branch information
David Robertson authored Sep 14, 2021
1 parent 01c88a0 commit 319b8b6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/10815.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Specify the type of token in generic "Invalid token" error messages.
2 changes: 1 addition & 1 deletion synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ async def validate_short_term_login_token(
try:
res = self.macaroon_gen.verify_short_term_login_token(login_token)
except Exception:
raise AuthError(403, "Invalid token", errcode=Codes.FORBIDDEN)
raise AuthError(403, "Invalid login token", errcode=Codes.FORBIDDEN)

await self.auth.check_auth_blocking(res.user_id)
return res
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def from_string(string: str) -> "RelationPaginationToken":
t, s = string.split("-")
return RelationPaginationToken(int(t), int(s))
except ValueError:
raise SynapseError(400, "Invalid token")
raise SynapseError(400, "Invalid relation pagination token")

def to_string(self) -> str:
return "%d-%d" % (self.topological, self.stream)
Expand Down Expand Up @@ -103,7 +103,7 @@ def from_string(string: str) -> "AggregationPaginationToken":
c, s = string.split("-")
return AggregationPaginationToken(int(c), int(s))
except ValueError:
raise SynapseError(400, "Invalid token")
raise SynapseError(400, "Invalid aggregation pagination token")

def to_string(self) -> str:
return "%d-%d" % (self.count, self.stream)
Expand Down
6 changes: 3 additions & 3 deletions synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ async def parse(cls, store: "DataStore", string: str) -> "RoomStreamToken":
)
except Exception:
pass
raise SynapseError(400, "Invalid token %r" % (string,))
raise SynapseError(400, "Invalid room stream token %r" % (string,))

@classmethod
def parse_stream_token(cls, string: str) -> "RoomStreamToken":
Expand All @@ -520,7 +520,7 @@ def parse_stream_token(cls, string: str) -> "RoomStreamToken":
return cls(topological=None, stream=int(string[1:]))
except Exception:
pass
raise SynapseError(400, "Invalid token %r" % (string,))
raise SynapseError(400, "Invalid room stream token %r" % (string,))

def copy_and_advance(self, other: "RoomStreamToken") -> "RoomStreamToken":
"""Return a new token such that if an event is after both this token and
Expand Down Expand Up @@ -619,7 +619,7 @@ async def from_string(cls, store: "DataStore", string: str) -> "StreamToken":
await RoomStreamToken.parse(store, keys[0]), *(int(k) for k in keys[1:])
)
except Exception:
raise SynapseError(400, "Invalid Token")
raise SynapseError(400, "Invalid stream token")

async def to_string(self, store: "DataStore") -> str:
return self._SEPARATOR.join(
Expand Down

0 comments on commit 319b8b6

Please sign in to comment.