conjur-api 4.31.0 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +1 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +22 -3
  5. data/Dockerfile +12 -3
  6. data/Gemfile +3 -3
  7. data/Jenkinsfile +69 -0
  8. data/LICENSE.md +195 -0
  9. data/README.md +16 -0
  10. data/Rakefile +34 -18
  11. data/ci/wait_for_server.sh +10 -0
  12. data/conjur-api.gemspec +6 -14
  13. data/dev/docker-compose.yml +23 -0
  14. data/dev/empty.yml +2 -0
  15. data/dev/start.sh +15 -0
  16. data/dev/stop.sh +6 -0
  17. data/docker-compose.yml +27 -0
  18. data/features/exists.feature +37 -0
  19. data/features/group.feature +11 -0
  20. data/features/host.feature +20 -0
  21. data/features/host_factory_create_host.feature +28 -0
  22. data/features/host_factory_token.feature +63 -0
  23. data/features/load_policy.feature +61 -0
  24. data/features/members.feature +51 -0
  25. data/features/new_api.feature +36 -0
  26. data/features/permitted.feature +43 -0
  27. data/features/permitted_roles.feature +30 -0
  28. data/features/public_keys.feature +11 -0
  29. data/features/resource_fields.feature +53 -0
  30. data/features/role_fields.feature +15 -0
  31. data/features/rotate_api_key.feature +13 -0
  32. data/features/step_definitions/api_steps.rb +4 -54
  33. data/features/step_definitions/policy_steps.rb +35 -0
  34. data/features/step_definitions/result_steps.rb +7 -0
  35. data/features/support/env.rb +14 -5
  36. data/features/support/hooks.rb +3 -0
  37. data/features/support/world.rb +5 -6
  38. data/features/update_password.feature +14 -0
  39. data/features/user.feature +17 -0
  40. data/features/variable_fields.feature +20 -0
  41. data/features/variable_value.feature +67 -0
  42. data/lib/conjur/acts_as_resource.rb +95 -65
  43. data/lib/conjur/acts_as_role.rb +102 -51
  44. data/lib/conjur/{audit-api.rb → acts_as_rolsource.rb} +10 -14
  45. data/lib/conjur/acts_as_user.rb +13 -22
  46. data/lib/conjur/api/authn.rb +37 -72
  47. data/lib/conjur/api/host_factories.rb +35 -55
  48. data/lib/conjur/api/policies.rb +56 -0
  49. data/lib/conjur/api/pubkeys.rb +36 -160
  50. data/lib/conjur/api/resources.rb +32 -116
  51. data/lib/conjur/api/roles.rb +28 -105
  52. data/lib/conjur/api/variables.rb +22 -91
  53. data/lib/conjur/api.rb +19 -46
  54. data/lib/conjur/base.rb +21 -132
  55. data/lib/conjur/base_object.rb +57 -0
  56. data/lib/conjur/{authn-api.rb → build_object.rb} +23 -11
  57. data/lib/conjur/cast.rb +12 -17
  58. data/lib/conjur/cert_utils.rb +1 -1
  59. data/lib/conjur/cidr.rb +1 -1
  60. data/lib/conjur/configuration.rb +13 -91
  61. data/lib/conjur/escape.rb +1 -2
  62. data/lib/conjur/group.rb +9 -65
  63. data/lib/conjur/has_attributes.rb +22 -59
  64. data/lib/conjur/host.rb +5 -35
  65. data/lib/conjur/host_factory.rb +40 -40
  66. data/lib/conjur/host_factory_token.rb +38 -23
  67. data/lib/conjur/id.rb +63 -0
  68. data/lib/conjur/layer.rb +5 -80
  69. data/lib/conjur/log.rb +1 -1
  70. data/lib/conjur/log_source.rb +1 -1
  71. data/lib/conjur/{secret.rb → policy.rb} +11 -14
  72. data/lib/conjur/{api/secrets.rb → policy_load_result.rb} +35 -22
  73. data/lib/conjur/query_string.rb +2 -1
  74. data/lib/conjur/resource.rb +5 -299
  75. data/lib/conjur/role.rb +5 -317
  76. data/lib/conjur/role_grant.rb +20 -28
  77. data/lib/conjur/user.rb +5 -63
  78. data/lib/conjur/variable.rb +31 -76
  79. data/lib/conjur/{authz-api.rb → webservice.rb} +8 -16
  80. data/lib/conjur-api/version.rb +2 -2
  81. data/publish.sh +7 -0
  82. data/spec/api_spec.rb +208 -0
  83. data/spec/cast_spec.rb +21 -0
  84. data/spec/{lib/cert_utils_spec.rb → cert_utils_spec.rb} +0 -0
  85. data/spec/{lib/cidr_spec.rb → cidr_spec.rb} +0 -0
  86. data/spec/{lib/configuration_spec.rb → configuration_spec.rb} +40 -140
  87. data/spec/{lib/has_attributes_spec.rb → has_attributes_spec.rb} +6 -2
  88. data/spec/{lib/log_source_spec.rb → log_source_spec.rb} +0 -0
  89. data/spec/{lib/log_spec.rb → log_spec.rb} +0 -0
  90. data/spec/roles_spec.rb +24 -0
  91. data/spec/spec_helper.rb +63 -78
  92. data/spec/ssl_spec.rb +3 -5
  93. data/spec/vendor/rest_client_spec.rb +0 -54
  94. data/test.sh +40 -0
  95. metadata +122 -281
  96. data/.kateproject +0 -5
  97. data/LICENSE +0 -22
  98. data/ci/test.sh +0 -9
  99. data/features/audit_resources.feature +0 -15
  100. data/features/audit_roles.feature +0 -15
  101. data/features/bootstrap.feature +0 -31
  102. data/features/step_definitions/cli_steps.rb +0 -5
  103. data/jenkins.sh +0 -27
  104. data/lib/conjur/acts_as_asset.rb +0 -88
  105. data/lib/conjur/annotations.rb +0 -186
  106. data/lib/conjur/api/audit.rb +0 -138
  107. data/lib/conjur/api/deputies.rb +0 -57
  108. data/lib/conjur/api/groups.rb +0 -111
  109. data/lib/conjur/api/hosts.rb +0 -109
  110. data/lib/conjur/api/info.rb +0 -126
  111. data/lib/conjur/api/layers.rb +0 -62
  112. data/lib/conjur/api/ldapsync.rb +0 -115
  113. data/lib/conjur/api/users.rb +0 -106
  114. data/lib/conjur/bootstrap.rb +0 -161
  115. data/lib/conjur/build_from_response.rb +0 -49
  116. data/lib/conjur/core-api.rb +0 -74
  117. data/lib/conjur/deputy.rb +0 -55
  118. data/lib/conjur/env.rb +0 -54
  119. data/lib/conjur/event_source.rb +0 -101
  120. data/lib/conjur/exists.rb +0 -60
  121. data/lib/conjur/graph.rb +0 -295
  122. data/lib/conjur/has_id.rb +0 -43
  123. data/lib/conjur/has_identifier.rb +0 -36
  124. data/lib/conjur/has_owner.rb +0 -51
  125. data/lib/conjur/host-factory-api.rb +0 -38
  126. data/lib/conjur/layer-api.rb +0 -13
  127. data/lib/conjur/ldap_sync_job.rb +0 -89
  128. data/lib/conjur/path_based.rb +0 -86
  129. data/lib/conjur/pubkeys-api.rb +0 -50
  130. data/lib/conjur/standard_methods.rb +0 -91
  131. data/reqspeed.rb +0 -20
  132. data/spec/api/authn_spec.rb +0 -81
  133. data/spec/api/graph_spec.rb +0 -117
  134. data/spec/api/groups_spec.rb +0 -40
  135. data/spec/api/hosts_spec.rb +0 -36
  136. data/spec/api/info_spec.rb +0 -89
  137. data/spec/api/layer_spec.rb +0 -18
  138. data/spec/api/ldapsync_spec.rb +0 -44
  139. data/spec/api/pubkeys_spec.rb +0 -66
  140. data/spec/api/resources_spec.rb +0 -92
  141. data/spec/api/roles_spec.rb +0 -100
  142. data/spec/api/secrets_spec.rb +0 -16
  143. data/spec/api/users_spec.rb +0 -71
  144. data/spec/api/variables_spec.rb +0 -112
  145. data/spec/cas_rest_client.rb +0 -17
  146. data/spec/cidr_helper.rb +0 -24
  147. data/spec/lib/acts_as_user_spec.rb +0 -27
  148. data/spec/lib/annotations_spec.rb +0 -109
  149. data/spec/lib/api_spec.rb +0 -480
  150. data/spec/lib/asset_spec.rb +0 -80
  151. data/spec/lib/audit_spec.rb +0 -155
  152. data/spec/lib/build_from_response_spec.rb +0 -49
  153. data/spec/lib/deputy_spec.rb +0 -25
  154. data/spec/lib/exists_spec.rb +0 -24
  155. data/spec/lib/group_spec.rb +0 -18
  156. data/spec/lib/host_spec.rb +0 -31
  157. data/spec/lib/resource_spec.rb +0 -240
  158. data/spec/lib/role_grant_spec.rb +0 -13
  159. data/spec/lib/role_spec.rb +0 -231
  160. data/spec/lib/standard_methods_spec.rb +0 -66
  161. data/spec/lib/user_spec.rb +0 -77
  162. data/spec/standard_methods_helper.rb +0 -41
  163. data/spec/variable_spec.rb +0 -101
  164. data/spec/vcr_cassettes/Conjur_Resource/_create/with_path-like_identifier.yml +0 -87
  165. data/spec/vcr_cassettes/Conjur_Resource/_create/with_un-encoded_path-like_identifier.yml +0 -87
  166. data/spec/vcr_cassettes/Conjur_Resource/_create/with_uuid_identifier.yml +0 -87
data/spec/lib/api_spec.rb DELETED
@@ -1,480 +0,0 @@
1
- require 'spec_helper'
2
- require 'fakefs/spec_helpers'
3
-
4
- shared_examples_for "API endpoint" do
5
- before { Conjur.configuration = Conjur::Configuration.new }
6
- subject { api }
7
- let(:service_name) { api.name.split('::')[-2].downcase }
8
- context "in development" do
9
- before(:each) do
10
- allow_any_instance_of(Conjur::Configuration).to receive(:env).and_return "development"
11
- end
12
-
13
- describe '#host' do
14
- subject { super().host }
15
- it do
16
- is_expected.to eq("http://localhost:#{Conjur.configuration.service_base_port + port_offset}")
17
- end
18
- end
19
- end
20
- context "'ci' account" do
21
- before {
22
- allow_any_instance_of(Conjur::Configuration).to receive(:account).and_return 'ci'
23
- }
24
- context "in stage" do
25
- before(:each) do
26
- allow_any_instance_of(Conjur::Configuration).to receive(:env).and_return "stage"
27
- end
28
-
29
- describe '#host' do
30
- subject { super().host }
31
- it do
32
- is_expected.to eq("https://#{service_name}-ci-conjur.herokuapp.com")
33
- end
34
- end
35
- end
36
- context "in ci" do
37
- before(:each) do
38
- allow_any_instance_of(Conjur::Configuration).to receive(:env).and_return "ci"
39
- end
40
-
41
- describe '#host' do
42
- subject { super().host }
43
- it do
44
- is_expected.to eq("https://#{service_name}-ci-conjur.herokuapp.com")
45
- end
46
- end
47
- end
48
- end
49
- end
50
-
51
- describe Conjur::API do
52
- describe "provides functions for id parsing" do
53
- describe "#parse_id(id, kind)" do
54
- subject { Conjur::API }
55
- let (:kind) { "sample-kind" }
56
-
57
- it "fails on non-string ids" do
58
- expect { subject.parse_id({}, kind) }.to raise_error /Unexpected class/
59
- end
60
-
61
- it "fails on malformed ids (<2 tokens)" do
62
- expect { subject.parse_id("foo", kind) }.to raise_error /Expecting at least two /
63
- expect { subject.parse_id("", kind) }.to raise_error /Expecting at least two /
64
- expect { subject.parse_id(nil, kind) }.to raise_error /Unexpected class/
65
- end
66
-
67
- describe "returns array of [account, kind, subkind, id]" do
68
- subject { Conjur::API.parse_id(id, kind) }
69
- def escaped smth ; Conjur::API.path_escape(smth) ; end
70
-
71
- context "for short id (2 tokens)" do
72
- let(:id) { "token#1:token#2" }
73
- let(:current_account) { "current_account" }
74
- before(:each) { allow(Conjur::Core::API).to receive(:conjur_account).and_return current_account }
75
-
76
- it "account: current account" do
77
- expect(subject[0]).to eq(current_account)
78
- end
79
-
80
- it "kind: passed kind" do
81
- expect(subject[1]).to eq(kind)
82
- end
83
-
84
- it "subkind: token #1 (escaped)" do
85
- expect(subject[2]).to eq(escaped("token#1"))
86
- end
87
-
88
- it "id: token #2 (escaped)" do
89
- expect(subject[3]).to eq(escaped("token#2"))
90
- end
91
- end
92
-
93
- context "for long ids (3+ tokens)" do
94
- let(:id) { "token#1:token#2:token#3:token#4" }
95
- it "account: token #1 (escaped)" do
96
- expect(subject[0]).to eq(escaped("token#1"))
97
- end
98
-
99
- it "kind: passed kind" do
100
- expect(subject[1]).to eq(kind)
101
- end
102
- it "subkind: token #2 (escaped)" do
103
- expect(subject[2]).to eq(escaped("token#2"))
104
- end
105
- it "id: tail of id starting from token#3" do
106
- expect(subject[3]).to eq(escaped("token#3:token#4"))
107
- end
108
- end
109
-
110
- end
111
- end
112
- describe "wrapper functions" do
113
- let(:result) { [:account,:kind,:id] }
114
- let(:id) { :input_id }
115
-
116
- it "#parse_role_id(id): calls parse_id(id, 'roles') and returns result" do
117
- expect(Conjur::API).to receive(:parse_id).with(id, 'roles').and_return(result)
118
- expect(Conjur::API.parse_role_id(id)).to eq(result)
119
- end
120
- it "#parse_resource_id(id): calls parse_id(id, 'resources') and returns result" do
121
- expect(Conjur::API).to receive(:parse_id).with(id, 'resources').and_return(result)
122
- expect(Conjur::API.parse_resource_id(id)).to eq(result)
123
- end
124
- end
125
- end
126
-
127
- context "host construction" do
128
- before { Conjur.configuration = Conjur::Configuration.new }
129
- context "of authn service" do
130
- let(:port_offset) { 0 }
131
- let(:api) { Conjur::Authn::API }
132
- it_should_behave_like "API endpoint"
133
- end
134
- context "of authz service" do
135
- let(:port_offset) { 100 }
136
- let(:api) { Conjur::Authz::API }
137
- subject { api }
138
- context "'ci' account" do
139
- before {
140
- allow_any_instance_of(Conjur::Configuration).to receive(:account).and_return 'ci'
141
- }
142
- context "in stage" do
143
- before(:each) do
144
- allow_any_instance_of(Conjur::Configuration).to receive(:env).and_return "stage"
145
- end
146
-
147
- describe '#host' do
148
- subject { super().host }
149
- it do
150
- is_expected.to eq("https://authz-stage-conjur.herokuapp.com")
151
- end
152
- end
153
- end
154
- context "in ci" do
155
- before(:each) do
156
- # Looks at "ENV['CONJUR_STACK']" first, stub this out
157
- allow(ENV).to receive(:[]).with('CONJUR_STACK').and_return nil
158
- allow_any_instance_of(Conjur::Configuration).to receive(:env).and_return "ci"
159
- end
160
-
161
- describe '#host' do
162
- subject { super().host }
163
- it do
164
- is_expected.to eq("https://authz-ci-conjur.herokuapp.com")
165
- end
166
- end
167
- end
168
- context "when ENV['CONJUR_STACK'] is set to 'v12'" do
169
- before do
170
- allow_any_instance_of(Conjur::Configuration).to receive(:stack).and_return "v12"
171
- allow_any_instance_of(Conjur::Configuration).to receive(:env).and_return "ci"
172
- end
173
-
174
- describe '#host' do
175
- subject { super().host }
176
- it { is_expected.to eq("https://authz-v12-conjur.herokuapp.com")}
177
- end
178
- end
179
- end
180
- context "in production" do
181
- before(:each) do
182
- allow_any_instance_of(Conjur::Configuration).to receive(:env).and_return "production"
183
- end
184
-
185
- describe '#host' do
186
- subject { super().host }
187
- it do
188
- is_expected.to eq("https://authz-v4-conjur.herokuapp.com")
189
- end
190
- end
191
- end
192
- context "in appliance" do
193
- before(:each) do
194
- allow_any_instance_of(Conjur::Configuration).to receive(:env).and_return "appliance"
195
- end
196
-
197
- describe '#host' do
198
- subject { super().host }
199
- it do
200
- is_expected.to eq("http://localhost:5100")
201
- end
202
- end
203
- end
204
- context "in named production version" do
205
- before(:each) do
206
- allow_any_instance_of(Conjur::Configuration).to receive(:env).and_return "production"
207
- allow_any_instance_of(Conjur::Configuration).to receive(:stack).and_return "waffle"
208
- end
209
-
210
- describe '#host' do
211
- subject { super().host }
212
- it do
213
- is_expected.to eq("https://authz-waffle-conjur.herokuapp.com")
214
- end
215
- end
216
- end
217
- end
218
- context "of core service" do
219
- let(:port_offset) { 200 }
220
- let(:api) { Conjur::Core::API }
221
- it_should_behave_like "API endpoint"
222
- end
223
- end
224
-
225
- shared_context "logged in", logged_in: true do
226
- let(:login) { "bob" }
227
- let(:token) { { 'data' => login, 'timestamp' => Time.now.to_s } }
228
- let(:remote_ip) { nil }
229
- let(:api_args) { [ token, remote_ip ].compact }
230
- subject(:api) { Conjur::API.new_from_token(*api_args) }
231
- let(:account) { 'some-account' }
232
- before { allow(Conjur::Core::API).to receive_messages conjur_account: account }
233
- end
234
-
235
- shared_context "logged in with an API key", logged_in: :api_key do
236
- include_context "logged in"
237
- let(:api_key) { "theapikey" }
238
- let(:api_args) { [ login, api_key, remote_ip ].compact }
239
- subject(:api) { Conjur::API.new_from_key(*api_args) }
240
- end
241
-
242
- shared_context "logged in with a token file", logged_in: :token_file do
243
- include FakeFS::SpecHelpers
244
- include_context "logged in"
245
- let(:token_file) { "token_file" }
246
- let(:api_args) { [ token_file, remote_ip ].compact }
247
- subject(:api) { Conjur::API.new_from_token_file(*api_args) }
248
- end
249
-
250
- def time_travel delta
251
- allow(api.authenticator).to receive(:gettime).and_wrap_original do |m|
252
- m[] + delta
253
- end
254
- allow(api.authenticator).to receive(:monotonic_time).and_wrap_original do |m|
255
- m[] + delta
256
- end
257
- allow(Time).to receive(:now).and_wrap_original do |m|
258
- m[] + delta
259
- end
260
- end
261
-
262
- describe '#token' do
263
- context 'with token file available', logged_in: :token_file do
264
- def write_token token
265
- File.write token_file, JSON.generate(token)
266
- end
267
-
268
- before do
269
- write_token token
270
- end
271
-
272
- it "reads the file to get a token" do
273
- expect(api.instance_variable_get("@token")).to eq(nil)
274
- expect(api.token).to eq(token)
275
- expect(api.credentials).to eq({ headers: { authorization: "Token token=\"#{Base64.strict_encode64(token.to_json)}\"" }, username: login })
276
- end
277
-
278
- context "after expiration" do
279
- it 'it reads a new token' do
280
- expect(Time.parse(api.token['timestamp'])).to be_within(5.seconds).of(Time.now)
281
-
282
- time_travel 6.minutes
283
- new_token = token.merge "timestamp" => Time.now.to_s
284
- write_token new_token
285
-
286
- expect(api.token).to eq(new_token)
287
- end
288
- end
289
- end
290
-
291
- context 'with API key available', logged_in: :api_key do
292
- it "authenticates to get a token" do
293
- expect(Conjur::API).to receive(:authenticate).with(login, api_key).and_return token
294
-
295
- expect(api.instance_variable_get("@token")).to eq(nil)
296
- expect(api.token).to eq(token)
297
- expect(api.credentials).to eq({ headers: { authorization: "Token token=\"#{Base64.strict_encode64(token.to_json)}\"" }, username: login })
298
- end
299
-
300
- context "after expiration" do
301
-
302
- shared_examples "it gets a new token" do
303
- it 'by refreshing' do
304
- allow(Conjur::API).to receive(:authenticate).with(login, api_key).and_return token
305
- expect(Time.parse(api.token['timestamp'])).to be_within(5.seconds).of(Time.now)
306
-
307
- time_travel 6.minutes
308
- new_token = token.merge "timestamp" => Time.now.to_s
309
-
310
- expect(Conjur::API).to receive(:authenticate).with(login, api_key).and_return new_token
311
- expect(api.token).to eq(new_token)
312
- end
313
- end
314
-
315
- it_should_behave_like "it gets a new token"
316
-
317
- context "with elevated privilege" do
318
- subject(:api) { Conjur::API.new_from_key(*api_args).with_privilege('reveal') }
319
- it_should_behave_like "it gets a new token"
320
- end
321
-
322
- context "with audit roles" do
323
- subject(:api) { Conjur::API.new_from_key(*api_args).with_audit_roles('account:host:host1') }
324
- it_should_behave_like "it gets a new token"
325
- end
326
-
327
- context "with audit resources" do
328
- subject(:api) { Conjur::API.new_from_key(*api_args).with_audit_resources('account:webservice:service1') }
329
- it_should_behave_like "it gets a new token"
330
- end
331
-
332
- end
333
- end
334
-
335
- context 'with no API key available', logged_in: true do
336
- it "returns the token used to create it" do
337
- expect(api.token).to eq token
338
- end
339
-
340
- it "doesn't try to refresh an old token" do
341
- expect(Conjur::API).not_to receive :authenticate
342
- api.token # vivify
343
- time_travel 6.minutes
344
- expect { api.token }.not_to raise_error
345
- end
346
- end
347
- end
348
-
349
- context "credential handling", logged_in: true do
350
- context "from token" do
351
- describe '#credentials' do
352
- subject { super().credentials }
353
- it { is_expected.to eq({ headers: { authorization: "Token token=\"#{Base64.strict_encode64(token.to_json)}\"" }, username: login }) }
354
- end
355
-
356
- describe "privileged" do
357
- describe '#credentials' do
358
- subject { super().with_privilege('elevate').credentials }
359
- it { is_expected.to eq({ headers: { authorization: "Token token=\"#{Base64.strict_encode64(token.to_json)}\"", :x_conjur_privilege=>"elevate" }, username: login }) }
360
- end
361
- end
362
-
363
- context "with remote_ip" do
364
- let(:remote_ip) { "66.0.0.1" }
365
- describe '#credentials' do
366
- subject { super().credentials }
367
- it { is_expected.to eq({ headers: { authorization: "Token token=\"#{Base64.strict_encode64(token.to_json)}\"", :x_forwarded_for=>"66.0.0.1" }, username: login }) }
368
- end
369
- end
370
- end
371
-
372
- context "from logged-in RestClient::Resource" do
373
- let (:authz_header) { %Q{Token token="#{token_encoded}"} }
374
- let (:priv_header) { nil }
375
- let (:forwarded_for_header) { nil }
376
- let (:audit_roles_header) { nil }
377
- let (:audit_resources_header) { nil }
378
- let (:username) { 'bob' }
379
- subject { resource.conjur_api }
380
-
381
- shared_examples "it can clone itself" do
382
- it "has the authz header" do
383
- expect(subject.credentials[:headers][:authorization]).to eq(authz_header)
384
- end
385
- it "has the conjur privilege header" do
386
- expect(subject.credentials[:headers][:x_conjur_privilege]).to eq(priv_header)
387
- end
388
- it "has the forwarded for header" do
389
- expect(subject.credentials[:headers][:x_forwarded_for]).to eq(forwarded_for_header)
390
- end
391
- it "has the audit_roles header" do
392
- expect(subject.credentials[:headers][:conjur_audit_roles]).to eq(audit_roles_header)
393
- end
394
- it "has the audit_resources header" do
395
- expect(subject.credentials[:headers][:conjur_audit_resources]).to eq(audit_resources_header)
396
- end
397
- it "has the username" do
398
- expect(subject.credentials[:username]).to eq(username)
399
- end
400
- end
401
-
402
- let(:token_encoded) { Base64.strict_encode64(token.to_json) }
403
- let(:base_headers) { { authorization: authz_header } }
404
- let(:headers) { base_headers }
405
- let(:resource) { RestClient::Resource.new("http://example.com", { headers: headers })}
406
- context 'basic functioning' do
407
- it_behaves_like 'it can clone itself'
408
- end
409
-
410
- context "privileged" do
411
- let(:priv_header) { 'elevate' }
412
- let(:headers) { base_headers.merge(x_conjur_privilege: priv_header) }
413
- it_behaves_like "it can clone itself"
414
- end
415
-
416
- context "forwarded for" do
417
- let(:forwarded_for_header) { "66.0.0.1" }
418
- let(:headers) { base_headers.merge(x_forwarded_for: forwarded_for_header) }
419
- it_behaves_like 'it can clone itself'
420
- end
421
-
422
- context "audit roles" do
423
- let(:audit_roles_header) { Conjur::API.encode_audit_ids(['account:kind:role1', 'account:kind:role2']) }
424
- let(:headers) { base_headers.merge(:conjur_audit_roles => audit_roles_header) }
425
- it_behaves_like 'it can clone itself'
426
- end
427
-
428
- context "audit resources" do
429
- let(:audit_resources_header) { Conjur::API.encode_audit_ids(['account:kind:resource1', 'account:kind:resource2']) }
430
- let(:headers) { base_headers.merge(:conjur_audit_resources => audit_resources_header) }
431
- it_behaves_like 'it can clone itself'
432
- end
433
-
434
- end
435
- end
436
-
437
- describe "#role_from_username", logged_in: true do
438
- it "returns a user role when username is plain" do
439
- expect(api.role_from_username("plain-username").roleid).to eq("#{account}:user:plain-username")
440
- end
441
-
442
- it "returns an appropriate role kind when username is qualified" do
443
- expect(api.role_from_username("host/foo/bar").roleid).to eq("#{account}:host:foo/bar")
444
- end
445
- end
446
-
447
- describe "#current_role", logged_in: true do
448
- context "when logged in as user" do
449
- let(:login) { 'joerandom' }
450
- it "returns a user role" do
451
- expect(api.current_role.roleid).to eq("#{account}:user:joerandom")
452
- end
453
- end
454
-
455
- context "when logged in as host" do
456
- let(:host) { "somehost" }
457
- let(:login) { "host/#{host}" }
458
- it "returns a host role" do
459
- expect(api.current_role.roleid).to eq("#{account}:host:somehost")
460
- end
461
- end
462
- end
463
-
464
- describe 'url escapes' do
465
- let(:urls){[
466
- 'foo/bar@baz',
467
- '/test/some group with spaces'
468
- ]}
469
-
470
- describe '#fully_escape' do
471
- let(:expected){[
472
- 'foo%2Fbar%40baz',
473
- '%2Ftest%2Fsome%20group%20with%20spaces'
474
- ]}
475
- it 'escapes the urls correctly' do
476
- expect(urls.map{|u| Conjur::API.fully_escape u}).to eq(expected)
477
- end
478
- end
479
- end
480
- end
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::ActsAsAsset do
4
- let(:asset) { Object.new }
5
- before {
6
- class << asset
7
- include Conjur::ActsAsAsset
8
-
9
- def options
10
- OPTIONS
11
- end
12
- end
13
- }
14
- let(:invoke) {
15
- send action
16
- }
17
- let(:add_member) {
18
- asset.add_member ROLE, MEMBER, OPTIONS
19
- }
20
- let(:remove_member) {
21
- asset.remove_member ROLE, MEMBER
22
- }
23
-
24
- shared_context "asset with role" do
25
- before(:each) {
26
- allow(asset).to receive(:core_conjur_account).and_return(ACCOUNT)
27
- allow(asset).to receive(:resource_kind).and_return(KIND)
28
- allow(asset).to receive(:resource_id).and_return(ID)
29
- allow(Conjur::Role).to receive(:new).and_return(role_base)
30
- }
31
- let(:role_base) {
32
- double(:"[]" => role_instance)
33
- }
34
- let(:role_instance) {
35
- double(grant_to: true, revoke_from: true)
36
- }
37
- end
38
-
39
- shared_examples_for "it obtains role via asset" do
40
- it "account=asset.core_conjur_account" do
41
- expect(asset).to receive(:core_conjur_account)
42
- invoke
43
- end
44
- it "kind=asset.resource_kind" do
45
- expect(asset).to receive(:resource_kind)
46
- invoke
47
- end
48
- it "id=asset.resource_id" do
49
- expect(asset).to receive(:resource_id)
50
- invoke
51
- end
52
-
53
- it "obtains role as #{ACCOUNT}:@:#{KIND}/#{ID}/#{ROLE}" do
54
- expect(Conjur::Role).to receive(:new).with("http://localhost:5100", {}).and_return role_base
55
- expect(role_base).to receive(:[]).with("#{CGI.escape ACCOUNT}/roles/@/#{KIND}/#{ID}/#{CGI.escape ROLE}").and_return role_instance
56
-
57
- invoke
58
- end
59
- end
60
-
61
- describe "#add_member" do
62
- let(:action) { :add_member }
63
- include_context "asset with role"
64
- it_behaves_like "it obtains role via asset"
65
- it 'calls role.grant_to(member,...)' do
66
- expect(role_instance).to receive(:grant_to).with(MEMBER, anything)
67
- invoke
68
- end
69
- end
70
-
71
- describe "#remove_member" do
72
- let(:action) { :remove_member }
73
- include_context "asset with role"
74
- it_behaves_like "it obtains role via asset"
75
- it 'calls role.revoke_from(member)' do
76
- expect(role_instance).to receive(:revoke_from).with(MEMBER)
77
- invoke
78
- end
79
- end
80
- end