gmcmillan-xmpp4r 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +91 -0
  3. data/COPYING +340 -0
  4. data/LICENSE +59 -0
  5. data/README.rdoc +122 -0
  6. data/README_ruby19.txt +43 -0
  7. data/Rakefile +258 -0
  8. data/data/doc/xmpp4r/examples/advanced/adventure/README +56 -0
  9. data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
  10. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
  11. data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
  12. data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
  13. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +424 -0
  14. data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
  15. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +346 -0
  16. data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
  17. data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
  18. data/data/doc/xmpp4r/examples/advanced/migrate.rb +88 -0
  19. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
  20. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
  21. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
  22. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +85 -0
  23. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +129 -0
  24. data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
  25. data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
  26. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
  27. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
  28. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
  29. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +109 -0
  30. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +146 -0
  31. data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +14 -0
  32. data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
  33. data/data/doc/xmpp4r/examples/basic/client.rb +70 -0
  34. data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
  35. data/data/doc/xmpp4r/examples/basic/echo.rb +37 -0
  36. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
  37. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +68 -0
  38. data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +12 -0
  39. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +41 -0
  40. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +82 -0
  41. data/data/doc/xmpp4r/examples/basic/register.rb +42 -0
  42. data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
  43. data/data/doc/xmpp4r/examples/basic/roster.rb +44 -0
  44. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
  45. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
  46. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +171 -0
  47. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +67 -0
  48. data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
  49. data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
  50. data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
  51. data/lib/xmpp4r.rb +118 -0
  52. data/lib/xmpp4r/base64.rb +32 -0
  53. data/lib/xmpp4r/bytestreams.rb +15 -0
  54. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +321 -0
  55. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +257 -0
  56. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +31 -0
  57. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +54 -0
  58. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +153 -0
  59. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +86 -0
  60. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +198 -0
  61. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +65 -0
  62. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +82 -0
  63. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +170 -0
  64. data/lib/xmpp4r/bytestreams/iq/si.rb +206 -0
  65. data/lib/xmpp4r/callbacks.rb +133 -0
  66. data/lib/xmpp4r/caps.rb +1 -0
  67. data/lib/xmpp4r/caps/c.rb +67 -0
  68. data/lib/xmpp4r/caps/helper/generator.rb +160 -0
  69. data/lib/xmpp4r/caps/helper/helper.rb +84 -0
  70. data/lib/xmpp4r/client.rb +345 -0
  71. data/lib/xmpp4r/command/helper/responder.rb +53 -0
  72. data/lib/xmpp4r/command/iq/command.rb +154 -0
  73. data/lib/xmpp4r/component.rb +103 -0
  74. data/lib/xmpp4r/connection.rb +231 -0
  75. data/lib/xmpp4r/dataforms.rb +5 -0
  76. data/lib/xmpp4r/dataforms/x/data.rb +297 -0
  77. data/lib/xmpp4r/debuglog.rb +63 -0
  78. data/lib/xmpp4r/delay.rb +5 -0
  79. data/lib/xmpp4r/delay/x/delay.rb +99 -0
  80. data/lib/xmpp4r/discovery.rb +8 -0
  81. data/lib/xmpp4r/discovery/helper/helper.rb +58 -0
  82. data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
  83. data/lib/xmpp4r/discovery/iq/discoinfo.rb +211 -0
  84. data/lib/xmpp4r/discovery/iq/discoitems.rb +147 -0
  85. data/lib/xmpp4r/entity_time.rb +6 -0
  86. data/lib/xmpp4r/entity_time/iq.rb +45 -0
  87. data/lib/xmpp4r/entity_time/responder.rb +57 -0
  88. data/lib/xmpp4r/errors.rb +284 -0
  89. data/lib/xmpp4r/feature_negotiation.rb +5 -0
  90. data/lib/xmpp4r/feature_negotiation/iq/feature.rb +28 -0
  91. data/lib/xmpp4r/framework/base.rb +55 -0
  92. data/lib/xmpp4r/framework/bot.rb +148 -0
  93. data/lib/xmpp4r/httpbinding.rb +5 -0
  94. data/lib/xmpp4r/httpbinding/client.rb +275 -0
  95. data/lib/xmpp4r/idgenerator.rb +37 -0
  96. data/lib/xmpp4r/iq.rb +221 -0
  97. data/lib/xmpp4r/jid.rb +167 -0
  98. data/lib/xmpp4r/last.rb +2 -0
  99. data/lib/xmpp4r/last/helper/helper.rb +37 -0
  100. data/lib/xmpp4r/last/iq/last.rb +67 -0
  101. data/lib/xmpp4r/location.rb +2 -0
  102. data/lib/xmpp4r/location/helper/helper.rb +56 -0
  103. data/lib/xmpp4r/location/location.rb +179 -0
  104. data/lib/xmpp4r/message.rb +226 -0
  105. data/lib/xmpp4r/muc.rb +14 -0
  106. data/lib/xmpp4r/muc/helper/mucbrowser.rb +92 -0
  107. data/lib/xmpp4r/muc/helper/mucclient.rb +469 -0
  108. data/lib/xmpp4r/muc/helper/simplemucclient.rb +332 -0
  109. data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
  110. data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
  111. data/lib/xmpp4r/muc/iq/mucowner.rb +15 -0
  112. data/lib/xmpp4r/muc/item.rb +143 -0
  113. data/lib/xmpp4r/muc/x/muc.rb +70 -0
  114. data/lib/xmpp4r/muc/x/mucuserinvite.rb +60 -0
  115. data/lib/xmpp4r/muc/x/mucuseritem.rb +36 -0
  116. data/lib/xmpp4r/presence.rb +232 -0
  117. data/lib/xmpp4r/pubsub.rb +8 -0
  118. data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
  119. data/lib/xmpp4r/pubsub/children/event.rb +49 -0
  120. data/lib/xmpp4r/pubsub/children/item.rb +35 -0
  121. data/lib/xmpp4r/pubsub/children/items.rb +53 -0
  122. data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
  123. data/lib/xmpp4r/pubsub/children/publish.rb +38 -0
  124. data/lib/xmpp4r/pubsub/children/retract.rb +41 -0
  125. data/lib/xmpp4r/pubsub/children/subscription.rb +62 -0
  126. data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
  127. data/lib/xmpp4r/pubsub/children/unsubscribe.rb +63 -0
  128. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +129 -0
  129. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +156 -0
  130. data/lib/xmpp4r/pubsub/helper/oauth_service_helper.rb +90 -0
  131. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +490 -0
  132. data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
  133. data/lib/xmpp4r/query.rb +15 -0
  134. data/lib/xmpp4r/reliable.rb +168 -0
  135. data/lib/xmpp4r/rexmladdons.rb +197 -0
  136. data/lib/xmpp4r/roster.rb +7 -0
  137. data/lib/xmpp4r/roster/helper/roster.rb +532 -0
  138. data/lib/xmpp4r/roster/iq/roster.rb +215 -0
  139. data/lib/xmpp4r/roster/x/roster.rb +138 -0
  140. data/lib/xmpp4r/rpc.rb +2 -0
  141. data/lib/xmpp4r/rpc/helper/client.rb +123 -0
  142. data/lib/xmpp4r/rpc/helper/server.rb +74 -0
  143. data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +67 -0
  144. data/lib/xmpp4r/rpc/iq/rpc.rb +23 -0
  145. data/lib/xmpp4r/sasl.rb +259 -0
  146. data/lib/xmpp4r/semaphore.rb +38 -0
  147. data/lib/xmpp4r/stream.rb +611 -0
  148. data/lib/xmpp4r/streamparser.rb +66 -0
  149. data/lib/xmpp4r/test/listener_mocker.rb +118 -0
  150. data/lib/xmpp4r/tune.rb +2 -0
  151. data/lib/xmpp4r/tune/helper/helper.rb +58 -0
  152. data/lib/xmpp4r/tune/tune.rb +113 -0
  153. data/lib/xmpp4r/vcard.rb +6 -0
  154. data/lib/xmpp4r/vcard/helper/vcard.rb +84 -0
  155. data/lib/xmpp4r/vcard/iq/vcard.rb +109 -0
  156. data/lib/xmpp4r/version.rb +7 -0
  157. data/lib/xmpp4r/version/helper/responder.rb +72 -0
  158. data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
  159. data/lib/xmpp4r/version/iq/version.rb +105 -0
  160. data/lib/xmpp4r/x.rb +37 -0
  161. data/lib/xmpp4r/xhtml.rb +1 -0
  162. data/lib/xmpp4r/xhtml/html.rb +115 -0
  163. data/lib/xmpp4r/xmpp4r.rb +20 -0
  164. data/lib/xmpp4r/xmppelement.rb +168 -0
  165. data/lib/xmpp4r/xmppstanza.rb +162 -0
  166. data/setup.rb +1586 -0
  167. data/test/bytestreams/tc_ibb.rb +188 -0
  168. data/test/bytestreams/tc_socks5bytestreams.rb +114 -0
  169. data/test/caps/tc_helper.rb +158 -0
  170. data/test/dataforms/tc_data.rb +81 -0
  171. data/test/delay/tc_xdelay.rb +51 -0
  172. data/test/discovery/tc_responder.rb +91 -0
  173. data/test/entity_time/tc_responder.rb +65 -0
  174. data/test/last/tc_helper.rb +75 -0
  175. data/test/lib/assert_equal_xml.rb +14 -0
  176. data/test/lib/clienttester.rb +149 -0
  177. data/test/muc/tc_muc_mucclient.rb +834 -0
  178. data/test/muc/tc_muc_simplemucclient.rb +114 -0
  179. data/test/muc/tc_mucowner.rb +50 -0
  180. data/test/pubsub/tc_helper.rb +785 -0
  181. data/test/pubsub/tc_nodeconfig.rb +61 -0
  182. data/test/pubsub/tc_subscriptionconfig.rb +41 -0
  183. data/test/roster/tc_helper.rb +523 -0
  184. data/test/roster/tc_iqqueryroster.rb +173 -0
  185. data/test/roster/tc_xroster.rb +73 -0
  186. data/test/rpc/tc_helper.rb +96 -0
  187. data/test/tc_callbacks.rb +129 -0
  188. data/test/tc_class_names.rb +146 -0
  189. data/test/tc_client.rb +30 -0
  190. data/test/tc_errors.rb +146 -0
  191. data/test/tc_idgenerator.rb +30 -0
  192. data/test/tc_iq.rb +113 -0
  193. data/test/tc_iqquery.rb +31 -0
  194. data/test/tc_jid.rb +204 -0
  195. data/test/tc_presence.rb +150 -0
  196. data/test/tc_rexml.rb +139 -0
  197. data/test/tc_stream.rb +193 -0
  198. data/test/tc_streamComponent.rb +105 -0
  199. data/test/tc_streamError.rb +129 -0
  200. data/test/tc_streamSend.rb +59 -0
  201. data/test/tc_streamparser.rb +137 -0
  202. data/test/tc_xmppstanza.rb +135 -0
  203. data/test/ts_xmpp4r.rb +44 -0
  204. data/test/tune/tc_helper_recv.rb +82 -0
  205. data/test/tune/tc_helper_send.rb +74 -0
  206. data/test/tune/tc_tune.rb +79 -0
  207. data/test/vcard/tc_helper.rb +49 -0
  208. data/test/vcard/tc_iqvcard.rb +62 -0
  209. data/test/version/tc_helper.rb +60 -0
  210. data/test/version/tc_iqqueryversion.rb +97 -0
  211. data/test/xhtml/tc_html.rb +41 -0
  212. data/tools/gen_requires.bash +31 -0
  213. data/tools/xmpp4r-gemspec-test.rb +11 -0
  214. data/xmpp4r.gemspec +249 -0
  215. metadata +299 -0
@@ -0,0 +1,188 @@
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/bytestreams'
10
+ require 'xmpp4r/semaphore'
11
+ include Jabber
12
+
13
+ class IBBTest < Test::Unit::TestCase
14
+ include ClientTester
15
+
16
+ def create_buffer(size)
17
+ ([nil] * size).collect { rand(256).chr }.join
18
+ end
19
+
20
+ def test_ibb_target2initiator
21
+ target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
22
+ initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
23
+
24
+ buffer = create_buffer(9999)
25
+
26
+ Thread.new do
27
+ target.accept
28
+ target.write(buffer)
29
+ Thread.pass
30
+ target.close
31
+ end
32
+
33
+ target.accept_wait
34
+
35
+ initiator.open
36
+
37
+ received = ''
38
+ while buf = initiator.read
39
+ received += buf
40
+ end
41
+
42
+ initiator.close
43
+
44
+ assert_equal(buffer, received)
45
+ end
46
+
47
+ def test_ibb_initiator2target
48
+ target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
49
+ initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
50
+
51
+ buffer = create_buffer(9999)
52
+
53
+ Thread.new do
54
+ target.accept_wait
55
+ initiator.open
56
+ initiator.write(buffer)
57
+ initiator.close
58
+ end
59
+
60
+
61
+ target.accept
62
+
63
+ received = ''
64
+ while buf = target.read
65
+ received += buf
66
+ end
67
+
68
+ target.close
69
+
70
+ assert_equal(buffer, received)
71
+ end
72
+
73
+ def test_ibb_pingpong
74
+ ignored_stanzas = 0
75
+ wait = Semaphore.new
76
+ @server.add_message_callback { ignored_stanzas += 1; wait.run }
77
+ @server.add_iq_callback { ignored_stanzas += 1; wait.run }
78
+
79
+
80
+ target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
81
+ initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
82
+
83
+ Thread.new do
84
+ target.accept
85
+
86
+ while buf = target.read
87
+ target.write(buf)
88
+ target.flush
89
+ end
90
+
91
+ target.close
92
+ end
93
+
94
+
95
+ assert_equal(0, ignored_stanzas)
96
+ @client.send("<iq from='1@a.com/1' type='set'>
97
+ <close xmlns='http://jabber.org/protocol/ibb' sid='another session id'/>
98
+ </iq>")
99
+ wait.wait
100
+ assert_equal(1, ignored_stanzas)
101
+
102
+
103
+ target.accept_wait
104
+ initiator.open
105
+
106
+
107
+ assert_equal(1, ignored_stanzas)
108
+ @client.send("<message from='1@a.com/1' type='error'>
109
+ <data xmlns='http://jabber.org/protocol/ibb' sid='another session id' seq='0'/>
110
+ </message>")
111
+ wait.wait
112
+ assert_equal(2, ignored_stanzas)
113
+ @client.send("<iq from='1@a.com/1' type='set'>
114
+ <close xmlns='http://jabber.org/protocol/ibb' sid='another session id'/>
115
+ </iq>")
116
+ wait.wait
117
+ assert_equal(3, ignored_stanzas)
118
+
119
+
120
+ 5.times do
121
+ buf = create_buffer(100)
122
+ initiator.write(buf)
123
+ initiator.flush
124
+
125
+ bufr = ''
126
+ begin
127
+ bufr += initiator.read
128
+ end while bufr.size < buf.size
129
+ assert_equal(buf, bufr)
130
+ end
131
+
132
+ initiator.close
133
+
134
+
135
+ assert_equal(3, ignored_stanzas)
136
+ end
137
+
138
+ def test_ibb_error
139
+ target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
140
+ initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
141
+
142
+ Thread.new do
143
+ target.accept
144
+
145
+ @server.send("<message from='1@a.com/1' type='error'>
146
+ <data xmlns='http://jabber.org/protocol/ibb' sid='#{target.instance_variable_get(:@session_id)}' seq='0'/>
147
+ </message>")
148
+ end
149
+
150
+
151
+ target.accept_wait
152
+ initiator.open
153
+
154
+ assert_nil(initiator.read)
155
+
156
+ initiator.close
157
+ end
158
+
159
+ def test_ibb_inactive
160
+ target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
161
+ initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
162
+
163
+ assert_nil(target.read)
164
+ assert_nil(initiator.read)
165
+
166
+ assert_raise(RuntimeError) {
167
+ target.write('a' * target.block_size)
168
+ }
169
+ assert_raise(RuntimeError) {
170
+ initiator.write('a' * initiator.block_size)
171
+ }
172
+ end
173
+
174
+ def test_ibb_queueitem
175
+ i1 = Bytestreams::IBBQueueItem.new(:close)
176
+ assert_equal(:close, i1.type)
177
+ assert_nil(i1.seq)
178
+
179
+ i2 = Bytestreams::IBBQueueItem.new(:data, 1, ['blah'].pack('m'))
180
+ assert_equal(:data, i2.type)
181
+ assert_equal(1, i2.seq)
182
+ assert_equal('blah', i2.data)
183
+
184
+ assert_raise(RuntimeError) {
185
+ i3 = Bytestreams::IBBQueueItem.new(:invalid)
186
+ }
187
+ end
188
+ end
@@ -0,0 +1,114 @@
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/bytestreams'
10
+ include Jabber
11
+
12
+ class SOCKS5BytestreamsTest < Test::Unit::TestCase
13
+ include ClientTester
14
+
15
+ @@server = Bytestreams::SOCKS5BytestreamsServer.new(65005)
16
+ @@server.add_address('localhost')
17
+
18
+ def create_buffer(size)
19
+ ([nil] * size).collect { rand(256).chr }.join
20
+ end
21
+
22
+ def test_server2multi
23
+ target1 = Bytestreams::SOCKS5BytestreamsTarget.new(@server, '1', '1@a.com/1', '1@a.com/2')
24
+ target2 = Bytestreams::SOCKS5BytestreamsTarget.new(@server, '2', '2@a.com/1', '2@a.com/2')
25
+ initiator1 = Bytestreams::SOCKS5BytestreamsInitiator.new(@client, '1', '1@a.com/1', '1@a.com/2')
26
+ initiator2 = Bytestreams::SOCKS5BytestreamsInitiator.new(@client, '2', '2@a.com/1', '2@a.com/2')
27
+ initiator1.add_streamhost(@@server)
28
+ initiator2.add_streamhost(@@server)
29
+
30
+ buf1 = create_buffer(8192)
31
+ buf2 = create_buffer(8192)
32
+
33
+ Thread.new do
34
+ target1.accept
35
+ target1.write(buf1)
36
+ target1.flush
37
+ target1.close
38
+ end
39
+
40
+ Thread.new do
41
+ target2.accept
42
+ target2.write(buf2)
43
+ target2.flush
44
+ target2.close
45
+ end
46
+
47
+ target1.accept_wait
48
+ target2.accept_wait
49
+ initiator1.open
50
+ initiator2.open
51
+
52
+ recv1 = ''
53
+ recv2 = ''
54
+
55
+ while buf = initiator2.read(256)
56
+ recv2 += buf
57
+ end
58
+
59
+ while buf = initiator1.read(256)
60
+ recv1 += buf
61
+ end
62
+
63
+ initiator1.close
64
+ initiator2.close
65
+
66
+ assert_equal(buf1, recv1)
67
+ assert_equal(buf2, recv2)
68
+ end
69
+
70
+ def test_pingpong
71
+ target = Bytestreams::SOCKS5BytestreamsTarget.new(@server, '1', '1@a.com/1', '1@a.com/2')
72
+ initiator = Bytestreams::SOCKS5BytestreamsInitiator.new(@client, '1', '1@a.com/1', '1@a.com/2')
73
+ initiator.add_streamhost(@@server)
74
+
75
+ Thread.new do
76
+ target.accept
77
+
78
+ while buf = target.read(256)
79
+ target.write(buf)
80
+ target.flush
81
+ end
82
+
83
+ target.close
84
+ end
85
+ target.accept_wait
86
+
87
+ initiator.open
88
+
89
+ 10.times do
90
+ buf = create_buffer(8192)
91
+ initiator.write(buf)
92
+ initiator.flush
93
+
94
+ bufr = ''
95
+ begin
96
+ bufr += initiator.read(256)
97
+ end while bufr.size < buf.size
98
+ assert_equal(buf, bufr)
99
+ end
100
+
101
+ initiator.close
102
+ end
103
+
104
+ def test_timeout
105
+ target = Bytestreams::SOCKS5BytestreamsTarget.new(@server, '1', '1@a.com/1', '1@a.com/2')
106
+
107
+ assert_nothing_raised do
108
+ Timeout::timeout(1) do
109
+ target.connect_timeout = 0.5
110
+ assert target.accept == false
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,158 @@
1
+ # coding: utf-8
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require File::dirname(__FILE__) + '/../lib/clienttester'
7
+
8
+ require 'xmpp4r/discovery'
9
+ require 'xmpp4r/caps/helper/helper'
10
+ require 'xmpp4r/dataforms'
11
+ include Jabber
12
+
13
+ class Caps::HelperTest < Test::Unit::TestCase
14
+ include ClientTester
15
+
16
+ ##
17
+ # Walk through the client/ server conversation defined
18
+ # in http://www.xmpp.org/extensions/xep-0115.html#usecases
19
+ # and assert conformance.
20
+ def test_caps_reply
21
+
22
+ # This will be invoked by 'wait_state' below...
23
+ state { |presence|
24
+ assert_kind_of(Jabber::Presence, presence)
25
+ c = presence.first_element('c')
26
+ assert_kind_of(Jabber::Caps::C, c)
27
+
28
+ # see http://www.xmpp.org/extensions/xep-0115.html#ver
29
+ assert_equal('SrFo9ar2CCk2EnOH4q4QANeuxLQ=', c.ver)
30
+
31
+ # version 1.5 of xep 0115 indicates that the <c /> stanzq MUST feature a 'hash' attribute
32
+ assert_equal('sha-1', c.hash)
33
+
34
+ assert_equal("http://home.gna.org/xmpp4r/##{Jabber::XMPP4R_VERSION}", c.node)
35
+ }
36
+
37
+ # Construct Caps::Helper which will send a <presence>
38
+ # stanza (with embedded <c/> advert) to the 'server'
39
+ h = Caps::Helper.new(@client, identities, features)
40
+
41
+ # The 'server' will receive the <presence> stanza and
42
+ # yield it to the 'state' block above, where an <iq> query
43
+ # will be sent back to the 'client,' to discover its capabilities.
44
+ # Wait here until the block has been executed.
45
+ wait_state
46
+
47
+ # The Caps::Helper will process the <iq> query from the 'server'
48
+ # and reply with an <iq> result providing the details of its
49
+ # identities and features.
50
+
51
+ state { |iq|
52
+ assert_kind_of(Jabber::Iq, iq)
53
+ assert_equal(:result, iq.type)
54
+ assert_equal('1867999907', iq.id)
55
+ assert_equal('new-big-computer.local', iq.to.to_s)
56
+
57
+ assert_kind_of(Jabber::Discovery::IqQueryDiscoInfo, iq.query)
58
+ assert_equal(iq.query.identities.size, identities.size)
59
+ get_category_iname_type = lambda{ |i| [i.category,i.iname,i.type] }
60
+ assert_equal(iq.query.identities.map(&get_category_iname_type).sort!, identities.map(&get_category_iname_type).sort!)
61
+
62
+ assert_equal(3, iq.query.features.size)
63
+ get_var = lambda { |f| f.var }
64
+ assert_equal(iq.query.features.sort, features.map(&get_var).sort)
65
+ }
66
+
67
+ send(iq_discovering_capabilities)
68
+
69
+ # The 'server' will receive the <iq> result from the
70
+ # 'client' and yield it to the block above. Wait here
71
+ # until that block exits.
72
+ wait_state
73
+ end
74
+
75
+ def test_custom_node
76
+ client_id='http://new-big-computer.local/client#321'
77
+
78
+ state { |presence|
79
+ c = presence.first_element('c')
80
+ assert_kind_of(Jabber::Caps::C, c)
81
+ assert_equal(client_id, c.node)
82
+ assert_equal('SrFo9ar2CCk2EnOH4q4QANeuxLQ=', c.ver)
83
+ }
84
+ h = Caps::Helper.new(@client, identities, features, client_id)
85
+ wait_state
86
+ end
87
+
88
+ def identities
89
+ [Jabber::Discovery::Identity.new('client', 'Exodus 0.9.1', 'pc')]
90
+ end
91
+
92
+ def features
93
+ [Jabber::Discovery::Feature.new("http://jabber.org/protocol/disco#info"),
94
+ Jabber::Discovery::Feature.new("http://jabber.org/protocol/disco#items"),
95
+ Jabber::Discovery::Feature.new("http://jabber.org/protocol/muc")]
96
+ end
97
+
98
+ def iq_discovering_capabilities
99
+ "<iq from='new-big-computer.local' type='get' to='matt@new-big-computer.local/capable_client' id='1867999907' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info'/></iq>"
100
+ end
101
+
102
+ ##
103
+ # http://www.xmpp.org/extensions/xep-0115.html#ver-gen-complex
104
+ def test_caps_complex
105
+ form = Dataforms::XData.new(:result)
106
+ form.add(Dataforms::XDataField.new('FORM_TYPE', :hidden)).value = 'urn:xmpp:dataforms:softwareinfo'
107
+ form.add(Dataforms::XDataField.new('ip_version')).values = ['ipv4', 'ipv6']
108
+ form.add(Dataforms::XDataField.new('software')).value = 'Psi' # re-ordered
109
+ form.add(Dataforms::XDataField.new('software_version')).value = '0.11'
110
+ form.add(Dataforms::XDataField.new('os')).value = 'Mac'
111
+ form.add(Dataforms::XDataField.new('os_version')).value = '10.5.1'
112
+ ver = Caps::generate_ver([Discovery::Identity.new('client', 'Psi 0.9.1', 'pc').set_xml_lang('en'),
113
+ Discovery::Identity.new('client', 'Ψ 0.9.1', 'pc').set_xml_lang('el')],
114
+ [Discovery::Feature.new('http://jabber.org/protocol/muc'), # re-ordered
115
+ Discovery::Feature.new('http://jabber.org/protocol/disco#info'),
116
+ Discovery::Feature.new('http://jabber.org/protocol/disco#items')],
117
+ [form])
118
+ assert_equal('8lu+88MRxmKM7yO3MEzY7YmTsWs=', ver)
119
+ end
120
+
121
+ ##
122
+ # http://www.xmpp.org/extensions/xep-0115.html#ver-gen-complex
123
+ def test_caps_complex_imported
124
+ query = IqQuery::import(REXML::Document.new(<<END).root)
125
+ <query xmlns='http://jabber.org/protocol/disco#info'
126
+ node='http://psi-im.org#8lu+88MRxmKM7yO3MEzY7YmTsWs='>
127
+ <identity xml:lang='en' category='client' name='Psi 0.9.1' type='pc'/>
128
+ <identity xml:lang='el' category='client' name='Ψ 0.9.1' type='pc'/>
129
+ <feature var='http://jabber.org/protocol/disco#info'/>
130
+ <feature var='http://jabber.org/protocol/disco#items'/>
131
+ <feature var='http://jabber.org/protocol/muc'/>
132
+ <x xmlns='jabber:x:data' type='result'>
133
+ <field var='FORM_TYPE' type='hidden'>
134
+ <value>urn:xmpp:dataforms:softwareinfo</value>
135
+ </field>
136
+ <field var='ip_version'>
137
+ <value>ipv4</value>
138
+ <value>ipv6</value>
139
+ </field>
140
+ <field var='os'>
141
+ <value>Mac</value>
142
+ </field>
143
+ <field var='os_version'>
144
+ <value>10.5.1</value>
145
+ </field>
146
+ <field var='software'>
147
+ <value>Psi</value>
148
+ </field>
149
+ <field var='software_version'>
150
+ <value>0.11</value>
151
+ </field>
152
+ </x>
153
+ </query>
154
+ END
155
+ assert_equal('8lu+88MRxmKM7yO3MEzY7YmTsWs=',
156
+ Caps::generate_ver_from_discoinfo(query))
157
+ end
158
+ end