summaryrefslogtreecommitdiff
path: root/tests/test_stanza_xep_0300.py
blob: 5ffd8e3b2cfc05b756e6fbb941da71438247b290 (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
"""
    Slixmpp: The Slick XMPP Library
    Copyright (C) 2017 Emmanuel Gil Peyrot
    This file is part of Slixmpp.

    See the file LICENSE for copying permission.
"""

import unittest
from slixmpp import Iq
from slixmpp.test import SlixTest
from slixmpp.plugins.xep_0300 import Hash
from slixmpp.xmlstream import register_stanza_plugin


class TestHash(SlixTest):

    def setUp(self):
        register_stanza_plugin(Iq, Hash)

    def testSimpleElement(self):
        """Test that the element is created correctly."""
        iq = Iq()
        iq['type'] = 'set'
        iq['hash']['algo'] = 'sha-256'
        iq['hash']['value'] = 'EQgS9n+h4fARf289cCQcGkKnsHcRqTwkd8xRbZBC+ds='

        self.check(iq, """
          <iq type="set">
            <hash xmlns="urn:xmpp:hashes:2" algo="sha-256">EQgS9n+h4fARf289cCQcGkKnsHcRqTwkd8xRbZBC+ds=</hash>
          </iq>
        """)

    def testInvalidAlgo(self):
        """Test that invalid algos raise an exception."""
        iq = Iq()
        iq['type'] = 'set'
        try:
            iq['hash']['algo'] = 'coucou'
        except ValueError:
            pass
        else:
            raise self.failureException

    #def testDisabledAlgo(self):
    #    """Test that disabled algos aren’t used."""
    #    iq = Iq()
    #    iq['type'] = 'set'
    #    try:
    #        iq['hash']['algo'] = 'sha-1'
    #    except ValueError:
    #        pass
    #    else:
    #        raise self.failureException


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