root/trunk/tests/test_ssl_args.rb

Revision 794, 1.8 kB (checked in by raggi, 9 months ago)

Added start_tls argument checks from brianmario

Line 
1 require "test/unit"
2 require 'tempfile'
3
4 $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5 require "eventmachine"
6
7 module EventMachine
8   def self._set_mocks
9     class <<self
10       alias set_tls_parms_old set_tls_parms
11       alias start_tls_old start_tls
12       def set_tls_parms *args; end
13       def start_tls *args; end
14     end
15   end
16  
17   def self._clear_mocks
18     class <<self
19       alias set_tls_parms set_tls_parms_old
20       alias start_tls start_tls_old
21     end
22   end
23 end
24  
25
26 class TestSslArgs < Test::Unit::TestCase
27   def setup
28     EventMachine._set_mocks
29   end
30  
31   def teardown
32     EventMachine._clear_mocks
33   end
34  
35   def test_tls_params_file_doesnt_exist
36     priv_file, cert_file = 'foo_priv_key', 'bar_cert_file'
37     [priv_file, cert_file].all? do |f|
38       assert(!File.exists?(f), "Cert file #{f} seems to exist, and should not for the tests")
39     end
40    
41     # associate_callback_target is a pain! (build!)
42     conn = EventMachine::Connection.new('foo')
43    
44     assert_raise(EventMachine::FileNotFoundException) do
45       conn.start_tls(:private_key_file => priv_file)
46     end
47     assert_raise(EventMachine::FileNotFoundException) do
48       conn.start_tls(:cert_chain_file => cert_file)
49     end
50     assert_raise(EventMachine::FileNotFoundException) do
51       conn.start_tls(:private_key_file => priv_file, :cert_chain_file => cert_file)
52     end
53   end
54  
55   def test_tls_params_file_does_exist
56     priv_file = Tempfile.new('em_test')
57     cert_file = Tempfile.new('em_test')
58     priv_file_path = priv_file.path
59     cert_file_path = cert_file.path
60     conn = EventMachine::Connection.new('foo')
61     params = {:private_key_file => priv_file_path, :cert_chain_file => cert_file_path}
62     begin
63       conn.start_tls params
64     rescue Object
65       assert(false, 'should not have raised an exception')
66     end
67   end
68 end
Note: See TracBrowser for help on using the browser.