Skip to content

Commit

Permalink
Require a certificate to use Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenharman committed Mar 29, 2012
1 parent e8429be commit 6256820
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/grocer/connection.rb
@@ -1,4 +1,5 @@
require 'forwardable'
require 'grocer/no_certificate_error'
require 'grocer/ssl_connection'

module Grocer
Expand Down Expand Up @@ -27,11 +28,16 @@ def write(content)
private

def ssl
@ssl_connection ||=
Grocer::SSLConnection.new(certificate: certificate,
passphrase: passphrase,
gateway: gateway,
port: port)
@ssl_connection ||= build_connection
end

def build_connection
fail Grocer::NoCertificateErrror unless certificate

Grocer::SSLConnection.new(certificate: certificate,
passphrase: passphrase,
gateway: gateway,
port: port)
end

def with_open_connection(&block)
Expand Down
4 changes: 4 additions & 0 deletions lib/grocer/no_certificate_error.rb
@@ -0,0 +1,4 @@
module Grocer
class NoCertificateErrror < StandardError
end
end
5 changes: 5 additions & 0 deletions spec/grocer/connection_spec.rb
Expand Up @@ -40,6 +40,11 @@
subject.port.should == connection_options[:port]
end

it 'requires a certificate' do
connection_options[:certificate] = nil
-> { subject.read }.should raise_error(Grocer::NoCertificateErrror)
end

context 'an open SSLConnection' do
before do
ssl.stubs(:connected?).returns(true)
Expand Down

0 comments on commit 6256820

Please sign in to comment.