This file is indexed.

/usr/lib/telepathy-gabble-tests/twisted/presence/initial-contact-presence.py is in telepathy-gabble-tests 0.18.3-2build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
"""
Test that contacts we're subscribed to have their presence go from unknown to
offline when we get the roster, even if we've got (unavailable) presence for
them before we receive the roster; and that receiving available presence from a
contact before we get the roster also works.

This serves as a regression test for
<https://bugs.freedesktop.org/show_bug.cgi?id=38603>, among other bugs.
"""

from gabbletest import exec_test, make_presence, sync_stream, elem
from servicetest import assertEquals, EventPattern, sync_dbus

import constants as cs
import ns

from twisted.words.xish import domish

AVAILABLE = (cs.PRESENCE_AVAILABLE, u'available', u'')
OFFLINE = (cs.PRESENCE_OFFLINE, u'offline', u'')
UNKNOWN = (cs.PRESENCE_UNKNOWN, u'unknown', u'')

def make_roster_item(jid, subscription):
    item = domish.Element((None, 'item'))
    item['jid'] = jid
    item['subscription'] = subscription
    return item

def test(q, bus, conn, stream):
    event = q.expect('stream-iq', query_ns=ns.ROSTER)

    amy, bob, che, dre, eve = conn.RequestHandles(cs.HT_CONTACT,
        ['amy@foo.com', 'bob@foo.com', 'che@foo.com', 'dre@foo.com',
         'eve@foo.com'])
    assertEquals({amy: UNKNOWN,
                  bob: UNKNOWN,
                  che: UNKNOWN,
                  dre: UNKNOWN,
                  eve: UNKNOWN,
                 },
        conn.SimplePresence.GetPresences([amy, bob, che, dre, eve]))

    # Before the server sends Gabble the roster, it relays an 'unavailable'
    # presence for one of the contacts we're subscribed to. This seems to
    # happen in practice when using Prosody with a shared roster: the presence
    # probes start coming back negatively before the shared roster is retrieved
    # and returned to the client.
    stream.send(make_presence('dre@foo.com', type='unavailable'))

    # Dre's presence is still unknown, since we don't have the roster. This
    # isn't a change per se---we checked above, and Dre's presence was
    # unknown---so it shouldn't be signalled.
    q.forbid_events([EventPattern('dbus-signal', signal='PresencesChanged',
        args=[{dre: UNKNOWN}])])

    # We also receive an available presence from Eve before the roster arrives:
    # this presence should behave normally.
    stream.send(make_presence('eve@foo.com'))
    q.expect('dbus-signal', signal='PresencesChanged', args=[{eve: AVAILABLE}])

    # We also get a message from a contact before we get the roster (presumably
    # they sent this while we were offline?). This shouldn't affect the contact
    # being reported as offline when we finally do get the roster, but it used
    # to: <https://bugs.freedesktop.org/show_bug.cgi?id=41743>.
    stream.send(
        elem('message', from_='amy@foo.com', type='chat')(
          elem('body')(u'why are you never online?')
        ))
    q.expect('dbus-signal', signal='MessageReceived')

    event.stanza['type'] = 'result'
    event.query.addChild(make_roster_item('amy@foo.com', 'both'))
    event.query.addChild(make_roster_item('bob@foo.com', 'from'))
    event.query.addChild(make_roster_item('che@foo.com', 'to'))
    event.query.addChild(make_roster_item('dre@foo.com', 'both'))
    event.query.addChild(make_roster_item('eve@foo.com', 'both'))
    stream.send(event.stanza)

    # The presence for contacts on the roster whose subscription is 'to' or
    # 'both' but for whom we haven't already received presence should change
    # from 'unknown' (as checked above) to 'offline'.
    e = q.expect('dbus-signal', signal='PresencesChanged')
    changed_presences, = e.args
    assertEquals(
        {amy: OFFLINE,
         che: OFFLINE,
         dre: OFFLINE,
        },
        changed_presences)

    assertEquals({amy: OFFLINE,
                  bob: UNKNOWN,
                  che: OFFLINE,
                  dre: OFFLINE,
                  eve: AVAILABLE,
                 },
        conn.SimplePresence.GetPresences([amy, bob, che, dre, eve]))

if __name__ == '__main__':
    exec_test(test)