forked from ibc/EventMachine-LE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sasl.rb
47 lines (37 loc) · 991 Bytes
/
test_sasl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'em_test_helper'
class TestSASL < Test::Unit::TestCase
# SASL authentication is usually done with UNIX-domain sockets, but
# we'll use TCP so this test will work on Windows. As far as the
# protocol handlers are concerned, there's no difference.
TestUser,TestPsw = "someone", "password"
class SaslServer < EM::Connection
include EM::Protocols::SASLauth
def validate usr, psw, sys, realm
usr == TestUser and psw == TestPsw
end
end
class SaslClient < EM::Connection
include EM::Protocols::SASLauthclient
end
def setup
@port = next_port
end
def test_sasl
resp = nil
EM.run {
EM.start_server( "127.0.0.1", @port, SaslServer )
c = EM.connect( "127.0.0.1", @port, SaslClient )
d = c.validate?( TestUser, TestPsw )
d.timeout 1
d.callback {
resp = true
EM.stop
}
d.errback {
resp = false
EM.stop
}
}
assert_equal( true, resp )
end
end