summaryrefslogtreecommitdiff
path: root/tests/test_xep_0454.py
blob: 8d43c7e3edce5715caf1b6ba65d1792bffbec3c0 (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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 et ts=4 sts=4 sw=4
#
# Copyright © 2022 Maxime “pep” Buquet <pep@bouah.net>
#
# Distributed under terms of the GPLv3+ license.

"""
    Tests for XEP-0454 (OMEMO Media Sharing) plugin.
"""

import unittest
from io import BytesIO
from slixmpp.test import SlixTest
from slixmpp.plugins.xep_0454 import XEP_0454


class TestMediaSharing(SlixTest):

    def testEncryptDecryptSmall(self):
        plain = b'qwertyuiop'
        ciphertext, fragment = XEP_0454.encrypt(input_file=BytesIO(plain))
        result = XEP_0454.decrypt(BytesIO(ciphertext), fragment)

        self.assertEqual(plain, result)

    def testEncryptDecrypt(self):
        plain = b'a' * 4096 + b'qwertyuiop'
        ciphertext, fragment = XEP_0454.encrypt(input_file=BytesIO(plain))
        result = XEP_0454.decrypt(BytesIO(ciphertext), fragment)

        self.assertEqual(plain, result)

    def testFormatURL(self):
        url = 'https://foo.bar'
        fragment = 'a' * 88
        result = XEP_0454.format_url(url, fragment)
        self.assertEqual('aesgcm://foo.bar#' + 'a' * 88, result)

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