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.
- checksums.yaml +4 -4
- data/.dockerignore +1 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +22 -3
- data/Dockerfile +12 -3
- data/Gemfile +3 -3
- data/Jenkinsfile +69 -0
- data/LICENSE.md +195 -0
- data/README.md +16 -0
- data/Rakefile +34 -18
- data/ci/wait_for_server.sh +10 -0
- data/conjur-api.gemspec +6 -14
- data/dev/docker-compose.yml +23 -0
- data/dev/empty.yml +2 -0
- data/dev/start.sh +15 -0
- data/dev/stop.sh +6 -0
- data/docker-compose.yml +27 -0
- data/features/exists.feature +37 -0
- data/features/group.feature +11 -0
- data/features/host.feature +20 -0
- data/features/host_factory_create_host.feature +28 -0
- data/features/host_factory_token.feature +63 -0
- data/features/load_policy.feature +61 -0
- data/features/members.feature +51 -0
- data/features/new_api.feature +36 -0
- data/features/permitted.feature +43 -0
- data/features/permitted_roles.feature +30 -0
- data/features/public_keys.feature +11 -0
- data/features/resource_fields.feature +53 -0
- data/features/role_fields.feature +15 -0
- data/features/rotate_api_key.feature +13 -0
- data/features/step_definitions/api_steps.rb +4 -54
- data/features/step_definitions/policy_steps.rb +35 -0
- data/features/step_definitions/result_steps.rb +7 -0
- data/features/support/env.rb +14 -5
- data/features/support/hooks.rb +3 -0
- data/features/support/world.rb +5 -6
- data/features/update_password.feature +14 -0
- data/features/user.feature +17 -0
- data/features/variable_fields.feature +20 -0
- data/features/variable_value.feature +67 -0
- data/lib/conjur/acts_as_resource.rb +95 -65
- data/lib/conjur/acts_as_role.rb +102 -51
- data/lib/conjur/{audit-api.rb → acts_as_rolsource.rb} +10 -14
- data/lib/conjur/acts_as_user.rb +13 -22
- data/lib/conjur/api/authn.rb +37 -72
- data/lib/conjur/api/host_factories.rb +35 -55
- data/lib/conjur/api/policies.rb +56 -0
- data/lib/conjur/api/pubkeys.rb +36 -160
- data/lib/conjur/api/resources.rb +32 -116
- data/lib/conjur/api/roles.rb +28 -105
- data/lib/conjur/api/variables.rb +22 -91
- data/lib/conjur/api.rb +19 -46
- data/lib/conjur/base.rb +21 -132
- data/lib/conjur/base_object.rb +57 -0
- data/lib/conjur/{authn-api.rb → build_object.rb} +23 -11
- data/lib/conjur/cast.rb +12 -17
- data/lib/conjur/cert_utils.rb +1 -1
- data/lib/conjur/cidr.rb +1 -1
- data/lib/conjur/configuration.rb +13 -91
- data/lib/conjur/escape.rb +1 -2
- data/lib/conjur/group.rb +9 -65
- data/lib/conjur/has_attributes.rb +22 -59
- data/lib/conjur/host.rb +5 -35
- data/lib/conjur/host_factory.rb +40 -40
- data/lib/conjur/host_factory_token.rb +38 -23
- data/lib/conjur/id.rb +63 -0
- data/lib/conjur/layer.rb +5 -80
- data/lib/conjur/log.rb +1 -1
- data/lib/conjur/log_source.rb +1 -1
- data/lib/conjur/{secret.rb → policy.rb} +11 -14
- data/lib/conjur/{api/secrets.rb → policy_load_result.rb} +35 -22
- data/lib/conjur/query_string.rb +2 -1
- data/lib/conjur/resource.rb +5 -299
- data/lib/conjur/role.rb +5 -317
- data/lib/conjur/role_grant.rb +20 -28
- data/lib/conjur/user.rb +5 -63
- data/lib/conjur/variable.rb +31 -76
- data/lib/conjur/{authz-api.rb → webservice.rb} +8 -16
- data/lib/conjur-api/version.rb +2 -2
- data/publish.sh +7 -0
- data/spec/api_spec.rb +208 -0
- data/spec/cast_spec.rb +21 -0
- data/spec/{lib/cert_utils_spec.rb → cert_utils_spec.rb} +0 -0
- data/spec/{lib/cidr_spec.rb → cidr_spec.rb} +0 -0
- data/spec/{lib/configuration_spec.rb → configuration_spec.rb} +40 -140
- data/spec/{lib/has_attributes_spec.rb → has_attributes_spec.rb} +6 -2
- data/spec/{lib/log_source_spec.rb → log_source_spec.rb} +0 -0
- data/spec/{lib/log_spec.rb → log_spec.rb} +0 -0
- data/spec/roles_spec.rb +24 -0
- data/spec/spec_helper.rb +63 -78
- data/spec/ssl_spec.rb +3 -5
- data/spec/vendor/rest_client_spec.rb +0 -54
- data/test.sh +40 -0
- metadata +122 -281
- data/.kateproject +0 -5
- data/LICENSE +0 -22
- data/ci/test.sh +0 -9
- data/features/audit_resources.feature +0 -15
- data/features/audit_roles.feature +0 -15
- data/features/bootstrap.feature +0 -31
- data/features/step_definitions/cli_steps.rb +0 -5
- data/jenkins.sh +0 -27
- data/lib/conjur/acts_as_asset.rb +0 -88
- data/lib/conjur/annotations.rb +0 -186
- data/lib/conjur/api/audit.rb +0 -138
- data/lib/conjur/api/deputies.rb +0 -57
- data/lib/conjur/api/groups.rb +0 -111
- data/lib/conjur/api/hosts.rb +0 -109
- data/lib/conjur/api/info.rb +0 -126
- data/lib/conjur/api/layers.rb +0 -62
- data/lib/conjur/api/ldapsync.rb +0 -115
- data/lib/conjur/api/users.rb +0 -106
- data/lib/conjur/bootstrap.rb +0 -161
- data/lib/conjur/build_from_response.rb +0 -49
- data/lib/conjur/core-api.rb +0 -74
- data/lib/conjur/deputy.rb +0 -55
- data/lib/conjur/env.rb +0 -54
- data/lib/conjur/event_source.rb +0 -101
- data/lib/conjur/exists.rb +0 -60
- data/lib/conjur/graph.rb +0 -295
- data/lib/conjur/has_id.rb +0 -43
- data/lib/conjur/has_identifier.rb +0 -36
- data/lib/conjur/has_owner.rb +0 -51
- data/lib/conjur/host-factory-api.rb +0 -38
- data/lib/conjur/layer-api.rb +0 -13
- data/lib/conjur/ldap_sync_job.rb +0 -89
- data/lib/conjur/path_based.rb +0 -86
- data/lib/conjur/pubkeys-api.rb +0 -50
- data/lib/conjur/standard_methods.rb +0 -91
- data/reqspeed.rb +0 -20
- data/spec/api/authn_spec.rb +0 -81
- data/spec/api/graph_spec.rb +0 -117
- data/spec/api/groups_spec.rb +0 -40
- data/spec/api/hosts_spec.rb +0 -36
- data/spec/api/info_spec.rb +0 -89
- data/spec/api/layer_spec.rb +0 -18
- data/spec/api/ldapsync_spec.rb +0 -44
- data/spec/api/pubkeys_spec.rb +0 -66
- data/spec/api/resources_spec.rb +0 -92
- data/spec/api/roles_spec.rb +0 -100
- data/spec/api/secrets_spec.rb +0 -16
- data/spec/api/users_spec.rb +0 -71
- data/spec/api/variables_spec.rb +0 -112
- data/spec/cas_rest_client.rb +0 -17
- data/spec/cidr_helper.rb +0 -24
- data/spec/lib/acts_as_user_spec.rb +0 -27
- data/spec/lib/annotations_spec.rb +0 -109
- data/spec/lib/api_spec.rb +0 -480
- data/spec/lib/asset_spec.rb +0 -80
- data/spec/lib/audit_spec.rb +0 -155
- data/spec/lib/build_from_response_spec.rb +0 -49
- data/spec/lib/deputy_spec.rb +0 -25
- data/spec/lib/exists_spec.rb +0 -24
- data/spec/lib/group_spec.rb +0 -18
- data/spec/lib/host_spec.rb +0 -31
- data/spec/lib/resource_spec.rb +0 -240
- data/spec/lib/role_grant_spec.rb +0 -13
- data/spec/lib/role_spec.rb +0 -231
- data/spec/lib/standard_methods_spec.rb +0 -66
- data/spec/lib/user_spec.rb +0 -77
- data/spec/standard_methods_helper.rb +0 -41
- data/spec/variable_spec.rb +0 -101
- data/spec/vcr_cassettes/Conjur_Resource/_create/with_path-like_identifier.yml +0 -87
- data/spec/vcr_cassettes/Conjur_Resource/_create/with_un-encoded_path-like_identifier.yml +0 -87
- data/spec/vcr_cassettes/Conjur_Resource/_create/with_uuid_identifier.yml +0 -87
data/spec/api/resources_spec.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'helpers/request_helpers'
|
3
|
-
|
4
|
-
describe Conjur::API, api: :dummy do
|
5
|
-
include RequestHelpers
|
6
|
-
|
7
|
-
describe '#create_resource' do
|
8
|
-
it "passes to resource#create" do
|
9
|
-
allow(api).to receive(:resource).with(:id).and_return(resource = double)
|
10
|
-
expect(resource).to receive :create
|
11
|
-
|
12
|
-
expect(api.create_resource(:id)).to eq(resource)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#resource' do
|
17
|
-
it "builds a path and creates a resource from it" do
|
18
|
-
res = api.resource "some-account:a-kind:the-id"
|
19
|
-
expect(res.url).to eq("#{authz_host}/some-account/resources/a-kind/the-id")
|
20
|
-
end
|
21
|
-
it "accepts an account-less resource" do
|
22
|
-
res = api.resource "a-kind:the-id"
|
23
|
-
expect(res.url).to eq("#{authz_host}/#{account}/resources/a-kind/the-id")
|
24
|
-
end
|
25
|
-
it "rejects an underspecified resource" do
|
26
|
-
expect { api.resource "the-id" }.to raise_error(/at least two tokens in the-id/)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '.resources' do
|
31
|
-
let(:ids) { %w(acc:kind:foo acc:chunky:bar) }
|
32
|
-
let(:resources) {
|
33
|
-
ids.map do |id|
|
34
|
-
{ 'id' => id }
|
35
|
-
end
|
36
|
-
}
|
37
|
-
it "counts resources" do
|
38
|
-
expect(Conjur::Resource).to receive(:all)
|
39
|
-
.with(host: authz_host, account: account, credentials: api.credentials, count: true).and_return(100)
|
40
|
-
|
41
|
-
expect(api.resources(count: true)).to eq(100)
|
42
|
-
end
|
43
|
-
it "lists all resources" do
|
44
|
-
expect(Conjur::Resource).to receive(:all)
|
45
|
-
.with(host: authz_host, account: account, credentials: api.credentials).and_return(resources)
|
46
|
-
|
47
|
-
expect(api.resources.map(&:url)).to eql(ids.map { |id| api.resource(id).url })
|
48
|
-
end
|
49
|
-
it "can filter by kind" do
|
50
|
-
expect(Conjur::Resource).to receive(:all)
|
51
|
-
.with(host: authz_host, account: account, credentials: api.credentials, kind: :chunky).and_return(resources)
|
52
|
-
|
53
|
-
expect(api.resources(kind: :chunky).map(&:url)).to eql(ids.map { |id| api.resource(id).url })
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#resources_permitted' do
|
58
|
-
let(:ids) { %w(foo bar baz) }
|
59
|
-
let(:kind) { 'variable' }
|
60
|
-
let(:priv) { 'execute' }
|
61
|
-
|
62
|
-
it 'creates the request correctly' do
|
63
|
-
expect_request(
|
64
|
-
method: :post,
|
65
|
-
url: "#{authz_host}/the-account/resources/#{kind}?check=true",
|
66
|
-
payload: {
|
67
|
-
:privilege => priv,
|
68
|
-
:identifiers => ids
|
69
|
-
}
|
70
|
-
).and_return(double("response", :code => 204))
|
71
|
-
|
72
|
-
res = api.resources_permitted?(kind, ids, priv)
|
73
|
-
expect(res[0]).to be(true)
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'signals failure' do
|
77
|
-
expect_request(
|
78
|
-
method: :post,
|
79
|
-
url: "#{authz_host}/the-account/resources/#{kind}?check=true",
|
80
|
-
payload: {
|
81
|
-
:privilege => priv,
|
82
|
-
:identifiers => ids
|
83
|
-
}
|
84
|
-
).and_return(double("response", :code => 403, :body => '[]'))
|
85
|
-
|
86
|
-
res = api.resources_permitted?(kind, ids, priv)
|
87
|
-
expect(res[0]).to be(false)
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
data/spec/api/roles_spec.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'helpers/request_helpers'
|
3
|
-
|
4
|
-
describe Conjur::API, api: :dummy do
|
5
|
-
include RequestHelpers
|
6
|
-
subject { api }
|
7
|
-
|
8
|
-
describe 'role_graph' do
|
9
|
-
let(:roles){ [ 'acct:user:alice', 'acct:user:bob', 'acct:user:eve' ] }
|
10
|
-
let(:options){ {} }
|
11
|
-
let(:current_role){ 'some-role' }
|
12
|
-
let(:graph){
|
13
|
-
[
|
14
|
-
[ 'acct:user:alice', 'acct:user:eve' ],
|
15
|
-
[ 'acct:user:bob', 'acct:user:eve']
|
16
|
-
]
|
17
|
-
}
|
18
|
-
let(:response){ {
|
19
|
-
graph: graph
|
20
|
-
}.to_json }
|
21
|
-
|
22
|
-
let(:graph_edges){
|
23
|
-
graph.map{|e| Conjur::Graph::Edge.new *e}
|
24
|
-
}
|
25
|
-
|
26
|
-
before do
|
27
|
-
allow(api).to receive(:current_role).and_return current_role
|
28
|
-
end
|
29
|
-
|
30
|
-
subject{ api.role_graph roles, options }
|
31
|
-
|
32
|
-
def role_graph_url_for roles, options, current_role
|
33
|
-
qs = options.reverse_merge(ancestors: true, descendants: true)
|
34
|
-
.merge(from_role: current_role, roles: roles).slice(:from_role, :ancestors, :descendants, :roles).to_query
|
35
|
-
"http://authz.example.com/#{account}/roles?#{qs}"
|
36
|
-
end
|
37
|
-
|
38
|
-
def expect_request_with_params params={}
|
39
|
-
expect_request(headers: credentials[:headers], method: :get,
|
40
|
-
url: role_graph_url_for(roles, options, current_role))
|
41
|
-
.and_return(response)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "gets /roles with the correct params" do
|
45
|
-
expect_request_with_params ancestors: true, descendants: true, from_role: current_role
|
46
|
-
subject
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when options[:ancestors] and options[:descendants] are false" do
|
50
|
-
let(:options){ { ancestors: false, descendants: false } }
|
51
|
-
it "gets /roles with the correct params" do
|
52
|
-
expect_request_with_params ancestors: false, descendants: false, from_role: current_role
|
53
|
-
subject
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when given options[:as_role] = 'foo'" do
|
58
|
-
it "sets the from_role param to 'foo'" do
|
59
|
-
expect_request_with_params from_role: 'foo'
|
60
|
-
subject
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "the result" do
|
65
|
-
it "is a Conjur::Graph" do
|
66
|
-
expect_request_with_params
|
67
|
-
expect(subject).to be_kind_of(Conjur::Graph)
|
68
|
-
end
|
69
|
-
it "has the right edges" do
|
70
|
-
expect_request_with_params
|
71
|
-
expect(subject.edges.to_set).to eq(graph_edges.to_set)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
describe '#role_name_from_username' do
|
78
|
-
|
79
|
-
before {
|
80
|
-
allow(api).to receive(:username) { username }
|
81
|
-
}
|
82
|
-
context "username is" do
|
83
|
-
[
|
84
|
-
[ 'the-user', 'user:the-user' ],
|
85
|
-
[ 'host/the-host', 'host:the-host' ],
|
86
|
-
[ 'host/a/quite/long/host/name', 'host:a/quite/long/host/name' ],
|
87
|
-
[ 'newkind/host/name', 'newkind:host/name' ],
|
88
|
-
].each do |p|
|
89
|
-
context "'#{p[0]}'" do
|
90
|
-
let(:username) { p[0] }
|
91
|
-
|
92
|
-
describe '#role_name_from_username' do
|
93
|
-
subject { super().role_name_from_username }
|
94
|
-
it { is_expected.to eq(p[1]) }
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
data/spec/api/secrets_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'standard_methods_helper'
|
3
|
-
|
4
|
-
describe Conjur::API, api: :dummy do
|
5
|
-
describe '#create_secret' do
|
6
|
-
it_should_behave_like 'standard_create with', :secret, nil, value: 'val' do
|
7
|
-
let(:invoke) { api.create_secret 'val' }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#secret' do
|
12
|
-
it_should_behave_like 'standard_show with', :secret, :id do
|
13
|
-
let(:invoke) { api.secret :id }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/spec/api/users_spec.rb
DELETED
@@ -1,71 +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 '#create_user' do
|
7
|
-
it_should_behave_like 'standard_create with', :user, nil, login: 'login', other: true do
|
8
|
-
let(:invoke) { api.create_user 'login', other: true }
|
9
|
-
end
|
10
|
-
|
11
|
-
include_examples 'CIDR create' do
|
12
|
-
def create opts
|
13
|
-
api.create_user 'login', opts
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'user#rotate_api_key' do
|
19
|
-
let(:userid){ 'alice@wonderland' }
|
20
|
-
let(:new_api_key){ 'new api key' }
|
21
|
-
it 'PUTS to /authn/users/api_key?id=:userid' do
|
22
|
-
expect_request(
|
23
|
-
method: :put,
|
24
|
-
url: "#{authn_host}/users/api_key?id=#{api.fully_escape userid}",
|
25
|
-
headers: credentials[:headers],
|
26
|
-
payload: ''
|
27
|
-
).and_return double('response', body: new_api_key)
|
28
|
-
expect(api.user(userid).rotate_api_key).to eq(new_api_key)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'user#update' do
|
33
|
-
let(:userid) { "alice@wonderland" }
|
34
|
-
it "PUTs to /users/:id?uidnumber=:uidnumber" do
|
35
|
-
expect_request(
|
36
|
-
method: :put,
|
37
|
-
url: "#{core_host}/users/#{api.fully_escape(userid)}",
|
38
|
-
headers: credentials[:headers],
|
39
|
-
payload: { uidnumber: 12345 }
|
40
|
-
)
|
41
|
-
api.user(userid).update(uidnumber: 12345)
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "find_users" do
|
47
|
-
|
48
|
-
let(:search_parameters) { {uidnumber: 12345} }
|
49
|
-
let(:search_result) { ["someuser"].to_json }
|
50
|
-
|
51
|
-
it "GETs /users/search with appropriate options, and returns parsed JSON response" do
|
52
|
-
expect_request(
|
53
|
-
method: :get,
|
54
|
-
url: "#{core_host}/users/search?uidnumber=12345",
|
55
|
-
headers: credentials[:headers]
|
56
|
-
).and_return search_result
|
57
|
-
|
58
|
-
parsed = double()
|
59
|
-
|
60
|
-
expect(JSON).to receive(:parse).with(search_result).and_return(parsed)
|
61
|
-
|
62
|
-
expect(api.find_users(search_parameters)).to eq(parsed)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe '#user' do
|
67
|
-
it_should_behave_like 'standard_show with', :user, :login do
|
68
|
-
let(:invoke) { api.user :login }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/spec/api/variables_spec.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'standard_methods_helper'
|
3
|
-
|
4
|
-
|
5
|
-
describe Conjur::API, api: :dummy do
|
6
|
-
describe '#create_variable' do
|
7
|
-
let(:invoke) { api.create_variable :type, :kind, other: true }
|
8
|
-
it_should_behave_like 'standard_create with', :variable, nil, mime_type: :type, kind: :kind, other: true
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#variable' do
|
12
|
-
let(:invoke) { api.variable :id }
|
13
|
-
it_should_behave_like 'standard_show with', :variable, :id
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
let (:expected_url) { nil }
|
18
|
-
let (:expected_headers) { {} }
|
19
|
-
shared_context "Stubbed API" do
|
20
|
-
before {
|
21
|
-
expect_request(
|
22
|
-
method: :get,
|
23
|
-
url: expected_url,
|
24
|
-
headers: credentials[:headers].merge(expected_headers)
|
25
|
-
) {
|
26
|
-
if defined? return_error
|
27
|
-
raise return_error
|
28
|
-
else
|
29
|
-
double( code: return_code, body: return_body )
|
30
|
-
end
|
31
|
-
}
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#variable_values" do
|
36
|
-
|
37
|
-
let (:varlist) { ["var/1","var/2","var/3" ] }
|
38
|
-
|
39
|
-
it 'requires non-empty array of variables' do
|
40
|
-
expect { api.variable_values("something") }.to raise_exception(ArgumentError)
|
41
|
-
expect { api.variable_values([]) }.to raise_exception(ArgumentError)
|
42
|
-
end
|
43
|
-
|
44
|
-
let (:expected_url) { "#{core_host}/variables/values?vars=#{varlist.map {|v| api.fully_escape(v) }.join(",")}" }
|
45
|
-
|
46
|
-
let (:invoke) { api.variable_values(varlist) }
|
47
|
-
|
48
|
-
describe "if '/variables/values' method is responding with JSON" do
|
49
|
-
include_context "Stubbed API"
|
50
|
-
let (:return_code) { '200' }
|
51
|
-
let (:return_body) { '{"var/1":"val1","var/2":"val2","var/3":"val3"}' }
|
52
|
-
it "returns Hash of values built from the response" do
|
53
|
-
expect(api).not_to receive(:variable)
|
54
|
-
expect(invoke).to eq({ "var/1"=>"val1", "var/2"=>"val2", "var/3"=>"val3" })
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "if '/variables/values' method is returning 404 error" do
|
59
|
-
include_context "Stubbed API"
|
60
|
-
let (:return_error) { RestClient::ResourceNotFound }
|
61
|
-
before {
|
62
|
-
expect(api).to receive(:variable).with("var/1").and_return(double(value:"val1_obtained_separately"))
|
63
|
-
expect(api).to receive(:variable).with("var/2").and_return(double(value:"val2_obtained_separately"))
|
64
|
-
expect(api).to receive(:variable).with("var/3").and_return(double(value:"val3_obtained_separately"))
|
65
|
-
}
|
66
|
-
it 'tries variables one by one and returns Hash of values' do
|
67
|
-
expect(invoke).to eq({ "var/1"=>"val1_obtained_separately",
|
68
|
-
"var/2"=>"val2_obtained_separately",
|
69
|
-
"var/3"=>"val3_obtained_separately"
|
70
|
-
})
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "if '/variables/values' method is returning any other error" do
|
75
|
-
include_context "Stubbed API"
|
76
|
-
let (:return_error) { RestClient::Forbidden }
|
77
|
-
it 're-raises error without checking particular variables' do
|
78
|
-
expect(api).not_to receive(:variable)
|
79
|
-
expect { invoke }.to raise_error(return_error)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#variable_expirations' do
|
86
|
-
include_context "Stubbed API"
|
87
|
-
let (:expected_url) { "#{core_host}/variables/expirations" }
|
88
|
-
let (:return_code) { '200' }
|
89
|
-
let (:return_body) { '[]' }
|
90
|
-
|
91
|
-
context "with no interval" do
|
92
|
-
subject {api.variable_expirations}
|
93
|
-
it { is_expected.to eq([]) }
|
94
|
-
end
|
95
|
-
|
96
|
-
context "with Fixnum interval" do
|
97
|
-
let (:interval) { 2.weeks }
|
98
|
-
let (:expected_headers) { {:params => { :duration => "PT#{interval.to_i}S" } } }
|
99
|
-
subject { api.variable_expirations(2.weeks) }
|
100
|
-
it { is_expected.to eq([]) }
|
101
|
-
end
|
102
|
-
|
103
|
-
context "with String interval" do
|
104
|
-
let (:interval) { 'P2W' }
|
105
|
-
let (:expected_headers) { {:params => { :duration => 'P2W' } } }
|
106
|
-
subject { api.variable_expirations('P2W') }
|
107
|
-
it { is_expected.to eq([]) }
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
data/spec/cas_rest_client.rb
DELETED
data/spec/cidr_helper.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
shared_examples_for "CIDR create" do
|
2
|
-
it "formats the CIDRs correctly" do
|
3
|
-
cidrs = %w(192.0.2.0/24 198.51.100.0/24)
|
4
|
-
expect do
|
5
|
-
create cidr: cidrs.map(&IPAddr.method(:new))
|
6
|
-
end.to call_standard_create_with anything, anything, hash_including(cidr: cidrs)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "parses addresses given as strings" do
|
10
|
-
expect do
|
11
|
-
create cidr: %w(192.0.2.0/255.255.255.128)
|
12
|
-
end.to call_standard_create_with anything, anything, hash_including(cidr: %w(192.0.2.0/25))
|
13
|
-
end
|
14
|
-
|
15
|
-
it "raises ArgumentError on invalid CIDR" do
|
16
|
-
expect do
|
17
|
-
create cidr: %w(192.0.2.0/255.255.0.255)
|
18
|
-
end.to raise_error ArgumentError
|
19
|
-
|
20
|
-
expect do
|
21
|
-
create cidr: %w(192.0.2.256/1)
|
22
|
-
end.to raise_error ArgumentError
|
23
|
-
end
|
24
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
describe Conjur::ActsAsUser, api: :dummy do
|
2
|
-
subject do
|
3
|
-
api.user 'kmitnick'
|
4
|
-
end
|
5
|
-
|
6
|
-
describe '#set_cidr_restrictions' do
|
7
|
-
it "sends the new restrictions to the authn server" do
|
8
|
-
expect_request(
|
9
|
-
headers: hash_including(content_type: :json),
|
10
|
-
url: "http://authn.example.com/users?id=kmitnick",
|
11
|
-
method: :put,
|
12
|
-
payload: { cidr: ['192.0.2.1/32'] }.to_json
|
13
|
-
)
|
14
|
-
subject.set_cidr_restrictions %w(192.0.2.1)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "resets the restrictions on the authn server if given empty cidr string" do
|
18
|
-
expect_request(
|
19
|
-
headers: hash_including(content_type: :json),
|
20
|
-
url: "http://authn.example.com/users?id=kmitnick",
|
21
|
-
method: :put,
|
22
|
-
payload: { cidr: [] }.to_json
|
23
|
-
)
|
24
|
-
subject.set_cidr_restrictions []
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'helpers/request_helpers'
|
3
|
-
|
4
|
-
describe Conjur::Annotations do
|
5
|
-
include RequestHelpers
|
6
|
-
include Conjur::Escape
|
7
|
-
|
8
|
-
let(:identifier){ 'the-r{source}&^-id' }
|
9
|
-
let(:kind){ 'some-kind' }
|
10
|
-
let(:account){ 'the-account' }
|
11
|
-
let(:resourceid){ [account, kind, identifier].join ':'}
|
12
|
-
let(:options){ { } }
|
13
|
-
let(:raw_annotations){ [{'name' => 'name', 'value' => 'bar'},
|
14
|
-
{'name' => 'comment', 'value' => 'some comment'}] }
|
15
|
-
let(:attributes){ { 'annotations' => raw_annotations } }
|
16
|
-
|
17
|
-
let(:resource){
|
18
|
-
double('resource', attributes: attributes, account: account,
|
19
|
-
kind: kind, identifier: identifier, resourceid: resourceid,
|
20
|
-
options: options
|
21
|
-
) }
|
22
|
-
|
23
|
-
let(:annotations){ Conjur::Annotations.new(resource) }
|
24
|
-
|
25
|
-
subject { annotations }
|
26
|
-
|
27
|
-
let(:url){ "#{Conjur::Authz::API.host}/#{account}/annotations/#{kind}/#{fully_escape identifier}" }
|
28
|
-
|
29
|
-
def expect_put_request url, payload
|
30
|
-
expect_request(
|
31
|
-
method: :put,
|
32
|
-
headers: {},
|
33
|
-
url: url,
|
34
|
-
payload: payload
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '[]' do
|
39
|
-
it "returns annotations" do
|
40
|
-
expect(subject[:name]).to eq('bar')
|
41
|
-
expect(subject[:comment]).to eq('some comment')
|
42
|
-
expect(subject['comment']).to eq(subject[:comment])
|
43
|
-
end
|
44
|
-
|
45
|
-
it "caches the get result" do
|
46
|
-
expect(resource).to receive(:attributes).exactly(1).times.and_return(attributes)
|
47
|
-
subject[:name]
|
48
|
-
subject[:name]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#each' do
|
53
|
-
it "yields each annotation pair" do
|
54
|
-
pairs = []
|
55
|
-
subject.each{|k,v| pairs << [k,v]}
|
56
|
-
expect(pairs).to eq([[:name, 'bar'], [:comment, 'some comment']])
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
it "is Enumerable" do
|
61
|
-
expect(subject).to be_a(Enumerable)
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#to_h' do
|
65
|
-
it "returns the correct hash" do
|
66
|
-
expect(subject.to_h).to eq({name: 'bar', comment: 'some comment'})
|
67
|
-
end
|
68
|
-
it "does not propagate modifications to the returned hash" do
|
69
|
-
expect(RestClient::Request).not_to receive(:execute)
|
70
|
-
subject.to_h[:name] = 'new name'
|
71
|
-
expect(subject[:name]).to eq(subject.to_h[:name])
|
72
|
-
expect(subject[:name]).to eq("bar")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "#merge!" do
|
77
|
-
let(:hash){ {blah: 'blahbah', zelda: 'link'} }
|
78
|
-
|
79
|
-
it "makes a put request for each pair" do
|
80
|
-
hash.each do |k,v|
|
81
|
-
expect_put_request(url, name: k, value: v)
|
82
|
-
end
|
83
|
-
expect(resource).to receive(:invalidate).exactly(hash.count).times.and_yield
|
84
|
-
subject.merge! hash
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '[]=' do
|
89
|
-
|
90
|
-
it "makes a put request" do
|
91
|
-
expect_put_request url, name: :blah, value: 'boo'
|
92
|
-
expect(resource).to receive(:invalidate).and_yield
|
93
|
-
subject[:blah] = 'boo'
|
94
|
-
end
|
95
|
-
|
96
|
-
it "forces a fresh request for the annotations" do
|
97
|
-
expect_put_request(url, name: :foo, value: 'bar')
|
98
|
-
expect(resource).to receive(:attributes).exactly(2).times.and_return(attributes)
|
99
|
-
expect(resource).to receive(:invalidate).and_yield
|
100
|
-
# One get request
|
101
|
-
expect(subject[:name]).to eq('bar')
|
102
|
-
# Update
|
103
|
-
subject[:foo] = 'bar'
|
104
|
-
# Second get request
|
105
|
-
expect(subject[:name]).to eq('bar')
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|