Sha256: 9c41823bbc62aecfb696052c541edba19dfe2bed39311f8d967ddf1fbf0e44b2

Contents?: true

Size: 1.9 KB

Versions: 74

Compression:

Stored size: 1.9 KB

Contents

$:.unshift "../lib"
require 'eventmachine'
require 'test/unit'

class TestSslVerify < Test::Unit::TestCase

  def setup
    $dir = File.dirname(File.expand_path(__FILE__)) + '/'
    $cert_from_file = File.read($dir+'client.crt')
  end

  module Client
    def connection_completed
      start_tls(:private_key_file => $dir+'client.key', :cert_chain_file => $dir+'client.crt')
    end

    def ssl_handshake_completed
      $client_handshake_completed = true
      close_connection
    end

    def unbind
      EM.stop_event_loop
    end
  end

  module AcceptServer
    def post_init
      start_tls(:verify_peer => true)
    end

    def ssl_verify_peer(cert)
      $cert_from_server = cert
      true
    end

    def ssl_handshake_completed
      $server_handshake_completed = true
    end
  end

  module DenyServer
    def post_init
      start_tls(:verify_peer => true)
    end

    def ssl_verify_peer(cert)
      $cert_from_server = cert
      # Do not accept the peer. This should now cause the connection to shut down without the SSL handshake being completed.
      false
    end

    def ssl_handshake_completed
      $server_handshake_completed = true
    end
  end

  def test_accept_server
    $client_handshake_completed, $server_handshake_completed = false, false
    EM.run {
      EM.start_server("127.0.0.1", 16784, AcceptServer)
      EM.connect("127.0.0.1", 16784, Client).instance_variable_get("@signature")
    }

    assert_equal($cert_from_file, $cert_from_server)
    assert($client_handshake_completed)
    assert($server_handshake_completed)
  end

  def test_deny_server
    $client_handshake_completed, $server_handshake_completed = false, false
    EM.run {
      EM.start_server("127.0.0.1", 16784, DenyServer)
      EM.connect("127.0.0.1", 16784, Client)
    }

    assert_equal($cert_from_file, $cert_from_server)
    assert(!$client_handshake_completed)
    assert(!$server_handshake_completed)
  end

end

Version data entries

74 entries across 74 versions & 10 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.7.4 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.7.3 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
MattHulse-eventmachine-0.0.1 tests/test_ssl_verify.rb
MattHulse-eventmachine-0.12.10 tests/test_ssl_verify.rb
eventmachine-eventmachine-0.12.8 tests/test_ssl_verify.rb
eventmachine-eventmachine-0.12.9 tests/test_ssl_verify.rb
classiccms-0.7.2 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.7.1 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.7.0 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.9 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.8 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.7 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.6 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.5 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.4 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.3 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.2 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.1 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb
classiccms-0.6.0 vendor/bundle/gems/eventmachine-0.12.10/tests/test_ssl_verify.rb