annotate jabberbot/_tests/test_capat.py @ 5924:9894a3344118

default password_checker function now customizable
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 19 Jan 2013 01:14:06 +0100
parents 313a1d430bcb
children
rev   line source
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2
3021
313a1d430bcb Skip the XEP-115 test if pyxmpp is not available.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 3019
diff changeset
3 import py
313a1d430bcb Skip the XEP-115 test if pyxmpp is not available.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 3019
diff changeset
4
313a1d430bcb Skip the XEP-115 test if pyxmpp is not available.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 3019
diff changeset
5 try:
313a1d430bcb Skip the XEP-115 test if pyxmpp is not available.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 3019
diff changeset
6 from jabberbot import capat
313a1d430bcb Skip the XEP-115 test if pyxmpp is not available.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 3019
diff changeset
7 except ImportError:
313a1d430bcb Skip the XEP-115 test if pyxmpp is not available.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 3019
diff changeset
8 py.test.skip("Skipping jabber bot tests - pyxmpp is not installed")
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
9
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
10 def test_ver_simple():
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2959
diff changeset
11 # example values supplied by the XEP
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2959
diff changeset
12 ident = (("client", "pc"), )
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
13 feat = ("http://jabber.org/protocol/disco#info",
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
14 "http://jabber.org/protocol/disco#items",
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
15 "http://jabber.org/protocol/muc",
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
16 )
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2959
diff changeset
17
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
18 assert capat.generate_ver(ident, feat) == "8RovUdtOmiAjzj+xI7SK5BCw3A8="
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
19
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
20 def test_ver_complex():
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
21 # this test should verify that ordering works properly
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
22 ident = (("client", "animal"),
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
23 ("client", "bear"), # type ordering after category ordering
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
24 ("apples", "bar"),
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
25 ("apple", "foo"), # "apples" starts with "apple"
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
26 # thus it's greater
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
27 )
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
28 feat = ()
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2959
diff changeset
29
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
30 expected = capat.hash_new('sha1')
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
31 expected.update("apple/foo<apples/bar<client/animal<client/bear<")
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
32 expected = capat.base64.b64encode(expected.digest())
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
33 assert capat.generate_ver(ident, feat) == expected
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
34
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
35 def test_xml():
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
36 try:
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
37 import pyxmpp.iq
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
38 except ImportError:
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
39 py.test.skip("pyxmpp needs to be installed for this test")
3021
313a1d430bcb Skip the XEP-115 test if pyxmpp is not available.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 3019
diff changeset
40
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
41 x = pyxmpp.iq.Iq(stanza_type='result', stanza_id='disco1',
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
42 from_jid='romeo@montague.lit/orchard',
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
43 to_jid='juliet@capulet.lit/chamber')
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
44 y = x.new_query(ns_uri='http://jabber.org/protocol/disco#info')
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
45 z = y.newChild(None, 'identity', None)
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
46 z.setProp('category', 'client')
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
47 z.setProp('type', 'pc')
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
48 y.newChild(None, 'feature', None).setProp(
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2959
diff changeset
49 'var', 'http://jabber.org/protocol/disco#info')
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
50 y.newChild(None, 'feature', None).setProp(
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
51 'var', 'http://jabber.org/protocol/disco#items')
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
52 y.newChild(None, 'feature', None).setProp(
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
53 'var', 'http://jabber.org/protocol/muc')
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2959
diff changeset
54
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
55 assert capat.hash_iq(x) == "8RovUdtOmiAjzj+xI7SK5BCw3A8="
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
56 # hash value taken from `test_ver_simple`
3021
313a1d430bcb Skip the XEP-115 test if pyxmpp is not available.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 3019
diff changeset
57