blather 0.4.15 → 0.4.16
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +13 -0
- data/.gitignore +18 -0
- data/CHANGELOG +150 -0
- data/Gemfile +4 -0
- data/Rakefile +32 -0
- data/TODO.md +2 -0
- data/blather.gemspec +49 -0
- data/lib/blather.rb +3 -0
- data/lib/blather/client/client.rb +139 -1
- data/lib/blather/client/dsl.rb +16 -0
- data/lib/blather/core_ext/active_support.rb +1 -1
- data/lib/blather/core_ext/ipaddr.rb +19 -0
- data/lib/blather/file_transfer/s5b.rb +8 -0
- data/lib/blather/roster_item.rb +5 -2
- data/lib/blather/stanza/disco.rb +7 -0
- data/lib/blather/stanza/disco/disco_info.rb +13 -19
- data/lib/blather/stanza/disco/disco_items.rb +5 -11
- data/lib/blather/stanza/presence.rb +15 -5
- data/lib/blather/stanza/presence/c.rb +103 -0
- data/lib/blather/stanza/x.rb +2 -4
- data/lib/blather/version.rb +3 -0
- data/lib/blather/xmpp_node.rb +8 -0
- data/spec/blather/client/client_spec.rb +87 -1
- data/spec/blather/client/dsl/pubsub_spec.rb +2 -2
- data/spec/blather/client/dsl_spec.rb +85 -5
- data/spec/blather/core_ext/nokogiri_spec.rb +1 -1
- data/spec/blather/errors/sasl_error_spec.rb +1 -1
- data/spec/blather/errors/stanza_error_spec.rb +2 -2
- data/spec/blather/errors/stream_error_spec.rb +2 -2
- data/spec/blather/errors_spec.rb +1 -1
- data/spec/blather/file_transfer_spec.rb +2 -2
- data/spec/blather/jid_spec.rb +1 -1
- data/spec/blather/roster_item_spec.rb +1 -1
- data/spec/blather/roster_spec.rb +1 -1
- data/spec/blather/stanza/discos/disco_info_spec.rb +1 -11
- data/spec/blather/stanza/discos/disco_items_spec.rb +1 -6
- data/spec/blather/stanza/iq/command_spec.rb +3 -3
- data/spec/blather/stanza/iq/ibb_spec.rb +2 -2
- data/spec/blather/stanza/iq/query_spec.rb +1 -1
- data/spec/blather/stanza/iq/roster_spec.rb +1 -1
- data/spec/blather/stanza/iq/s5b_spec.rb +2 -2
- data/spec/blather/stanza/iq/si_spec.rb +2 -2
- data/spec/blather/stanza/iq/vcard_spec.rb +3 -3
- data/spec/blather/stanza/iq_spec.rb +1 -1
- data/spec/blather/stanza/message_spec.rb +2 -2
- data/spec/blather/stanza/presence/c_spec.rb +46 -0
- data/spec/blather/stanza/presence/status_spec.rb +1 -1
- data/spec/blather/stanza/presence/subscription_spec.rb +1 -1
- data/spec/blather/stanza/presence_spec.rb +1 -1
- data/spec/blather/stanza/pubsub/affiliations_spec.rb +2 -2
- data/spec/blather/stanza/pubsub/create_spec.rb +3 -3
- data/spec/blather/stanza/pubsub/event_spec.rb +2 -2
- data/spec/blather/stanza/pubsub/items_spec.rb +2 -2
- data/spec/blather/stanza/pubsub/publish_spec.rb +2 -2
- data/spec/blather/stanza/pubsub/retract_spec.rb +2 -2
- data/spec/blather/stanza/pubsub/subscribe_spec.rb +2 -2
- data/spec/blather/stanza/pubsub/subscription_spec.rb +3 -3
- data/spec/blather/stanza/pubsub/subscriptions_spec.rb +2 -2
- data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +2 -2
- data/spec/blather/stanza/pubsub_owner/delete_spec.rb +2 -2
- data/spec/blather/stanza/pubsub_owner/purge_spec.rb +3 -3
- data/spec/blather/stanza/pubsub_owner_spec.rb +2 -2
- data/spec/blather/stanza/pubsub_spec.rb +2 -8
- data/spec/blather/stanza/x_spec.rb +1 -6
- data/spec/blather/stanza_spec.rb +1 -1
- data/spec/blather/stream/client_spec.rb +3 -3
- data/spec/blather/stream/component_spec.rb +1 -1
- data/spec/blather/stream/parser_spec.rb +1 -1
- data/spec/blather/xmpp_node_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -12
- data/yard/templates/default/class/html/handlers.erb +18 -0
- data/yard/templates/default/class/setup.rb +10 -0
- data/yard/templates/default/class/text/handlers.erb +1 -0
- metadata +123 -13
- data/lib/test.rb +0 -55
@@ -1,9 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'blather/client/dsl'
|
3
3
|
|
4
4
|
describe Blather::DSL do
|
5
5
|
before do
|
6
|
-
@client =
|
6
|
+
@client = Blather::Client.new
|
7
|
+
@stream = mock()
|
8
|
+
@stream.stubs(:send)
|
9
|
+
@client.post_init @stream, Blather::JID.new('n@d/r')
|
7
10
|
@dsl = Class.new { include Blather::DSL }.new
|
8
11
|
Blather::Client.stubs(:new).returns(@client)
|
9
12
|
end
|
@@ -95,7 +98,7 @@ describe Blather::DSL do
|
|
95
98
|
it 'provides a "say" helper' do
|
96
99
|
to, msg = 'me@me.com', 'hello!'
|
97
100
|
Blather::Stanza::Message.stubs(:next_id).returns 0
|
98
|
-
@client.expects(:write).with
|
101
|
+
@client.expects(:write).with Blather::Stanza::Message.new(to, msg)
|
99
102
|
@dsl.say to, msg
|
100
103
|
end
|
101
104
|
|
@@ -111,7 +114,7 @@ describe Blather::DSL do
|
|
111
114
|
expected_stanza = Blather::Stanza::Disco::DiscoItems.new
|
112
115
|
expected_stanza.to = who
|
113
116
|
expected_stanza.node = where
|
114
|
-
@client.expects(:write).with
|
117
|
+
@client.expects(:write).with expected_stanza
|
115
118
|
@dsl.discover what, who, where
|
116
119
|
end
|
117
120
|
|
@@ -122,10 +125,87 @@ describe Blather::DSL do
|
|
122
125
|
expected_stanza = Blather::Stanza::Disco::DiscoInfo.new
|
123
126
|
expected_stanza.to = who
|
124
127
|
expected_stanza.node = where
|
125
|
-
@client.expects(:write).with
|
128
|
+
@client.expects(:write).with expected_stanza
|
126
129
|
@dsl.discover what, who, where
|
127
130
|
end
|
128
131
|
|
132
|
+
it 'provides a caps set helper' do
|
133
|
+
@dsl.must_respond_to :set_caps
|
134
|
+
node = 'http://code.google.com/p/exodus'
|
135
|
+
identities = [Blather::Stanza::Iq::DiscoInfo::Identity.new({:name => 'Exodus 0.9.1', :type => 'pc', :category => 'client'})]
|
136
|
+
features = %w{
|
137
|
+
http://jabber.org/protocol/caps
|
138
|
+
http://jabber.org/protocol/disco#info
|
139
|
+
http://jabber.org/protocol/disco#items
|
140
|
+
http://jabber.org/protocol/muc
|
141
|
+
}
|
142
|
+
@dsl.set_caps node, identities, features
|
143
|
+
@client.caps.node.must_equal "#{node}##{@client.caps.ver}"
|
144
|
+
@client.caps.identities.must_equal identities
|
145
|
+
@client.caps.features.map{ |f| f.var }.must_equal features
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'provides a caps send helper' do
|
149
|
+
@dsl.must_respond_to :send_caps
|
150
|
+
@client.caps.node = 'http://code.google.com/p/exodus'
|
151
|
+
@client.caps.identities = [Blather::Stanza::Iq::DiscoInfo::Identity.new({:name => 'Exodus 0.9.1', :type => 'pc', :category => 'client'})]
|
152
|
+
@client.caps.features = %w{
|
153
|
+
http://jabber.org/protocol/caps
|
154
|
+
http://jabber.org/protocol/disco#info
|
155
|
+
http://jabber.org/protocol/disco#items
|
156
|
+
http://jabber.org/protocol/muc
|
157
|
+
}
|
158
|
+
expected_stanza = Blather::Stanza.import(parse_stanza(<<-XML).root)
|
159
|
+
<presence>
|
160
|
+
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1"
|
161
|
+
node="http://code.google.com/p/exodus"
|
162
|
+
ver="QgayPKawpkPSDYmwT/WM94uAlu0="
|
163
|
+
/>
|
164
|
+
</presence>
|
165
|
+
XML
|
166
|
+
@client.expects(:write).with expected_stanza
|
167
|
+
@client.expects(:register_handler).with(:disco_info, :type => :get, :node => "http://code.google.com/p/exodus#QgayPKawpkPSDYmwT/WM94uAlu0=")
|
168
|
+
@dsl.send_caps
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'responds with correct disco stanza after sending caps and receiving query' do
|
172
|
+
@client.caps.node = 'http://code.google.com/p/exodus'
|
173
|
+
@client.caps.identities = [Blather::Stanza::Iq::DiscoInfo::Identity.new({:name => 'Exodus 0.9.1', :type => 'pc', :category => 'client'})]
|
174
|
+
@client.caps.features = %w{
|
175
|
+
http://jabber.org/protocol/caps
|
176
|
+
http://jabber.org/protocol/disco#info
|
177
|
+
http://jabber.org/protocol/disco#items
|
178
|
+
http://jabber.org/protocol/muc
|
179
|
+
}
|
180
|
+
stanza = <<-XML
|
181
|
+
<iq from='juliet@capulet.lit/chamber'
|
182
|
+
id='disco1'
|
183
|
+
to='romeo@montague.lit/orchard'
|
184
|
+
type='get'>
|
185
|
+
<query xmlns='http://jabber.org/protocol/disco#info'
|
186
|
+
node='http://code.google.com/p/exodus#QgayPKawpkPSDYmwT/WM94uAlu0='/>
|
187
|
+
</iq>
|
188
|
+
XML
|
189
|
+
@stanza = Blather::Stanza.import(parse_stanza(stanza).root)
|
190
|
+
|
191
|
+
expected_stanza = Blather::Stanza.import(parse_stanza(<<-XML).root)
|
192
|
+
<iq type="result" id="disco1" to="juliet@capulet.lit/chamber">
|
193
|
+
<query xmlns="http://jabber.org/protocol/disco#info" node="http://code.google.com/p/exodus#QgayPKawpkPSDYmwT/WM94uAlu0=">
|
194
|
+
<identity name="Exodus 0.9.1" category="client" type="pc"/>
|
195
|
+
<feature var="http://jabber.org/protocol/caps"/>
|
196
|
+
<feature var="http://jabber.org/protocol/disco#info"/>
|
197
|
+
<feature var="http://jabber.org/protocol/disco#items"/>
|
198
|
+
<feature var="http://jabber.org/protocol/muc"/>
|
199
|
+
</query>
|
200
|
+
</iq>
|
201
|
+
XML
|
202
|
+
@dsl.send_caps
|
203
|
+
# client writes a Client::Cap object but it's the same as a DiscoInfo
|
204
|
+
# this is a hack to pass the same-class check in XMPPNode#eql?
|
205
|
+
@client.expects(:write).with { |n| Blather::Stanza.import(n) == expected_stanza }
|
206
|
+
@client.receive_data @stanza
|
207
|
+
end
|
208
|
+
|
129
209
|
Blather::Stanza.handler_list.each do |handler_method|
|
130
210
|
it "provides a helper method for #{handler_method}" do
|
131
211
|
guards = [:chat?, {:body => 'exit'}]
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def stanza_error_node(type = 'cancel', error = 'internal-server-error', msg = nil)
|
4
4
|
node = Blather::Stanza::Message.new 'error@jabber.local', 'test message', :error
|
5
5
|
|
6
6
|
node << (error_node = Blather::XMPPNode.new('error'))
|
7
7
|
error_node['type'] = type.to_s
|
8
|
-
|
8
|
+
|
9
9
|
error_node << (err = Blather::XMPPNode.new(error, error_node.document))
|
10
10
|
err.namespace = 'urn:ietf:params:xml:ns:xmpp-stanzas'
|
11
11
|
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def stream_error_node(error = 'internal-server-error', msg = nil)
|
4
4
|
node = Blather::XMPPNode.new('error')
|
5
5
|
node.namespace = {'stream' => Blather::Stream::STREAM_NS}
|
6
|
-
|
6
|
+
|
7
7
|
node << (err = Blather::XMPPNode.new(error, node.document))
|
8
8
|
err.namespace = 'urn:ietf:params:xml:ns:xmpp-streams'
|
9
9
|
|
data/spec/blather/errors_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'blather/client/dsl'
|
3
3
|
|
4
4
|
module MockFileReceiver
|
@@ -97,4 +97,4 @@ describe Blather::FileTransfer do
|
|
97
97
|
transfer = Blather::FileTransfer.new(@client, iq)
|
98
98
|
transfer.decline
|
99
99
|
end
|
100
|
-
end
|
100
|
+
end
|
data/spec/blather/jid_spec.rb
CHANGED
data/spec/blather/roster_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def disco_info_xml
|
4
4
|
<<-XML
|
@@ -219,11 +219,6 @@ describe Blather::Stanza::Iq::DiscoInfo::Identity do
|
|
219
219
|
n.xml_lang.must_equal 'de'
|
220
220
|
end
|
221
221
|
|
222
|
-
it 'raises an error if equality is sent a non DiscoInfo::Identity object' do
|
223
|
-
a = Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
|
224
|
-
lambda { a == 'foo' }.must_raise RuntimeError
|
225
|
-
end
|
226
|
-
|
227
222
|
it 'can determine equality' do
|
228
223
|
a = Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
|
229
224
|
a.must_equal Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
|
@@ -245,11 +240,6 @@ describe Blather::Stanza::Iq::DiscoInfo::Feature do
|
|
245
240
|
n.var.must_equal 'foo'
|
246
241
|
end
|
247
242
|
|
248
|
-
it 'raises an error if equality is sent a non DiscoInfo::Feature object' do
|
249
|
-
a = Blather::Stanza::Iq::DiscoInfo::Feature.new('var')
|
250
|
-
lambda { a == 'foo' }.must_raise RuntimeError
|
251
|
-
end
|
252
|
-
|
253
243
|
it 'can determine equality' do
|
254
244
|
a = Blather::Stanza::Iq::DiscoInfo::Feature.new('var')
|
255
245
|
a.must_equal Blather::Stanza::Iq::DiscoInfo::Feature.new('var')
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def disco_items_xml
|
4
4
|
<<-XML
|
@@ -146,11 +146,6 @@ describe Blather::Stanza::Iq::DiscoItems::Item do
|
|
146
146
|
n.name.must_equal 'Books by and about Shakespeare'
|
147
147
|
end
|
148
148
|
|
149
|
-
it 'raises an error when compared against a non DiscoItems::Item' do
|
150
|
-
a = Blather::Stanza::Iq::DiscoItems::Item.new('foo@bar/baz')
|
151
|
-
lambda { a == 'test' }.must_raise RuntimeError
|
152
|
-
end
|
153
|
-
|
154
149
|
it 'can determine equality' do
|
155
150
|
a = Blather::Stanza::Iq::DiscoItems::Item.new('foo@bar/baz')
|
156
151
|
a.must_equal Blather::Stanza::Iq::DiscoItems::Item.new('foo@bar/baz')
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def command_xml
|
4
4
|
<<-XML
|
@@ -90,7 +90,7 @@ describe Blather::Stanza::Iq::Command do
|
|
90
90
|
c.action.must_equal :execute
|
91
91
|
c.reply.action.must_equal nil
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
it 'removes action on reply!' do
|
95
95
|
c = Blather::XMPPNode.import parse_stanza(command_xml).root
|
96
96
|
c.action.must_equal :execute
|
@@ -203,4 +203,4 @@ describe Blather::Stanza::Iq::Command do
|
|
203
203
|
r.command.xpath('ns:x', :ns => Blather::Stanza::X.registered_ns).wont_be_empty
|
204
204
|
r.xpath('ns:x', :ns => Blather::Stanza::X.registered_ns).must_be_empty
|
205
205
|
end
|
206
|
-
end
|
206
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def s5b_open_xml
|
4
4
|
<<-XML
|
@@ -57,4 +57,4 @@ describe Blather::Stanza::Iq::S5b do
|
|
57
57
|
node.streamhost_used = 'used@example.com/foo'
|
58
58
|
node.streamhost_used.jid.to_s.must_equal 'used@example.com/foo'
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def si_xml
|
4
4
|
<<-XML
|
@@ -98,4 +98,4 @@ describe Blather::Stanza::Iq::Si::Si::File do
|
|
98
98
|
file.desc = 'This is a test. If this were a real file...'
|
99
99
|
file.desc.must_equal 'This is a test. If this were a real file...'
|
100
100
|
end
|
101
|
-
end
|
101
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def vcard_xml
|
4
4
|
<<-XML
|
@@ -44,7 +44,7 @@ describe Blather::Stanza::Iq::Vcard do
|
|
44
44
|
new_vcard["NICKNAME"] = 'Mercutio'
|
45
45
|
|
46
46
|
query.vcard = new_vcard
|
47
|
-
|
47
|
+
|
48
48
|
query.xpath('ns:vCard', :ns => 'vcard-temp').size.must_equal 1
|
49
49
|
query.find_first('ns:vCard/ns:NICKNAME', :ns => 'vcard-temp').content.must_equal 'Mercutio'
|
50
50
|
end
|
@@ -93,4 +93,4 @@ describe Blather::Stanza::Iq::Vcard::Vcard do
|
|
93
93
|
query.vcard['NICKNAME'] = 'Mercutio'
|
94
94
|
query.vcard['NICKNAME'].must_equal 'Mercutio'
|
95
95
|
end
|
96
|
-
end
|
96
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def ichat_message_xml
|
4
4
|
<<-XML
|
@@ -245,4 +245,4 @@ describe Blather::Stanza::Message do
|
|
245
245
|
r.form
|
246
246
|
r.xpath('ns:x', :ns => Blather::Stanza::X.registered_ns).wont_be_empty
|
247
247
|
end
|
248
|
-
end
|
248
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def c_xml
|
4
|
+
<<-XML
|
5
|
+
<presence from='bard@shakespeare.lit/globe'>
|
6
|
+
<c xmlns='http://jabber.org/protocol/caps'
|
7
|
+
hash='sha-1'
|
8
|
+
node='http://www.chatopus.com'
|
9
|
+
ver='zHyEOgxTrkpSdGcQKH8EFPLsriY='/>
|
10
|
+
</presence>
|
11
|
+
XML
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'Blather::Stanza::Presence::C' do
|
15
|
+
it 'registers itself' do
|
16
|
+
Blather::XMPPNode.class_from_registration(:c, 'http://jabber.org/protocol/caps' ).must_equal Blather::Stanza::Presence::C
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'must be importable' do
|
20
|
+
c = Blather::XMPPNode.import(parse_stanza(c_xml).root).must_be_instance_of Blather::Stanza::Presence::C
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'ensures hash is one of Blather::Stanza::Presence::C::VALID_HASH_TYPES' do
|
24
|
+
lambda { Blather::Stanza::Presence::C.new nil, nil, :invalid_type_name }.must_raise(Blather::ArgumentError)
|
25
|
+
|
26
|
+
Blather::Stanza::Presence::C::VALID_HASH_TYPES.each do |valid_hash|
|
27
|
+
c = Blather::Stanza::Presence::C.new nil, nil, valid_hash
|
28
|
+
c.hash.must_equal valid_hash.to_sym
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'can set a hash on creation' do
|
33
|
+
c = Blather::Stanza::Presence::C.new nil, nil, :md5
|
34
|
+
c.hash.must_equal :md5
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can set a node on creation' do
|
38
|
+
c = Blather::Stanza::Presence::C.new 'http://www.chatopus.com'
|
39
|
+
c.node.must_equal 'http://www.chatopus.com'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can set a ver on creation' do
|
43
|
+
c = Blather::Stanza::Presence::C.new nil, 'zHyEOgxTrkpSdGcQKH8EFPLsriY='
|
44
|
+
c.ver.must_equal 'zHyEOgxTrkpSdGcQKH8EFPLsriY='
|
45
|
+
end
|
46
|
+
end
|