Skip to content

Commit d909c00

Browse files
David MaloneyDavid Maloney
authored andcommitted
better spec coverage
1 parent 3a72fa4 commit d909c00

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

lib/rex/sslscan/result.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module Rex::SSLScan
66
class Result
77

8-
attr_accessor :sslv2
8+
attr_accessor :openssl_sslv2
99

1010
attr_reader :ciphers
1111
attr_reader :supported_versions
@@ -201,7 +201,9 @@ def to_s
201201
if @cert
202202
text <<" \n\n #{@cert.to_text}"
203203
end
204-
text << "\n\n *** WARNING: Your OS hates freedom! Your OpenSSL libs are compiled without SSLv2 support!"
204+
if openssl_sslv2 == false
205+
text << "\n\n *** WARNING: Your OS hates freedom! Your OpenSSL libs are compiled without SSLv2 support!"
206+
end
205207
text
206208
end
207209
end

lib/rex/sslscan/scanner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def valid?
5151
# @return [Result] object containing the details of the scan
5252
def scan
5353
scan_result = Rex::SSLScan::Result.new
54-
scan_result.sslv2 = sslv2
54+
scan_result.openssl_sslv2 = sslv2
5555
# If we can't get any SSL connection, then don't bother testing
5656
# individual ciphers.
5757
if test_ssl == :rejected and test_tls == :rejected

spec/lib/rex/sslscan/result_spec.rb

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
end
4747

4848
it "should return an empty array for #tlsv1" do
49-
subject.sslv2.should == []
49+
subject.tlsv1.should == []
5050
end
5151

5252
it "should return an empty array for #weak_ciphers" do
@@ -469,16 +469,58 @@
469469
end
470470
end
471471

472-
context "when OpenSSL is compiled without SSLv2" do
473-
before(:each) do
474-
subject.add_cipher(:SSLv3, "AES256-SHA", 256, :accepted)
475-
subject.add_cipher(:TLSv1, "AES256-SHA", 256, :accepted)
476-
subject.add_cipher(:SSLv3, "AES128-SHA", 128, :accepted)
477-
subject.sslv2 = false
472+
context "when printing the results" do
473+
context "when OpenSSL is compiled without SSLv2" do
474+
before(:each) do
475+
subject.add_cipher(:SSLv3, "AES256-SHA", 256, :accepted)
476+
subject.add_cipher(:TLSv1, "AES256-SHA", 256, :accepted)
477+
subject.add_cipher(:SSLv3, "AES128-SHA", 128, :accepted)
478+
subject.openssl_sslv2 = false
479+
end
480+
it "should warn the user" do
481+
subject.to_s.should include "*** WARNING: Your OS hates freedom! Your OpenSSL libs are compiled without SSLv2 support!"
482+
end
478483
end
479-
it "should warn the user" do
480-
subject.to_s.should include "*** WARNING: Your OS hates freedom! Your OpenSSL libs are compiled without SSLv2 support!"
484+
485+
context "when we have SSL results" do
486+
before(:each) do
487+
subject.add_cipher(:SSLv3, "AES256-SHA", 256, :accepted)
488+
subject.add_cipher(:TLSv1, "AES256-SHA", 256, :accepted)
489+
subject.add_cipher(:SSLv3, "AES128-SHA", 128, :accepted)
490+
subject.add_cipher(:SSLv3, "EXP-RC2-CBC-MD5", 40, :accepted)
491+
492+
cert = OpenSSL::X509::Certificate.new
493+
key = OpenSSL::PKey::RSA.new 2048
494+
cert.version = 2 #
495+
cert.serial = 1
496+
cert.subject = OpenSSL::X509::Name.parse "/DC=org/DC=ruby-lang/CN=Ruby CA"
497+
cert.issuer = cert.subject
498+
cert.public_key = key.public_key
499+
cert.not_before = Time.now
500+
cert.not_after = cert.not_before + 2 * 365 * 24 * 60 * 60 # 2
501+
502+
subject.cert = cert
503+
end
504+
505+
it "should contain the certificate" do
506+
subject.to_s.should include "Issuer: DC=org, DC=ruby-lang, CN=Ruby CA"
507+
subject.to_s.should include "Subject: DC=org, DC=ruby-lang, CN=Ruby CA"
508+
end
509+
510+
it "should have a table with our SSL Cipher Results" do
511+
subject.to_s.should include "Accepted * SSLv3 40 EXP-RC2-CBC-MD5"
512+
subject.to_s.should include "Accepted SSLv3 128 AES128-SHA"
513+
subject.to_s.should include "Accepted SSLv3 256 AES256-SHA"
514+
subject.to_s.should include "Accepted TLSv1 256 AES256-SHA"
515+
end
516+
end
517+
518+
it "should return an appropriate message when SSL is not supported" do
519+
subject.stub(:supports_ssl?).and_return(false)
520+
subject.to_s.should == "Server does not appear to support SSL on this port!"
481521
end
522+
523+
482524
end
483525

484526
end

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
require 'simplecov'
12
require 'rubygems'
23
require 'bundler'
34
Bundler.setup(:default, :test)
45

6+
SimpleCov.start
57
# add project lib directory to load path
68
spec_pathname = Pathname.new(__FILE__).dirname
79
root_pathname = spec_pathname.join('..').expand_path

0 commit comments

Comments
 (0)