gmcmillan-xmpp4r 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +91 -0
- data/COPYING +340 -0
- data/LICENSE +59 -0
- data/README.rdoc +122 -0
- data/README_ruby19.txt +43 -0
- data/Rakefile +258 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/README +56 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +424 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.rb +346 -0
- data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
- data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
- data/data/doc/xmpp4r/examples/advanced/migrate.rb +88 -0
- data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
- data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
- data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
- data/data/doc/xmpp4r/examples/advanced/recvfile.rb +85 -0
- data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +129 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
- data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +109 -0
- data/data/doc/xmpp4r/examples/advanced/xmpping.rb +146 -0
- data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +14 -0
- data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/client.rb +70 -0
- data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
- data/data/doc/xmpp4r/examples/basic/echo.rb +37 -0
- data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/mass_sender.rb +68 -0
- data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +12 -0
- data/data/doc/xmpp4r/examples/basic/mucinfo.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +82 -0
- data/data/doc/xmpp4r/examples/basic/register.rb +42 -0
- data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
- data/data/doc/xmpp4r/examples/basic/roster.rb +44 -0
- data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
- data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
- data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +171 -0
- data/data/doc/xmpp4r/examples/basic/send_vcard.rb +67 -0
- data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
- data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
- data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
- data/lib/xmpp4r.rb +118 -0
- data/lib/xmpp4r/base64.rb +32 -0
- data/lib/xmpp4r/bytestreams.rb +15 -0
- data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +321 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +257 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +31 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +54 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +153 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +86 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +198 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +65 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +82 -0
- data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +170 -0
- data/lib/xmpp4r/bytestreams/iq/si.rb +206 -0
- data/lib/xmpp4r/callbacks.rb +133 -0
- data/lib/xmpp4r/caps.rb +1 -0
- data/lib/xmpp4r/caps/c.rb +67 -0
- data/lib/xmpp4r/caps/helper/generator.rb +160 -0
- data/lib/xmpp4r/caps/helper/helper.rb +84 -0
- data/lib/xmpp4r/client.rb +345 -0
- data/lib/xmpp4r/command/helper/responder.rb +53 -0
- data/lib/xmpp4r/command/iq/command.rb +154 -0
- data/lib/xmpp4r/component.rb +103 -0
- data/lib/xmpp4r/connection.rb +231 -0
- data/lib/xmpp4r/dataforms.rb +5 -0
- data/lib/xmpp4r/dataforms/x/data.rb +297 -0
- data/lib/xmpp4r/debuglog.rb +63 -0
- data/lib/xmpp4r/delay.rb +5 -0
- data/lib/xmpp4r/delay/x/delay.rb +99 -0
- data/lib/xmpp4r/discovery.rb +8 -0
- data/lib/xmpp4r/discovery/helper/helper.rb +58 -0
- data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
- data/lib/xmpp4r/discovery/iq/discoinfo.rb +211 -0
- data/lib/xmpp4r/discovery/iq/discoitems.rb +147 -0
- data/lib/xmpp4r/entity_time.rb +6 -0
- data/lib/xmpp4r/entity_time/iq.rb +45 -0
- data/lib/xmpp4r/entity_time/responder.rb +57 -0
- data/lib/xmpp4r/errors.rb +284 -0
- data/lib/xmpp4r/feature_negotiation.rb +5 -0
- data/lib/xmpp4r/feature_negotiation/iq/feature.rb +28 -0
- data/lib/xmpp4r/framework/base.rb +55 -0
- data/lib/xmpp4r/framework/bot.rb +148 -0
- data/lib/xmpp4r/httpbinding.rb +5 -0
- data/lib/xmpp4r/httpbinding/client.rb +275 -0
- data/lib/xmpp4r/idgenerator.rb +37 -0
- data/lib/xmpp4r/iq.rb +221 -0
- data/lib/xmpp4r/jid.rb +167 -0
- data/lib/xmpp4r/last.rb +2 -0
- data/lib/xmpp4r/last/helper/helper.rb +37 -0
- data/lib/xmpp4r/last/iq/last.rb +67 -0
- data/lib/xmpp4r/location.rb +2 -0
- data/lib/xmpp4r/location/helper/helper.rb +56 -0
- data/lib/xmpp4r/location/location.rb +179 -0
- data/lib/xmpp4r/message.rb +226 -0
- data/lib/xmpp4r/muc.rb +14 -0
- data/lib/xmpp4r/muc/helper/mucbrowser.rb +92 -0
- data/lib/xmpp4r/muc/helper/mucclient.rb +469 -0
- data/lib/xmpp4r/muc/helper/simplemucclient.rb +332 -0
- data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
- data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
- data/lib/xmpp4r/muc/iq/mucowner.rb +15 -0
- data/lib/xmpp4r/muc/item.rb +143 -0
- data/lib/xmpp4r/muc/x/muc.rb +70 -0
- data/lib/xmpp4r/muc/x/mucuserinvite.rb +60 -0
- data/lib/xmpp4r/muc/x/mucuseritem.rb +36 -0
- data/lib/xmpp4r/presence.rb +232 -0
- data/lib/xmpp4r/pubsub.rb +8 -0
- data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
- data/lib/xmpp4r/pubsub/children/event.rb +49 -0
- data/lib/xmpp4r/pubsub/children/item.rb +35 -0
- data/lib/xmpp4r/pubsub/children/items.rb +53 -0
- data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
- data/lib/xmpp4r/pubsub/children/publish.rb +38 -0
- data/lib/xmpp4r/pubsub/children/retract.rb +41 -0
- data/lib/xmpp4r/pubsub/children/subscription.rb +62 -0
- data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
- data/lib/xmpp4r/pubsub/children/unsubscribe.rb +63 -0
- data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +129 -0
- data/lib/xmpp4r/pubsub/helper/nodehelper.rb +156 -0
- data/lib/xmpp4r/pubsub/helper/oauth_service_helper.rb +90 -0
- data/lib/xmpp4r/pubsub/helper/servicehelper.rb +490 -0
- data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
- data/lib/xmpp4r/query.rb +15 -0
- data/lib/xmpp4r/reliable.rb +168 -0
- data/lib/xmpp4r/rexmladdons.rb +197 -0
- data/lib/xmpp4r/roster.rb +7 -0
- data/lib/xmpp4r/roster/helper/roster.rb +532 -0
- data/lib/xmpp4r/roster/iq/roster.rb +215 -0
- data/lib/xmpp4r/roster/x/roster.rb +138 -0
- data/lib/xmpp4r/rpc.rb +2 -0
- data/lib/xmpp4r/rpc/helper/client.rb +123 -0
- data/lib/xmpp4r/rpc/helper/server.rb +74 -0
- data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +67 -0
- data/lib/xmpp4r/rpc/iq/rpc.rb +23 -0
- data/lib/xmpp4r/sasl.rb +259 -0
- data/lib/xmpp4r/semaphore.rb +38 -0
- data/lib/xmpp4r/stream.rb +611 -0
- data/lib/xmpp4r/streamparser.rb +66 -0
- data/lib/xmpp4r/test/listener_mocker.rb +118 -0
- data/lib/xmpp4r/tune.rb +2 -0
- data/lib/xmpp4r/tune/helper/helper.rb +58 -0
- data/lib/xmpp4r/tune/tune.rb +113 -0
- data/lib/xmpp4r/vcard.rb +6 -0
- data/lib/xmpp4r/vcard/helper/vcard.rb +84 -0
- data/lib/xmpp4r/vcard/iq/vcard.rb +109 -0
- data/lib/xmpp4r/version.rb +7 -0
- data/lib/xmpp4r/version/helper/responder.rb +72 -0
- data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
- data/lib/xmpp4r/version/iq/version.rb +105 -0
- data/lib/xmpp4r/x.rb +37 -0
- data/lib/xmpp4r/xhtml.rb +1 -0
- data/lib/xmpp4r/xhtml/html.rb +115 -0
- data/lib/xmpp4r/xmpp4r.rb +20 -0
- data/lib/xmpp4r/xmppelement.rb +168 -0
- data/lib/xmpp4r/xmppstanza.rb +162 -0
- data/setup.rb +1586 -0
- data/test/bytestreams/tc_ibb.rb +188 -0
- data/test/bytestreams/tc_socks5bytestreams.rb +114 -0
- data/test/caps/tc_helper.rb +158 -0
- data/test/dataforms/tc_data.rb +81 -0
- data/test/delay/tc_xdelay.rb +51 -0
- data/test/discovery/tc_responder.rb +91 -0
- data/test/entity_time/tc_responder.rb +65 -0
- data/test/last/tc_helper.rb +75 -0
- data/test/lib/assert_equal_xml.rb +14 -0
- data/test/lib/clienttester.rb +149 -0
- data/test/muc/tc_muc_mucclient.rb +834 -0
- data/test/muc/tc_muc_simplemucclient.rb +114 -0
- data/test/muc/tc_mucowner.rb +50 -0
- data/test/pubsub/tc_helper.rb +785 -0
- data/test/pubsub/tc_nodeconfig.rb +61 -0
- data/test/pubsub/tc_subscriptionconfig.rb +41 -0
- data/test/roster/tc_helper.rb +523 -0
- data/test/roster/tc_iqqueryroster.rb +173 -0
- data/test/roster/tc_xroster.rb +73 -0
- data/test/rpc/tc_helper.rb +96 -0
- data/test/tc_callbacks.rb +129 -0
- data/test/tc_class_names.rb +146 -0
- data/test/tc_client.rb +30 -0
- data/test/tc_errors.rb +146 -0
- data/test/tc_idgenerator.rb +30 -0
- data/test/tc_iq.rb +113 -0
- data/test/tc_iqquery.rb +31 -0
- data/test/tc_jid.rb +204 -0
- data/test/tc_presence.rb +150 -0
- data/test/tc_rexml.rb +139 -0
- data/test/tc_stream.rb +193 -0
- data/test/tc_streamComponent.rb +105 -0
- data/test/tc_streamError.rb +129 -0
- data/test/tc_streamSend.rb +59 -0
- data/test/tc_streamparser.rb +137 -0
- data/test/tc_xmppstanza.rb +135 -0
- data/test/ts_xmpp4r.rb +44 -0
- data/test/tune/tc_helper_recv.rb +82 -0
- data/test/tune/tc_helper_send.rb +74 -0
- data/test/tune/tc_tune.rb +79 -0
- data/test/vcard/tc_helper.rb +49 -0
- data/test/vcard/tc_iqvcard.rb +62 -0
- data/test/version/tc_helper.rb +60 -0
- data/test/version/tc_iqqueryversion.rb +97 -0
- data/test/xhtml/tc_html.rb +41 -0
- data/tools/gen_requires.bash +31 -0
- data/tools/xmpp4r-gemspec-test.rb +11 -0
- data/xmpp4r.gemspec +249 -0
- metadata +299 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
|
4
|
+
$:.unshift File::dirname(__FILE__) + '/../../lib'
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require File::dirname(__FILE__) + '/../lib/clienttester'
|
8
|
+
require 'xmpp4r/muc'
|
9
|
+
require 'xmpp4r/semaphore'
|
10
|
+
include Jabber
|
11
|
+
|
12
|
+
class SimpleMUCClientTest < Test::Unit::TestCase
|
13
|
+
include ClientTester
|
14
|
+
|
15
|
+
def test_new1
|
16
|
+
m = MUC::SimpleMUCClient.new(@client)
|
17
|
+
assert_equal(nil, m.jid)
|
18
|
+
assert_equal(nil, m.my_jid)
|
19
|
+
assert_equal({}, m.roster)
|
20
|
+
assert(!m.active?)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_complex
|
24
|
+
m = MUC::SimpleMUCClient.new(@client)
|
25
|
+
|
26
|
+
block_args = []
|
27
|
+
wait = Semaphore.new
|
28
|
+
block = lambda { |*a| block_args = a; wait.run }
|
29
|
+
m.on_room_message(&block)
|
30
|
+
m.on_message(&block)
|
31
|
+
m.on_private_message(&block)
|
32
|
+
m.on_subject(&block)
|
33
|
+
m.on_join(&block)
|
34
|
+
m.on_leave(&block)
|
35
|
+
m.on_self_leave(&block)
|
36
|
+
|
37
|
+
state { |pres|
|
38
|
+
assert_kind_of(Presence, pres)
|
39
|
+
assert_equal(JID.new('hag66@shakespeare.lit/pda'), pres.from)
|
40
|
+
assert_equal(JID.new('darkcave@macbeth.shakespeare.lit/thirdwitch'), pres.to)
|
41
|
+
send("<presence from='darkcave@macbeth.shakespeare.lit/firstwitch' to='hag66@shakespeare.lit/pda'>" +
|
42
|
+
"<x xmlns='http://jabber.org/protocol/muc#user'><item affiliation='owner' role='moderator'/></x>" +
|
43
|
+
"</presence>" +
|
44
|
+
"<presence from='darkcave@macbeth.shakespeare.lit/secondwitch' to='hag66@shakespeare.lit/pda'>" +
|
45
|
+
"<x xmlns='http://jabber.org/protocol/muc#user'><item affiliation='admin' role='moderator'/></x>" +
|
46
|
+
"</presence>" +
|
47
|
+
"<presence from='darkcave@macbeth.shakespeare.lit/thirdwitch' to='hag66@shakespeare.lit/pda'>" +
|
48
|
+
"<x xmlns='http://jabber.org/protocol/muc#user'><item affiliation='member' role='participant'/></x>" +
|
49
|
+
"</presence>")
|
50
|
+
}
|
51
|
+
m.my_jid = 'hag66@shakespeare.lit/pda'
|
52
|
+
assert_equal(m, m.join('darkcave@macbeth.shakespeare.lit/thirdwitch'))
|
53
|
+
wait_state
|
54
|
+
assert(m.active?)
|
55
|
+
assert_equal(3, m.roster.size)
|
56
|
+
|
57
|
+
state { |msg|
|
58
|
+
assert_kind_of(Message, msg)
|
59
|
+
assert_equal(:groupchat, msg.type)
|
60
|
+
assert_equal(JID.new('hag66@shakespeare.lit/pda'), msg.from)
|
61
|
+
assert_equal(JID.new('darkcave@macbeth.shakespeare.lit'), msg.to)
|
62
|
+
assert_equal('TestCasing room', msg.subject)
|
63
|
+
assert_nil(msg.body)
|
64
|
+
send(msg.set_from('darkcave@macbeth.shakespeare.lit/thirdwitch').set_to('hag66@shakespeare.lit/pda'))
|
65
|
+
}
|
66
|
+
assert_nil(m.subject)
|
67
|
+
wait.wait
|
68
|
+
m.subject = 'TestCasing room'
|
69
|
+
wait_state
|
70
|
+
wait.wait
|
71
|
+
|
72
|
+
# FIXME : **Intermittently** failing (especially during RCOV run) at this line with:
|
73
|
+
# 1) Failure:
|
74
|
+
# test_complex(SimpleMUCClientTest) [./test/muc/tc_muc_simplemucclient.rb:71]:
|
75
|
+
# <[nil, "thirdwitch", "TestCasing room"]> expected but was
|
76
|
+
# <[nil, "secondwitch"]>.
|
77
|
+
#
|
78
|
+
#assert_equal([nil, 'thirdwitch', 'TestCasing room'], block_args)
|
79
|
+
|
80
|
+
# FIXME : **Intermittently** failing (especially during RCOV run) at this line with:
|
81
|
+
# 1) Failure:
|
82
|
+
# test_complex(SimpleMUCClientTest) [./test/muc/tc_muc_simplemucclient.rb:80]:
|
83
|
+
# <"TestCasing room"> expected but was
|
84
|
+
# <nil>.
|
85
|
+
#
|
86
|
+
#assert_equal('TestCasing room', m.subject)
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_kick
|
91
|
+
m = MUC::SimpleMUCClient.new(@client)
|
92
|
+
|
93
|
+
state { |presence|
|
94
|
+
send("<presence from='test@test/test'/>")
|
95
|
+
}
|
96
|
+
m.join('test@test/test')
|
97
|
+
wait_state
|
98
|
+
|
99
|
+
state { |iq|
|
100
|
+
assert_kind_of(Iq, iq)
|
101
|
+
assert_equal('http://jabber.org/protocol/muc#admin', iq.queryns)
|
102
|
+
assert_kind_of(MUC::IqQueryMUCAdmin, iq.query)
|
103
|
+
assert_equal(1, iq.query.items.size)
|
104
|
+
assert_equal('pistol', iq.query.items[0].nick)
|
105
|
+
assert_equal(:none, iq.query.items[0].role)
|
106
|
+
assert_equal('Avaunt, you cullion!', iq.query.items[0].reason)
|
107
|
+
a = iq.answer(false)
|
108
|
+
a.type = :result
|
109
|
+
send(a)
|
110
|
+
}
|
111
|
+
m.kick('pistol', 'Avaunt, you cullion!')
|
112
|
+
wait_state
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift '../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'xmpp4r'
|
7
|
+
require 'xmpp4r/muc'
|
8
|
+
include Jabber
|
9
|
+
|
10
|
+
class MUCOwnerTest < Test::Unit::TestCase
|
11
|
+
def test_parse
|
12
|
+
s = <<EOF
|
13
|
+
<iq from='darkcave@macbeth.shakespeare.lit'
|
14
|
+
id='config1'
|
15
|
+
to='crone1@shakespeare.lit/desktop'
|
16
|
+
type='result'>
|
17
|
+
<query xmlns='http://jabber.org/protocol/muc#owner'>
|
18
|
+
<x xmlns='jabber:x:data' type='form'>
|
19
|
+
<title>Configuration for "darkcave" Room</title>
|
20
|
+
<instructions>
|
21
|
+
Complete this form to make changes to
|
22
|
+
the configuration of your room.
|
23
|
+
</instructions>
|
24
|
+
<field
|
25
|
+
type='hidden'
|
26
|
+
var='FORM_TYPE'>
|
27
|
+
<value>http://jabber.org/protocol/muc#roomconfig</value>
|
28
|
+
</field>
|
29
|
+
<field
|
30
|
+
label='Natural-Language Room Name'
|
31
|
+
type='text-single'
|
32
|
+
var='muc#roomconfig_roomname'>
|
33
|
+
<value>A Dark Cave</value>
|
34
|
+
</field>
|
35
|
+
</x>
|
36
|
+
</query>
|
37
|
+
</iq>
|
38
|
+
EOF
|
39
|
+
iq = Iq::import(REXML::Document.new(s).root)
|
40
|
+
|
41
|
+
assert_kind_of(Iq, iq)
|
42
|
+
assert_kind_of(MUC::IqQueryMUCOwner, iq.query)
|
43
|
+
assert_kind_of(Dataforms::XData, iq.query.x)
|
44
|
+
assert_kind_of(Dataforms::XData, iq.query.x('jabber:x:data'))
|
45
|
+
assert_kind_of(Dataforms::XData, iq.query.x(Dataforms::XData))
|
46
|
+
|
47
|
+
assert_equal(1, iq.query.x.fields.size)
|
48
|
+
assert_equal('Natural-Language Room Name', iq.query.x.fields[0].label)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,785 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File::dirname(__FILE__) + '/../../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require File::dirname(__FILE__) + '/../lib/clienttester'
|
7
|
+
|
8
|
+
require 'xmpp4r'
|
9
|
+
require 'xmpp4r/pubsub/helper/servicehelper'
|
10
|
+
include Jabber
|
11
|
+
|
12
|
+
# Jabber.debug = true
|
13
|
+
|
14
|
+
class PubSub::ServiceHelperTest < Test::Unit::TestCase
|
15
|
+
include ClientTester
|
16
|
+
|
17
|
+
##
|
18
|
+
# subscribe_to
|
19
|
+
# examples 30 and 31 from
|
20
|
+
# http://www.xmpp.org/extensions/xep-0060.html#subscriber-subscribe
|
21
|
+
def test_subscribe
|
22
|
+
pubsub = 'pubsub.example.org'
|
23
|
+
h = PubSub::ServiceHelper.new(@client,pubsub)
|
24
|
+
assert_kind_of(Jabber::PubSub::ServiceHelper,h)
|
25
|
+
state { |iq|
|
26
|
+
assert_kind_of(Jabber::Iq,iq)
|
27
|
+
assert_equal(:set,iq.type)
|
28
|
+
assert_equal(pubsub, iq.to.to_s)
|
29
|
+
assert_equal(@client.jid, iq.from)
|
30
|
+
assert_equal(1, iq.children.size)
|
31
|
+
assert_equal('http://jabber.org/protocol/pubsub', iq.pubsub.namespace)
|
32
|
+
assert_equal(1, iq.pubsub.children.size)
|
33
|
+
assert_equal('subscribe',iq.pubsub.children.first.name)
|
34
|
+
assert_equal('princely_musings',iq.pubsub.children.first.attributes['node'])
|
35
|
+
assert_equal(@client.jid.strip.to_s,iq.pubsub.children.first.attributes['jid'])
|
36
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'>
|
37
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
38
|
+
<subscription node='#{iq.pubsub.children.first.attributes['node']}' jid='#{iq.from.strip}'
|
39
|
+
subid='ba49252aaa4f5d320c24d3766f0bdcade78c78d3'
|
40
|
+
subscription='subscribed'/>
|
41
|
+
</pubsub>
|
42
|
+
</iq>")
|
43
|
+
}
|
44
|
+
subscription = h.subscribe_to('princely_musings')
|
45
|
+
assert_kind_of(Jabber::PubSub::Subscription,subscription)
|
46
|
+
assert_equal(@client.jid.strip,subscription.jid)
|
47
|
+
assert_equal('princely_musings',subscription.node)
|
48
|
+
assert_equal('ba49252aaa4f5d320c24d3766f0bdcade78c78d3',subscription.subid)
|
49
|
+
assert_equal(:subscribed,subscription.subscription)
|
50
|
+
wait_state
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# subscribe error condition
|
55
|
+
# example 44 from
|
56
|
+
# http://www.xmpp.org/extensions/xep-0060.html#subscriber-subscribe-configure
|
57
|
+
def test_subscribe_configuration_required
|
58
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
59
|
+
assert_kind_of(PubSub::ServiceHelper,h)
|
60
|
+
state { |iq|
|
61
|
+
assert_kind_of(Jabber::Iq,iq)
|
62
|
+
assert_equal(:set,iq.type)
|
63
|
+
assert_equal(1, iq.children.size)
|
64
|
+
assert_equal('http://jabber.org/protocol/pubsub', iq.pubsub.namespace)
|
65
|
+
assert_equal(1, iq.pubsub.children.size)
|
66
|
+
assert_equal('subscribe',iq.pubsub.children.first.name)
|
67
|
+
assert_equal('princely_musings',iq.pubsub.children.first.attributes['node'])
|
68
|
+
assert_equal(@client.jid.strip.to_s,iq.pubsub.children.first.attributes['jid'])
|
69
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'>
|
70
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
71
|
+
<subscription node='#{iq.pubsub.children.first.attributes['node']}' jid='#{iq.from.strip}'
|
72
|
+
subid='ba49252aaa4f5d320c24d3766f0bdcade78c78d3'
|
73
|
+
subscription='unconfigured'/>
|
74
|
+
<subscribe-options>
|
75
|
+
<required/>
|
76
|
+
</subscribe-options>
|
77
|
+
</pubsub>
|
78
|
+
</iq>")
|
79
|
+
}
|
80
|
+
subscription = h.subscribe_to('princely_musings')
|
81
|
+
assert_kind_of(Jabber::PubSub::Subscription,subscription)
|
82
|
+
assert_equal(@client.jid.strip,subscription.jid)
|
83
|
+
assert_equal('princely_musings',subscription.node)
|
84
|
+
assert_equal('ba49252aaa4f5d320c24d3766f0bdcade78c78d3',subscription.subid)
|
85
|
+
assert_equal(:unconfigured,subscription.subscription)
|
86
|
+
wait_state
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# subscribe error condition
|
91
|
+
# example 43 from
|
92
|
+
# http://www.xmpp.org/extensions/xep-0060.html#subscriber-subscribe-approval
|
93
|
+
def test_subscribe_approval_required
|
94
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
95
|
+
assert_kind_of(PubSub::ServiceHelper,h)
|
96
|
+
state { |iq|
|
97
|
+
assert_kind_of(Jabber::Iq,iq)
|
98
|
+
assert_equal(:set,iq.type)
|
99
|
+
assert_equal(1, iq.children.size)
|
100
|
+
assert_equal('http://jabber.org/protocol/pubsub', iq.pubsub.namespace)
|
101
|
+
assert_equal(1, iq.pubsub.children.size)
|
102
|
+
assert_equal('subscribe',iq.pubsub.children.first.name)
|
103
|
+
assert_equal('princely_musings',iq.pubsub.children.first.attributes['node'])
|
104
|
+
assert_equal(@client.jid.strip.to_s,iq.pubsub.children.first.attributes['jid'])
|
105
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'>
|
106
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
107
|
+
<subscription node='#{iq.pubsub.children.first.attributes['node']}' jid='#{iq.from.strip}'
|
108
|
+
subid='ba49252aaa4f5d320c24d3766f0bdcade78c78d3'
|
109
|
+
subscription='pending'/>
|
110
|
+
|
111
|
+
</pubsub>
|
112
|
+
</iq>")
|
113
|
+
}
|
114
|
+
subscription = h.subscribe_to('princely_musings')
|
115
|
+
assert_kind_of(Jabber::PubSub::Subscription,subscription)
|
116
|
+
assert_equal(@client.jid.strip,subscription.jid)
|
117
|
+
assert_equal('princely_musings',subscription.node)
|
118
|
+
assert_equal('ba49252aaa4f5d320c24d3766f0bdcade78c78d3',subscription.subid)
|
119
|
+
assert_equal(:pending,subscription.subscription)
|
120
|
+
assert_equal(true,subscription.need_approval?)
|
121
|
+
wait_state
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# unsubscribe from
|
126
|
+
# examples 48 and 49 from
|
127
|
+
# http://www.xmpp.org/extensions/xep-0060.html#subscriber-unsubscribe-request
|
128
|
+
def test_unsubscribe
|
129
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
130
|
+
assert_kind_of(PubSub::ServiceHelper,h)
|
131
|
+
state { |iq|
|
132
|
+
assert_kind_of(Jabber::Iq,iq)
|
133
|
+
assert_equal(:set,iq.type)
|
134
|
+
assert_equal(1, iq.children.size)
|
135
|
+
assert_equal('http://jabber.org/protocol/pubsub', iq.pubsub.namespace)
|
136
|
+
assert_equal(1, iq.pubsub.children.size)
|
137
|
+
assert_equal('unsubscribe',iq.pubsub.children.first.name)
|
138
|
+
assert_equal('princely_musings',iq.pubsub.children.first.attributes['node'])
|
139
|
+
assert_equal(@client.jid.strip.to_s,iq.pubsub.children.first.attributes['jid'])
|
140
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'/>")
|
141
|
+
}
|
142
|
+
unsubscribe = h.unsubscribe_from('princely_musings')
|
143
|
+
assert_equal(true, unsubscribe)
|
144
|
+
wait_state
|
145
|
+
end
|
146
|
+
|
147
|
+
##
|
148
|
+
# get subscription options
|
149
|
+
# examples 56 and 57 from
|
150
|
+
# http://www.xmpp.org/extensions/xep-0060.html#subscriber-configure-request
|
151
|
+
def test_get_subscription_options
|
152
|
+
pubsub = Jabber::JID.new('pubsub.example.org')
|
153
|
+
node = 'princely_musings'
|
154
|
+
jid = Jabber::JID.new('test@test.com/test')
|
155
|
+
h = PubSub::ServiceHelper.new(@client, pubsub)
|
156
|
+
|
157
|
+
state { |iq|
|
158
|
+
assert_kind_of(Jabber::Iq, iq)
|
159
|
+
assert_equal(:get, iq.type)
|
160
|
+
assert_equal(pubsub, iq.to)
|
161
|
+
assert_kind_of(Jabber::PubSub::SubscriptionConfig, iq.pubsub.first_element('options'))
|
162
|
+
assert_equal(node, iq.pubsub.first_element('options').node)
|
163
|
+
assert_equal(jid.strip, iq.pubsub.first_element('options').jid)
|
164
|
+
|
165
|
+
send( "<iq type='result'
|
166
|
+
from='#{iq.to}'
|
167
|
+
to='#{iq.from}'
|
168
|
+
id='#{iq.id}'>
|
169
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
170
|
+
<options node='#{iq.pubsub.first_element('options').node}' jid='#{iq.pubsub.first_element('options').jid}'>
|
171
|
+
<x xmlns='jabber:x:data' type='form'>
|
172
|
+
<field var='FORM_TYPE' type='hidden'>
|
173
|
+
<value>http://jabber.org/protocol/pubsub#subscribe_options</value>
|
174
|
+
</field>
|
175
|
+
<field var='pubsub#deliver' type='boolean'
|
176
|
+
label='Enable delivery?'>
|
177
|
+
<value>1</value>
|
178
|
+
</field>
|
179
|
+
</x>
|
180
|
+
</options>
|
181
|
+
</pubsub>
|
182
|
+
</iq>")
|
183
|
+
}
|
184
|
+
|
185
|
+
options = h.get_options_from(node, jid)
|
186
|
+
assert_kind_of(Jabber::PubSub::SubscriptionConfig, options)
|
187
|
+
assert_equal({'pubsub#deliver'=>'1'}, options.options)
|
188
|
+
wait_state
|
189
|
+
end
|
190
|
+
|
191
|
+
##
|
192
|
+
# set subscription options
|
193
|
+
# examples 65 and 66 from
|
194
|
+
# http://www.xmpp.org/extensions/xep-0060.html#subscriber-configure-submit
|
195
|
+
def test_set_subscription_options
|
196
|
+
pubsub = Jabber::JID.new('pubsub.example.org')
|
197
|
+
node = 'princely_musings'
|
198
|
+
jid = Jabber::JID.new('test@test.com/test')
|
199
|
+
options = {'pubsub#deliver' => '0'}
|
200
|
+
h = PubSub::ServiceHelper.new(@client, pubsub)
|
201
|
+
|
202
|
+
state { |iq|
|
203
|
+
assert_kind_of(Jabber::Iq, iq)
|
204
|
+
assert_equal(:set, iq.type)
|
205
|
+
assert_equal(pubsub, iq.to)
|
206
|
+
assert_kind_of(Jabber::PubSub::SubscriptionConfig, iq.pubsub.first_element('options'))
|
207
|
+
assert_equal(node, iq.pubsub.first_element('options').node)
|
208
|
+
assert_equal(jid.strip, iq.pubsub.first_element('options').jid)
|
209
|
+
|
210
|
+
send( "<iq type='result'
|
211
|
+
from='#{iq.to}'
|
212
|
+
to='#{iq.from}'
|
213
|
+
id='#{iq.id}'/>")
|
214
|
+
}
|
215
|
+
|
216
|
+
assert_nothing_raised do
|
217
|
+
assert_equal(true, h.set_options_for(node, jid, options) )
|
218
|
+
end
|
219
|
+
wait_state
|
220
|
+
end
|
221
|
+
|
222
|
+
##
|
223
|
+
# create node with default configuration
|
224
|
+
# example 119 and 121 from
|
225
|
+
# http://www.xmpp.org/extensions/xep-0060.html#owner-create-default
|
226
|
+
def test_create
|
227
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
228
|
+
assert_kind_of(PubSub::ServiceHelper, h)
|
229
|
+
|
230
|
+
state { |iq|
|
231
|
+
assert_kind_of(Jabber::Iq, iq)
|
232
|
+
assert_equal(:set, iq.type)
|
233
|
+
assert_equal(1, iq.children.size)
|
234
|
+
assert_equal('http://jabber.org/protocol/pubsub', iq.pubsub.namespace)
|
235
|
+
assert_equal(2, iq.pubsub.children.size)
|
236
|
+
assert_equal('create', iq.pubsub.children.first.name)
|
237
|
+
assert_equal('mynode', iq.pubsub.children.first.attributes['node'])
|
238
|
+
assert_equal('configure', iq.pubsub.children[1].name)
|
239
|
+
assert_equal({}, iq.pubsub.children[1].attributes)
|
240
|
+
assert_equal([], iq.pubsub.children[1].children)
|
241
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'/>")
|
242
|
+
}
|
243
|
+
assert_equal('mynode', h.create_node('mynode'))
|
244
|
+
wait_state
|
245
|
+
end
|
246
|
+
|
247
|
+
##
|
248
|
+
# create node with configuration
|
249
|
+
# example 123 and 124 from
|
250
|
+
# http://www.xmpp.org/extensions/xep-0060.html#owner-create-and-configure
|
251
|
+
def test_create_configure
|
252
|
+
node = 'mynode'
|
253
|
+
options = {'pubsub#access_model'=>'open'}
|
254
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
255
|
+
|
256
|
+
state { |iq|
|
257
|
+
assert_kind_of(Jabber::Iq, iq)
|
258
|
+
assert_equal(:set, iq.type)
|
259
|
+
assert_equal(1, iq.children.size)
|
260
|
+
assert_equal('http://jabber.org/protocol/pubsub', iq.pubsub.namespace)
|
261
|
+
assert_equal(2, iq.pubsub.children.size)
|
262
|
+
assert_equal('create', iq.pubsub.children.first.name)
|
263
|
+
assert_equal(node, iq.pubsub.children.first.attributes['node'])
|
264
|
+
assert_kind_of(Jabber::PubSub::NodeConfig, iq.pubsub.children[1])
|
265
|
+
assert_equal(options, iq.pubsub.children[1].options)
|
266
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'/>")
|
267
|
+
}
|
268
|
+
|
269
|
+
assert_nothing_raised do
|
270
|
+
assert_equal(node, h.create_node(node, Jabber::PubSub::NodeConfig.new(node, options)))
|
271
|
+
end
|
272
|
+
|
273
|
+
wait_state
|
274
|
+
end
|
275
|
+
|
276
|
+
##
|
277
|
+
# create node a collection node
|
278
|
+
# example 203 and 204 from
|
279
|
+
# http://www.xmpp.org/extensions/xep-0060.html#collections-createnode
|
280
|
+
def test_create_collection
|
281
|
+
node = 'mynode'
|
282
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
283
|
+
required_options = {'pubsub#node_type' => 'collection'}
|
284
|
+
state { |iq|
|
285
|
+
assert_kind_of(Jabber::Iq, iq)
|
286
|
+
assert_equal(:set, iq.type)
|
287
|
+
assert_equal(1, iq.children.size)
|
288
|
+
assert_equal('http://jabber.org/protocol/pubsub', iq.pubsub.namespace)
|
289
|
+
assert_equal(2, iq.pubsub.children.size)
|
290
|
+
assert_equal('create', iq.pubsub.children.first.name)
|
291
|
+
assert_equal(node, iq.pubsub.children.first.attributes['node'])
|
292
|
+
assert_kind_of(Jabber::PubSub::NodeConfig, iq.pubsub.children[1])
|
293
|
+
assert_equal(required_options, iq.pubsub.children[1].options)
|
294
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'/>")
|
295
|
+
}
|
296
|
+
assert_equal('mynode', h.create_collection_node('mynode'))
|
297
|
+
wait_state
|
298
|
+
end
|
299
|
+
|
300
|
+
##
|
301
|
+
# delete node
|
302
|
+
# example 144 and 145 from
|
303
|
+
# http://www.xmpp.org/extensions/xep-0060.html#owner-delete-request
|
304
|
+
def test_delete
|
305
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
306
|
+
|
307
|
+
state { |iq|
|
308
|
+
assert_kind_of(Jabber::Iq, iq)
|
309
|
+
assert_equal(:set, iq.type)
|
310
|
+
assert_equal(1, iq.children.size)
|
311
|
+
assert_equal(1, iq.pubsub.children.size)
|
312
|
+
assert_equal('delete', iq.pubsub.children.first.name)
|
313
|
+
assert_equal('mynode', iq.pubsub.children.first.attributes['node'])
|
314
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'/>")
|
315
|
+
}
|
316
|
+
h.delete_node('mynode')
|
317
|
+
wait_state
|
318
|
+
end
|
319
|
+
|
320
|
+
##
|
321
|
+
# publish to a node
|
322
|
+
# example 88 and 89 from
|
323
|
+
# http://www.xmpp.org/extensions/xep-0060.html#publisher-publish
|
324
|
+
def test_publish
|
325
|
+
node = 'mynode'
|
326
|
+
item1 = Jabber::PubSub::Item.new
|
327
|
+
item1.text = 'foobar'
|
328
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
329
|
+
state { |iq|
|
330
|
+
assert_kind_of(Jabber::Iq, iq)
|
331
|
+
assert_equal(:set, iq.type)
|
332
|
+
assert_equal(1, iq.children.size)
|
333
|
+
assert_equal(1, iq.pubsub.children.size)
|
334
|
+
assert_equal('publish', iq.pubsub.children[0].name)
|
335
|
+
assert_equal(node, iq.pubsub.children[0].attributes['node'])
|
336
|
+
assert_equal(1, iq.pubsub.children[0].children.size)
|
337
|
+
assert_equal('item', iq.pubsub.children[0].children[0].name)
|
338
|
+
assert_equal(1, iq.pubsub.children[0].children[0].children.size)
|
339
|
+
assert_equal(item1.children[0].to_s, iq.pubsub.children[0].children[0].children[0].to_s)
|
340
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'/>")
|
341
|
+
}
|
342
|
+
assert_nothing_raised { h.publish_item_to(node, item1) }
|
343
|
+
wait_state
|
344
|
+
end
|
345
|
+
|
346
|
+
##
|
347
|
+
# publish item with id
|
348
|
+
# example 88 and 89 from
|
349
|
+
# http://www.xmpp.org/extensions/xep-0060.html#publisher-publish
|
350
|
+
def test_publish_pubsub_item_with_id
|
351
|
+
item1 = Jabber::PubSub::Item.new
|
352
|
+
item1.text = 'foobar'
|
353
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
354
|
+
|
355
|
+
state { |iq|
|
356
|
+
assert_kind_of(Jabber::Iq, iq)
|
357
|
+
assert_equal(:set, iq.type)
|
358
|
+
assert_equal(1, iq.children.size)
|
359
|
+
assert_equal(1, iq.pubsub.children.size)
|
360
|
+
assert_equal('publish', iq.pubsub.children[0].name)
|
361
|
+
assert_equal(1, iq.pubsub.children[0].children.size)
|
362
|
+
assert_equal('item', iq.pubsub.children[0].children[0].name)
|
363
|
+
assert_equal('blubb', iq.pubsub.children[0].children[0].attributes['id'] )
|
364
|
+
assert_equal(1, iq.pubsub.children[0].children[0].children.size)
|
365
|
+
assert_equal(item1.children[0].to_s, iq.pubsub.children[0].children[0].children[0].to_s)
|
366
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'/>")
|
367
|
+
}
|
368
|
+
assert_nothing_raised { h.publish_item_with_id_to('mynode', item1,"blubb") }
|
369
|
+
wait_state
|
370
|
+
end
|
371
|
+
|
372
|
+
##
|
373
|
+
# publish item and trap client-side error
|
374
|
+
# examples 88 from
|
375
|
+
# http://www.xmpp.org/extensions/xep-0060.html#publisher-publish
|
376
|
+
def test_publish_pubsub_item_with_id_and_produce_a_local_error
|
377
|
+
item1 = 'foobarbaz'
|
378
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
379
|
+
|
380
|
+
assert_raise RuntimeError do h.publish_item_with_id_to('mynode', item1,"blubb") end
|
381
|
+
end
|
382
|
+
|
383
|
+
##
|
384
|
+
# publish item and trap server-side error
|
385
|
+
# examples 88 from
|
386
|
+
# http://www.xmpp.org/extensions/xep-0060.html#publisher-publish
|
387
|
+
# and 93 from
|
388
|
+
# http://www.xmpp.org/extensions/xep-0060.html#publisher-publish-error-forbidden
|
389
|
+
def test_publish_pubsub_item_with_id_and_produce_an_error
|
390
|
+
item1 = Jabber::PubSub::Item.new
|
391
|
+
item1.text = "foobarbaz"
|
392
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
393
|
+
|
394
|
+
state { |iq|
|
395
|
+
assert_kind_of(Jabber::Iq, iq)
|
396
|
+
assert_equal(:set, iq.type)
|
397
|
+
assert_equal(1, iq.children.size)
|
398
|
+
assert_equal(1, iq.pubsub.children.size)
|
399
|
+
assert_equal('publish', iq.pubsub.children[0].name)
|
400
|
+
assert_equal(1, iq.pubsub.children[0].children.size)
|
401
|
+
assert_equal('item', iq.pubsub.children[0].children[0].name)
|
402
|
+
assert_equal('blubb', iq.pubsub.children[0].children[0].attributes['id'] )
|
403
|
+
assert_equal(1, iq.pubsub.children[0].children[0].children.size)
|
404
|
+
assert_equal(item1.children[0].to_s, iq.pubsub.children[0].children[0].children[0].to_s)
|
405
|
+
send("<iq type='error' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'/>
|
406
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
407
|
+
<publish node='#{iq.pubsub.children[0].attributes['node']}'>
|
408
|
+
<item id='#{iq.pubsub.children[0].children[0].attributes['id']}'/>
|
409
|
+
</publish>
|
410
|
+
</pubsub>
|
411
|
+
<error type='auth'>
|
412
|
+
<forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
|
413
|
+
</error>")
|
414
|
+
}
|
415
|
+
assert_raise Jabber::ServerError do h.publish_item_with_id_to('mynode', item1,"blubb") end
|
416
|
+
wait_state
|
417
|
+
end
|
418
|
+
|
419
|
+
##
|
420
|
+
# retrieve all items
|
421
|
+
# examples 70 and 71 from
|
422
|
+
# http://www.xmpp.org/extensions/xep-0060.html#subscriber-retrieve-returnall
|
423
|
+
def test_items
|
424
|
+
item1 = Jabber::PubSub::Item.new("1")
|
425
|
+
item1.text = 'foobar'
|
426
|
+
item2 = Jabber::PubSub::Item.new("2")
|
427
|
+
item2.text = 'barfoo'
|
428
|
+
|
429
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
430
|
+
|
431
|
+
state { |iq|
|
432
|
+
assert_kind_of(Jabber::Iq, iq)
|
433
|
+
assert_equal(:get, iq.type)
|
434
|
+
assert_equal(1, iq.pubsub.children.size)
|
435
|
+
assert_equal('items', iq.pubsub.children.first.name)
|
436
|
+
assert_equal('mynode', iq.pubsub.children.first.attributes['node'])
|
437
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'>
|
438
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
439
|
+
<items node='mynode'>
|
440
|
+
#{item1.to_s}
|
441
|
+
#{item2.to_s}
|
442
|
+
</items>
|
443
|
+
</pubsub>
|
444
|
+
</iq>")
|
445
|
+
}
|
446
|
+
|
447
|
+
items = h.get_items_from('mynode')
|
448
|
+
assert_equal(2, items.size)
|
449
|
+
assert_kind_of(REXML::Text, items['1'])
|
450
|
+
assert_kind_of(REXML::Text, items['2'])
|
451
|
+
assert_equal(item1.children.join, items['1'].to_s)
|
452
|
+
assert_equal(item2.children.join, items['2'].to_s)
|
453
|
+
wait_state
|
454
|
+
end
|
455
|
+
|
456
|
+
##
|
457
|
+
# retrieve some items
|
458
|
+
# example 76 from
|
459
|
+
# http://xmpp.org/extensions/xep-0060.html#subscriber-retrieve-requestsome
|
460
|
+
def test_items_with_max_items
|
461
|
+
node_name = "mynode"
|
462
|
+
max_items = 2
|
463
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
464
|
+
|
465
|
+
state { |iq|
|
466
|
+
assert_kind_of(Jabber::Iq, iq)
|
467
|
+
assert_equal(:get, iq.type)
|
468
|
+
assert_equal(1, iq.pubsub.children.size)
|
469
|
+
assert_equal('items', iq.pubsub.children.first.name)
|
470
|
+
assert_equal(node_name, iq.pubsub.children.first.attributes['node'])
|
471
|
+
assert_equal(max_items.to_s, iq.pubsub.children.first.attributes['max_items'])
|
472
|
+
# response doesn't matter; was previously tested, so send a simple result
|
473
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}' />")
|
474
|
+
}
|
475
|
+
|
476
|
+
h.get_items_from(node_name, max_items)
|
477
|
+
wait_state
|
478
|
+
end
|
479
|
+
|
480
|
+
##
|
481
|
+
# get affiliation
|
482
|
+
# example 184 and 185 from
|
483
|
+
# http://www.xmpp.org/extensions/xep-0060.html#owner-affiliations-retrieve-success1
|
484
|
+
def test_affiliations
|
485
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
486
|
+
|
487
|
+
state { |iq|
|
488
|
+
assert_kind_of(Jabber::Iq, iq)
|
489
|
+
assert_equal(:get, iq.type)
|
490
|
+
assert_equal(1, iq.pubsub.children.size)
|
491
|
+
assert_equal('affiliations', iq.pubsub.children.first.name)
|
492
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'>
|
493
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
494
|
+
<affiliations>
|
495
|
+
<affiliation node='node1' affiliation='owner'/>
|
496
|
+
<affiliation node='node2' affiliation='publisher'/>
|
497
|
+
<affiliation node='node5' affiliation='outcast'/>
|
498
|
+
<affiliation node='node6' affiliation='owner'/>
|
499
|
+
</affiliations>
|
500
|
+
</pubsub>
|
501
|
+
</iq>")
|
502
|
+
}
|
503
|
+
|
504
|
+
a = h.get_affiliations
|
505
|
+
assert_kind_of(Hash, a)
|
506
|
+
assert_equal(4, a.size)
|
507
|
+
assert_equal(:owner, a['node1'])
|
508
|
+
assert_equal(:publisher, a['node2'])
|
509
|
+
assert_equal(:outcast, a['node5'])
|
510
|
+
assert_equal(:owner, a['node6'])
|
511
|
+
wait_state
|
512
|
+
end
|
513
|
+
|
514
|
+
# http://xmpp.org/extensions/xep-0060.html#owner-affiliations-modify
|
515
|
+
def test_set_affiliations
|
516
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.shakespeare.lit')
|
517
|
+
|
518
|
+
state { |iq|
|
519
|
+
assert_kind_of(Jabber::Iq, iq)
|
520
|
+
assert_equal(:set, iq.type)
|
521
|
+
assert_equal(1, iq.pubsub.children.size)
|
522
|
+
assert_equal('affiliations', iq.pubsub.children[0].name)
|
523
|
+
assert_equal('affiliation', iq.pubsub.children[0].children[0].name)
|
524
|
+
assert_equal('bard@shakespeare.lit', iq.pubsub.children[0].children[0].attributes['jid'])
|
525
|
+
assert_equal('publisher', iq.pubsub.children[0].children[0].attributes['affiliation'])
|
526
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'/>")
|
527
|
+
}
|
528
|
+
|
529
|
+
a = h.set_affiliations('princely_musings', 'bard@shakespeare.lit', :publisher)
|
530
|
+
wait_state
|
531
|
+
end
|
532
|
+
|
533
|
+
##
|
534
|
+
# get_subscriptions_from
|
535
|
+
# example 171 and 172 from
|
536
|
+
# http://www.xmpp.org/extensions/xep-0060.html#owner-subscriptions-retrieve-request
|
537
|
+
def test_subscriptions
|
538
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
539
|
+
state { |iq|
|
540
|
+
assert_kind_of(Jabber::Iq, iq)
|
541
|
+
assert_equal(:get, iq.type)
|
542
|
+
assert_equal(1, iq.pubsub.children.size)
|
543
|
+
assert_equal('subscriptions', iq.pubsub.children.first.name)
|
544
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'>
|
545
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
|
546
|
+
<subscriptions node='node1'>
|
547
|
+
<subscription jid='hamlet@denmark.lit' subscription='subscribed'/>
|
548
|
+
<subscription jid='polonius@denmark.lit' subscription='unconfigured'/>
|
549
|
+
<subscription jid='bernardo@denmark.lit' subscription='subscribed' subid='123-abc'/>
|
550
|
+
<subscription jid='bernardo@denmark.lit' subscription='subscribed' subid='004-yyy'/>
|
551
|
+
</subscriptions>
|
552
|
+
</pubsub>
|
553
|
+
</iq>")
|
554
|
+
}
|
555
|
+
|
556
|
+
s = h.get_subscriptions_from('node1')
|
557
|
+
assert_kind_of(Array,s)
|
558
|
+
assert_equal(4,s.size)
|
559
|
+
assert_kind_of(Jabber::PubSub::Subscription,s[0])
|
560
|
+
assert_kind_of(Jabber::PubSub::Subscription,s[1])
|
561
|
+
assert_kind_of(Jabber::PubSub::Subscription,s[2])
|
562
|
+
assert_kind_of(Jabber::PubSub::Subscription,s[3])
|
563
|
+
assert_equal(:subscribed,s[0].state)
|
564
|
+
assert_equal(:unconfigured,s[1].state)
|
565
|
+
assert_equal(JID.new("hamlet@denmark.lit"),s[0].jid)
|
566
|
+
assert_equal("123-abc",s[2].subid)
|
567
|
+
wait_state
|
568
|
+
end
|
569
|
+
|
570
|
+
##
|
571
|
+
# get_subscribers
|
572
|
+
# example 171 and 172 from
|
573
|
+
# http://www.xmpp.org/extensions/xep-0060.html#owner-subscriptions-retrieve
|
574
|
+
def test_subscribers
|
575
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
576
|
+
|
577
|
+
state { |iq|
|
578
|
+
assert_kind_of(Jabber::Iq, iq)
|
579
|
+
assert_equal(:get, iq.type)
|
580
|
+
assert_equal(1, iq.pubsub.children.size)
|
581
|
+
assert_equal('subscriptions', iq.pubsub.children.first.name)
|
582
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'>
|
583
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
584
|
+
<subscriptions node='princely_musings'>
|
585
|
+
<subscription jid='peter@denmark.lit' subscription='subscribed'/>
|
586
|
+
<subscription jid='frank@denmark.lit' subscription='subscribed'/>
|
587
|
+
<subscription jid='albrecht@denmark.lit' subscription='unconfigured'/>
|
588
|
+
<subscription jid='hugo@denmark.lit' subscription='pending'/>
|
589
|
+
</subscriptions>
|
590
|
+
</pubsub>
|
591
|
+
</iq>")
|
592
|
+
}
|
593
|
+
|
594
|
+
s = h.get_subscribers_from('princely_musings')
|
595
|
+
assert_equal(4,s.size)
|
596
|
+
assert_kind_of(Jabber::JID,s[0])
|
597
|
+
assert_kind_of(Jabber::JID,s[1])
|
598
|
+
assert_kind_of(Jabber::JID,s[2])
|
599
|
+
assert_kind_of(Jabber::JID,s[3])
|
600
|
+
wait_state
|
601
|
+
end
|
602
|
+
|
603
|
+
##
|
604
|
+
# get_all_subscriptions
|
605
|
+
def test_get_all_subscriptions
|
606
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
607
|
+
|
608
|
+
state { |iq|
|
609
|
+
assert_kind_of(Jabber::Iq, iq)
|
610
|
+
assert_equal(:get, iq.type)
|
611
|
+
assert_equal(1, iq.pubsub.children.size)
|
612
|
+
assert_equal('subscriptions', iq.pubsub.children.first.name)
|
613
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'>
|
614
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
615
|
+
<subscriptions>
|
616
|
+
<subscription node='node1' jid='francisco@denmark.lit' subscription='subscribed'/>
|
617
|
+
<subscription node='node2' jid='francisco@denmark.lit' subscription='subscribed'/>
|
618
|
+
<subscription node='node5' jid='francisco@denmark.lit' subscription='unconfigured'/>
|
619
|
+
<subscription node='node6' jid='francisco@denmark.lit' subscription='pending'/>
|
620
|
+
</subscriptions>
|
621
|
+
</pubsub>
|
622
|
+
</iq>")
|
623
|
+
}
|
624
|
+
|
625
|
+
s = h.get_subscriptions_from_all_nodes
|
626
|
+
assert_kind_of(Array,s)
|
627
|
+
assert_equal(4,s.size)
|
628
|
+
assert_kind_of(Jabber::PubSub::Subscription,s[0])
|
629
|
+
assert_kind_of(Jabber::PubSub::Subscription,s[1])
|
630
|
+
assert_kind_of(Jabber::PubSub::Subscription,s[2])
|
631
|
+
assert_kind_of(Jabber::PubSub::Subscription,s[3])
|
632
|
+
assert_equal(:subscribed,s[0].state)
|
633
|
+
assert_equal(:unconfigured,s[2].state)
|
634
|
+
assert_equal(:pending,s[3].state)
|
635
|
+
assert_equal(JID.new("francisco@denmark.lit"),s[0].jid)
|
636
|
+
assert_equal("node1",s[0].node)
|
637
|
+
|
638
|
+
wait_state
|
639
|
+
end
|
640
|
+
|
641
|
+
##
|
642
|
+
# get all subscriptions with no subscriptions
|
643
|
+
def test_get_all_subscriptions_with_no_subscriptions
|
644
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
645
|
+
|
646
|
+
state { |iq|
|
647
|
+
assert_kind_of(Jabber::Iq, iq)
|
648
|
+
assert_equal(:get, iq.type)
|
649
|
+
assert_equal(1, iq.pubsub.children.size)
|
650
|
+
assert_equal('subscriptions', iq.pubsub.children.first.name)
|
651
|
+
send("<iq type='result' to='#{iq.from}' from='#{iq.to}' id='#{iq.id}'>
|
652
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
653
|
+
<subscriptions />
|
654
|
+
</pubsub>
|
655
|
+
</iq>")
|
656
|
+
}
|
657
|
+
|
658
|
+
s = h.get_subscriptions_from_all_nodes
|
659
|
+
assert_kind_of(Array,s)
|
660
|
+
assert_equal(0,s.size)
|
661
|
+
wait_state
|
662
|
+
end
|
663
|
+
|
664
|
+
##
|
665
|
+
# get configuration for a node
|
666
|
+
# example 125 and 126 from
|
667
|
+
# http://www.xmpp.org/extensions/xep-0060.html#owner-configure-request
|
668
|
+
def test_get_node_config
|
669
|
+
pubsub = 'pubsub.example.org'
|
670
|
+
h = PubSub::ServiceHelper.new(@client, pubsub)
|
671
|
+
|
672
|
+
state { |iq|
|
673
|
+
assert_kind_of(Jabber::Iq, iq)
|
674
|
+
assert_equal(:get, iq.type)
|
675
|
+
assert_equal(pubsub, iq.to.to_s)
|
676
|
+
assert_kind_of(Jabber::PubSub::OwnerNodeConfig, iq.pubsub.first_element('configure'))
|
677
|
+
|
678
|
+
send( "<iq type='result'
|
679
|
+
from='#{iq.to}'
|
680
|
+
to='#{iq.from}'
|
681
|
+
id='#{iq.id}'>
|
682
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
|
683
|
+
<configure node='princely_musings'>
|
684
|
+
<x xmlns='jabber:x:data' type='form'>
|
685
|
+
<field var='FORM_TYPE' type='hidden'>
|
686
|
+
<value>http://jabber.org/protocol/pubsub#node_config</value>
|
687
|
+
</field>
|
688
|
+
<field var='pubsub#title' type='text-single'
|
689
|
+
label='A friendly name for the node'/>
|
690
|
+
</x>
|
691
|
+
</configure>
|
692
|
+
</pubsub>
|
693
|
+
</iq>")
|
694
|
+
}
|
695
|
+
|
696
|
+
config = h.get_config_from('princelymusings')
|
697
|
+
assert_kind_of(Jabber::PubSub::OwnerNodeConfig, config)
|
698
|
+
wait_state
|
699
|
+
end
|
700
|
+
|
701
|
+
##
|
702
|
+
# owner set configuration for a node
|
703
|
+
# example 133
|
704
|
+
# http://xmpp.org/extensions/xep-0060.html#owner-configure
|
705
|
+
def test_set_node_config
|
706
|
+
node = 'princely_musings'
|
707
|
+
pubsub = 'pubsub.shakespeare.lit'
|
708
|
+
h = PubSub::ServiceHelper.new(@client,pubsub)
|
709
|
+
|
710
|
+
state { |iq|
|
711
|
+
assert_kind_of(Jabber::Iq,iq)
|
712
|
+
assert_equal(:set, iq.type)
|
713
|
+
assert_equal(pubsub, iq.to.to_s)
|
714
|
+
|
715
|
+
config = iq.pubsub.first_element('configure')
|
716
|
+
assert_kind_of(Jabber::PubSub::OwnerNodeConfig, config)
|
717
|
+
assert_kind_of(Jabber::Dataforms::XData, config.form)
|
718
|
+
|
719
|
+
assert_equal(config.options["pubsub#title"], "Princely Musings (Atom)")
|
720
|
+
assert_equal(config.options["pubsub#deliver_notifications"], "1")
|
721
|
+
assert_equal(config.options["pubsub#deliver_payloads"], "1")
|
722
|
+
assert_equal(config.options["pubsub#persist_items"], "1")
|
723
|
+
assert_equal(config.options["pubsub#max_items"], "10")
|
724
|
+
assert_equal(config.options["pubsub#access_model"], "open")
|
725
|
+
assert_equal(config.options["pubsub#publish_model"], "publishers")
|
726
|
+
assert_equal(config.options["pubsub#send_last_published_item"], "never")
|
727
|
+
assert_equal(config.options["pubsub#presence_based_delivery"], "false")
|
728
|
+
assert_equal(config.options["pubsub#notify_config"], "0")
|
729
|
+
assert_equal(config.options["pubsub#notify_delete"], "0")
|
730
|
+
assert_equal(config.options["pubsub#notify_retract"], "0")
|
731
|
+
assert_equal(config.options["pubsub#notify_sub"], "0")
|
732
|
+
assert_equal(config.options["pubsub#max_payload_size"], "1028")
|
733
|
+
assert_equal(config.options["pubsub#type"], "http://www.w3.org/2005/Atom")
|
734
|
+
assert_equal(config.options["pubsub#body_xslt"], "http://jabxslt.jabberstudio.org/atom_body.xslt")
|
735
|
+
|
736
|
+
send("<iq type='result' from='#{iq.to}' to='#{iq.from}' id='#{iq.id}'/>")
|
737
|
+
}
|
738
|
+
|
739
|
+
config = Jabber::PubSub::OwnerNodeConfig.new(node)
|
740
|
+
config.options = {
|
741
|
+
"pubsub#title" => "Princely Musings (Atom)",
|
742
|
+
"pubsub#deliver_notifications" => "1",
|
743
|
+
"pubsub#deliver_payloads" => "1",
|
744
|
+
"pubsub#persist_items" => "1",
|
745
|
+
"pubsub#max_items" => "10",
|
746
|
+
"pubsub#access_model" => "open",
|
747
|
+
"pubsub#publish_model" => "publishers",
|
748
|
+
"pubsub#send_last_published_item" => "never",
|
749
|
+
"pubsub#presence_based_delivery" => "false",
|
750
|
+
"pubsub#notify_config" => "0",
|
751
|
+
"pubsub#notify_delete" => "0",
|
752
|
+
"pubsub#notify_retract" => "0",
|
753
|
+
"pubsub#notify_sub" => "0",
|
754
|
+
"pubsub#max_payload_size" => "1028",
|
755
|
+
"pubsub#type" => "http://www.w3.org/2005/Atom",
|
756
|
+
"pubsub#body_xslt" => "http://jabxslt.jabberstudio.org/atom_body.xslt"
|
757
|
+
}
|
758
|
+
|
759
|
+
assert_kind_of(Jabber::PubSub::OwnerNodeConfig, config)
|
760
|
+
h.set_config_for(node, config)
|
761
|
+
wait_state
|
762
|
+
end
|
763
|
+
|
764
|
+
def test_delete_item
|
765
|
+
pubsub = 'pubsub.example.org'
|
766
|
+
h = PubSub::ServiceHelper.new(@client, pubsub)
|
767
|
+
|
768
|
+
state { |iq|
|
769
|
+
assert_kind_of(Jabber::Iq, iq)
|
770
|
+
assert_kind_of(Jabber::PubSub::IqPubSub, iq.pubsub)
|
771
|
+
assert_kind_of(Jabber::PubSub::Retract, iq.pubsub.first_element('retract'))
|
772
|
+
assert_equal(1, iq.pubsub.first_element('retract').items.size)
|
773
|
+
assert_equal('ae890ac52d0df67ed7cfdf51b644e901', iq.pubsub.first_element('retract').items[0].id)
|
774
|
+
send(iq.answer.set_type(:result))
|
775
|
+
}
|
776
|
+
|
777
|
+
h.delete_item_from('princely_musings', 'ae890ac52d0df67ed7cfdf51b644e901')
|
778
|
+
wait_state
|
779
|
+
end
|
780
|
+
|
781
|
+
def test_to_s
|
782
|
+
h = PubSub::ServiceHelper.new(@client,'pubsub.example.org')
|
783
|
+
assert_equal('pubsub.example.org',h.to_s)
|
784
|
+
end
|
785
|
+
end
|