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
@@ -1,155 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::API, api: :dummy do
4
- describe "audit API methods" do
5
-
6
- let(:options){ {since:Time.at(0).to_s, till: Time.now.to_s, :has_annotation => 'puppet', some_unwanted_option: 'heloo!'} }
7
- let(:expected_options){ options.slice(:since, :till, :has_annotation) }
8
- let(:response){ ['some event'] }
9
- let(:include_options){ false }
10
- let(:query){ include_options ? '?' + expected_options.to_query : '' }
11
- let(:expected_path){ nil }
12
- let(:expected_url){ "#{Conjur::Audit::API.host}/#{expected_path}#{query}" }
13
-
14
- def expect_json_request
15
- expect_request(
16
- headers: credentials[:headers],
17
- url: expected_url,
18
- method: :get
19
- ).and_return response.to_json
20
- end
21
-
22
-
23
- describe "#audit" do
24
- let(:expected_path){ '' }
25
- let(:args){ [] }
26
- let(:full_args){ include_options ? args + [options] : args }
27
-
28
- shared_examples_for "gets all visible events" do
29
- it "GETs /" do
30
- expect_json_request
31
- expect(api.audit(*full_args)).to eq(response)
32
- end
33
- end
34
-
35
- context "when called without options" do
36
- let(:include_options){ false }
37
- it_behaves_like "gets all visible events"
38
- end
39
-
40
- context "when called with all options" do
41
- let(:include_options){ true }
42
- it_behaves_like "gets all visible events"
43
- end
44
- end
45
-
46
- describe "#audit_role" do
47
- let(:role_id){ 'acct:user:foobar' }
48
- let(:role){ double('role', roleid: role_id) }
49
- let(:expected_path){ "roles/#{CGI.escape role_id}" }
50
- let(:args){ [role_id] }
51
- let(:full_args){ include_options ? args + [options] : args }
52
- shared_examples_for "gets roles feed" do
53
- it "GETs roles/:role_id" do
54
- expect_json_request
55
- expect(api.audit_role(*full_args)).to eq(response)
56
- end
57
- end
58
-
59
- context "when called with a role id" do
60
- let(:args){ [role_id] }
61
- it_behaves_like "gets roles feed"
62
- end
63
-
64
- context "when called with a role instance" do
65
- let(:audit_role_args){ [role] }
66
- it_behaves_like "gets roles feed"
67
- end
68
-
69
- context "when called with all options" do
70
- let(:include_options){ true }
71
- let(:args){ [ role_id ] }
72
- it_behaves_like "gets roles feed"
73
- end
74
- end
75
-
76
-
77
- describe "#audit_resource" do
78
- let(:resource_id){ 'acct:food:bacon' }
79
- let(:resource){ double('resource', resourceid: resource_id) }
80
- let(:expected_path){ "resources/#{CGI.escape resource_id}" }
81
- let(:args){[resource_id]}
82
- let(:full_args){ include_options ? args + [options] : args }
83
- shared_examples_for "gets the resource feed" do
84
- it "GETS resources/:resource_id" do
85
- expect_json_request
86
- expect(api.audit_resource(*full_args)).to eq(response)
87
- end
88
- end
89
-
90
- context "when called with resource id" do
91
- let(:args){ [resource_id] }
92
- it_behaves_like "gets the resource feed"
93
- end
94
-
95
- context "when called with resource instance" do
96
- let(:args){ [resource] }
97
- it_behaves_like "gets the resource feed"
98
- end
99
-
100
- context "when called with all options" do
101
- let(:include_options) { true }
102
- it_behaves_like "gets the resource feed"
103
- end
104
- end
105
-
106
- describe "#audit_send" do
107
- let(:username) { "user" }
108
- let(:api){ Conjur::API.new_from_key username, 'key' }
109
- let(:credentials) { { headers: { authorization: "Token token=\"stub\"" } } } #, username: username } }
110
-
111
- before do
112
- allow(api).to receive_messages credentials: credentials
113
- end
114
-
115
- context "valid input" do
116
- let(:http_parameters) {
117
- {
118
- headers: credentials[:headers].merge(content_type: "text/plain"),
119
- method: :post ,
120
- url: "#{Conjur::Authz::API.host}/audit"
121
- }
122
- }
123
-
124
- it "sends Hash as JSON" do
125
- event = { action: "login", user: "alice" }
126
- expect(RestClient::Request).to receive(:execute).with(
127
- http_parameters.merge( payload: event.to_json )
128
- )
129
- api.audit_send event
130
- end
131
- it "sends array as JSON" do
132
- events = [ { action: "login", user: "alice" }, { action: "sudo", user: "alice" } ]
133
- expect(RestClient::Request).to receive(:execute).with(
134
- http_parameters.merge( payload: events.to_json )
135
- )
136
- api.audit_send events
137
- end
138
-
139
- it "sends string as is (consider it preformatted JSON)" do
140
- events_serialized = "this is supposed to be JSON"
141
- expect(RestClient::Request).to receive(:execute).with(
142
- http_parameters.merge( payload: events_serialized )
143
- )
144
- api.audit_send events_serialized
145
- end
146
- end
147
-
148
- it "rejects any other types of arguments" do
149
- expect { api.audit_send( api ) }.to raise_error(ArgumentError)
150
- end
151
-
152
- end
153
- end
154
- end
155
-
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::BuildFromResponse do
4
- describe "::build_from_response", logging: :temp do
5
- let(:location) { "http://example.com" }
6
- let(:attrs) {{ 'some' => 'foo', 'other' => 'bar' }}
7
- let(:response) do
8
- double "response", headers: { location: location }, body: attrs.to_json
9
- end
10
- subject { double "class", name: 'some' }
11
- let(:constructed) { double "object" }
12
- let(:credentials) { "whatever" }
13
-
14
- before do
15
- subject.extend Conjur::BuildFromResponse
16
- expect(subject).to receive(:new).with(location, credentials).and_return constructed
17
- expect(constructed).to receive(:attributes=).with attrs
18
-
19
- constructed.extend Conjur::LogSource
20
- allow(constructed).to receive_messages username: 'whatever'
21
- end
22
-
23
- it "passes the location credentials and attributes" do
24
- subject.build_from_response response, credentials
25
- end
26
-
27
- context "with a resource(-ish) class" do
28
- before do
29
- allow(constructed).to receive_messages resource_kind: 'chunky', resource_id: 'bacon'
30
- end
31
-
32
- it "logs creation correctly" do
33
- subject.build_from_response response, credentials
34
- expect(log).to match(/Created chunky bacon/)
35
- end
36
- end
37
-
38
- context "with a id(-ish) class" do
39
- before do
40
- allow(constructed).to receive_messages id: 'bacon'
41
- end
42
-
43
- it "logs creation correctly" do
44
- subject.build_from_response response, credentials
45
- expect(log).to match(/Created some bacon/)
46
- end
47
- end
48
- end
49
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Deputy, api: :dummy do
4
- let(:api_key) { 'theapikey' }
5
-
6
- subject(:deputy) { Conjur::Deputy.new 'http://example.com/deputies/my%2Fhostname', nil }
7
- before { deputy.attributes = { 'api_key' => api_key } }
8
-
9
- describe '#resource' do
10
- subject { deputy.resource }
11
- it { is_expected.to be }
12
- end
13
-
14
- describe '#login' do
15
- it "is extracted from the uri" do
16
- expect(deputy.login).to eq('deputy/my/hostname')
17
- end
18
- end
19
-
20
- describe '#api_key' do
21
- it "is extracted from attributes" do
22
- expect(deputy.api_key).to eq api_key
23
- end
24
- end
25
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Exists do
4
- subject(:resource) { Object.new.tap {|o| o.send :extend, Conjur::Exists } }
5
-
6
- describe '#exists?' do
7
- subject { resource.exists? }
8
-
9
- context "when head returns 200" do
10
- before { allow(resource).to receive_messages head: "" }
11
- it { is_expected.to be_truthy }
12
- end
13
-
14
- context "when forbidden" do
15
- before { allow(resource).to receive(:head) { raise RestClient::Forbidden }}
16
- it { is_expected.to be_truthy }
17
- end
18
-
19
- context "when not found" do
20
- before { allow(resource).to receive(:head) { raise RestClient::ResourceNotFound }}
21
- it { is_expected.to be_falsey }
22
- end
23
- end
24
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Group, api: :dummy do
4
- let(:id) { 'the-anonymous' }
5
- subject { api.group id }
6
-
7
- describe '#update' do
8
- it "PUTs to /groups/:id" do
9
- expect_request(
10
- method: :put,
11
- url: "#{core_host}/groups/#{api.fully_escape(id)}",
12
- headers: credentials[:headers],
13
- payload: { gidnumber: 12345 }
14
- )
15
- api.group(id).update(gidnumber: 12345)
16
- end
17
- end
18
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Host, api: :dummy do
4
- subject(:host) { Conjur::Host.new 'http://example.com/hosts/my%2Fhostname', nil }
5
-
6
- describe '#resource' do
7
- subject { super().resource }
8
- it { is_expected.to be }
9
- end
10
-
11
- describe '#login' do
12
- subject { super().login }
13
- it { is_expected.to eq('host/my/hostname') }
14
- end
15
-
16
- it "fetches enrollment_url" do
17
- stub_request(:head, "http://example.com/hosts/my%2Fhostname/enrollment_url").
18
- to_return(:status => 200, :headers => {location: 'foo'})
19
- expect(subject.enrollment_url).to eq('foo')
20
- end
21
-
22
- describe '#update' do
23
- it "calls set_cidr_restrictions if given CIDR" do
24
- expect(host).to receive(:set_cidr_restrictions).with(['192.0.2.0/24'])
25
- host.update cidr: ['192.0.2.0/24']
26
-
27
- expect(host).to_not receive(:set_cidr_restrictions)
28
- host.update foo: 42
29
- end
30
- end
31
- end
@@ -1,240 +0,0 @@
1
- require 'spec_helper'
2
- require 'helpers/request_helpers'
3
-
4
- describe Conjur::Resource, api: :dummy, logging: :temp do
5
- include RequestHelpers
6
-
7
- let(:account) { "the-account" }
8
- let(:uuid) { "ddd1f59a-494d-48fb-b045-0374c4a6eef9" }
9
-
10
- context "identifier" do
11
- include Conjur::Escape
12
- let(:resource) { Conjur::Resource.new("#{Conjur::Authz::API.host}/#{account}/resources/#{kind}/#{path_escape identifier}") }
13
-
14
- context "Object with an #id" do
15
- let(:kind) { "host" }
16
- let(:identifier) do
17
- "foobar"
18
- end
19
- it "identifier should obtained from the id" do
20
- expect(resource.identifier).to eq("foobar")
21
- end
22
- end
23
-
24
- [ [ "foo", "bar/baz" ], [ "f:o", "bar" ], [ "@f", "bar.baz" ], [ "@f", "bar baz" ], [ "@f", "@:bar/baz" ] ].each do |p|
25
- context "of /#{p[0]}/#{p[1]}" do
26
- let(:kind) { p[0] }
27
- let(:identifier) { p[1] }
28
- context "resource_kind" do
29
- subject { resource.kind }
30
- specify { is_expected.to eq(p[0]) }
31
- end
32
- context "resource_id" do
33
- subject { resource.identifier }
34
- specify { is_expected.to eq( p[1] ) }
35
- end
36
- end
37
- end
38
- end
39
-
40
- let(:uri) { "#{authz_host}/some-account/resources/the-kind/resource-id" }
41
- subject { Conjur::Resource.new uri }
42
-
43
- describe '#create' do
44
- it "simply puts" do
45
- expect_request(
46
- method: :put,
47
- url: uri,
48
- payload: {},
49
- headers: {}
50
- ).and_return "new resource"
51
- expect(subject.create).to eq("new resource")
52
- end
53
- end
54
-
55
- describe '#permitted_roles' do
56
- it 'gets the list from /roles/allowed_to' do
57
- expect_request(
58
- method: :get,
59
- url: "http://authz.example.com/some-account/roles/allowed_to/nuke/the-kind/resource-id",
60
- headers: {}
61
- ).and_return '["foo", "bar"]'
62
-
63
- expect(subject.permitted_roles("nuke")).to eq(['foo', 'bar'])
64
- end
65
-
66
- it 'supports counting' do
67
- expect_request(
68
- method: :get,
69
- url: "http://authz.example.com/some-account/roles/allowed_to/nuke/the-kind/resource-id?count=true",
70
- headers: {}
71
- ).and_return({count: 12}.to_json)
72
-
73
- expect(subject.permitted_roles("nuke", count: true)).to eq(12)
74
- end
75
-
76
- it 'supports filtering' do
77
- expect_request(
78
- method: :get,
79
- url: "http://authz.example.com/some-account/roles/allowed_to/nuke/the-kind/resource-id?search=hamsters",
80
- headers: {}
81
- ).and_return '["foo", "bar"]'
82
-
83
- expect(subject.permitted_roles("nuke", search: 'hamsters')).to eq(['foo', 'bar'])
84
- end
85
- end
86
-
87
- describe '#give_to' do
88
- it "puts the owner field" do
89
- expect_request(
90
- method: :put,
91
- url: uri,
92
- payload: {owner: 'new-owner' },
93
- headers: {}
94
- )
95
-
96
- subject.give_to 'new-owner'
97
- end
98
- end
99
-
100
- describe '#delete' do
101
- it 'simply deletes' do
102
- expect_request(
103
- method: :delete,
104
- url: uri,
105
- headers: {}
106
- )
107
-
108
- subject.delete
109
- end
110
- end
111
-
112
- describe '#permit' do
113
- it 'posts permit for every privilege' do
114
- privileges = [:nuke, :fry]
115
- privileges.each do |p|
116
- expect_request(
117
- method: :post,
118
- url: uri + "/?permit&privilege=#{p}&role=dr-strangelove",
119
- headers: {},
120
- payload: {}
121
- )
122
- end
123
- subject.permit privileges, "dr-strangelove"
124
- end
125
- end
126
-
127
- describe '#deny' do
128
- it 'posts deny for every privilege' do
129
- privileges = [:nuke, :fry]
130
- privileges.each do |p|
131
- expect_request(
132
- method: :post,
133
- url: uri + "/?deny&privilege=#{p}&role=james-bond",
134
- headers: {},
135
- payload: {}
136
- )
137
- end
138
- subject.deny privileges, "james-bond"
139
- end
140
- end
141
-
142
- describe '#permitted?' do
143
- it 'gets the ?permitted? action' do
144
- expect_request(
145
- method: :get,
146
- url: uri + "/?check=true&privilege=fry",
147
- headers: {}
148
- )
149
- subject.permitted? 'fry'
150
- end
151
- context "with status 204" do
152
- before {
153
- allow(subject).to receive_message_chain(:[], :get)
154
- }
155
- specify {
156
- expect(subject.permitted?('fry')).to be_truthy
157
- }
158
- end
159
- context "with status 404" do
160
- before {
161
- allow(subject).to receive_message_chain(:[], :get) { raise RestClient::ResourceNotFound }
162
- }
163
- specify {
164
- expect(subject.permitted?('fry')).to be_falsey
165
- }
166
- end
167
- context "with status 403" do
168
- before {
169
- allow(subject).to receive_message_chain(:[], :get) { raise RestClient::Forbidden }
170
- }
171
- specify {
172
- expect(subject.permitted?('fry')).to be_falsey
173
- }
174
- end
175
- end
176
-
177
- describe '.all' do
178
- it "calls /account/resources" do
179
- expect_request(
180
- method: :get,
181
- url: "http://authz.example.com/the-account/resources/",
182
- headers: {}
183
- ).and_return '["foo", "bar"]'
184
-
185
- expect(Conjur::Resource.all host: authz_host, account: account).to eql(%w(foo bar))
186
- end
187
-
188
- it "can filter by owner" do
189
- expect_request(
190
- method: :get,
191
- url: "http://authz.example.com/the-account/resources/chunky/?owner=alice",
192
- headers: {}
193
- ).and_return '["foo", "bar"]'
194
-
195
- expect(Conjur::Resource.all host: authz_host, account: account, kind: :chunky, owner: 'alice')
196
- .to eql(%w(foo bar))
197
- end
198
-
199
- it "can filter by kind" do
200
- expect_request(
201
- method: :get,
202
- url: "http://authz.example.com/the-account/resources/chunky/",
203
- headers: {}
204
- ).and_return '["foo", "bar"]'
205
-
206
- expect(Conjur::Resource.all host: authz_host, account: account, kind: :chunky)
207
- .to eql(%w(foo bar))
208
- end
209
-
210
- it "can count" do
211
- expect_request(
212
- method: :get,
213
- url: "http://authz.example.com/the-account/resources/?count=true",
214
- headers: {}
215
- ).and_return({count: 12}.to_json)
216
-
217
- expect(Conjur::Resource.all host: authz_host, account: account, count: true).to eq(12)
218
- end
219
-
220
- it "passes search, limit, and offset params" do
221
- expect_request(
222
- method: :get,
223
- # Note that to_query sorts the keys
224
- url: "http://authz.example.com/the-account/resources/?limit=5&offset=6&search=something",
225
- headers: {}
226
- ).and_return '["foo", "bar"]'
227
- expect(Conjur::Resource.all(host: authz_host, account: account, search: 'something', limit:5, offset:6)).to eq(%w(foo bar))
228
- end
229
-
230
- it "uses the given authz url" do
231
- expect_request(
232
- method: :get,
233
- url: "http://otherhost.example.com/the-account/resources/",
234
- headers: {}
235
- ).and_return '["foo", "bar"]'
236
-
237
- Conjur::Resource.all host: 'http://otherhost.example.com', account: account
238
- end
239
- end
240
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::RoleGrant, api: :dummy do
4
- describe '::parse_from_json' do
5
- it "creates role, member and grantor roles" do
6
- rg = Conjur::RoleGrant::parse_from_json({role: 'acc:k:r', member: 'acc:k:m', grantor: 'acc:k:g', admin_option: true}.stringify_keys, {})
7
- expect(rg.role.url).to eq("#{authz_host}/acc/roles/k/r")
8
- expect(rg.member.url).to eq("#{authz_host}/acc/roles/k/m")
9
- expect(rg.grantor.url).to eq("#{authz_host}/acc/roles/k/g")
10
- expect(rg.admin_option).to eq(true)
11
- end
12
- end
13
- end