jabber4r-revive 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +5 -4
  2. data/.rspec +3 -3
  3. data/.travis.yml +7 -7
  4. data/CHANGELOG +11 -1
  5. data/Gemfile +3 -3
  6. data/README.md +29 -29
  7. data/Rakefile +70 -70
  8. data/jabber4r-revive.gemspec +25 -25
  9. data/lib/jabber4r.rb +38 -33
  10. data/lib/jabber4r/bosh.rb +21 -0
  11. data/lib/jabber4r/bosh/authentication.rb +13 -0
  12. data/lib/jabber4r/bosh/authentication/non_sasl.rb +219 -0
  13. data/lib/jabber4r/bosh/authentication/sasl.rb +239 -0
  14. data/lib/jabber4r/bosh/session.rb +144 -0
  15. data/lib/jabber4r/connection.rb +259 -258
  16. data/lib/jabber4r/debugger.rb +60 -60
  17. data/lib/jabber4r/jid.rb +20 -19
  18. data/lib/jabber4r/protocol.rb +249 -257
  19. data/lib/jabber4r/protocol/authentication.rb +14 -0
  20. data/lib/jabber4r/protocol/authentication/non_sasl.rb +138 -0
  21. data/lib/jabber4r/protocol/authentication/sasl.rb +88 -0
  22. data/lib/jabber4r/protocol/iq.rb +259 -259
  23. data/lib/jabber4r/protocol/message.rb +245 -245
  24. data/lib/jabber4r/protocol/parsed_xml_element.rb +207 -207
  25. data/lib/jabber4r/protocol/presence.rb +160 -160
  26. data/lib/jabber4r/protocol/xml_element.rb +143 -143
  27. data/lib/jabber4r/rexml_1.8_patch.rb +15 -15
  28. data/lib/jabber4r/roster.rb +38 -38
  29. data/lib/jabber4r/session.rb +615 -615
  30. data/lib/jabber4r/version.rb +10 -3
  31. data/spec/lib/jabber4r/bosh/authentication/non_sasl_spec.rb +79 -0
  32. data/spec/lib/jabber4r/bosh/authentication/sasl_spec.rb +42 -0
  33. data/spec/lib/jabber4r/bosh/session_spec.rb +406 -0
  34. data/spec/lib/jabber4r/bosh_spec.rb +0 -0
  35. data/spec/lib/jabber4r/connection_spec.rb +174 -174
  36. data/spec/lib/jabber4r/debugger_spec.rb +35 -35
  37. data/spec/lib/jabber4r/jid_spec.rb +197 -197
  38. data/spec/lib/jabber4r/protocol/authentication/non_sasl_spec.rb +79 -0
  39. data/spec/lib/jabber4r/protocol/authentication/sasl_spec.rb +42 -0
  40. data/spec/spec_helper.rb +11 -11
  41. data/spec/support/mocks/tcp_socket_mock.rb +8 -8
  42. metadata +61 -45
  43. data/Gemfile.lock +0 -45
  44. data/lib/jabber4r/bosh_session.rb +0 -224
  45. data/spec/lib/jabber4r/bosh_session_spec.rb +0 -150
@@ -1,150 +0,0 @@
1
- # coding: utf-8
2
- require "spec_helper"
3
-
4
- describe Jabber::BoshSession do
5
- let(:successful_login) { '<body xmlns="http://jabber.org/protocol/httpbind"><iq type="result" xmlns="jabber:client" id="2034"/></body>' }
6
- let(:successful_open_stream) do
7
- [
8
- '<body xmlns="http://jabber.org/protocol/httpbind" xmlns:xmpp="urn:xmpp:xbosh" xmlns:stream="http://etherx.jabber.org/streams"',
9
- 'authid="3780309894" sid="ce21410" from="localhost"',
10
- 'wait="60" requests="2" inactivity="30" maxpause="120" polling="2" ver="1.8" secure="true" />'
11
- ].join " "
12
- end
13
- let(:is_open_stream?) { ->(data) { x = Ox.parse(data); ["1", "localhost"] == [x[:rid], x[:to]] } }
14
- let(:is_login?) { ->(data) { x = Ox.parse(data); ["1", "ce21410"] == [x[:rid], x[:sid]] } }
15
- let(:bosh_session) { described_class.bind("strech@localhost/resource", "password") }
16
-
17
- before { Jabber::BoshSession.any_instance.stub(:generate_next_rid).and_return "1" }
18
-
19
- describe "#bind" do
20
- context "when session successfuly binded" do
21
- before do
22
- stub_request(:post, "http://localhost:5280/http-bind")
23
- .with(body: is_open_stream?)
24
- .to_return(body: successful_open_stream)
25
-
26
- stub_request(:post, "http://localhost:5280/http-bind")
27
- .with(body: is_login?)
28
- .to_return(body: successful_login)
29
- end
30
-
31
- it { expect(bosh_session).to be_alive }
32
- end
33
-
34
- context "when couldn't open stream" do
35
- context "when response body missed authid attribute" do
36
- let(:malformed_body) { '<body xmlns="http://jabber.org/protocol/httpbind" sid="ce21410" />' }
37
-
38
- before do
39
- stub_request(:post, "http://localhost:5280/http-bind")
40
- .with(body: is_open_stream?)
41
- .to_return(body: malformed_body)
42
-
43
- WebMock.should_not have_requested(:post, "http://localhost:5280/http-bind")
44
- .with(body: is_login?)
45
- end
46
-
47
- it { expect { bosh_session }.to raise_error Jabber::XMLMalformedError, "Couldn't find <body /> attribute [authid]" }
48
- end
49
-
50
- context "when response body missed sid attribute" do
51
- let(:malformed_body) { '<body xmlns="http://jabber.org/protocol/httpbind" authid="3780309894" />' }
52
-
53
- before do
54
- stub_request(:post, "http://localhost:5280/http-bind")
55
- .with(body: is_open_stream?)
56
- .to_return(body: malformed_body)
57
-
58
- WebMock.should_not have_requested(:post, "http://localhost:5280/http-bind")
59
- .with(body: is_login?)
60
- end
61
-
62
- it { expect { bosh_session }.to raise_error Jabber::XMLMalformedError, "Couldn't find <body /> attribute [sid]" }
63
- end
64
-
65
- context "when response was not 200 OK" do
66
- before do
67
- stub_request(:post, "http://localhost:5280/http-bind")
68
- .with(body: is_open_stream?)
69
- .to_return(body: "Foo", status: 401)
70
-
71
- WebMock.should_not have_requested(:post, "http://localhost:5280/http-bind")
72
- .with(body: is_login?)
73
- end
74
-
75
- it { expect { bosh_session }.to raise_error Net::HTTPBadResponse }
76
- end
77
- end
78
-
79
- context "when couldn't login in opened stream" do
80
- context "when response is a malformed xml without IQ tag" do
81
- let(:malformed_body) { '<body xmlns="http://jabber.org/protocol/httpbind"></body>' }
82
-
83
- before do
84
- stub_request(:post, "http://localhost:5280/http-bind")
85
- .with(body: is_open_stream?)
86
- .to_return(body: successful_open_stream)
87
-
88
- stub_request(:post, "http://localhost:5280/http-bind")
89
- .with(body: is_login?)
90
- .to_return(body: malformed_body)
91
- end
92
-
93
- it { expect { bosh_session }.to raise_error Jabber::XMLMalformedError, "Couldn't find xml tag <iq/>" }
94
- end
95
-
96
- context "when response has type not equal 'result'" do
97
- let(:malformed_body) { '<body xmlns="http://jabber.org/protocol/httpbind"><iq type="error" xmlns="jabber:client" id="2034"/></body>' }
98
-
99
- before do
100
- stub_request(:post, "http://localhost:5280/http-bind")
101
- .with(body: is_open_stream?)
102
- .to_return(body: successful_open_stream)
103
-
104
- stub_request(:post, "http://localhost:5280/http-bind")
105
- .with(body: is_login?)
106
- .to_return(body: malformed_body)
107
- end
108
-
109
- it { expect { bosh_session }.to raise_error Jabber::AuthenticationError, "Failed to login" }
110
- end
111
-
112
- context "when response was not 200 OK" do
113
- before do
114
- stub_request(:post, "http://localhost:5280/http-bind")
115
- .with(body: is_open_stream?)
116
- .to_return(body: successful_open_stream)
117
-
118
- stub_request(:post, "http://localhost:5280/http-bind")
119
- .with(body: is_login?)
120
- .to_return(body: "Foo", status: 401)
121
- end
122
-
123
- it { expect { bosh_session }.to raise_error Net::HTTPBadResponse }
124
- end
125
- end
126
- end
127
-
128
- describe "#to_json" do
129
- let(:json) { JSON.parse(bosh_session.to_json) }
130
-
131
- before do
132
- stub_request(:post, "http://localhost:5280/http-bind")
133
- .with(body: is_open_stream?)
134
- .to_return(body: successful_open_stream)
135
-
136
-
137
- stub_request(:post, "http://localhost:5280/http-bind")
138
- .with(body: is_login?)
139
- .to_return(body: successful_login)
140
- end
141
-
142
- it { expect(json).to have_key "jid" }
143
- it { expect(json).to have_key "rid" }
144
- it { expect(json).to have_key "sid" }
145
-
146
- it { expect(json["jid"]).to eq "strech@localhost/resource"}
147
- it { expect(json["rid"]).to eq "1"}
148
- it { expect(json["sid"]).to eq "ce21410"}
149
- end
150
- end