source: ralphm-patches/roster_item_more.patch @ 54:03ec57713c90

Last change on this file since 54:03ec57713c90 was 54:03ec57713c90, checked in by Ralph Meijer <ralphm@…>, 9 years ago

Upstreamed Request patches, split out c2s patches in managable chunks, prepare for release of Wokkel 0.7.0.

File size: 3.1 KB
  • wokkel/im.py

    # HG changeset patch
    # Parent a8623e33ce6e62e39e0049451c5f65016c8b30b7
    Record sender on received roster sets to support alternative roster sources.
    
    TODO: roster item removal notifications.
    
    diff -r a8623e33ce6e wokkel/im.py
    a b  
    371371    @ivar groups: Set of groups this contact is categorized in. Groups are
    372372                  represented by an opaque identifier of type C{unicode}.
    373373    @type groups: C{set}
     374    @ivar approved: Signals pre-approved subscription.
     375    @type approved: C{bool}
     376    @ivar remove: Signals roster item removal.
     377    @type remove: C{bool}
     378    @ivar sender: The JID of the entity that sent this roster item.
     379    @type sender: L{JID}
    374380    """
    375381
    376382    __subscriptionStates = {(False, False): None,
     
    381387    def __init__(self, entity, subscriptionTo=False, subscriptionFrom=False,
    382388                       name=None, groups=None):
    383389        self.entity = entity
     390        self.name = name
    384391        self.subscriptionTo = subscriptionTo
    385392        self.subscriptionFrom = subscriptionFrom
    386         self.name = name
    387393        self.groups = groups or set()
    388394
    389395        self.pendingOut = False
    390396        self.approved = False
    391397        self.remove = False
    392398
     399        self.sender = None
     400
    393401
    394402    def toElement(self):
    395403        element = domish.Element((NS_ROSTER, 'item'))
     
    505513            raise error.StanzaError('service-unavailable')
    506514
    507515        item = RosterItem.fromElement(iq.query.item)
     516        if iq.hasAttribute('from'):
     517            item.sender = jid.internJID(iq['from'])
    508518
    509519        if item.remove:
    510520            d = defer.maybeDeferred(self.onRosterRemove, item.entity)
  • wokkel/test/test_im.py

    diff -r a8623e33ce6e wokkel/test/test_im.py
    a b  
    764764        return d
    765765
    766766
    767     def test_onRosterSetUntrusted(self):
     767    def test_onRosterSetIgnored(self):
    768768        """
    769         Roster pushes from untrusted sources will be not be handled.
     769        Ignored roster pushes return a service unavailable error.
    770770        """
    771771        xml = """
    772772          <iq type='set' from='bad@example.org'>
     
    790790        return d
    791791
    792792
     793    def test_onRosterSetOtherSource(self):
     794        """
     795        Roster pushes can be sent from other entities, too.
     796        """
     797        xml = """
     798          <iq type='set' from='other@example.org'>
     799            <query xmlns='jabber:iq:roster'>
     800              <item jid='user@example.org'/>
     801            </query>
     802          </iq>
     803        """
     804
     805        items = []
     806
     807        def onRosterSet(item):
     808            items.append(item)
     809
     810        def cb(result):
     811            item = items[0]
     812            self.assertEquals(JID('other@example.org'), item.sender)
     813
     814        self.service.onRosterSet = onRosterSet
     815
     816        d = self.handleRequest(xml)
     817        d.addCallback(cb)
     818        return d
     819
     820
    793821    def test_onRosterRemove(self):
    794822        """
    795823        A roster push causes onRosterSet to be called with the parsed item.
Note: See TracBrowser for help on using the repository browser.