Sha256: b368d7acf42a47206b96ee64ceb71075b1d64a2b2c8b2685dc919e1ef9a069cd

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'

RSpec.describe Cryptor::SymmetricEncryption::SecretKey do
  let(:algorithm)  { :BassOmatic }
  let(:key_bytes)  { 42 }
  let(:cipher)     { Cryptor::SymmetricEncryption::Cipher.new(algorithm, key_bytes: key_bytes) }
  let(:secret_key) { "\xBA\x55" }
  let(:secret_uri) { "secret.key:///#{algorithm};#{Cryptor::Encoding.encode(secret_key)}" }

  before do
    allow(Cryptor::SymmetricEncryption::Cipher).to receive(:[]).and_return(cipher)
  end

  subject { described_class.new(secret_uri) }

  it 'generates random keys' do
    expect(described_class.random_key(algorithm)).to be_a described_class
  end

  it 'serializes to a URI' do
    expect(subject.to_secret_uri).to eq secret_uri
  end

  it 'serializes to a key fingerprint' do
    expect(URI(subject.fingerprint).scheme).to eq 'ni'
  end

  it 'inspects without revealing the secret key' do
    expect(subject.inspect).not_to include(secret_key)
    expect(subject.inspect).not_to include(Cryptor::Encoding.encode(secret_key))
  end

  it 'raises ArgumentError if given a bogus URI' do
    expect do
      described_class.new('http://www.google.com/')
    end.to raise_exception(ArgumentError)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cryptor-1.1.1 spec/cryptor/symmetric_encryption/secret_key_spec.rb
cryptor-1.1.0 spec/cryptor/symmetric_encryption/secret_key_spec.rb