File: test_resourceprep.py

package info (click to toggle)
slidge 0.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,516 kB
  • sloc: python: 20,548; xml: 518; sh: 57; javascript: 27; makefile: 14
file content (39 lines) | stat: -rw-r--r-- 1,052 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from unittest import mock

import pytest
from slixmpp import JID

from slidge.group import LegacyParticipant
from slidge.db.models import Participant


@pytest.fixture
def muc():
    muc = mock.MagicMock()
    muc.jid = JID("room@component")
    return muc


def test_unassigned_code_points(muc):
    part = LegacyParticipant(muc, Participant(nickname="fiesta! 🎉"))
    assert "🎉" not in part.jid.resource


def test_control_chars(muc):
    part = LegacyParticipant(
        muc, Participant(nickname="leet hackk\ber and I have control chars in my nick")
    )
    assert "\b" not in part.jid.resource


def test_control_chars_and_unassigned_code_points(muc):
    part = LegacyParticipant(
        muc,
        Participant(
            nickname="I'm a leet hackk\ber"
            + "🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉" * 10
            + ", I have control chars, emojis in my nick and a ridiculously long nickname"
        ),
    )
    assert "\b" not in part.jid.resource
    assert "🎉" not in part.jid.resource