Sha256: 84cb3f877af09f4f89044e02ff6eb6dd6a41717fa5c82acb8686f7af11769ece

Contents?: true

Size: 1.86 KB

Versions: 18

Compression:

Stored size: 1.86 KB

Contents

require "spec_helper"
require "conjur/conjurize"

describe Conjur::Conjurize do
  let(:certificate) do
    OpenSSL::X509::Certificate.new.tap do |cert|
      key = OpenSSL::PKey::RSA.new 512
      cert.public_key = key.public_key
      cert.not_before = Time.now
      cert.not_after = 1.minute.from_now
      cert.sign key, OpenSSL::Digest::SHA256.new
    end
  end

  let(:certfile) do
    Tempfile.new("cert").tap do |file|
      file.write certificate.to_pem
      file.close
    end
  end

  let(:host_id) { "somehostid" }
  let(:api_key) { "very_secret_key" }
  let(:account) { "testacct" }
  let(:appliance_url) { "https://example.com" }

  before do
    allow(Conjur.config).to receive_messages \
      account: account,
      cert_file: certfile.path,
      appliance_url: appliance_url
  end

  describe ".generate" do
    it "puts all the relevant data in the script" do
      script = Conjur::Conjurize.generate "id" => host_id, "api_key" => api_key
      expect(script).to include host_id, api_key, account, certificate.to_pem
    end

    it "dumps JSON if required" do
      allow(Conjur::Conjurize).to receive_messages options: { json: true }
      expect(
        JSON.load(
          Conjur::Conjurize.generate(
            "id" => host_id,
            "api_key" => api_key
          )
        )
      ).to eq \
        "id" => host_id,
        "api_key" => api_key,
        "account" => account,
        "certificate" => certificate.to_pem.strip,
        "appliance_url" => appliance_url
    end
  end

  describe ".configuration" do
    it "gathers all the configuration options" do
      expect(
        Conjur::Conjurize.configuration("id" => host_id, "api_key" => api_key)
      ).to eq \
        "id" => host_id,
        "api_key" => api_key,
        "account" => account,
        "certificate" => certificate.to_pem.strip,
        "appliance_url" => appliance_url
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
conjur-cli-5.6.6 spec/conjurize_spec.rb
conjur-cli-5.6.5 spec/conjurize_spec.rb
conjur-cli-5.6.4 spec/conjurize_spec.rb
conjur-cli-5.6.3 spec/conjurize_spec.rb
conjur-cli-5.5.0 spec/conjurize_spec.rb
conjur-cli-5.4.0 spec/conjurize_spec.rb
conjur-cli-5.3.0 spec/conjurize_spec.rb
conjur-cli-5.2.5 spec/conjurize_spec.rb
conjur-cli-5.2.4 spec/conjurize_spec.rb
conjur-cli-5.2.3 spec/conjurize_spec.rb
conjur-cli-5.2.1 spec/conjurize_spec.rb
conjur-cli-5.2.0 spec/conjurize_spec.rb
conjur-cli-5.1.2 spec/conjurize_spec.rb
conjur-cli-5.1.1 spec/conjurize_spec.rb
conjur-cli-5.1.0 spec/conjurize_spec.rb
conjur-cli-4.30.1 spec/conjurize_spec.rb
conjur-cli-4.30.0 spec/conjurize_spec.rb
conjur-cli-4.29.0 spec/conjurize_spec.rb