Sha256: 6a753e6abab8682712818f6c6419122586e792f141e12c9d3553e263fbe7e5bb

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

require 'cryptic/keypair'

# TODO: Update tests to work
describe Cryptic::Keypair do
  let :private_keys do
    keys = [
      './cryptic_private.pem',
      File.read('./cryptic_private.pem')
    ]

    # Repeat the keys for zipping
    keys *= 2
  end

  let :public_keys do
    keys = [
      './cryptic_public.pem',
      File.read('./cryptic_public.pem')
    ]

    # Repeat the keys in opposing order for zipping
    keys += keys.reverse
  end

  it 'should be able to create a keypair from a private key' do
    private_keys.uniq.each do |private_key|
      expect {
        Cryptic::Keypair.new(
          private_key,
          passphrase: 'P4$SpHr4z3'
        )
      }.to_not raise_error
    end
  end

  it 'should be able to create a keypair from a private key and a public key' do
    private_keys.zip(public_keys).each do |private_key, public_key|
      expect {
        Cryptic::Keypair.new(
          private_key,
          passphrase: 'P4$SpHr4z3',
          public_key: public_key
        )
      }.to_not raise_error
    end
  end

  # TODO: Add custom error classes below once implemented

  it 'should not be able to create a keypair with an empty private key' do
    expect { Cryptic::Keypair.new('') }.to raise_error
    expect { Cryptic::Keypair.new(nil) }.to raise_error
  end

  it 'should not be able to create a keypair with an invalid private key' do
    public_keys.uniq.each do |public_key|
      expect {
        Cryptic::Keypair.new(
          public_key,
          passphrase: 'P4$SpHr4z3'
        )
      }.to raise_error

      expect { Cryptic::Keypair.new(public_key) }.to raise_error
    end

    expect { Cryptic::Keypair.new('invalid') }.to raise_error
  end

  it 'should not be able to create a keypair with an invalid passphrase' do
    private_keys.uniq.each do |private_key|
      expect {
        Cryptic::Keypair.new(
          private_key,
          passphrase: 'BadPassphrase'
        )
      }.to raise_error
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cryptic-1.0.0.beta.11 spec/keypair_spec.rb
cryptic-1.0.0.beta.10 spec/keypair_spec.rb