summaryrefslogtreecommitdiff
path: root/spec/ruby/library/openssl
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
commit1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch)
treea3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/library/openssl
parent75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff)
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/openssl')
-rw-r--r--spec/ruby/library/openssl/cipher_spec.rb9
-rw-r--r--spec/ruby/library/openssl/config/freeze_spec.rb16
-rw-r--r--spec/ruby/library/openssl/hmac/digest_spec.rb16
-rw-r--r--spec/ruby/library/openssl/hmac/hexdigest_spec.rb16
-rw-r--r--spec/ruby/library/openssl/random/pseudo_bytes_spec.rb8
-rw-r--r--spec/ruby/library/openssl/random/random_bytes_spec.rb6
-rw-r--r--spec/ruby/library/openssl/random/shared/random_bytes.rb29
-rw-r--r--spec/ruby/library/openssl/shared/constants.rb11
-rw-r--r--spec/ruby/library/openssl/x509/name/parse_spec.rb48
9 files changed, 159 insertions, 0 deletions
diff --git a/spec/ruby/library/openssl/cipher_spec.rb b/spec/ruby/library/openssl/cipher_spec.rb
new file mode 100644
index 0000000000..c3eb1280a2
--- /dev/null
+++ b/spec/ruby/library/openssl/cipher_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+require 'openssl'
+
+describe "OpenSSL::Cipher's CipherError" do
+ it "exists under OpenSSL::Cipher namespace" do
+ OpenSSL::Cipher.should have_constant :CipherError
+ end
+end
diff --git a/spec/ruby/library/openssl/config/freeze_spec.rb b/spec/ruby/library/openssl/config/freeze_spec.rb
new file mode 100644
index 0000000000..2ed48ae629
--- /dev/null
+++ b/spec/ruby/library/openssl/config/freeze_spec.rb
@@ -0,0 +1,16 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../shared/constants', __FILE__)
+
+require 'openssl'
+
+describe "OpenSSL::Config#freeze" do
+ it "needs to be reviewed for completeness"
+
+ it "freezes" do
+ c = OpenSSL::Config.new
+ lambda{c['foo'] = [ ['key', 'value'] ]}.should_not raise_error
+ c.freeze
+ c.frozen?.should be_true
+ lambda{c['foo'] = [ ['key', 'value'] ]}.should raise_error
+ end
+end
diff --git a/spec/ruby/library/openssl/hmac/digest_spec.rb b/spec/ruby/library/openssl/hmac/digest_spec.rb
new file mode 100644
index 0000000000..36edee87bd
--- /dev/null
+++ b/spec/ruby/library/openssl/hmac/digest_spec.rb
@@ -0,0 +1,16 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../shared/constants', __FILE__)
+require 'openssl'
+
+describe "OpenSSL::HMAC.digest" do
+ it "returns an SHA1 digest" do
+ cur_digest = OpenSSL::Digest::SHA1.new
+ cur_digest.digest.should == HMACConstants::BlankSHA1Digest
+ digest = OpenSSL::HMAC.digest(cur_digest,
+ HMACConstants::Key,
+ HMACConstants::Contents)
+ digest.should == HMACConstants::SHA1Digest
+ end
+end
+
+# Should add in similar specs for MD5, RIPEMD160, and SHA256
diff --git a/spec/ruby/library/openssl/hmac/hexdigest_spec.rb b/spec/ruby/library/openssl/hmac/hexdigest_spec.rb
new file mode 100644
index 0000000000..b61bcf6a8f
--- /dev/null
+++ b/spec/ruby/library/openssl/hmac/hexdigest_spec.rb
@@ -0,0 +1,16 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../shared/constants', __FILE__)
+require 'openssl'
+
+describe "OpenSSL::HMAC.hexdigest" do
+ it "returns an SHA1 hex digest" do
+ cur_digest = OpenSSL::Digest::SHA1.new
+ cur_digest.hexdigest.should == HMACConstants::BlankSHA1HexDigest
+ hexdigest = OpenSSL::HMAC.hexdigest(cur_digest,
+ HMACConstants::Key,
+ HMACConstants::Contents)
+ hexdigest.should == HMACConstants::SHA1Hexdigest
+ end
+end
+
+# Should add in similar specs for MD5, RIPEMD160, and SHA256
diff --git a/spec/ruby/library/openssl/random/pseudo_bytes_spec.rb b/spec/ruby/library/openssl/random/pseudo_bytes_spec.rb
new file mode 100644
index 0000000000..83c8cc13c8
--- /dev/null
+++ b/spec/ruby/library/openssl/random/pseudo_bytes_spec.rb
@@ -0,0 +1,8 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/random_bytes.rb', __FILE__)
+
+if defined?(OpenSSL::Random.pseudo_bytes)
+ describe "OpenSSL::Random.pseudo_bytes" do
+ it_behaves_like :openssl_random_bytes, :pseudo_bytes
+ end
+end
diff --git a/spec/ruby/library/openssl/random/random_bytes_spec.rb b/spec/ruby/library/openssl/random/random_bytes_spec.rb
new file mode 100644
index 0000000000..b8bd209eb0
--- /dev/null
+++ b/spec/ruby/library/openssl/random/random_bytes_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/random_bytes.rb', __FILE__)
+
+describe "OpenSSL::Random.random_bytes" do
+ it_behaves_like :openssl_random_bytes, :random_bytes
+end
diff --git a/spec/ruby/library/openssl/random/shared/random_bytes.rb b/spec/ruby/library/openssl/random/shared/random_bytes.rb
new file mode 100644
index 0000000000..399e40de39
--- /dev/null
+++ b/spec/ruby/library/openssl/random/shared/random_bytes.rb
@@ -0,0 +1,29 @@
+require File.expand_path('../../../../../spec_helper', __FILE__)
+require 'openssl'
+
+describe :openssl_random_bytes, shared: true do |cmd|
+ it "generates a random binary string of specified length" do
+ (1..64).each do |idx|
+ bytes = OpenSSL::Random.send(@method, idx)
+ bytes.should be_kind_of(String)
+ bytes.length.should == idx
+ end
+ end
+
+ it "generates different binary strings with subsequent invocations" do
+ # quick and dirty check, but good enough
+ values = []
+ 256.times do
+ val = OpenSSL::Random.send(@method, 16)
+ # make sure the random bytes are not repeating
+ values.include?(val).should == false
+ values << val
+ end
+ end
+
+ it "raises ArgumentError on negative arguments" do
+ lambda {
+ OpenSSL::Random.send(@method, -1)
+ }.should raise_error(ArgumentError)
+ end
+end
diff --git a/spec/ruby/library/openssl/shared/constants.rb b/spec/ruby/library/openssl/shared/constants.rb
new file mode 100644
index 0000000000..0bed4156a1
--- /dev/null
+++ b/spec/ruby/library/openssl/shared/constants.rb
@@ -0,0 +1,11 @@
+# -*- encoding: binary -*-
+module HMACConstants
+
+ Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
+ Key = 'sekrit'
+
+ BlankSHA1Digest = "\3329\243\356^kK\r2U\277\357\225`\030\220\257\330\a\t"
+ SHA1Digest = "\236\022\323\341\037\236\262n\344\t\372:\004J\242\330\257\270\363\264"
+ BlankSHA1HexDigest = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
+ SHA1Hexdigest = "9e12d3e11f9eb26ee409fa3a044aa2d8afb8f3b4"
+end
diff --git a/spec/ruby/library/openssl/x509/name/parse_spec.rb b/spec/ruby/library/openssl/x509/name/parse_spec.rb
new file mode 100644
index 0000000000..c42760fdb7
--- /dev/null
+++ b/spec/ruby/library/openssl/x509/name/parse_spec.rb
@@ -0,0 +1,48 @@
+require File.expand_path('../../../../../spec_helper', __FILE__)
+require 'openssl'
+
+describe "OpenSSL::X509::Name.parse" do
+ it "parses a /-delimited string of key-value pairs into a Name" do
+ dn = "/DC=org/DC=ruby-lang/CN=www.ruby-lang.org"
+ name = OpenSSL::X509::Name.parse(dn)
+
+ name.to_s.should == dn
+
+ ary = name.to_a
+
+ ary[0][0].should == "DC"
+ ary[1][0].should == "DC"
+ ary[2][0].should == "CN"
+ ary[0][1].should == "org"
+ ary[1][1].should == "ruby-lang"
+ ary[2][1].should == "www.ruby-lang.org"
+ ary[0][2].should == OpenSSL::ASN1::IA5STRING
+ ary[1][2].should == OpenSSL::ASN1::IA5STRING
+ ary[2][2].should == OpenSSL::ASN1::UTF8STRING
+ end
+
+ it "parses a comma-delimited string of key-value pairs into a name" do
+ dn = "DC=org, DC=ruby-lang, CN=www.ruby-lang.org"
+ name = OpenSSL::X509::Name.parse(dn)
+
+ name.to_s.should == "/DC=org/DC=ruby-lang/CN=www.ruby-lang.org"
+
+ ary = name.to_a
+
+ ary[0][1].should == "org"
+ ary[1][1].should == "ruby-lang"
+ ary[2][1].should == "www.ruby-lang.org"
+ end
+
+ it "raises TypeError if the given string contains no key/value pairs" do
+ lambda do
+ OpenSSL::X509::Name.parse("hello")
+ end.should raise_error(TypeError)
+ end
+
+ it "raises OpenSSL::X509::NameError if the given string contains invalid keys" do
+ lambda do
+ OpenSSL::X509::Name.parse("hello=goodbye")
+ end.should raise_error(OpenSSL::X509::NameError)
+ end
+end