Sha256: 1c9486e4bd6967fdc42b7af5423a501cb82444936c8bfa0a99afb3bc0a83f00b

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

# -*- encoding: utf-8 -*-
require "spec_helper"

describe Sequel::Plugins::Vault do
  let(:db) { Sequel.mock(autoid: 1) }
  let(:klass) do
    Class.new(Sequel::Model(db[:vm])) do
      set_primary_key :id
      unrestrict_primary_key
      set_columns([:id, :secret, :secret_digest, :key_id])

      plugin :vault
    end
  end
  let(:dataset) { klass.dataset }
  let(:model) { klass.new }
  let(:keys) do
    ["fih3l0Z9e4NBpy5KIj+rmXVexY5O9LspzuqCFyqavjg=",
     "woRXJWevRaxZLxgoiEQtCDPBSf9TNg57bki0RUK1U48="]
  end
  let(:secret) { "Attack at once." }
  let(:cypher) { klass.encrypt(keys, secret) }
  let(:digest) { OpenSSL::HMAC.digest('sha512', keys.last, secret) }

  it "should encrypt vault attributes" do
    klass.vault_attributes(keys, :secret)
    model.secret = secret
    expect(model.values[:secret]).to_not eq(secret)
    expect(model.secret).to eq(secret)
    expect(model.key_id).to eq(2)
  end

  it "should allow nil value" do
    klass.vault_attributes(keys, :secret)
    model.secret = nil
    expect(model.values[:secret]).to be_nil
    expect(model.secret).to be_nil
    expect(model.key_id).to be_nil
  end

  it "should write a digest of the value" do
    klass.vault_attributes(keys, :secret)
    model.secret = secret
    expect(model.values[:secret_digest]).to_not eq(secret)
    expect(model.secret_digest).to eq(digest)
    expect(model.key_id).to eq(2)
  end

  it "should provide a digest lookup" do
    dataset._fetch = { id: 1, secret: cypher, secret_digest: digest }
    klass.vault_attributes(keys, :secret)
    lookup = klass.secret_lookup("secret")
    expect(lookup.secret).to eq(secret)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sequel_vault-0.5.1 spec/sequel_vault_spec.rb
sequel_vault-0.5 spec/sequel_vault_spec.rb
sequel_vault-0.4 spec/sequel_vault_spec.rb