plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:

- support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace
- maintains one identity across both versions of OMEMO
- migrates data from the old plugin
- includes more features for protocol stability
- uses SCE for modern OMEMO
- fully type-checked, linted and format-checked
- added type hints to various pieces of backend code used by the plugin
- added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy)
- core (xmpp): enabled `send` trigger and made it an asyncPoint

fix 375
This commit is contained in:
Syndace 2022-08-23 21:06:24 +02:00
commit 75ae8160ae
2 changed files with 2202 additions and 1414 deletions

View file

@ -16,9 +16,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Type-check with `mypy --strict`
# Lint with `pylint`
from datetime import date, datetime, time, timezone
import pytest

View file

@ -16,11 +16,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Type-check with `mypy --strict --disable-error-code no-untyped-call`
# Lint with `pylint`
from datetime import datetime, timezone
from typing import Callable, Iterator, Optional, cast
from typing import Callable, cast
import pytest
@ -77,8 +74,8 @@ class CustomAffixImpl(SCECustomAffix):
</xs:element>"""
def create(self, stanza: domish.Element) -> domish.Element:
recipient = cast(Optional[str], stanza.getAttribute("to", None))
sender = cast(Optional[str], stanza.getAttribute("from", None))
recipient = stanza.getAttribute("to", None)
sender = stanza.getAttribute("from", None)
if recipient is None or sender is None:
raise ValueError(
@ -487,21 +484,15 @@ def test_namespace_conversion() -> None: # pylint: disable=missing-function-doc
envelope_serialized = XEP_0420.pack_stanza(profile, stanza)
envelope = string_to_domish(envelope_serialized.decode("utf-8"))
content = next(cast(Iterator[domish.Element], envelope.elements(NS_SCE, "content")))
content = next(envelope.elements(NS_SCE, "content"))
# The body should have been assigned ``jabber:client`` as its namespace
assert next(
cast(Iterator[domish.Element], content.elements("jabber:client", "body")),
None
) is not None
assert next(content.elements("jabber:client", "body"), None) is not None
XEP_0420.unpack_stanza(profile, stanza, envelope_serialized)
# The body should still have ``jabber:client`` after unpacking
assert next(
cast(Iterator[domish.Element], stanza.elements("jabber:client", "body")),
None
) is not None
assert next(stanza.elements("jabber:client", "body"), None) is not None
def test_non_encryptable_elements() -> None: # pylint: disable=missing-function-docstring
@ -520,18 +511,11 @@ def test_non_encryptable_elements() -> None: # pylint: disable=missing-function
envelope_serialized = XEP_0420.pack_stanza(profile, stanza)
envelope = string_to_domish(envelope_serialized.decode("utf-8"))
content = next(cast(Iterator[domish.Element], envelope.elements(NS_SCE, "content")))
content = next(envelope.elements(NS_SCE, "content"))
# The store hint must not have been moved to the content element
assert next(
cast(Iterator[domish.Element], stanza.elements(NS_HINTS, "store")),
None
) is not None
assert next(
cast(Iterator[domish.Element], content.elements(NS_HINTS, "store")),
None
) is None
assert next(stanza.elements(NS_HINTS, "store"), None) is not None
assert next(content.elements(NS_HINTS, "store"), None) is None
stanza = string_to_domish(
"""<message from="foo@example.com" to="bar@example.com"></message>"""
@ -548,10 +532,7 @@ def test_non_encryptable_elements() -> None: # pylint: disable=missing-function
XEP_0420.unpack_stanza(profile, stanza, envelope_serialized)
assert next(
cast(Iterator[domish.Element], stanza.elements(NS_HINTS, "store")),
None
) is None
assert next(stanza.elements(NS_HINTS, "store"), None) is None
def test_schema_validation() -> None: # pylint: disable=missing-function-docstring