Skip to content
This repository
Browse code

made MiniSSL validate key/cert file existence

Previously, MiniSSL accepted invalid paths for the key/cert file
and timed out on the first request. Now, MiniSSL raises an ArgumentError
if one of these files does not exist.

Fix for puma/puma#168
  • Loading branch information...
commit 30ea3d05061cf50ff0993652222a1f8204c8d375 1 parent 23257c8
Daniel Harrington rubiii authored

Showing 2 changed files with 36 additions and 1 deletion. Show diff stats Hide diff stats

  1. +14 1 lib/puma/minissl.rb
  2. +22 0 test/test_minissl.rb
15 lib/puma/minissl.rb
@@ -79,7 +79,20 @@ def peeraddr
79 79 end
80 80
81 81 class Context
82   - attr_accessor :key, :cert, :verify_mode
  82 + attr_accessor :verify_mode
  83 +
  84 + attr_reader :key
  85 + attr_reader :cert
  86 +
  87 + def key=(key)
  88 + raise ArgumentError, "No such key file '#{key}'" unless File.exist? key
  89 + @key = key
  90 + end
  91 +
  92 + def cert=(cert)
  93 + raise ArgumentError, "No such cert file '#{cert}'" unless File.exist? cert
  94 + @cert = cert
  95 + end
83 96 end
84 97
85 98 VERIFY_NONE = 0
22 test/test_minissl.rb
... ... @@ -0,0 +1,22 @@
  1 +require 'test/unit'
  2 +
  3 +require 'puma'
  4 +require 'puma/minissl'
  5 +
  6 +class TestMiniSSL < Test::Unit::TestCase
  7 +
  8 + def test_raises_with_invalid_key_file
  9 + ctx = Puma::MiniSSL::Context.new
  10 +
  11 + exception = assert_raise(ArgumentError) { ctx.key = "/no/such/key" }
  12 + assert_equal("No such key file '/no/such/key'", exception.message)
  13 + end unless defined? JRUBY_VERSION
  14 +
  15 + def test_raises_with_invalid_cert_file
  16 + ctx = Puma::MiniSSL::Context.new
  17 +
  18 + exception = assert_raise(ArgumentError) { ctx.cert = "/no/such/cert" }
  19 + assert_equal("No such cert file '/no/such/cert'", exception.message)
  20 + end unless defined? JRUBY_VERSION
  21 +
  22 +end

0 comments on commit 30ea3d0

Please sign in to comment.
Something went wrong with that request. Please try again.