Sha256: 1a205644be09cd0de341467365b8acb1ed130f5247f972f0347df15a86bc2183

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require "rubygems"
require "bundler/setup"
require 'tempfile'
require 'ostruct'

require "simplecov"
SimpleCov.start

module RSpec::Core::DSL
  def describe_command *argv, &block
    describe *argv do
      let(:invoke) do
        Conjur::CLI.error_device = $stderr
        Conjur::CLI.run argv.first.split(' ')
      end
      instance_eval &block
    end
  end
end

shared_context "with fake endpoints and test config" do
  let(:authn_host) { 'https://authn.example.com' }
  let(:authz_host) { 'https://authz.example.com' }
  let(:core_host) { 'https://core.example.com' }
  before do
    Conjur::Authn::API.stub host: authn_host
    Conjur::Authz::API.stub host: authz_host
    Conjur::Core::API.stub host: core_host

    ENV['GLI_DEBUG'] = 'true'
  end
end

shared_context "with mock authn" do
  include_context "with fake endpoints and test config"
  let(:netrcfile) { Tempfile.new 'authtest' }
  let(:netrc) { Netrc.read(netrcfile.path) }
  let(:account) { 'the-account' }
  before do
    Conjur::Core::API.stub conjur_account: account
    Conjur::Authn.stub netrc: netrc, host: authn_host
    Conjur::Config.merge 'account' => account
  end

end

shared_context "when logged in", logged_in: true do
  include_context "with mock authn"
  let(:username) { 'dknuth' }
  let(:api_key) { 'sekrit' }
  let(:api) { Conjur::API.new_from_key(username, api_key) }
  before do
    api.stub credentials: {}
    netrc[authn_host] = [username, api_key]
    Conjur::Command.stub api: api
  end
end

shared_context "when not logged in", logged_in: false do
  include_context "with mock authn"
end

  
def post_response(id, attributes = {})
  attributes[:id] = id
  
  OpenStruct.new({
    headers: { location: [ collection_url, id ].join('/') }, 
    body: attributes.to_json
  })
end

require 'write_expectation'

require 'conjur/cli'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
conjur-cli-2.6.0 spec/spec_helper.rb