summaryrefslogtreecommitdiff
path: root/itests/test_pep.py
blob: 382c22b67d8a9ad232600c38963638fbd6771ac7 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import asyncio
import unittest
from uuid import uuid4
from slixmpp.exceptions import IqError
from slixmpp.test.integration import SlixIntegration
from slixmpp.xmlstream import ElementBase, register_stanza_plugin
from slixmpp.plugins.xep_0060.stanza import Item

class Mystanza(ElementBase):
    namespace = 'random-ns'
    name = 'mystanza'
    plugin_attrib = 'mystanza'
    interfaces = {'test'}

register_stanza_plugin(Item, Mystanza)

class TestPEP(SlixIntegration):
    async def asyncSetUp(self):
        await super().asyncSetUp()
        self.add_client(
            self.envjid('CI_ACCOUNT1'),
            self.envstr('CI_ACCOUNT1_PASSWORD'),
        )
        self.add_client(
            self.envjid('CI_ACCOUNT2'),
            self.envstr('CI_ACCOUNT2_PASSWORD'),
        )
        self.register_plugins(['xep_0222', 'xep_0223'])
        for client in self.clients:
            client.auto_authorize = True
        await self.connect_clients()

    async def test_pep_public(self):
        """Check we can get and set public PEP data"""
        stanza = Mystanza()
        stanza['test'] = str(uuid4().hex)
        try:
            await self.clients[0]['xep_0060'].delete_node(
                self.clients[0].boundjid.bare,
                node=stanza.namespace,
            )
        except:
            pass
        await self.clients[0]['xep_0222'].store(stanza, node=stanza.namespace, id='toto')
        fetched = await self.clients[0]['xep_0222'].retrieve(
            stanza.namespace,
        )
        fetched_stanza = fetched['pubsub']['items']['item']['mystanza']
        self.assertEqual(fetched_stanza['test'], stanza['test'])

    async def test_pep_private(self):
        """Check we can get and set private PEP data"""
        stanza = Mystanza()
        stanza['test'] = str(uuid4().hex)
        await self.clients[0]['xep_0223'].store(
            stanza, node='private-random', id='toto'
        )
        fetched = await self.clients[0]['xep_0223'].retrieve(
            'private-random',
        )
        fetched_stanza = fetched['pubsub']['items']['item']['mystanza']
        self.assertEqual(fetched_stanza['test'], stanza['test'])

        with self.assertRaises(IqError):
            fetched = await self.clients[1]['xep_0060'].get_item(
                jid=self.clients[0].boundjid.bare,
                node='private-random',
                item_id='toto',
            )

suite = unittest.TestLoader().loadTestsFromTestCase(TestPEP)