vines 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/Gemfile +3 -0
  2. data/README.md +48 -0
  3. data/Rakefile +6 -58
  4. data/bin/vines +12 -2
  5. data/conf/certs/ca-bundle.crt +568 -39
  6. data/conf/config.rb +9 -42
  7. data/lib/vines.rb +1 -8
  8. data/lib/vines/command/cert.rb +4 -4
  9. data/lib/vines/command/init.rb +3 -3
  10. data/lib/vines/config.rb +9 -0
  11. data/lib/vines/kit.rb +2 -7
  12. data/lib/vines/storage/local.rb +50 -17
  13. data/lib/vines/store.rb +6 -4
  14. data/lib/vines/stream.rb +1 -1
  15. data/lib/vines/stream/http/session.rb +0 -0
  16. data/lib/vines/stream/http/sessions.rb +0 -0
  17. data/lib/vines/stream/parser.rb +3 -2
  18. data/lib/vines/token_bucket.rb +19 -10
  19. data/lib/vines/version.rb +1 -1
  20. data/test/cluster/publisher_test.rb +45 -33
  21. data/test/cluster/sessions_test.rb +32 -39
  22. data/test/cluster/subscriber_test.rb +93 -78
  23. data/test/config/host_test.rb +2 -4
  24. data/test/config/pubsub_test.rb +132 -126
  25. data/test/config_test.rb +2 -4
  26. data/test/contact_test.rb +80 -66
  27. data/test/error_test.rb +54 -55
  28. data/test/jid_test.rb +1 -2
  29. data/test/kit_test.rb +22 -17
  30. data/test/router_test.rb +187 -146
  31. data/test/stanza/iq/disco_info_test.rb +59 -59
  32. data/test/stanza/iq/disco_items_test.rb +36 -34
  33. data/test/stanza/iq/private_storage_test.rb +138 -143
  34. data/test/stanza/iq/roster_test.rb +198 -175
  35. data/test/stanza/iq/session_test.rb +17 -18
  36. data/test/stanza/iq/vcard_test.rb +117 -116
  37. data/test/stanza/iq/version_test.rb +47 -46
  38. data/test/stanza/iq_test.rb +53 -49
  39. data/test/stanza/message_test.rb +92 -89
  40. data/test/stanza/presence/probe_test.rb +2 -5
  41. data/test/stanza/presence/subscribe_test.rb +67 -54
  42. data/test/stanza/pubsub/create_test.rb +86 -108
  43. data/test/stanza/pubsub/delete_test.rb +141 -114
  44. data/test/stanza/pubsub/publish_test.rb +256 -320
  45. data/test/stanza/pubsub/subscribe_test.rb +169 -150
  46. data/test/stanza/pubsub/unsubscribe_test.rb +111 -142
  47. data/test/stanza_test.rb +61 -54
  48. data/test/storage/ldap_test.rb +1 -2
  49. data/test/storage/local_test.rb +3 -5
  50. data/test/storage/null_test.rb +3 -4
  51. data/test/storage/storage_tests.rb +1 -3
  52. data/test/storage_test.rb +1 -2
  53. data/test/store_test.rb +1 -2
  54. data/test/stream/client/auth_test.rb +61 -63
  55. data/test/stream/client/ready_test.rb +7 -8
  56. data/test/stream/client/session_test.rb +19 -18
  57. data/test/stream/component/handshake_test.rb +40 -37
  58. data/test/stream/component/ready_test.rb +76 -61
  59. data/test/stream/component/start_test.rb +7 -8
  60. data/test/stream/http/auth_test.rb +3 -4
  61. data/test/stream/http/ready_test.rb +52 -60
  62. data/test/stream/http/request_test.rb +1 -3
  63. data/test/stream/http/sessions_test.rb +2 -3
  64. data/test/stream/http/start_test.rb +3 -4
  65. data/test/stream/parser_test.rb +3 -4
  66. data/test/stream/sasl_test.rb +105 -86
  67. data/test/stream/server/auth_test.rb +40 -36
  68. data/test/stream/server/outbound/auth_test.rb +3 -4
  69. data/test/stream/server/ready_test.rb +51 -51
  70. data/test/test_helper.rb +42 -0
  71. data/test/token_bucket_test.rb +38 -18
  72. data/test/user_test.rb +79 -49
  73. data/vines.gemspec +33 -0
  74. data/web/chat/javascripts/app.js +1 -1
  75. data/web/lib/coffeescripts/layout.coffee +1 -1
  76. data/web/lib/javascripts/base.js +10 -10
  77. data/web/lib/javascripts/jquery.js +4 -4
  78. metadata +31 -128
  79. data/README +0 -35
  80. data/lib/vines/storage/couchdb.rb +0 -129
  81. data/lib/vines/storage/mongodb.rb +0 -132
  82. data/lib/vines/storage/redis.rb +0 -127
  83. data/lib/vines/storage/sql.rb +0 -220
  84. data/test/rake_test_loader.rb +0 -17
  85. data/test/storage/couchdb_test.rb +0 -107
  86. data/test/storage/mock_mongo.rb +0 -40
  87. data/test/storage/mongodb_test.rb +0 -81
  88. data/test/storage/redis_test.rb +0 -51
  89. data/test/storage/sql_test.rb +0 -62
@@ -1,8 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'tmpdir'
4
- require 'vines'
5
- require 'minitest/autorun'
3
+ require 'test_helper'
6
4
 
7
5
  describe Vines::Stream::Http::Request do
8
6
  PASSWORD = File.expand_path('../passwords')
@@ -1,9 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'vines'
4
- require 'minitest/autorun'
3
+ require 'test_helper'
5
4
 
6
- class SessionsTest < MiniTest::Unit::TestCase
5
+ describe Vines::Stream::Http::Sessions do
7
6
  class MockSessions < Vines::Stream::Http::Sessions
8
7
  def start_timer
9
8
  # do nothing
@@ -1,10 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'vines'
4
- require 'minitest/autorun'
3
+ require 'test_helper'
5
4
 
6
- class HttpStartTest < MiniTest::Unit::TestCase
7
- def setup
5
+ describe Vines::Stream::Http::Start do
6
+ before do
8
7
  @stream = MiniTest::Mock.new
9
8
  @state = Vines::Stream::Http::Start.new(@stream)
10
9
  end
@@ -1,12 +1,11 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'vines'
4
- require 'minitest/autorun'
3
+ require 'test_helper'
5
4
 
6
- class ParserTest < MiniTest::Unit::TestCase
5
+ describe Vines::Stream::Parser do
7
6
  STREAM_START = '<stream:stream to="wonderland.lit" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams">'.freeze
8
7
 
9
- def setup
8
+ before do
10
9
  @events = []
11
10
  @parser = Vines::Stream::Parser.new.tap do |p|
12
11
  p.stream_open {|el| @events << el }
@@ -1,13 +1,15 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'vines'
4
- require 'minitest/autorun'
3
+ require 'test_helper'
5
4
 
6
5
  describe Vines::Stream::SASL do
6
+ subject { Vines::Stream::SASL.new(stream) }
7
+ let(:stream) { MiniTest::Mock.new }
8
+ let(:storage) { MiniTest::Mock.new }
9
+ let(:romeo) { Vines::User.new(jid: 'romeo@verona.lit') }
10
+
7
11
  before do
8
- @stream = MiniTest::Mock.new
9
- @sasl = Vines::Stream::SASL.new(@stream)
10
- def @sasl.log
12
+ def subject.log
11
13
  Class.new do
12
14
  def method_missing(*args)
13
15
  # do nothing
@@ -17,95 +19,104 @@ describe Vines::Stream::SASL do
17
19
  end
18
20
 
19
21
  describe '#plain_auth' do
20
- it 'fails with invalid input' do
21
- proc { @sasl.plain_auth(nil) }.must_raise Vines::SaslErrors::IncorrectEncoding
22
- proc { @sasl.plain_auth('') }.must_raise Vines::SaslErrors::NotAuthorized
23
- proc { @sasl.plain_auth('bogus') }.must_raise Vines::SaslErrors::IncorrectEncoding
24
- proc { @sasl.plain_auth('=dmVyb25hLmxpdA==') }.must_raise Vines::SaslErrors::IncorrectEncoding
25
- proc { @sasl.plain_auth("dmVyb25hLmxpdA==\n") }.must_raise Vines::SaslErrors::IncorrectEncoding
22
+ before do
23
+ stream.expect :domain, 'verona.lit'
24
+ end
25
+
26
+ it 'fails with empty input' do
27
+ -> { subject.plain_auth(nil) }.must_raise Vines::SaslErrors::IncorrectEncoding
28
+ -> { subject.plain_auth('') }.must_raise Vines::SaslErrors::NotAuthorized
29
+ end
30
+
31
+ it 'fails with plain text' do
32
+ -> { subject.plain_auth('bogus') }.must_raise Vines::SaslErrors::IncorrectEncoding
33
+ end
34
+
35
+ it 'fails with incorrectly encoded base64 text' do
36
+ -> { subject.plain_auth('=dmVyb25hLmxpdA==') }.must_raise Vines::SaslErrors::IncorrectEncoding
37
+ -> { subject.plain_auth("dmVyb25hLmxpdA==\n") }.must_raise Vines::SaslErrors::IncorrectEncoding
26
38
  end
27
39
 
28
- it 'fails when authzid does not match authcid' do
29
- @stream.expect(:domain, 'verona.lit')
40
+ it 'fails when authzid does not match authcid username' do
30
41
  encoded = Base64.strict_encode64("juliet@verona.lit\x00romeo\x00secr3t")
31
- proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::InvalidAuthzid
42
+ -> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::InvalidAuthzid
43
+ stream.verify
44
+ end
45
+
46
+ it 'fails when authzid does not match authcid domain' do
32
47
  encoded = Base64.strict_encode64("romeo@wonderland.lit\x00romeo\x00secr3t")
33
- proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::InvalidAuthzid
34
- @stream.verify.must_equal true
48
+ -> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::InvalidAuthzid
49
+ stream.verify
50
+ end
51
+
52
+ it 'fails when username and password are missing' do
53
+ encoded = Base64.strict_encode64("\x00\x00")
54
+ -> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
35
55
  end
36
56
 
37
57
  it 'fails when username is missing' do
38
58
  encoded = Base64.strict_encode64("\x00\x00secr3t")
39
- proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
40
- encoded = Base64.strict_encode64("\x00\x00")
41
- proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
59
+ -> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
42
60
  end
43
61
 
44
- it 'fails when password is missing' do
62
+ it 'fails when password is missing with delimiter' do
45
63
  encoded = Base64.strict_encode64("\x00romeo\x00")
46
- proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
64
+ -> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
65
+ end
66
+
67
+ it 'fails when password is missing' do
47
68
  encoded = Base64.strict_encode64("\x00romeo")
48
- proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
69
+ -> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
49
70
  end
50
71
 
51
72
  it 'fails with invalid jid' do
52
- @stream.expect(:domain, 'verona.lit')
53
- jid = 'a' * 1024
54
- encoded = Base64.strict_encode64("\x00#{jid}\x00secr3t")
55
- proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
56
- @stream.verify.must_equal true
73
+ encoded = Base64.strict_encode64("\x00#{'a' * 1024}\x00secr3t")
74
+ -> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
75
+ stream.verify
57
76
  end
58
77
 
59
78
  it 'fails with invalid password' do
60
- romeo = Vines::JID.new('romeo@verona.lit')
61
- storage = MiniTest::Mock.new
62
- storage.expect(:authenticate, nil, [romeo, 'secr3t'])
63
- @stream.expect(:domain, 'verona.lit')
64
- @stream.expect(:storage, storage)
79
+ storage.expect :authenticate, nil, [romeo.jid, 'secr3t']
80
+ stream.expect :storage, storage
65
81
 
66
82
  encoded = Base64.strict_encode64("\x00romeo\x00secr3t")
67
- proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
68
- @stream.verify.must_equal true
69
- storage.verify.must_equal true
83
+ -> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
84
+
85
+ stream.verify
86
+ storage.verify
70
87
  end
71
88
 
72
89
  it 'passes with valid password' do
73
- romeo = Vines::JID.new('romeo@verona.lit')
74
- storage = MiniTest::Mock.new
75
- storage.expect(:authenticate, Vines::User.new(jid: romeo), [romeo, 'secr3t'])
76
- @stream.expect(:domain, 'verona.lit')
77
- @stream.expect(:storage, storage)
90
+ storage.expect :authenticate, romeo, [romeo.jid, 'secr3t']
91
+ stream.expect :storage, storage
78
92
 
79
93
  encoded = Base64.strict_encode64("\x00romeo\x00secr3t")
80
- @sasl.plain_auth(encoded).must_equal Vines::User.new(jid: romeo)
81
- @stream.verify.must_equal true
82
- storage.verify.must_equal true
94
+ subject.plain_auth(encoded).must_equal romeo
95
+
96
+ stream.verify
97
+ storage.verify
83
98
  end
84
99
 
85
100
  it 'passes with valid password and authzid provided by strophe and blather' do
86
- romeo = Vines::JID.new('romeo@verona.lit')
87
- storage = MiniTest::Mock.new
88
- storage.expect(:authenticate, Vines::User.new(jid: romeo), [romeo, 'secr3t'])
89
- @stream.expect(:domain, 'verona.lit')
90
- @stream.expect(:storage, storage)
101
+ storage.expect :authenticate, romeo, [romeo.jid, 'secr3t']
102
+ stream.expect :storage, storage
91
103
 
92
104
  encoded = Base64.strict_encode64("romeo@Verona.LIT\x00romeo\x00secr3t")
93
- @sasl.plain_auth(encoded).must_equal Vines::User.new(jid: romeo)
94
- @stream.verify.must_equal true
95
- storage.verify.must_equal true
105
+ subject.plain_auth(encoded).must_equal romeo
106
+
107
+ stream.verify
108
+ storage.verify
96
109
  end
97
110
 
98
111
  it 'passes with valid password and authzid provided by smack' do
99
- romeo = Vines::JID.new('romeo@verona.lit')
100
- storage = MiniTest::Mock.new
101
- storage.expect(:authenticate, Vines::User.new(jid: romeo), [romeo, 'secr3t'])
102
- @stream.expect(:domain, 'verona.lit')
103
- @stream.expect(:storage, storage)
112
+ storage.expect :authenticate, romeo, [romeo.jid, 'secr3t']
113
+ stream.expect :storage, storage
104
114
 
105
115
  encoded = Base64.strict_encode64("romeo\x00romeo\x00secr3t")
106
- @sasl.plain_auth(encoded).must_equal Vines::User.new(jid: romeo)
107
- @stream.verify.must_equal true
108
- storage.verify.must_equal true
116
+ subject.plain_auth(encoded).must_equal romeo
117
+
118
+ stream.verify
119
+ storage.verify
109
120
  end
110
121
 
111
122
  it 'raises temporary-auth-failure when storage backend fails' do
@@ -114,51 +125,59 @@ describe Vines::Stream::SASL do
114
125
  raise 'boom'
115
126
  end
116
127
  end.new
117
- @stream.expect(:domain, 'verona.lit')
118
- @stream.expect(:storage, storage)
119
128
 
129
+ stream.expect :storage, storage
120
130
  encoded = Base64.strict_encode64("\x00romeo\x00secr3t")
121
- proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::TemporaryAuthFailure
122
- @stream.verify.must_equal true
131
+ -> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::TemporaryAuthFailure
132
+ stream.verify
123
133
  end
124
134
  end
125
135
 
126
136
  describe '#external_auth' do
127
- it 'fails with invalid input' do
128
- @stream.expect(:remote_domain, 'verona.lit')
129
- proc { @sasl.external_auth(nil) }.must_raise Vines::SaslErrors::IncorrectEncoding
130
- proc { @sasl.external_auth('') }.must_raise Vines::SaslErrors::InvalidAuthzid
131
- proc { @sasl.external_auth('bogus') }.must_raise Vines::SaslErrors::IncorrectEncoding
132
- proc { @sasl.external_auth('=dmVyb25hLmxpdA==') }.must_raise Vines::SaslErrors::IncorrectEncoding
133
- proc { @sasl.external_auth("dmVyb25hLmxpdA==\n") }.must_raise Vines::SaslErrors::IncorrectEncoding
134
- @stream.verify.must_equal true
137
+ it 'fails with empty input' do
138
+ stream.expect :remote_domain, 'verona.lit'
139
+ -> { subject.external_auth(nil) }.must_raise Vines::SaslErrors::IncorrectEncoding
140
+ -> { subject.external_auth('') }.must_raise Vines::SaslErrors::InvalidAuthzid
141
+ stream.verify
142
+ end
143
+
144
+ it 'fails with plain text' do
145
+ -> { subject.external_auth('bogus') }.must_raise Vines::SaslErrors::IncorrectEncoding
146
+ stream.verify
147
+ end
148
+
149
+ it 'fails with incorrectly encoded base64 text' do
150
+ -> { subject.external_auth('=dmVyb25hLmxpdA==') }.must_raise Vines::SaslErrors::IncorrectEncoding
151
+ -> { subject.external_auth("dmVyb25hLmxpdA==\n") }.must_raise Vines::SaslErrors::IncorrectEncoding
152
+ stream.verify
135
153
  end
136
154
 
137
155
  it 'passes with empty authzid and matching cert' do
138
- @stream.expect(:remote_domain, 'verona.lit')
139
- @stream.expect(:cert_domain_matches?, true, ['verona.lit'])
140
- @sasl.external_auth('=').must_equal true
141
- @stream.verify.must_equal true
156
+ stream.expect :remote_domain, 'verona.lit'
157
+ stream.expect :cert_domain_matches?, true, ['verona.lit']
158
+ subject.external_auth('=').must_equal true
159
+ stream.verify
142
160
  end
143
161
 
144
162
  it 'fails with empty authzid and non-matching cert' do
145
- @stream.expect(:remote_domain, 'verona.lit')
146
- @stream.expect(:cert_domain_matches?, false, ['verona.lit'])
147
- proc { @sasl.external_auth('=') }.must_raise Vines::SaslErrors::NotAuthorized
148
- @stream.verify.must_equal true
163
+ stream.expect :remote_domain, 'verona.lit'
164
+ stream.expect :cert_domain_matches?, false, ['verona.lit']
165
+ -> { subject.external_auth('=') }.must_raise Vines::SaslErrors::NotAuthorized
166
+ stream.verify
149
167
  end
150
168
 
151
169
  it 'fails when authzid does not match stream from address' do
152
- @stream.expect(:remote_domain, 'not.verona.lit')
153
- proc { @sasl.external_auth('dmVyb25hLmxpdA==') }.must_raise Vines::SaslErrors::InvalidAuthzid
154
- @stream.verify.must_equal true
170
+ stream.expect :remote_domain, 'not.verona.lit'
171
+ -> { subject.external_auth('dmVyb25hLmxpdA==') }.must_raise Vines::SaslErrors::InvalidAuthzid
172
+ stream.verify
155
173
  end
156
174
 
157
175
  it 'passes when authzid matches stream from address' do
158
- @stream.expect(:remote_domain, 'verona.lit')
159
- @stream.expect(:cert_domain_matches?, true, ['verona.lit'])
160
- @sasl.external_auth('dmVyb25hLmxpdA==').must_equal true
161
- @stream.verify.must_equal true
176
+ stream.expect :remote_domain, 'verona.lit'
177
+ stream.expect :remote_domain, 'verona.lit'
178
+ stream.expect :cert_domain_matches?, true, ['verona.lit']
179
+ subject.external_auth('dmVyb25hLmxpdA==').must_equal true
180
+ stream.verify
162
181
  end
163
182
  end
164
183
  end
@@ -1,57 +1,61 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'vines'
4
- require 'minitest/autorun'
3
+ require 'test_helper'
5
4
 
6
5
  describe Vines::Stream::Server::Auth do
7
6
  # disable logging for tests
8
7
  Class.new.extend(Vines::Log).log.level = Logger::FATAL
9
8
 
9
+ subject { Vines::Stream::Server::Auth.new(stream) }
10
+ let(:stream) { MiniTest::Mock.new }
11
+
10
12
  before do
11
- @stream = MiniTest::Mock.new
12
- @state = Vines::Stream::Server::Auth.new(@stream)
13
+ class << stream
14
+ attr_accessor :remote_domain
15
+ end
16
+ stream.remote_domain = 'wonderland.lit'
13
17
  end
14
18
 
15
- describe 'external auth' do
16
- it 'passes with empty authzid' do
17
- @stream.expect(:remote_domain, 'wonderland.lit')
18
- @stream.expect(:cert_domain_matches?, true, ['wonderland.lit'])
19
- @stream.expect(:write, nil, ['<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>'])
20
- @stream.expect(:advance, nil, [Vines::Stream::Server::FinalRestart])
21
- @stream.expect(:reset, nil)
22
- @stream.expect(:authentication_mechanisms, ['EXTERNAL'])
23
- node = node(%Q{<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="EXTERNAL">=</auth>})
24
- @state.node(node)
25
- assert @stream.verify
19
+ describe 'when given a valid authzid' do
20
+ before do
21
+ stream.expect :cert_domain_matches?, true, ['wonderland.lit']
22
+ stream.expect :write, nil, ['<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>']
23
+ stream.expect :advance, nil, [Vines::Stream::Server::FinalRestart]
24
+ stream.expect :reset, nil
25
+ stream.expect :authentication_mechanisms, ['EXTERNAL']
26
+ end
27
+
28
+ it 'passes external auth with empty authzid' do
29
+ node = external('=')
30
+ subject.node(node)
31
+ stream.verify
26
32
  end
27
33
 
28
- it 'passes when authzid matches from domain' do
29
- @stream.expect(:remote_domain, 'wonderland.lit')
30
- @stream.expect(:cert_domain_matches?, true, ['wonderland.lit'])
31
- @stream.expect(:write, nil, ['<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>'])
32
- @stream.expect(:advance, nil, [Vines::Stream::Server::FinalRestart])
33
- @stream.expect(:reset, nil)
34
- @stream.expect(:authentication_mechanisms, ['EXTERNAL'])
35
- node = node(%Q{<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="EXTERNAL">#{Base64.strict_encode64('wonderland.lit')}</auth>})
36
- @state.node(node)
37
- assert @stream.verify
34
+ it 'passes external auth with authzid matching from domain' do
35
+ node = external(Base64.strict_encode64('wonderland.lit'))
36
+ subject.node(node)
37
+ stream.verify
38
+ end
39
+ end
40
+
41
+ describe 'when given an invalid authzid' do
42
+ before do
43
+ stream.expect :write, nil, ['</stream:stream>']
44
+ stream.expect :close_connection_after_writing, nil
45
+ stream.expect :error, nil, [Vines::SaslErrors::InvalidAuthzid]
46
+ stream.expect :authentication_mechanisms, ['EXTERNAL']
38
47
  end
39
48
 
40
- it 'fails when authzid does not match from domain' do
41
- @stream.expect(:remote_domain, 'wonderland.lit')
42
- @stream.expect(:write, nil, ['</stream:stream>'])
43
- @stream.expect(:close_connection_after_writing, nil)
44
- @stream.expect(:error, nil, [Vines::SaslErrors::InvalidAuthzid])
45
- @stream.expect(:authentication_mechanisms, ['EXTERNAL'])
46
- node = node(%Q{<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="EXTERNAL">#{Base64.strict_encode64('verona.lit')}</auth>})
47
- @state.node(node)
48
- assert @stream.verify
49
+ it 'fails external auth with mismatched from domain' do
50
+ node = external(Base64.strict_encode64('verona.lit'))
51
+ subject.node(node)
52
+ stream.verify
49
53
  end
50
54
  end
51
55
 
52
56
  private
53
57
 
54
- def node(xml)
55
- Nokogiri::XML(xml).root
58
+ def external(authzid)
59
+ node(%Q{<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="EXTERNAL">#{authzid}</auth>})
56
60
  end
57
61
  end
@@ -1,10 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'vines'
4
- require 'minitest/autorun'
3
+ require 'test_helper'
5
4
 
6
- class OutboundAuthTest < MiniTest::Unit::TestCase
7
- def setup
5
+ describe Vines::Stream::Server::Outbound::Auth do
6
+ before do
8
7
  @stream = MiniTest::Mock.new
9
8
  @state = Vines::Stream::Server::Outbound::Auth.new(@stream)
10
9
  end
@@ -1,93 +1,93 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'vines'
4
- require 'minitest/autorun'
3
+ require 'test_helper'
5
4
 
6
- class ServerReadyTest < MiniTest::Unit::TestCase
7
- STANZAS = []
5
+ describe Vines::Stream::Server::Ready do
6
+ subject { Vines::Stream::Server::Ready.new(stream, nil) }
7
+ let(:stream) { MiniTest::Mock.new }
8
8
 
9
- def setup
10
- @stream = MiniTest::Mock.new
11
- @state = Vines::Stream::Server::Ready.new(@stream, nil)
12
- def @state.to_stanza(node)
13
- Vines::Stanza.from_node(node, @stream).tap do |stanza|
9
+ SERVER_STANZAS = []
10
+
11
+ before do
12
+ def subject.to_stanza(node)
13
+ Vines::Stanza.from_node(node, stream).tap do |stanza|
14
14
  def stanza.process
15
- ServerReadyTest::STANZAS << self
15
+ SERVER_STANZAS << self
16
16
  end if stanza
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
- def teardown
22
- STANZAS.clear
21
+ after do
22
+ SERVER_STANZAS.clear
23
23
  end
24
24
 
25
- def test_good_node_processes
25
+ it 'processes a valid node' do
26
26
  config = MiniTest::Mock.new
27
27
  config.expect(:local_jid?, true, [Vines::JID.new('romeo@verona.lit')])
28
28
 
29
- @stream.expect(:config, config)
30
- @stream.expect(:remote_domain, 'wonderland.lit')
31
- @stream.expect(:domain, 'verona.lit')
32
- @stream.expect(:user=, nil, [Vines::User.new(jid: 'alice@wonderland.lit')])
29
+ stream.expect(:config, config)
30
+ stream.expect(:remote_domain, 'wonderland.lit')
31
+ stream.expect(:domain, 'verona.lit')
32
+ stream.expect(:user=, nil, [Vines::User.new(jid: 'alice@wonderland.lit')])
33
33
 
34
34
  node = node(%Q{<message from="alice@wonderland.lit" to="romeo@verona.lit"/>})
35
- @state.node(node)
36
- assert_equal 1, STANZAS.size
37
- assert @stream.verify
35
+ subject.node(node)
36
+ assert_equal 1, SERVER_STANZAS.size
37
+ assert stream.verify
38
38
  assert config.verify
39
39
  end
40
40
 
41
- def test_unsupported_stanza_type
41
+ it 'raises unsupported-stanza-type stream error' do
42
42
  node = node('<bogus/>')
43
- assert_raises(Vines::StreamErrors::UnsupportedStanzaType) { @state.node(node) }
44
- assert STANZAS.empty?
45
- assert @stream.verify
43
+ -> { subject.node(node) }.must_raise Vines::StreamErrors::UnsupportedStanzaType
44
+ assert SERVER_STANZAS.empty?
45
+ assert stream.verify
46
46
  end
47
47
 
48
- def test_improper_addressing_missing_to
48
+ it 'raises improper-addressing stream error when to address is missing' do
49
49
  node = node(%Q{<message from="alice@wonderland.lit"/>})
50
- assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) }
51
- assert STANZAS.empty?
52
- assert @stream.verify
50
+ -> { subject.node(node) }.must_raise Vines::StreamErrors::ImproperAddressing
51
+ assert SERVER_STANZAS.empty?
52
+ assert stream.verify
53
53
  end
54
54
 
55
- def test_improper_addressing_invalid_to
55
+ it 'raises jid-malformed stanza error when to address is invalid' do
56
56
  node = node(%Q{<message from="alice@wonderland.lit" to=" "/>})
57
- assert_raises(Vines::StanzaErrors::JidMalformed) { @state.node(node) }
58
- assert STANZAS.empty?
59
- assert @stream.verify
57
+ -> { subject.node(node) }.must_raise Vines::StanzaErrors::JidMalformed
58
+ assert SERVER_STANZAS.empty?
59
+ assert stream.verify
60
60
  end
61
61
 
62
- def test_improper_addressing_missing_from
62
+ it 'raises improper-addressing stream error' do
63
63
  node = node(%Q{<message to="romeo@verona.lit"/>})
64
- assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) }
65
- assert STANZAS.empty?
66
- assert @stream.verify
64
+ -> { subject.node(node) }.must_raise Vines::StreamErrors::ImproperAddressing
65
+ assert SERVER_STANZAS.empty?
66
+ assert stream.verify
67
67
  end
68
68
 
69
- def test_improper_addressing_invalid_from
69
+ it 'raises jid-malformed stanza error for invalid from address' do
70
70
  node = node(%Q{<message from=" " to="romeo@verona.lit"/>})
71
- assert_raises(Vines::StanzaErrors::JidMalformed) { @state.node(node) }
72
- assert STANZAS.empty?
73
- assert @stream.verify
71
+ -> { subject.node(node) }.must_raise Vines::StanzaErrors::JidMalformed
72
+ assert SERVER_STANZAS.empty?
73
+ assert stream.verify
74
74
  end
75
75
 
76
- def test_invalid_from
77
- @stream.expect(:remote_domain, 'wonderland.lit')
76
+ it 'raises invalid-from stream error' do
77
+ stream.expect(:remote_domain, 'wonderland.lit')
78
78
  node = node(%Q{<message from="alice@bogus.lit" to="romeo@verona.lit"/>})
79
- assert_raises(Vines::StreamErrors::InvalidFrom) { @state.node(node) }
80
- assert STANZAS.empty?
81
- assert @stream.verify
79
+ -> { subject.node(node) }.must_raise Vines::StreamErrors::InvalidFrom
80
+ assert SERVER_STANZAS.empty?
81
+ assert stream.verify
82
82
  end
83
83
 
84
- def test_host_unknown
85
- @stream.expect(:remote_domain, 'wonderland.lit')
86
- @stream.expect(:domain, 'verona.lit')
84
+ it 'raises host-unknown stream error' do
85
+ stream.expect(:remote_domain, 'wonderland.lit')
86
+ stream.expect(:domain, 'verona.lit')
87
87
  node = node(%Q{<message from="alice@wonderland.lit" to="romeo@bogus.lit"/>})
88
- assert_raises(Vines::StreamErrors::HostUnknown) { @state.node(node) }
89
- assert STANZAS.empty?
90
- assert @stream.verify
88
+ -> { subject.node(node) }.must_raise Vines::StreamErrors::HostUnknown
89
+ assert SERVER_STANZAS.empty?
90
+ assert stream.verify
91
91
  end
92
92
 
93
93
  private