Sha256: 9d10cb36557d105a257f094a63c9e392938a267ee67616db3716dc145b49bf5d

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe Conjur::Role do
  let(:account) { "the-account" }
  let(:kind) { "test" }
  let(:role) { Conjur::API.new_from_token({ 'data' => 'the-login' }).role([ account, kind, id ].join(":")) }
  subject { role }

  describe ".new" do
    context "with plain id" do
      let(:id) { "foo" }
      its(:options) { should == {:headers=>{:authorization=>"Token token=\"eyJkYXRhIjoidGhlLWxvZ2luIn0=\""}, :username=>'the-login'} }
      its(:kind) { should == kind }
      its(:id) { should == id }
    end

    context "with more complex id" do
      let(:id) { "foo/bar" }
      its(:kind) { should == kind }
      its(:id) { should == id }
    end
  end

  let(:id) { "role/id" }

  describe "#grant_to" do
    it "should take hash as the second argument and put it" do
      members = double "members request"
      subject.should_receive(:[]).with('?members&member=other').and_return(members)
      members.should_receive(:put).with admin_option: true
      subject.grant_to "other", admin_option: true
    end

    it "works without arguments" do
      members = double "members request"
      subject.should_receive(:[]).with('?members&member=other').and_return(members)
      members.should_receive(:put).with nil
      subject.grant_to "other"
    end

    context deprecated: 'v3' do # remove in 3.0
      it "should also accept the deprecated argument format with extra options" do
        members = double "members request"
        subject.should_receive(:[]).with('?members&member=other').and_return(members)
        members.should_receive(:put).with admin_option: true, foo: 'bar'
        subject.grant_to "other", true, foo: 'bar'
      end

      it "should also accept the deprecated argument format without extra options" do
        members = double "members request"
        subject.should_receive(:[]).with('?members&member=other').and_return(members)
        members.should_receive(:put).with admin_option: true, foo: 'bar'
        subject.grant_to "other", true, foo: 'bar'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
conjur-api-2.4.0 spec/lib/role_spec.rb
conjur-api-2.3.1 spec/lib/role_spec.rb