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

Commit

Permalink
Remove GroupID construct.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed May 25, 2022
1 parent 17a6aa0 commit 431034a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 43 deletions.
23 changes: 0 additions & 23 deletions synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,29 +320,6 @@ class EventID(DomainSpecificString):
SIGIL = "$"


@attr.s(slots=True, frozen=True, repr=False)
class GroupID(DomainSpecificString):
"""Structure representing a group ID."""

SIGIL = "+"

@classmethod
def from_string(cls: Type[DS], s: str) -> DS:
group_id: DS = super().from_string(s) # type: ignore

if not group_id.localpart:
raise SynapseError(400, "Group ID cannot be empty", Codes.INVALID_PARAM)

if contains_invalid_mxid_characters(group_id.localpart):
raise SynapseError(
400,
"Group ID can only contain characters a-z, 0-9, or '=_-./'",
Codes.INVALID_PARAM,
)

return group_id


mxid_localpart_allowed_characters = set(
"_-./=" + string.ascii_lowercase + string.digits
)
Expand Down
21 changes: 1 addition & 20 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from synapse.api.errors import SynapseError
from synapse.types import GroupID, RoomAlias, UserID, map_username_to_mxid_localpart
from synapse.types import RoomAlias, UserID, map_username_to_mxid_localpart

from tests import unittest

Expand Down Expand Up @@ -62,25 +62,6 @@ def test_validate(self):
self.assertFalse(RoomAlias.is_valid(id_string))


class GroupIDTestCase(unittest.TestCase):
def test_parse(self):
group_id = GroupID.from_string("+group/=_-.123:my.domain")
self.assertEqual("group/=_-.123", group_id.localpart)
self.assertEqual("my.domain", group_id.domain)

def test_validate(self):
bad_ids = ["$badsigil:domain", "+:empty"] + [
"+group" + c + ":domain" for c in "A%?æ£"
]
for id_string in bad_ids:
try:
GroupID.from_string(id_string)
self.fail("Parsing '%s' should raise exception" % id_string)
except SynapseError as exc:
self.assertEqual(400, exc.code)
self.assertEqual("M_INVALID_PARAM", exc.errcode)


class MapUsernameTestCase(unittest.TestCase):
def testPassThrough(self):
self.assertEqual(map_username_to_mxid_localpart("test1234"), "test1234")
Expand Down

0 comments on commit 431034a

Please sign in to comment.