root/trunk/tests/test_sasl.rb

Revision 720, 1.7 kB (checked in by francis, 1 year ago)

used deferrable's timeout, a little cleaner

  • Property svn:keywords set to Id
Line 
1 # $Id$
2 #
3 # Author:: Francis Cianfrocca (gmail: blackhedd)
4 # Homepage::  http://rubyeventmachine.com
5 # Date:: 8 April 2006
6 #
7 # See EventMachine and EventMachine::Connection for documentation and
8 # usage examples.
9 #
10 #----------------------------------------------------------------------------
11 #
12 # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13 # Gmail: blackhedd
14 #
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of either: 1) the GNU General Public License
17 # as published by the Free Software Foundation; either version 2 of the
18 # License, or (at your option) any later version; or 2) Ruby's License.
19 #
20 # See the file COPYING for complete licensing information.
21 #
22 #---------------------------------------------------------------------------
23 #
24 #
25 #
26
27 $:.unshift "../lib"
28 require 'eventmachine'
29 require 'test/unit'
30
31
32 class TestSASL < Test::Unit::TestCase
33
34         # SASL authentication is usually done with UNIX-domain sockets, but
35         # we'll use TCP so this test will work on Windows. As far as the
36         # protocol handlers are concerned, there's no difference.
37
38
39         Host,Port = "127.0.0.1",9560
40         TestUser,TestPsw = "someone", "password"
41
42         class SaslServer < EM::Connection
43                 include EM::Protocols::SASLauth
44                 def validate usr, psw, sys, realm
45                         usr == TestUser and psw == TestPsw
46                 end
47         end
48
49         class SaslClient < EM::Connection
50                 include EM::Protocols::SASLauthclient
51         end
52
53         def test_sasl
54                 resp = nil
55                 EM.run {
56                         EM.start_server( Host, Port, SaslServer )
57
58                         c = EM.connect( Host, Port, SaslClient )
59                         d = c.validate?( TestUser, TestPsw )
60                         d.timeout 2
61                         d.callback {
62                                 resp = true
63                                 EM.stop
64                         }
65                         d.errback {
66                                 resp = false
67                                 EM.stop
68                         }
69                 }
70                 assert_equal( true, resp )
71         end
72
73 end
74
Note: See TracBrowser for help on using the browser.