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,50 +0,0 @@
1
- #
2
- # Copyright (C) 2013 Conjur Inc
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- # this software and associated documentation files (the "Software"), to deal in
6
- # the Software without restriction, including without limitation the rights to
7
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
- # the Software, and to permit persons to whom the Software is furnished to do so,
9
- # subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- #
21
- require 'conjur/api'
22
- require 'conjur/configuration'
23
-
24
- class Conjur::Configuration
25
- # @!attribute pubkeys_url
26
- # The url for the {http://developer.conjur.net/reference/services/pubkyes Conjur public keys service}.
27
- #
28
- # @note You should not generally set this value. Instead, Conjur will derive it from the
29
- # {Conjur::Configuration#account} and {Conjur::Configuration#appliance_url}
30
- # properties.
31
- #
32
- # @return [String] the pubkeys service url
33
- add_option :pubkeys_url do
34
- account_service_url 'pubkeys', 400
35
- end
36
- end
37
-
38
- class Conjur::API
39
- class << self
40
- # @api private
41
- #
42
- # Url to the pubkeys service.
43
- # @return [String] the url
44
- def pubkeys_asset_host
45
- Conjur.configuration.pubkeys_url
46
- end
47
- end
48
- end
49
-
50
- require 'conjur/api/pubkeys'
@@ -1,91 +0,0 @@
1
- #
2
- # Copyright (C) 2013 Conjur Inc
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- # this software and associated documentation files (the "Software"), to deal in
6
- # the Software without restriction, including without limitation the rights to
7
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
- # the Software, and to permit persons to whom the Software is furnished to do so,
9
- # subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- #
21
-
22
- require 'active_support/dependencies/autoload'
23
- require 'active_support/core_ext'
24
-
25
- module Conjur
26
- # @api private
27
- # This module provides a number of "standard" `REST` helpers,
28
- # to wit, create, list and show.
29
- module StandardMethods
30
-
31
- protected
32
-
33
- # @api private
34
- #
35
- # Create this resource by sending a POST request to its URL.
36
- #
37
- # @param [String] host the url of the service (for example, https://conjur.host.com/api)
38
- # @param [String] type the asset `kind` (for example, 'user', 'group')
39
- # @param [String, nil] id the id of the new asset
40
- # @param [Hash] options options to pass through to `RestClient::Resource`'s `post` method.
41
- # @return [Object] an instance of a class determined by `type`. For example, if `type` is
42
- # `'user'`, the class will be `Conjur::User`.
43
- def standard_create(host, type, id = nil, options = nil)
44
- log do |logger|
45
- logger << "Creating #{type}"
46
- logger << " #{id}" if id
47
- unless options.blank?
48
- logger << " with options #{options.to_json}"
49
- end
50
- end
51
- options ||= {}
52
- options[:id] = id if id
53
- resp = RestClient::Resource.new(host, credentials)[type.to_s.pluralize].post(options)
54
- "Conjur::#{type.to_s.classify}".constantize.build_from_response(resp, credentials)
55
- end
56
-
57
- # @api private
58
- #
59
- # Fetch a list of assets by sending a GET request to the URL for resources of the given `type`.
60
- #
61
- # @param [String] host the url of the service (for example, https://conjur.host.com/api)
62
- # @param [String] type the asset `kind` (for example, 'user', 'group')
63
- # @param [Hash] options options to pass through to `RestClient::Resource`'s `post` method.
64
- # @return [Array<Object>] an array of instances of the asset class determined by `type`. For example, if
65
- # `type` is `'group'`, and array of `Conjur::Group` instances will be returned.
66
- def standard_list(host, type, options)
67
- JSON.parse(RestClient::Resource.new(host, credentials)[type.to_s.pluralize].get(options)).collect do |item|
68
- # Note that we don't want to fully_escape the ids below -- methods like #layer, #host, etc don't expect
69
- # ids to be escaped, and will escape them again!.
70
- if item.is_a? String # lists w/o details are just list of ids
71
- send(type,item)
72
- else # list w/ details consists of hashes
73
- send(type, item['id']).tap { |obj| obj.attributes=item }
74
- end
75
- end
76
- end
77
-
78
- # @api private
79
- #
80
- # Fetch details of an asset by sending a GET request to its URL.
81
- #
82
- # @param [String] host the url of the service (for example, https://conjur.host.com/api)
83
- # @param [String] type the asset `kind` (for example, 'user', 'group')
84
- # @param [String, nil] id the id of the asset to show
85
- # @return [Object] an instance of a class determined by `type`. For example, if `type` is
86
- # `'user'`, the class will be `Conjur::User`.
87
- def standard_show(host, type, id)
88
- "Conjur::#{type.to_s.classify}".constantize.new(host, credentials)[ [type.to_s.pluralize, fully_escape(id)].join('/') ]
89
- end
90
- end
91
- end
data/reqspeed.rb DELETED
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # a hackish script to gauge the time it takes to load various components
3
-
4
- $require_level = 0
5
- alias :orig_require :require
6
- def require(file)
7
- rl = $require_level
8
- r0 = Time.now
9
- $require_level += 1
10
- r = orig_require(file)
11
- $require_level -=1
12
- c = caller[0][/.*?:[^:]+/]
13
- c = '' unless c =~ /conjur/
14
- printf "%5.02f %s %s %s\n", Time.now - r0, '-' * rl, file, c + (r ? '' : ' (already required)')
15
- r
16
- end
17
-
18
- #$:.prepend 'lib'
19
-
20
- require ARGV.first
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
- require 'cas_rest_client'
3
- require 'helpers/request_helpers'
4
-
5
- describe Conjur::API do
6
- include RequestHelpers
7
-
8
- let(:host) { 'http://authn.example.com' }
9
- let(:user) { 'kmitnick' }
10
- let(:password) { 'sikret' }
11
-
12
- before do
13
- allow(Conjur::Authn::API).to receive_messages host: host
14
- end
15
-
16
- describe "::login" do
17
- it "gets /users/login" do
18
- expect_request(
19
- method: :get, url: "http://authn.example.com/users/login",
20
- user: user,
21
- password: password,
22
- headers: {}
23
- ).and_return(response = double)
24
- expect(Conjur::API::login(user, password)).to eq(response)
25
- end
26
- end
27
-
28
- describe "::login_cas" do
29
- let(:response) { "response body" }
30
- let(:cas_uri) { 'http://cas.example.com' }
31
-
32
- it "uses CasRestClient to authenticate" do
33
- stub_const 'CasRestClient', MockCasRestClient.new(double("response", body: response))
34
- expect(Conjur::API.login_cas(user, password, cas_uri)).to eq(response)
35
- expect(CasRestClient.options).to eq({
36
- username: user,
37
- password: password,
38
- uri: "http://cas.example.com/v1/tickets",
39
- use_cookies: false
40
- })
41
- expect(CasRestClient.url).to eq("http://authn.example.com/users/login")
42
- end
43
- end
44
-
45
- describe "::authenticate" do
46
- it "posts the password and dejsons the result" do
47
- expect_request(
48
- method: :post, url: "http://authn.example.com/users/#{user}/authenticate",
49
- payload: password, headers: { content_type: 'text/plain' }
50
- ).and_return '{ "response": "foo"}'
51
- expect(Conjur::API.authenticate(user, password)).to eq({ 'response' => 'foo' })
52
- end
53
- end
54
-
55
- describe "::update_password" do
56
- it "logs in and puts the new password" do
57
- expect_request(
58
- method: :put,
59
- url: "http://authn.example.com/users/password",
60
- user: user,
61
- password: password,
62
- payload: 'new-password',
63
- headers: { }
64
- ).and_return :response
65
- expect(Conjur::API.update_password(user, password, 'new-password')).to eq(:response)
66
- end
67
- end
68
-
69
- describe '::rotate_api_key' do
70
- it 'puts with basic auth' do
71
- expect_request(
72
- method: :put,
73
- url: 'http://authn.example.com/users/api_key',
74
- user: user,
75
- password: password,
76
- headers: { }
77
- ).and_return double('response', body: 'new api key')
78
- expect(Conjur::API.rotate_api_key user, password).to eq('new api key')
79
- end
80
- end
81
- end
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Graph do
4
- let(:edges){ [
5
- [ 'a', 'b' ],
6
- [ 'a', 'c'],
7
- [ 'c', 'd'],
8
- ['b', 'd'],
9
- [ 'd', 'e'],
10
- # make two connected components
11
- ['o', 'q'],
12
- ['x', 'o']
13
- ]}
14
- let(:edges_with_admin) { edges.each {|e| e.push(false)} }
15
-
16
- let(:short_json_graph){ edges.to_json }
17
- let(:long_edges){ edges.map{|e| {'parent' => e[0], 'child' => e[1]}} }
18
- let(:long_hash_graph){ {'graph' => long_edges} }
19
- let(:long_json_graph){ long_hash_graph.to_json }
20
-
21
- describe "json methods" do
22
- subject{described_class.new edges}
23
- it "converts to long json correctly" do
24
- expect(subject.to_json).to eq(long_json_graph)
25
- expect(subject.as_json).to eq(long_hash_graph)
26
- end
27
-
28
- it "converts to short json correctly" do
29
- expect(subject.to_json(true)).to eq(short_json_graph)
30
- expect(subject.as_json(true)).to eq(edges)
31
- end
32
- end
33
-
34
- describe "#vertices" do
35
- subject{Conjur::Graph.new(edges).vertices.to_set}
36
- it "contains all unique members of edges" do
37
- expect(subject.to_set).to eq(edges.flatten.uniq.to_set)
38
- end
39
- end
40
-
41
- describe "#to_dot" do
42
- let(:name){ nil }
43
- subject{ Conjur::Graph.new(edges).to_dot(name) }
44
- before do
45
- File.write('/tmp/conjur-graph-spec.dot', subject)
46
- end
47
-
48
- let(:role_to_node_id) do
49
- {}.tap do |h|
50
- edges.flatten.uniq.each do |v|
51
- expect(subject =~ /^\s*([a-z][0-9a-z_\-]*)\s*\[label\="(#{v})"\]/i).to be_truthy
52
- h[$2] = $1
53
- end
54
- end
55
- end
56
-
57
- context "when given a name" do
58
- let(:name){ 'foo' }
59
- it "names the digraph" do
60
- expect(subject).to match(/\A\s*digraph\s+foo\s*\{/)
61
- end
62
- end
63
-
64
- it "defines all the vertices in the graph" do
65
- edges.flatten.uniq.each do |v|
66
- expect(subject).to match(/^\s*[a-z][0-9a-z_\-]*\s*\[label\="#{v}"\]/i)
67
- end
68
- end
69
-
70
- it "defines all the edges in the graph" do
71
- edges.each do |e|
72
- parent_id = role_to_node_id[e[0]]
73
- child_id = role_to_node_id[e[1]]
74
- expect(subject).to match(/^\s*#{parent_id}\s*\->\s*#{child_id}/)
75
- end
76
- end
77
- end
78
-
79
- shared_examples "it creates a new Graph" do
80
- let(:arg) { graph_edges }
81
- let(:edge_objects){ graph_edges.map{|e| Conjur::Graph::Edge.new(*e) }}
82
-
83
- subject{ described_class.new arg }
84
-
85
- def self.it_accepts_the_argument
86
- it "accepts the argument" do
87
- expect(subject.edges.to_set).to eq(edge_objects.to_set)
88
- end
89
- end
90
- describe "given an array of edges" do
91
- it_accepts_the_argument
92
- end
93
-
94
- describe "given a hash of {'graph' => <array of edges>}" do
95
- let(:arg){ {'graph' => graph_edges} }
96
- it_accepts_the_argument
97
- end
98
-
99
- describe "given a JSON string" do
100
- let(:arg){ {'graph' => graph_edges}.to_json }
101
- it_accepts_the_argument
102
- end
103
- end
104
-
105
- describe "Graph.new" do
106
- it_should_behave_like "it creates a new Graph" do
107
- let(:graph_edges) { edges }
108
- end
109
- end
110
-
111
- describe "Graph.new with admin_option present" do
112
- it_should_behave_like "it creates a new Graph" do
113
- let(:graph_edges) { edges_with_admin }
114
- end
115
- end
116
-
117
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
- require 'standard_methods_helper'
3
-
4
- describe Conjur::API, api: :dummy do
5
- subject { api }
6
-
7
- describe '#groups' do
8
- it_should_behave_like 'standard_list with', :group, :options do
9
- let(:invoke) { subject.groups :options }
10
- end
11
- end
12
-
13
- describe '#create_group' do
14
- it_should_behave_like 'standard_create with', :group, :id, :options do
15
- let(:invoke) { subject.create_group :id, :options }
16
- end
17
-
18
- it_should_behave_like 'standard_create with', :group, :id, gidnumber: 371509 do
19
- let(:invoke) { subject.create_group :id, gidnumber: 371509 }
20
- end
21
- end
22
-
23
- describe '#group' do
24
- it_should_behave_like 'standard_show with', :group, :id do
25
- let(:invoke) { subject.group :id }
26
- end
27
- end
28
-
29
- describe '#find_groups' do
30
- it "searches the group by GID" do
31
- expect_request(
32
- method: :get,
33
- url: "#{core_host}/groups/search?gidnumber=12345",
34
- headers: credentials[:headers]
35
- ).and_return ['foo'].to_json
36
-
37
- expect(api.find_groups(gidnumber: 12345)).to eq(['foo'])
38
- end
39
- end
40
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
- require 'standard_methods_helper'
3
- require 'cidr_helper'
4
-
5
- describe Conjur::API, api: :dummy do
6
- describe '::enroll_host' do
7
- it "uses Net::HTTP to get something" do
8
- response = double "response",
9
- code: '200', body: 'foobar'
10
- allow(response).to receive(:[]).with('Content-Type').and_return 'text/whatever'
11
-
12
- url = URI.parse "http://example.com"
13
- allow(Net::HTTP).to receive(:get_response).with(url).and_return response
14
-
15
- expect(Conjur::API.enroll_host("http://example.com")).to eq(['text/whatever', 'foobar'])
16
- end
17
- end
18
-
19
- describe '#create_host' do
20
- it_should_behave_like "standard_create with", :host, nil, some: :options do
21
- let(:invoke) { subject.create_host some: :options }
22
- end
23
-
24
- include_examples 'CIDR create' do
25
- def create opts
26
- api.create_host opts
27
- end
28
- end
29
- end
30
-
31
- describe '#host' do
32
- it_should_behave_like "standard_show with", :host, :id do
33
- let(:invoke) { subject.host :id }
34
- end
35
- end
36
- end
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
- require 'standard_methods_helper'
3
-
4
- describe Conjur::API, api: :dummy do
5
- before do
6
- # The standard test setup doesn't do this
7
- allow(Conjur.configuration).to receive(:appliance_url).and_return 'https://example.com/api'
8
- end
9
-
10
- let(:version_string) { '4.5.0-75-gde404a6' }
11
- let(:response_json){
12
- {
13
- 'services' => {
14
- 'authn' => {
15
- 'version' => version_string
16
- }
17
- }
18
- }
19
- }
20
- let(:response){ double('response', body: response_json.to_json) }
21
-
22
- describe '+appliance_info' do
23
- subject{ Conjur::API.appliance_info }
24
- context 'when /info does not exist' do
25
- it 'raises a FeatureNotAvailable exception' do
26
- expect_request(
27
- method: :get,
28
- url: 'https://example.com/info'
29
- ).and_raise RestClient::ResourceNotFound
30
- expect{ subject }.to raise_error(Conjur::FeatureNotAvailable)
31
- end
32
- end
33
-
34
- context 'when /info exists' do
35
- it 'returns the response json' do
36
- expect_request(
37
- method: :get,
38
- url: 'https://example.com/info'
39
- ).and_return response
40
-
41
- expect(subject).to eq(response_json)
42
- end
43
- end
44
- end
45
-
46
- describe '+service_names' do
47
- subject{ Conjur::API.service_names }
48
- it 'returns the service names' do
49
- expect_request(
50
- method: :get,
51
- url: 'https://example.com/info'
52
- ).and_return response
53
- expect(subject).to eq(%w(authn))
54
- end
55
- end
56
-
57
- describe '+service_version' do
58
- subject{ Conjur::API.service_version(service)}
59
- context 'when the service name is valid' do
60
- let(:service){'authn'}
61
- let(:expected_version){ "4.5.0".to_version }
62
- before {
63
- expect_request(
64
- method: :get,
65
- url: 'https://example.com/info'
66
- ).at_least(1).times.and_return response
67
- }
68
- it 'returns the version as a Semantic::Version' do
69
- expect(subject).to eq(expected_version)
70
- end
71
- describe 'can be compared' do
72
- it 'returns the version as a Semantic::Version' do
73
- expect(subject >= Semantic::Version.new('4.5.0')).to eq(true)
74
- end
75
- end
76
- end
77
-
78
- context 'when the service name is not valid' do
79
- let(:service){'blahblah'}
80
- it 'raises an exception' do
81
- expect_request(
82
- method: :get,
83
- url: 'https://example.com/info'
84
- ).at_least(1).times.and_return response
85
- expect{ subject }.to raise_error(RuntimeError, /Unknown service/i)
86
- end
87
- end
88
- end
89
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
- require 'webmock/rspec'
3
-
4
- describe Conjur::Layer do
5
- subject { Conjur::Layer.new 'http://example.com/layers/my%2Flayername', nil }
6
-
7
- describe "#add_host" do
8
- it "casts Host to roleid" do
9
- host = double(:host)
10
- expect(host).to receive(:roleid).and_return "the-hostid"
11
- stub_request(:post, "http://example.com/layers/my%2Flayername/hosts")
12
- .with(body: {hostid: 'the-hostid' })
13
-
14
-
15
- subject.add_host host
16
- end
17
- end
18
- end
@@ -1,44 +0,0 @@
1
- #
2
- # Copyright (C) 2016 Conjur Inc
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- # this software and associated documentation files (the "Software"), to deal in
6
- # the Software without restriction, including without limitation the rights to
7
-
8
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
- #
10
- require 'spec_helper'
11
- require 'helpers/request_helpers'
12
-
13
- describe Conjur::API, api: :dummy do
14
- include RequestHelpers
15
- describe 'LDAP policy methods' do
16
- let(:appliance_url){ "http://example.com/api" }
17
- before do
18
- allow(Conjur.configuration).to receive(:appliance_url).and_return appliance_url
19
- end
20
-
21
- describe '#ldap_sync_policy' do
22
- let(:profile) { 'default' }
23
- let(:url){ "#{appliance_url}/ldap-sync/policy?config_name=#{profile}" }
24
- let(:policy_event){
25
- %Q{data: {"policy": "a policy"}}
26
- }
27
-
28
- let(:response){ double('response', :body => policy_event, :headers => { :content_type => 'text/event-stream' }) }
29
- subject{ api.ldap_sync_policy('default') }
30
- before do
31
- expect_request(
32
- url: url,
33
- method: :get,
34
- headers: credentials[:headers]
35
- ).and_return response
36
- end
37
-
38
- it 'returns a Hash with a policy' do
39
- expect(subject).to be_kind_of Hash
40
- end
41
- end
42
-
43
- end
44
- end
@@ -1,66 +0,0 @@
1
- #
2
- # Copyright (C) 2013 Conjur Inc
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- # this software and associated documentation files (the "Software"), to deal in
6
- # the Software without restriction, including without limitation the rights to
7
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
- # the Software, and to permit persons to whom the Software is furnished to do so,
9
- # subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- #
21
- require 'spec_helper'
22
-
23
- describe Conjur::API, api: :dummy do
24
- let(:pubkeys_url){ "http://pubkeys.example.com/api/pubkeys" }
25
- def pubkeys_url_for *path
26
- [pubkeys_url, path.map{|p| CGI.escape(p)} ].join("/")
27
- end
28
-
29
- before do
30
- allow(Conjur::API).to receive_messages(pubkeys_asset_host: pubkeys_url)
31
- end
32
-
33
- describe "#public_keys" do
34
- it "GETs /:username" do
35
- expect_request(
36
- url: pubkeys_url_for("bob"),
37
- method: :get,
38
- headers: credentials[:headers],
39
- ).and_return "key key key"
40
- expect(api.public_keys("bob")).to eq("key key key")
41
- end
42
- end
43
-
44
- describe "#add_public_key" do
45
- it "POSTs /:username with the data" do
46
- expect_request(
47
- url: pubkeys_url_for("bob"),
48
- method: :post,
49
- headers: credentials[:headers],
50
- payload: "key data",
51
- )
52
- api.add_public_key("bob", "key data")
53
- end
54
- end
55
-
56
- describe "#delete_public_key" do
57
- it "DELETEs /:username/:keyname" do
58
- expect_request(
59
- url: pubkeys_url_for("bob", "bob-key"),
60
- method: :delete,
61
- headers: credentials[:headers]
62
- )
63
- api.delete_public_key("bob", "bob-key")
64
- end
65
- end
66
- end