<commit_before>require 'spec_helper'
require 'conjur/cli'
require 'conjur/command/rspec/describe_command'
require 'conjur/command/rspec/output_matchers'

POLICY_FIXTURE_FILE = "#{File.dirname(__FILE__)}/round-trip/yaml/org.yml"
PLAN_FIXTURE_FILE = "#{File.dirname(__FILE__)}/import/import.yml"

describe Conjur::Command::Policy do
  let(:account) { "cucumber" }
  let(:ownerid) { "#{account}:user:alice" }
  let(:api) { double(:api, username: "alice") }
  let(:records){ double(:records) }
  let(:loader){ Conjur::Policy::YAML::Loader }
  let(:resolver){ Conjur::Policy::YAML::Resolver }
  let(:plan){ double(:plan, actions: ['action']) }
  let(:namespace) { nil }

  shared_examples_for "execute the plan" do
    it 'loads the plan and executes the actions' do
      expect(described_class).to receive(:execute).with(api, plan.actions)
      invoke
    end
  end

  before do
    allow(described_class).to receive(:api).and_return api
    allow(loader).to receive(:load).with(
        File.read(POLICY_FIXTURE_FILE),
        POLICY_FIXTURE_FILE).and_return records
    allow(Conjur::Policy::Resolver).to receive(:resolve).with(records, account, ownerid, namespace).and_return records
    allow(Conjur::Policy::Planner).to receive(:plan).with(records, api).and_return plan
  end

  describe_command "policy load --namespace foo #{POLICY_FIXTURE_FILE}" do
    let(:namespace) { "foo" }
    it_should_behave_like "execute the plan"
  end

  describe_command "policy load --namespace foo --context conjur.json #{POLICY_FIXTURE_FILE}" do
    let(:namespace) { "foo" }
    let(:context_hash){
      { 'foo' => 'bar', 'x' => 'y' }<commit_msg>update spec to assume no special api privilege<commit_after>require 'spec_helper'
require 'conjur/cli'
require 'conjur/command/rspec/describe_command'
require 'conjur/command/rspec/output_matchers'

POLICY_FIXTURE_FILE = "#{File.dirname(__FILE__)}/round-trip/yaml/org.yml"
PLAN_FIXTURE_FILE = "#{File.dirname(__FILE__)}/import/import.yml"

describe Conjur::Command::Policy do
  let(:account) { "cucumber" }
  let(:ownerid) { "#{account}:user:alice" }
  let(:api) { double(:api, username: "alice", privilege: nil) }
  let(:records){ double(:records) }
  let(:loader){ Conjur::Policy::YAML::Loader }
  let(:resolver){ Conjur::Policy::YAML::Resolver }
  let(:plan){ double(:plan, actions: ['action']) }
  let(:namespace) { nil }

  shared_examples_for "execute the plan" do
    it 'loads the plan and executes the actions' do
      expect(described_class).to receive(:execute).with(api, plan.actions)
      invoke
    end
  end

  before do
    allow(described_class).to receive(:api).and_return api
    allow(loader).to receive(:load).with(
        File.read(POLICY_FIXTURE_FILE),
        POLICY_FIXTURE_FILE).and_return records
    allow(Conjur::Policy::Resolver).to receive(:resolve).with(records, account, ownerid, namespace).and_return records
    allow(Conjur::Policy::Planner).to receive(:plan).with(records, api).and_return plan
  end

  describe_command "policy load --namespace foo #{POLICY_FIXTURE_FILE}" do
    let(:namespace) { "foo" }
    it_should_behave_like "execute the plan"
  end

  describe_command "policy load --namespace foo --context conjur.json #{POLICY_FIXTURE_FILE}" do
    let(:namespace) { "foo" }
    let(:context_hash){
      { 'foo' => 'bar', 'x' => 'y' }
{'fraction_non_alphanumeric': 0.14995483288166214, 'fraction_numerical': 0.0, 'mean_word_length': 4.911032028469751, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7024807', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1093, 'n_words': 221}