sslcheck 0.9.5 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51b5701a3d326048e59aa81785d096d9d5e4e15c
4
- data.tar.gz: 078098c638a5e5a8c4ffb262522e525c38b1cb54
3
+ metadata.gz: 4d4251f26088c6cda3ea58337487f6a775a840f1
4
+ data.tar.gz: d881012a9c13e3d11e62ac9febba24b4fd6c214d
5
5
  SHA512:
6
- metadata.gz: 202bcdefd4a17ade919d6020e0e58fd874edd0620f0d0b5ce40df9c47026387e275ec3fffe4900f7d9afd3bcd5e0ed5897d1b6089cb3b02cfffa74afd97655ff
7
- data.tar.gz: a974d145b55cbe75e435c5a71f5cd651ef53db6ff85617995f6dfe9f6ff6e488a3c059032c254bd15edc492e2f544e6f375131b2398c007f8b600f63260cc009
6
+ metadata.gz: 085c88e749846da6c9fe93d4e916a12ba96a1b56ba3ab48d64063fdd897f5043a8cda94d8182cdfcf1d8a7a283186839690319168ee06039d396ed3bc26940f8
7
+ data.tar.gz: ab57c766f1868f5beaaa875cf8079e1ef14f59b2f9c788377a8ead127566be904d1c38929c423d00d31e59a5d63ab7a0b8992ef61a94840caf8b0c435c2e4eae
data/README.md CHANGED
@@ -48,6 +48,18 @@ Are there any errors?
48
48
  => []
49
49
  ```
50
50
 
51
+ ## Timeouts
52
+
53
+ By default, connections to verify a certificate will timeout after 30 seconds. To
54
+ change this behavior, specify your own timeout, in seconds, on the `SSLCheck::Client`
55
+ class.
56
+
57
+ ```
58
+ SSLCheck::Client.timeout_seconds = 10 # A 10 second timeout
59
+ check = SSLCheck::Check.new
60
+ check.check("github.com")
61
+ ```
62
+
51
63
  What are the details of the certificate?
52
64
 
53
65
  The peer certificate found during the check is available with a rich
@@ -3,6 +3,10 @@ require 'spec_helper'
3
3
  module SSLCheck
4
4
  describe 'Client' do
5
5
  context "Getting Certificates" do
6
+ before do
7
+ Client.timeout_seconds = 1
8
+ end
9
+
6
10
  context "When Things Go Well" do
7
11
  it 'should have the host name' do
8
12
  sut = Client.new
@@ -41,9 +45,10 @@ module SSLCheck
41
45
 
42
46
  context "When the URL is not a real TLD or gTLD" do
43
47
  it 'should raise a connection error' do
48
+ Client.timeout_seconds = 1
44
49
  sut = Client.new
45
50
  response = sut.get("https://www.domain.does.not.exist.aljdahkqhb")
46
- expect(response.errors.first).to be_a(SSLCheck::Errors::Connection::SocketError)
51
+ expect(response.errors.first).to be_a(SSLCheck::Errors::Connection::Timeout)
47
52
  end
48
53
  end
49
54
 
@@ -71,5 +76,41 @@ module SSLCheck
71
76
  end
72
77
  end
73
78
  end
79
+ describe 'Timeout' do
80
+ before do
81
+ Client.timeout_seconds = 30
82
+ end
83
+
84
+ it 'should use the timeout value when making connections' do
85
+ expect(Timeout).to receive(:timeout).with(30)
86
+ sut = Client.new
87
+ sut.get('https://www.sslinsight.com')
88
+ end
89
+ context 'When the timeout is not set' do
90
+ it 'should default to 30 seconds' do
91
+ expect(SSLCheck::Client.timeout_seconds).to eq(30)
92
+ end
93
+ end
94
+ context 'overriding the default timeout' do
95
+ it 'should use the supplied timeout value' do
96
+ SSLCheck::Client.timeout_seconds = 10
97
+ expect(SSLCheck::Client.timeout_seconds).to eq(10)
98
+ end
99
+ it 'should use the timeout value when making connections' do
100
+ SSLCheck::Client.timeout_seconds = 10
101
+ expect(Timeout).to receive(:timeout).with(10)
102
+ sut = Client.new
103
+ sut.get('https://www.sslinsight.com')
104
+ end
105
+ end
106
+ context 'When the timeout expires' do
107
+ it 'should raise a connection error' do
108
+ SSLCheck::Client.timeout_seconds = 1
109
+ sut = Client.new
110
+ response = sut.get("https://www.domain.does.not.exist.aljdahkqhb")
111
+ expect(response.errors.first).to be_a(SSLCheck::Errors::Connection::Timeout)
112
+ end
113
+ end
114
+ end
74
115
  end
75
116
  end
@@ -4,6 +4,16 @@ require 'openssl'
4
4
 
5
5
  module SSLCheck
6
6
  class Client
7
+ @@timeout_seconds = 30
8
+
9
+ def self.timeout_seconds
10
+ @@timeout_seconds
11
+ end
12
+
13
+ def self.timeout_seconds=(seconds)
14
+ @@timeout_seconds = seconds
15
+ end
16
+
7
17
  class Response
8
18
  attr_accessor :host_name, :errors
9
19
 
@@ -34,21 +44,33 @@ module SSLCheck
34
44
 
35
45
  def get(url)
36
46
  begin
37
- uri = determine_uri(url)
47
+ Timeout::timeout(Client.timeout_seconds) {
48
+ uri = determine_uri(url)
49
+
50
+ sock = TCPSocket.new(uri.host, 443)
51
+ ctx = OpenSSL::SSL::SSLContext.new
52
+ ctx.set_params(
53
+ :verify_mode => OpenSSL::SSL::VERIFY_PEER,
54
+ :timeout => Client.timeout_seconds,
55
+ :ssl_timeout => Client.timeout_seconds,
56
+ )
57
+
58
+ ctx.timeout = Client.timeout_seconds
59
+ ctx.ssl_timeout = Client.timeout_seconds
38
60
 
39
- sock = TCPSocket.new(uri.host, 443)
40
- ctx = OpenSSL::SSL::SSLContext.new
41
- ctx.set_params(:verify_mode => OpenSSL::SSL::VERIFY_PEER)
61
+ @socket = OpenSSL::SSL::SSLSocket.new(sock, ctx).tap do |socket|
62
+ socket.sync_close = true
63
+ socket.connect
64
+ @response.host_name = uri.host
65
+ @response.raw_peer_cert = OpenSSL::X509::Certificate.new(socket.peer_cert)
66
+ @response.raw_peer_cert_chain = socket.peer_cert_chain
67
+ end
42
68
 
43
- @socket = OpenSSL::SSL::SSLSocket.new(sock, ctx).tap do |socket|
44
- socket.sync_close = true
45
- socket.connect
46
- @response.host_name = uri.host
47
- @response.raw_peer_cert = OpenSSL::X509::Certificate.new(socket.peer_cert)
48
- @response.raw_peer_cert_chain = socket.peer_cert_chain
49
- end
69
+ @socket.sysclose
50
70
 
51
- @socket.sysclose
71
+ }
72
+ rescue Timeout::Error, Errno::ETIMEDOUT
73
+ @response.errors << SSLCheck::Errors::Connection::Timeout.new({:name => "Timeout Error", :type => :timeout_error, :message => "The connection to #{url} took too long."})
52
74
  rescue SocketError
53
75
  @response.errors << SSLCheck::Errors::Connection::SocketError.new({:name => "Connection Error", :type => :socket_error, :message => "The connection to #{url} failed."})
54
76
  rescue URI::InvalidURIError
@@ -4,6 +4,7 @@ module SSLCheck
4
4
  class InvalidURI < GenericError; end
5
5
  class SSLVerify < GenericError; end
6
6
  class SocketError < GenericError; end
7
+ class Timeout < GenericError; end
7
8
  end
8
9
 
9
10
  module Validation
@@ -1,3 +1,3 @@
1
1
  module SSLCheck
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sslcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clayton Lengel-Zigich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-06 00:00:00.000000000 Z
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport