Class: Caps::HelperTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
ClientTester
Defined in:
lib/gems/xmpp4r-0.4/test/caps/tc_helper.rb

Instance Method Summary collapse

Instance Method Details

#featuresObject



90
91
92
93
94
# File 'lib/gems/xmpp4r-0.4/test/caps/tc_helper.rb', line 90

def features
  [Jabber::Discovery::Feature.new("http://jabber.org/protocol/disco#info"),
   Jabber::Discovery::Feature.new("http://jabber.org/protocol/disco#items"),
   Jabber::Discovery::Feature.new("http://jabber.org/protocol/muc")]
end

#identitiesObject



86
87
88
# File 'lib/gems/xmpp4r-0.4/test/caps/tc_helper.rb', line 86

def identities
  [Jabber::Discovery::Identity.new('client', 'Exodus 0.9.1', 'pc')]
end

#iq_discovering_capabilitiesObject



96
97
98
# File 'lib/gems/xmpp4r-0.4/test/caps/tc_helper.rb', line 96

def iq_discovering_capabilities
  "<iq from='new-big-computer.local' type='get' to='[email protected]/capable_client' id='1867999907' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info'/></iq>"
end

#test_caps_complexObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/gems/xmpp4r-0.4/test/caps/tc_helper.rb', line 102

def test_caps_complex
  form = Dataforms::XData.new(:result)
  form.add(Dataforms::XDataField.new('FORM_TYPE', :hidden)).value = 'urn:xmpp:dataforms:softwareinfo'
  form.add(Dataforms::XDataField.new('ip_version')).values = ['ipv4', 'ipv6']
  form.add(Dataforms::XDataField.new('software')).value = 'Psi' # re-ordered
  form.add(Dataforms::XDataField.new('software_version')).value = '0.11'
  form.add(Dataforms::XDataField.new('os')).value = 'Mac'
  form.add(Dataforms::XDataField.new('os_version')).value = '10.5.1'
  ver = Caps::generate_ver([Discovery::Identity.new('client', 'Psi 0.9.1', 'pc').set_xml_lang('en'),
                            Discovery::Identity.new('client', 'Ψ 0.9.1', 'pc').set_xml_lang('el')],
                           [Discovery::Feature.new('http://jabber.org/protocol/muc'), # re-ordered
                            Discovery::Feature.new('http://jabber.org/protocol/disco#info'),
                            Discovery::Feature.new('http://jabber.org/protocol/disco#items')],
                           [form])
  assert_equal('8lu+88MRxmKM7yO3MEzY7YmTsWs=', ver)
end

#test_caps_complex_importedObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/gems/xmpp4r-0.4/test/caps/tc_helper.rb', line 121

def test_caps_complex_imported
  query = IqQuery::import(REXML::Document.new(<<END).root)
<query xmlns='http://jabber.org/protocol/disco#info'
       node='http://psi-im.org#8lu+88MRxmKM7yO3MEzY7YmTsWs='>
  <identity xml:lang='en' category='client' name='Psi 0.9.1' type='pc'/>
  <identity xml:lang='el' category='client' name='Ψ 0.9.1' type='pc'/>
  <feature var='http://jabber.org/protocol/disco#info'/>
  <feature var='http://jabber.org/protocol/disco#items'/>
  <feature var='http://jabber.org/protocol/muc'/>
  <x xmlns='jabber:x:data' type='result'>
    <field var='FORM_TYPE' type='hidden'>
      <value>urn:xmpp:dataforms:softwareinfo</value>
    </field>
    <field var='ip_version'>
      <value>ipv4</value>
      <value>ipv6</value>
    </field>
    <field var='os'>
      <value>Mac</value>
    </field>
    <field var='os_version'>
      <value>10.5.1</value>
    </field>
    <field var='software'>
      <value>Psi</value>
    </field>
    <field var='software_version'>
      <value>0.11</value>
    </field>
  </x>
</query>
END
  assert_equal('8lu+88MRxmKM7yO3MEzY7YmTsWs=',
               Caps::generate_ver_from_discoinfo(query))
end

#test_caps_replyObject

Walk through the client/ server conversation defined in www.xmpp.org/extensions/xep-0115.html#usecases and assert conformance.



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
# File 'lib/gems/xmpp4r-0.4/test/caps/tc_helper.rb', line 19

def test_caps_reply
  # This will be invoked by 'wait_state' below...
  state { |presence|
    assert_kind_of(Jabber::Presence, presence)
    c = presence.first_element('c')
    assert_kind_of(Jabber::Caps::C, c)

    # see http://www.xmpp.org/extensions/xep-0115.html#ver
    assert_equal('SrFo9ar2CCk2EnOH4q4QANeuxLQ=', c.ver)

    # version 1.5 of xep 0115 indicates that the <c /> stanzq MUST feature a 'hash' attribute
    assert_equal('sha-1', c.hash)

    assert_equal("http://home.gna.org/xmpp4r/##{Jabber::XMPP4R_VERSION}", c.node)

    send(iq_discovering_capabilities)
  }

  # Construct Caps::Helper which will send a <presence>
  # stanza (with embedded <c/> advert) to the 'server'
  h = Caps::Helper.new(@client, identities, features)

  # The 'server' will receive the <presence> stanza and
  # yield it to the 'state' block above, where an <iq> query
  # will be sent back to the 'client,' to discover its capabilities.
  # Wait here until the block has been executed.
  wait_state

  # The Caps::Helper will process the <iq> query from the 'server'
  # and reply with an <iq> result providing the details of its
  # identities and features.

  state { |iq|
    assert_kind_of(Jabber::Iq, iq)
    assert_equal(:result, iq.type)
    assert_equal('1867999907', iq.id)
    assert_equal('new-big-computer.local', iq.to.to_s)

    assert_kind_of(Jabber::Discovery::IqQueryDiscoInfo, iq.query)
    assert_equal(iq.query.identities.size, identities.size)
    get_category_iname_type = lambda{ |i| [i.category,i.iname,i.type] }
    assert_equal(iq.query.identities.map(&get_category_iname_type).sort!, identities.map(&get_category_iname_type).sort!)

    assert_equal(3, iq.query.features.size)
    get_var = lambda { |f| f.var }
    assert_equal(iq.query.features.sort, features.map(&get_var).sort)
  }

  # The 'server' will receive the <iq> result from the
  # 'client' and yield it to the block above. Wait here
  # until that block exits.
  wait_state
end

#test_custom_nodeObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/gems/xmpp4r-0.4/test/caps/tc_helper.rb', line 73

def test_custom_node
  client_id='http://new-big-computer.local/client#321'

  state { |presence|
    c = presence.first_element('c')
    assert_kind_of(Jabber::Caps::C, c)
    assert_equal(client_id, c.node)
    assert_equal('SrFo9ar2CCk2EnOH4q4QANeuxLQ=', c.ver)
  }
  h = Caps::Helper.new(@client, identities, features, client_id)
  wait_state
end