spec/spki_spec.rb in r509-0.9.2 vs spec/spki_spec.rb in r509-0.10.0
- old
+ new
@@ -16,10 +16,16 @@
end
it "generates a spki with custom digest" do
spki = R509::SPKI.new(:key => @key, :message_digest => "sha256")
spki.to_pem.should_not be_nil
+ case
+ when @key.rsa?
+ spki.signature_algorithm.should(match(/sha256/i))
+ when @key.dsa?
+ spki.signature_algorithm.should(match(/sha1/i))
+ end
spki.verify_signature
end
it "stores the key" do
spki = R509::SPKI.new(:key => @key)
@@ -35,10 +41,22 @@
shared_examples_for "spki + private key" do
it "verifies they match" do
expect { R509::SPKI.new(:key => @key, :spki => @spki) }.to_not raise_error
end
+ it "returns the correct signature_algorithm" do
+ spki = R509::SPKI.new( :spki => @spki, :key => @key )
+ case
+ when @key.rsa?
+ spki.signature_algorithm.should(match(/RSA/i))
+ when @key.dsa?
+ spki.signature_algorithm.should(match(/DSA/i))
+ when @key.ec?
+ spki.signature_algorithm.should(match(/ecdsa/i))
+ end
+ end
+
it "errors if they don't match" do
expect { R509::SPKI.new(:key => @key, :spki => @spki2) }.to raise_error(R509::R509Error,'Key does not match SPKI.')
end
end
@@ -59,52 +77,52 @@
expect { R509::SPKI.new({}) }.to raise_error(ArgumentError,'Must provide either :spki or :key')
end
context "rsa" do
context "no existing spki" do
before :all do
- @key = R509::PrivateKey.new(:type => :rsa, :bit_strength => 1024)
+ @key = R509::PrivateKey.new(:type => "rsa", :bit_length => 1024)
end
include_examples "create spki with private key"
end
context "existing spki + private key" do
before :all do
- @key = R509::PrivateKey.new(:type => :rsa, :bit_strength => 512)
- @key2 = R509::PrivateKey.new(:type => :rsa, :bit_strength => 512)
+ @key = R509::PrivateKey.new(:type => "rsa", :bit_length => 512)
+ @key2 = R509::PrivateKey.new(:type => "rsa", :bit_length => 512)
@spki = R509::SPKI.new(:key => @key).to_pem
@spki2 = R509::SPKI.new(:key => @key2).to_pem
end
include_examples "spki + private key"
end
end
context "dsa" do
context "no existing spki" do
before :all do
- @key = R509::PrivateKey.new(:type => :dsa, :bit_strength => 1024)
+ @key = R509::PrivateKey.new(:type => "dsa", :bit_length => 1024)
end
include_examples "create spki with private key"
end
context "existing spki + private key" do
before :all do
- @key = R509::PrivateKey.new(:type => :dsa, :bit_strength => 512)
- @key2 = R509::PrivateKey.new(:type => :dsa, :bit_strength => 512)
+ @key = R509::PrivateKey.new(:type => "dsa", :bit_length => 512)
+ @key2 = R509::PrivateKey.new(:type => "dsa", :bit_length => 512)
@spki = R509::SPKI.new(:key => @key).to_pem
@spki2 = R509::SPKI.new(:key => @key2).to_pem
end
include_examples "spki + private key"
end
end
context "elliptic curve", :ec => true do
context "no existing spki" do
before :all do
- @key = R509::PrivateKey.new(:type => :ec)
+ @key = R509::PrivateKey.new(:type => "EC")
end
include_examples "create spki with private key"
end
context "existing spki + private key" do
before :all do
- @key = R509::PrivateKey.new(:type => :ec)
- @key2 = R509::PrivateKey.new(:type => :ec)
+ @key = R509::PrivateKey.new(:type => "ec")
+ @key2 = R509::PrivateKey.new(:type => "ec")
@spki = R509::SPKI.new(:key => @key).to_pem
@spki2 = R509::SPKI.new(:key => @key2).to_pem
end
include_examples "spki + private key"
end
@@ -154,36 +172,37 @@
spki.rsa?.should == true
spki.dsa?.should == false
end
it "returns error when asking for curve_name on non-ec" do
spki = R509::SPKI.new( :spki => @spki )
- expect { spki.curve_name }.to raise_error(R509::R509Error,'Curve name is only available with EC SPKIs')
+ expect { spki.curve_name }.to raise_error(R509::R509Error,'Curve name is only available with EC')
end
it "returns RSA key algorithm for RSA" do
spki = R509::SPKI.new( :spki => @spki )
- spki.key_algorithm.should == :rsa
+ spki.key_algorithm.should == "RSA"
end
- it "gets RSA bit strength" do
+ it "gets RSA bit length" do
spki = R509::SPKI.new( :spki => @spki )
+ spki.bit_length.should == 2048
spki.bit_strength.should == 2048
end
it "loads a DSA spkac" do
spki = R509::SPKI.new( :spki => @spki_dsa )
spki.to_pem.should == @spki_dsa
end
- it "gets DSA bit strength" do
+ it "gets DSA bit length" do
spki = R509::SPKI.new( :spki => @spki_dsa )
- spki.bit_strength.should == 2048
+ spki.bit_length.should == 2048
end
it "dsa?" do
spki = R509::SPKI.new( :spki => @spki_dsa )
spki.dsa?.should == true
spki.rsa?.should == false
end
it "returns DSA key algorithm for DSA" do
spki = R509::SPKI.new( :spki => @spki_dsa )
- spki.key_algorithm.should == :dsa
+ spki.key_algorithm.should == "DSA"
end
context "elliptic curve", :ec => true do
it "loads an spkac" do
spki = R509::SPKI.new( :spki => @spki_ec )
@@ -191,17 +210,17 @@
end
it "returns the curve name" do
spki = R509::SPKI.new( :spki => @spki_ec )
spki.curve_name.should == 'secp384r1'
end
- it "raises error on bit strength" do
+ it "raises error on bit length" do
spki = R509::SPKI.new( :spki => @spki_ec )
- expect { spki.bit_strength }.to raise_error(R509::R509Error,'Bit strength is not available for EC at this time.')
+ expect { spki.bit_length }.to raise_error(R509::R509Error,'Bit length is not available for EC at this time.')
end
it "returns the key algorithm" do
spki = R509::SPKI.new( :spki => @spki_ec )
- spki.key_algorithm.should == :ec
+ spki.key_algorithm.should == "EC"
end
it "returns the public key" do
spki = R509::SPKI.new( :spki => @spki_ec )
spki.public_key.should_not == nil
end
@@ -228,9 +247,9 @@
spki.ec?.should == false
spki.dsa?.should == false
end
it "returns RSA key algorithm for RSA CSR" do
spki = R509::SPKI.new( :spki => @spki )
- spki.key_algorithm.should == :rsa
+ spki.key_algorithm.should == "RSA"
end
end
end