conjur-cli 4.8.0 → 4.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,20 +28,20 @@ describe Conjur::Command::Roles, logged_in: true do
28
28
  describe_command "role:create --as-role test:foo test:the-role" do
29
29
  it "creates the role with acting_as option" do
30
30
  api.should_receive(:role).with("test:foo").and_return double("test:foo", exists?: true, roleid: "test:test:foo")
31
- api.should_receive(:role).with("test:the-role").and_return role = double("new-role")
31
+ api.should_receive(:role).with("test:the-role").and_return role = double("new-role", roleid: "test:the-role")
32
32
  role.should_receive(:create).with({acting_as: "test:test:foo"})
33
33
 
34
- invoke
34
+ expect { invoke }.to write("Created role test:the-role")
35
35
  end
36
36
  end
37
37
  describe_command "role:create --as-group the-group test:the-role" do
38
38
  it "creates the role with with acting_as option" do
39
39
  api.should_receive(:group).with("the-group").and_return group = double("the-group", roleid: "test:group:the-group")
40
40
  api.should_receive(:role).with(group.roleid).and_return double("group:the-group", exists?: true, roleid: "test:group:the-group")
41
- api.should_receive(:role).with("test:the-role").and_return role = double("new-role")
41
+ api.should_receive(:role).with("test:the-role").and_return role = double("new-role", roleid: "test:the-role")
42
42
  role.should_receive(:create).with({acting_as: "test:group:the-group"})
43
43
 
44
- invoke
44
+ expect { invoke }.to write("Created role test:the-role")
45
45
  end
46
46
  end
47
47
  end
@@ -44,5 +44,4 @@ describe Conjur::Command::Variables, logged_in: true do
44
44
  end
45
45
 
46
46
 
47
-
48
47
  end
data/spec/config_spec.rb CHANGED
@@ -5,6 +5,27 @@ describe Conjur::Config do
5
5
  after {
6
6
  Conjur::Config.clear
7
7
  }
8
+
9
+ describe ".default_config_files" do
10
+ subject { Conjur::Config.default_config_files }
11
+ around do |example|
12
+ realhome = ENV.delete 'HOME'
13
+ ENV['HOME'] = '/home/isfake'
14
+ example.run
15
+ ENV['HOME'] = realhome
16
+ end
17
+
18
+ context "when CONJURRC is not set" do
19
+ around do |example|
20
+ oldrc = ENV.delete 'CONJURRC'
21
+ example.run
22
+ ENV['CONJURRC'] = oldrc
23
+ end
24
+
25
+ it { should include('/home/isfake/.conjurrc') }
26
+ end
27
+ end
28
+
8
29
  describe "#load" do
9
30
  it "resolves the cert_file" do
10
31
  Conjur::Config.load([ File.expand_path('conjurrc', File.dirname(__FILE__)) ])
@@ -5,16 +5,25 @@ describe Conjur::DSL::Runner, logged_in: true do
5
5
  let(:filename) { nil }
6
6
  let(:runner) { Conjur::DSL::Runner.new script, filename }
7
7
  let(:script) { "user 'alice'" }
8
+ let(:alice) {
9
+ Conjur::User.new("alice").tap do |user|
10
+ user.attributes = { "api_key" => "the-api-key" }
11
+ end
12
+ }
8
13
  before {
9
14
  Conjur.stub(:account).and_return "the-account"
10
15
  runner.stub(:api).and_return api
11
16
  }
12
- it "should store the api_key in the context keyed by roleid" do
13
- user = Conjur::User.new("alice")
14
- user.attributes = { "api_key" => "the-api-key" }
17
+ it "should populate the root ownerid" do
18
+ api.should_receive(:user).with("alice").and_return double("alice-exists", exists?: false)
19
+ api.should_receive(:create_user).with(id: "alice", ownerid: "user:bob").and_return alice
15
20
 
21
+ runner.owner = "user:bob"
22
+ runner.execute
23
+ end
24
+ it "should store the api_key in the context keyed by roleid" do
16
25
  api.should_receive(:user).with("alice").and_return double("alice-exists", exists?: false)
17
- api.should_receive(:create_user).with(id: "alice").and_return user
26
+ api.should_receive(:create_user).with(id: "alice").and_return alice
18
27
 
19
28
  runner.execute
20
29
 
data/spec/env_spec.rb ADDED
@@ -0,0 +1,180 @@
1
+ require 'spec_helper'
2
+ require 'conjur/conjurenv'
3
+
4
+ describe Conjur::Env do
5
+
6
+ describe "#initialize" do
7
+
8
+ describe "requires either :file or :yaml parameter" do
9
+ before {
10
+ Conjur::Env.any_instance.should_not_receive(:parse)
11
+ }
12
+ it "fails if both options are provided" do
13
+ expect { Conjur::Env.new(file: 'f', yaml: 'y') }.to raise_error ":file and :yaml options can not be provided together"
14
+ end
15
+ it "fails if neither option is provided" do
16
+ expect { Conjur::Env.new() }.to raise_error "either :file or :yaml option is mandatory"
17
+ end
18
+ it "fails if :yaml option is empty or is not a string" do
19
+ expect { Conjur::Env.new(yaml: "") }.to raise_error ":yaml option should be non-empty string"
20
+ expect { Conjur::Env.new(yaml: nil) }.to raise_error ":yaml option should be non-empty string"
21
+ expect { Conjur::Env.new(yaml: 2) }.to raise_error ":yaml option should be non-empty string"
22
+ end
23
+ it "fails if :file option is empty or is not a string"do
24
+ expect { Conjur::Env.new(file: "") }.to raise_error ":file option should be non-empty string"
25
+ expect { Conjur::Env.new(file: nil) }.to raise_error ":file option should be non-empty string"
26
+ expect { Conjur::Env.new(file: 2) }.to raise_error ":file option should be non-empty string"
27
+ end
28
+ end
29
+
30
+ describe "with correct parameters" do
31
+
32
+ let(:parsed) { :parsed_structure_stub }
33
+
34
+ describe "if :file parameter provided" do
35
+ it "does not catch any errors from File.read" do
36
+ Conjur::Env.any_instance.should_not_receive(:parse)
37
+ File.stub(:read).with('unexisting').and_return { raise "Custom error" }
38
+ expect { Conjur::Env.new(file: 'unexisting') }.to raise_error "Custom error"
39
+ end
40
+
41
+ it "if file is readable, passes contents to #parse and stores result in @definition attribute" do
42
+ File.should_receive(:read).with("somefile").and_return(:file_contents)
43
+ Conjur::Env.any_instance.should_receive(:parse).with(:file_contents).and_return(:stub_parsed)
44
+ Conjur::Env.new(file:"somefile").instance_variable_get("@definition").should == :stub_parsed
45
+ end
46
+ end
47
+ it "if :yaml parameter provided, passes it to #parse and stores result in @definition attribute" do
48
+ Conjur::Env.any_instance.should_receive(:parse).with("custom yaml").and_return(:stub_parsed)
49
+ Conjur::Env.new(yaml:"custom yaml").instance_variable_get("@definition").should == :stub_parsed
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "#parse (called from 'initialize')" do
55
+
56
+ it 'parses input as YAML and does not hide YAML errors' do
57
+ YAML.should_receive(:load).with("custom yaml").and_return { raise "Custom error" }
58
+ expect { Conjur::Env.new(yaml: "custom yaml") }.to raise_error "Custom error"
59
+ end
60
+
61
+ it "fails unless YAML represents a Hash" do
62
+ expect { Conjur::Env.new(yaml: "[ 1,2,3 ]") }.to raise_error "Definition should be a Hash"
63
+ end
64
+
65
+ it "fails if values are not literal, !tmp or !var" do
66
+ expect { Conjur::Env.new(yaml: "{a: literal, b: !tmp tempfile, c: !var conjurvar, d: { x: another literal }}") }.to raise_error /^Definition can not include values of types/
67
+ expect { Conjur::Env.new(yaml: "{a: literal, b: !tmp tempfile, c: !var conjurvar}") }.to_not raise_error
68
+ end
69
+
70
+ it 'does not allow empty values for !tmp and !var' do
71
+ expect { Conjur::Env.new(yaml: "{a: literal, b: !tmp , c: !var conjurvar }") }.to raise_error "ConjurTempfile requires a parameter"
72
+ expect { Conjur::Env.new(yaml: "{a: literal, b: !tmp tempfile, c: !var }") }.to raise_error "ConjurVariable requires a parameter"
73
+ expect { Conjur::Env.new(yaml: "{a: literal, b: !tmp tempfile, c: !var conjurvar}") }.to_not raise_error
74
+ end
75
+
76
+ it "Returns hash consisting of literals, ConjurTempfile and ConjurVariable objects" do
77
+ result = Conjur::Env.new(yaml: "{a: literal, b: !tmp 'sometmp', c: !var 'somevar'}").instance_variable_get("@definition")
78
+ result.keys.sort.should == ["a","b","c"]
79
+ result["a"].should == 'literal'
80
+ result["b"].should be_a_kind_of(Conjur::Env::ConjurTempfile)
81
+ result["c"].should be_a_kind_of(Conjur::Env::ConjurVariable)
82
+ end
83
+ end
84
+
85
+ describe "#obtain", logged_in: true do
86
+ let(:subject) { Conjur::Env.new(yaml: "{a: literal, b: !tmp tempfile, c: !var conjurvar}") }
87
+ before {
88
+ api.stub(:variable_values).with(["tempfile","conjurvar"]).and_return({"tempfile" => "stubtemp", "conjurvar" => "stubvar" })
89
+ }
90
+
91
+ it "requests variable_values with list of !var and !tmp values" do
92
+ Conjur::Env::ConjurTempfile.any_instance.stub(:evaluate).and_return(:stub_value) # avoid tempfiles creation
93
+ api.should_receive(:variable_values).with(["tempfile","conjurvar"]).and_return({"tempfile" => "stub1", "conjurvar" => "stub2" })
94
+ subject.obtain(api)
95
+ end
96
+
97
+ it 'does not suppress api errors' do
98
+ api.stub(:variable_values).and_return { raise "Custom API error" }
99
+ expect { subject.obtain(api) }.to raise_error "Custom API error"
100
+ end
101
+
102
+ describe "for !tmp creates temporary files with Conjur variable value" do
103
+ it "in /dev/shm if it exists" do
104
+ tempfile = double(path: '/dev/shm/newfile', close: true)
105
+ File.should_receive(:directory?).with("/dev/shm").and_return(true)
106
+ File.should_receive(:writable?).with("/dev/shm").and_return(true)
107
+ Tempfile.should_receive(:new).with("conjur","/dev/shm").and_return(tempfile)
108
+ tempfile.should_receive(:write).with("stubtemp")
109
+ subject.obtain(api)
110
+ end
111
+ it "otherwise uses Tempfile defaults" do
112
+ tempfile = double(path: '/tmp/newfile', close: true)
113
+ File.should_receive(:directory?).with("/dev/shm").and_return(false)
114
+ Tempfile.should_receive(:new).with("conjur").and_return(tempfile)
115
+ tempfile.should_receive(:write).with("stubtemp")
116
+ subject.obtain(api)
117
+ end
118
+ end
119
+
120
+ describe "returns hash consisting of original keys and following values" do
121
+ before {
122
+ tempfile=double(path:"/stub/tempfile",write: true, close: true)
123
+ File.stub(:directory?).with("/dev/shm").and_return(true)
124
+ File.stub(:writable?).with("/dev/shm").and_return(true)
125
+ Tempfile.stub(:new).with("conjur","/dev/shm").and_return(tempfile)
126
+ }
127
+ let(:result) { subject.obtain(api) }
128
+
129
+ it 'literals' do
130
+ result.should include("a"=>"literal")
131
+ end
132
+ it '!tmp: names of temp files' do
133
+ result.should include("b"=>"/stub/tempfile")
134
+ end
135
+ it '!var: variable values' do
136
+ result.should include("c"=>"stubvar")
137
+ end
138
+ end
139
+ end
140
+
141
+ describe "#check", logged_in: true do
142
+
143
+ let(:subject) { Conjur::Env.new(yaml: "{a: literal, b: !tmp tempfile_b, c: !var conjurvar_c, d: !tmp tempfile_d, e: !var conjurvar_e }") }
144
+ before {
145
+ api.should_not_receive(:variable_values)
146
+ Tempfile.should_not_receive(:new)
147
+ }
148
+ let(:permitted) { double(permitted?:true) }
149
+ let(:restricted) { double(permitted?:false) }
150
+
151
+ it "requests resource 'execute' permission for each !var and !tmp value" do
152
+ api.should_receive(:resource).with("variable:tempfile_b").and_return(permitted)
153
+ api.should_receive(:resource).with("variable:conjurvar_c").and_return(permitted)
154
+ api.should_receive(:resource).with("variable:tempfile_d").and_return(permitted)
155
+ api.should_receive(:resource).with("variable:conjurvar_e").and_return(permitted)
156
+ permitted.should_receive(:permitted?).exactly(4).times.with(:execute).and_return(true)
157
+ subject.check(api)
158
+ end
159
+
160
+ it 'does not rescue from unexpected api errors' do
161
+ api.should_receive(:resource).with("variable:tempfile_b").and_return { raise "Custom error" }
162
+ expect { subject.check(api) }.to raise_error "Custom error"
163
+ end
164
+
165
+ it "returns Hash consisting of original keys and following statuses: :literal, :available, :unavailable" do
166
+ api.should_receive(:resource).with("variable:tempfile_b").and_return(permitted)
167
+ api.should_receive(:resource).with("variable:conjurvar_c").and_return(restricted)
168
+ api.should_receive(:resource).with("variable:tempfile_d").and_return(restricted)
169
+ api.should_receive(:resource).with("variable:conjurvar_e").and_return(permitted)
170
+
171
+ result = subject.check(api).should == { "a" => :literal,
172
+ "b" => :available,
173
+ "c" => :unavailable,
174
+ "d" => :unavailable,
175
+ "e" => :available
176
+ }
177
+ end
178
+ end
179
+
180
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.0
4
+ version: 4.9.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-04-02 00:00:00.000000000 Z
13
+ date: 2014-05-23 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
15
31
  - !ruby/object:Gem::Dependency
16
32
  name: conjur-api
17
33
  requirement: !ruby/object:Gem::Requirement
@@ -19,7 +35,7 @@ dependencies:
19
35
  requirements:
20
36
  - - ! '>='
21
37
  - !ruby/object:Gem::Version
22
- version: 4.7.2
38
+ version: '4.8'
23
39
  type: :runtime
24
40
  prerelease: false
25
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,7 +43,7 @@ dependencies:
27
43
  requirements:
28
44
  - - ! '>='
29
45
  - !ruby/object:Gem::Version
30
- version: 4.7.2
46
+ version: '4.8'
31
47
  - !ruby/object:Gem::Dependency
32
48
  name: gli
33
49
  requirement: !ruby/object:Gem::Requirement
@@ -245,6 +261,7 @@ files:
245
261
  - lib/conjur/command/audit.rb
246
262
  - lib/conjur/command/authn.rb
247
263
  - lib/conjur/command/dsl_command.rb
264
+ - lib/conjur/command/env.rb
248
265
  - lib/conjur/command/field.rb
249
266
  - lib/conjur/command/groups.rb
250
267
  - lib/conjur/command/hosts.rb
@@ -262,6 +279,7 @@ files:
262
279
  - lib/conjur/command/users.rb
263
280
  - lib/conjur/command/variables.rb
264
281
  - lib/conjur/config.rb
282
+ - lib/conjur/conjurenv.rb
265
283
  - lib/conjur/dsl/runner.rb
266
284
  - lib/conjur/identifier_manipulation.rb
267
285
  - lib/conjur/version.rb
@@ -270,6 +288,7 @@ files:
270
288
  - spec/command/assets_spec.rb
271
289
  - spec/command/audit_spec.rb
272
290
  - spec/command/authn_spec.rb
291
+ - spec/command/env_spec.rb
273
292
  - spec/command/groups_spec.rb
274
293
  - spec/command/hosts_spec.rb
275
294
  - spec/command/init_spec.rb
@@ -282,6 +301,7 @@ files:
282
301
  - spec/config_spec.rb
283
302
  - spec/conjurrc
284
303
  - spec/dsl/runner_spec.rb
304
+ - spec/env_spec.rb
285
305
  - spec/spec_helper.rb
286
306
  homepage: https://github.com/conjurinc/cli-ruby
287
307
  licenses:
@@ -296,12 +316,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
296
316
  - - ! '>='
297
317
  - !ruby/object:Gem::Version
298
318
  version: '0'
319
+ segments:
320
+ - 0
321
+ hash: 4419990204005105741
299
322
  required_rubygems_version: !ruby/object:Gem::Requirement
300
323
  none: false
301
324
  requirements:
302
325
  - - ! '>='
303
326
  - !ruby/object:Gem::Version
304
327
  version: '0'
328
+ segments:
329
+ - 0
330
+ hash: 4419990204005105741
305
331
  requirements: []
306
332
  rubyforge_project:
307
333
  rubygems_version: 1.8.25
@@ -325,6 +351,7 @@ test_files:
325
351
  - spec/command/assets_spec.rb
326
352
  - spec/command/audit_spec.rb
327
353
  - spec/command/authn_spec.rb
354
+ - spec/command/env_spec.rb
328
355
  - spec/command/groups_spec.rb
329
356
  - spec/command/hosts_spec.rb
330
357
  - spec/command/init_spec.rb
@@ -337,4 +364,5 @@ test_files:
337
364
  - spec/config_spec.rb
338
365
  - spec/conjurrc
339
366
  - spec/dsl/runner_spec.rb
367
+ - spec/env_spec.rb
340
368
  - spec/spec_helper.rb