VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/lib/gems/2.5.0/gems/eventmachine-le-1.1.7/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/lib/gems/2.5.0/gems/eventmachine-le-1.1.7/tests/test_ssl_args.rb
require "test/unit"
require 'tempfile'

require 'em_test_helper'

module EM
  def self._set_mocks
    class <<self
      alias set_tls_parms_old set_tls_parms
      alias start_tls_old start_tls
      begin
        old, $VERBOSE = $VERBOSE, nil
        def set_tls_parms *args; end
        def start_tls *args; end
      ensure
        $VERBOSE = old
      end
    end
  end

  def self._clear_mocks
    class <<self
      begin
        old, $VERBOSE = $VERBOSE, nil
        alias set_tls_parms set_tls_parms_old
        alias start_tls start_tls_old
      ensure
        $VERBOSE = old
      end
    end
  end
end

  

class TestSslArgs < Test::Unit::TestCase
  def setup
    EM._set_mocks
  end
  
  def teardown
    EM._clear_mocks
  end
  
  def test_tls_params_file_doesnt_exist
    priv_file, cert_file = 'foo_priv_key', 'bar_cert_file'
    [priv_file, cert_file].all? do |f|
      assert(!File.exists?(f), "Cert file #{f} seems to exist, and should not for the tests")
    end
    
    # associate_callback_target is a pain! (build!)
    conn = EM::Connection.new('foo')
    
    assert_raises(EM::FileNotFoundException) do
      conn.start_tls(:private_key_file => priv_file)
    end
    assert_raises(EM::FileNotFoundException) do
      conn.start_tls(:cert_chain_file => cert_file)
    end
    assert_raises(EM::FileNotFoundException) do
      conn.start_tls(:private_key_file => priv_file, :cert_chain_file => cert_file)
    end
  end
  
  def test_tls_params_file_does_exist
    priv_file = Tempfile.new('em_test')
    cert_file = Tempfile.new('em_test')
    priv_file_path = priv_file.path
    cert_file_path = cert_file.path
    conn = EM::Connection.new('foo')
    params = {:private_key_file => priv_file_path, :cert_chain_file => cert_file_path}
    begin
      conn.start_tls params
    rescue Object
      assert(false, 'should not have raised an exception')
    end
  end
end if EM.ssl?

VaKeR 2022