Sha256: f1a959e24119f1f8bf4664ea7fbe4bbed8340b88625058ed022935094a6b6530

Contents?: true

Size: 1.89 KB

Versions: 21

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

describe RightSupport::Validation::OpenSSL do
  GOOD_PEM_PUB_RSA            = read_fixture('good_pub_rsa.pem') unless const_defined?('GOOD_PEM_PUB_RSA')
  GOOD_PEM_PRIV_RSA           = read_fixture('good_priv_rsa.pem') unless const_defined?('GOOD_PEM_PRIV_RSA')
  GOOD_ENCRYPTED_PEM_PRIV_RSA = read_fixture('encrypted_priv_rsa.pem') unless const_defined?('GOOD_ENCRYPTED_PEM_PRIV_RSA')
  GOOD_SSH_PUB_RSA            = read_fixture('good_pub_rsa.ssh') unless const_defined?('GOOD_SSH_PUB_RSA')
  GOOD_SSH_PUB_DSA            = read_fixture('good_pub_dsa.ssh') unless const_defined?('GOOD_SSH_PUB_DSA')
  GOOD_PEM_PRIV_DSA           = read_fixture('good_priv_dsa.pem') unless const_defined?('GOOD_PEM_PRIV_DSA')

  context :pem_public_key? do
    it 'recognizes valid keys' do
      RightSupport::Validation.pem_public_key?(GOOD_PEM_PUB_RSA).should == true
    end
    it 'recognizes bad keys' do
      RightSupport::Validation.pem_public_key?(corrupt(GOOD_PEM_PUB_RSA)).should == false
      RightSupport::Validation.pem_public_key?(nil).should == false
      RightSupport::Validation.pem_public_key?('').should == false
    end
  end

  context :pem_private_key? do
    it 'recognizes valid keys' do
      RightSupport::Validation.pem_private_key?(GOOD_PEM_PRIV_RSA).should == true
      RightSupport::Validation.pem_private_key?(GOOD_PEM_PRIV_DSA).should == true
    end
    it 'considers encrypted keys to be "bad" (not usable)' do
      RightSupport::Validation.pem_private_key?(GOOD_ENCRYPTED_PEM_PRIV_RSA).should == false
    end
    it 'recognizes bad keys' do
      RightSupport::Validation.pem_private_key?(corrupt(GOOD_PEM_PRIV_RSA)).should == false
      RightSupport::Validation.pem_private_key?(corrupt(GOOD_PEM_PRIV_RSA, 16)).should == false
      RightSupport::Validation.pem_private_key?(nil).should == false
      RightSupport::Validation.pem_private_key?('').should == false
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
right_support-2.11.3 spec/validation/openssl_spec.rb
right_support-2.11.2 spec/validation/openssl_spec.rb
right_support-2.10.1 spec/validation/openssl_spec.rb
right_support-2.9.6 spec/validation/openssl_spec.rb
right_support-2.9.5 spec/validation/openssl_spec.rb
right_support-2.9.4 spec/validation/openssl_spec.rb
right_support-2.9.3 spec/validation/openssl_spec.rb
right_support-2.9.2 spec/validation/openssl_spec.rb
right_support-2.9.1 spec/validation/openssl_spec.rb
right_support-2.8.46 spec/validation/openssl_spec.rb
right_support-2.8.45 spec/validation/openssl_spec.rb
right_support-2.8.44 spec/validation/openssl_spec.rb
right_support-2.8.43 spec/validation/openssl_spec.rb
right_support-2.8.42 spec/validation/openssl_spec.rb
right_support-2.8.41 spec/validation/openssl_spec.rb
right_support-2.8.40 spec/validation/openssl_spec.rb
right_support-2.8.39 spec/validation/openssl_spec.rb
right_support-2.8.38 spec/validation/openssl_spec.rb
right_support-2.8.37 spec/validation/openssl_spec.rb
right_support-2.8.36 spec/validation/openssl_spec.rb