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
@@ -29,66 +29,51 @@ describe Conjur::Configuration do
|
|
29
29
|
configuration.account = "the-account"
|
30
30
|
configuration.appliance_url = "https://conjur/api"
|
31
31
|
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
it "can still be changed by changing the appliance_url" do
|
33
|
+
configuration.appliance_url = "https://other/api"
|
34
|
+
expect(configuration.core_url).to eq "https://other/api"
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
it "can still be changed by changing the authn_url" do
|
38
|
+
configuration.authn_url = "http://authn-docker"
|
39
|
+
expect(configuration.core_url).to eq "https://conjur/api"
|
40
|
+
expect(configuration.authn_url).to eq "http://authn-docker"
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
context "and duplicated" do
|
44
|
+
subject { configuration.clone override_options }
|
45
|
+
let(:override_options) { Hash.new }
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
describe '#account' do
|
48
|
+
subject { super().account }
|
49
|
+
it { is_expected.to eq(configuration.account) }
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
describe '#appliance_url' do
|
53
|
+
subject { super().appliance_url }
|
54
|
+
it { is_expected.to eq(configuration.appliance_url) }
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
describe '#core_url' do
|
58
|
+
subject { super().core_url }
|
59
|
+
it { is_expected.to eq(configuration.appliance_url) }
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
62
|
+
context "appliance_url overridden" do
|
63
|
+
let(:override_options) {
|
64
|
+
{ :appliance_url => "https://example/api" }
|
65
|
+
}
|
66
|
+
it "is ignored by the configuration core_url" do
|
67
|
+
expect(configuration.core_url).to eq("https://conjur/api")
|
68
|
+
end
|
69
|
+
it "is reflected in the copy core_url" do
|
70
|
+
expect(subject.core_url).to eq("https://example/api")
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
|
77
|
-
before {
|
78
|
-
ENV.delete('CONJUR_ENV')
|
79
|
-
}
|
80
|
-
context "default env" do
|
81
|
-
describe '#env' do
|
82
|
-
subject { super().env }
|
83
|
-
it { is_expected.to eq("production") }
|
84
|
-
end
|
85
|
-
end
|
86
|
-
context "default stack" do
|
87
|
-
describe '#stack' do
|
88
|
-
subject { super().stack }
|
89
|
-
it { is_expected.to eq("v4") }
|
90
|
-
end
|
91
|
-
end
|
76
|
+
describe "url generation" do
|
92
77
|
describe 'authn_url' do
|
93
78
|
before {
|
94
79
|
allow_any_instance_of(Conjur::Configuration).to receive(:account).and_return "the-account"
|
@@ -106,110 +91,25 @@ describe Conjur::Configuration do
|
|
106
91
|
context "without appliance_url" do
|
107
92
|
describe '#authn_url' do
|
108
93
|
subject { super().authn_url }
|
109
|
-
it { is_expected.to eq("
|
94
|
+
it { is_expected.to eq("http://localhost:5000") }
|
110
95
|
end
|
111
96
|
end
|
112
97
|
end
|
113
|
-
|
98
|
+
|
99
|
+
describe 'core_url' do
|
114
100
|
before {
|
115
101
|
allow_any_instance_of(Conjur::Configuration).to receive(:account).and_return "the-account"
|
116
102
|
}
|
103
|
+
subject { super().core_url }
|
117
104
|
context "with appliance_url" do
|
118
105
|
before {
|
119
106
|
allow_any_instance_of(Conjur::Configuration).to receive(:appliance_url).and_return "http://example.com"
|
120
107
|
}
|
121
108
|
|
122
|
-
|
123
|
-
subject { super().authz_url }
|
124
|
-
it { is_expected.to eq("http://example.com/authz") }
|
125
|
-
end
|
126
|
-
end
|
127
|
-
context "without appliance_url" do
|
128
|
-
describe '#authz_url' do
|
129
|
-
subject { super().authz_url }
|
130
|
-
it { is_expected.to eq("https://authz-v4-conjur.herokuapp.com") }
|
131
|
-
end
|
132
|
-
context "with specific stack" do
|
133
|
-
before { allow_any_instance_of(Conjur::Configuration).to receive(:stack).and_return "the-stack" }
|
134
|
-
|
135
|
-
describe '#authz_url' do
|
136
|
-
subject { super().authz_url }
|
137
|
-
it { is_expected.to eq("https://authz-the-stack-conjur.herokuapp.com") }
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
context "CONJUR_ENV = 'test'" do
|
144
|
-
describe '#env' do
|
145
|
-
subject { super().env }
|
146
|
-
it { is_expected.to eq("test") }
|
147
|
-
end
|
148
|
-
before {
|
149
|
-
allow_any_instance_of(Conjur::Configuration).to receive(:account).and_return "the-account"
|
150
|
-
}
|
151
|
-
describe 'authn_url' do
|
152
|
-
context "with appliance_url hostname" do
|
153
|
-
before {
|
154
|
-
allow_any_instance_of(Conjur::Configuration).to receive(:appliance_url).and_return "http://example.com"
|
155
|
-
}
|
156
|
-
|
157
|
-
describe '#authn_url' do
|
158
|
-
subject { super().authn_url }
|
159
|
-
it { is_expected.to eq("http://example.com/authn") }
|
160
|
-
end
|
161
|
-
end
|
162
|
-
context "with appliance_url hostname and non-trailing-slash path" do
|
163
|
-
before {
|
164
|
-
allow_any_instance_of(Conjur::Configuration).to receive(:appliance_url).and_return "http://example.com/api"
|
165
|
-
}
|
166
|
-
|
167
|
-
describe '#authn_url' do
|
168
|
-
subject { super().authn_url }
|
169
|
-
it { is_expected.to eq("http://example.com/api/authn") }
|
170
|
-
end
|
109
|
+
it { is_expected.to eq("http://example.com") }
|
171
110
|
end
|
172
111
|
context "without appliance_url" do
|
173
|
-
|
174
|
-
subject { super().authn_url }
|
175
|
-
it { is_expected.to eq("http://localhost:5000") }
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
describe 'authz_url' do
|
180
|
-
context "with appliance_url" do
|
181
|
-
before {
|
182
|
-
allow_any_instance_of(Conjur::Configuration).to receive(:appliance_url).and_return "http://example.com/api/"
|
183
|
-
}
|
184
|
-
|
185
|
-
describe '#authz_url' do
|
186
|
-
subject { super().authz_url }
|
187
|
-
it { is_expected.to eq("http://example.com/api/authz") }
|
188
|
-
end
|
189
|
-
end
|
190
|
-
context "without appliance_url" do
|
191
|
-
describe '#authz_url' do
|
192
|
-
subject { super().authz_url }
|
193
|
-
it { is_expected.to eq("http://localhost:5100") }
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
describe 'core_url' do
|
198
|
-
context "with appliance_url" do
|
199
|
-
before {
|
200
|
-
allow_any_instance_of(Conjur::Configuration).to receive(:appliance_url).and_return "http://example.com/api"
|
201
|
-
}
|
202
|
-
|
203
|
-
describe '#core_url' do
|
204
|
-
subject { super().core_url }
|
205
|
-
it { is_expected.to eq("http://example.com/api") }
|
206
|
-
end
|
207
|
-
end
|
208
|
-
context "without appliance_url" do
|
209
|
-
describe '#core_url' do
|
210
|
-
subject { super().core_url }
|
211
|
-
it { is_expected.to eq("http://localhost:5200") }
|
212
|
-
end
|
112
|
+
it { is_expected.to eq("http://localhost:5000") }
|
213
113
|
end
|
214
114
|
end
|
215
115
|
end
|
@@ -13,10 +13,14 @@ describe Conjur::HasAttributes do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
let(:object) { new_object }
|
16
|
+
let(:second_object) { new_object }
|
16
17
|
let(:attributes) { { 'id' => 'the-id' } }
|
18
|
+
let(:rbac_resource_resource) { double(:rbac_resource_resource, url: object.url) }
|
17
19
|
|
18
20
|
before {
|
19
|
-
|
21
|
+
allow(object).to receive(:rbac_resource_resource).and_return(rbac_resource_resource)
|
22
|
+
allow(second_object).to receive(:rbac_resource_resource).and_return(rbac_resource_resource)
|
23
|
+
expect(rbac_resource_resource).to receive(:get).with(no_args).and_return(double(:response, body: attributes.to_json))
|
20
24
|
}
|
21
25
|
|
22
26
|
it "should fetch attributes from the server" do
|
@@ -47,7 +51,7 @@ describe Conjur::HasAttributes do
|
|
47
51
|
context "enabled" do
|
48
52
|
it "caches the attributes across objects" do
|
49
53
|
expect(object.attributes).to eq(attributes)
|
50
|
-
expect(
|
54
|
+
expect(second_object.attributes).to eq(attributes)
|
51
55
|
expect(cache.table).to eq({
|
52
56
|
"alice.http://example.com/the-object" => attributes
|
53
57
|
})
|
File without changes
|
File without changes
|
data/spec/roles_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conjur::API do
|
4
|
+
describe '#role_name_from_username' do
|
5
|
+
let(:account) { "the-account" }
|
6
|
+
context "when username is" do
|
7
|
+
[
|
8
|
+
[ 'the-user', 'the-account:user:the-user' ],
|
9
|
+
[ 'host/the-host', 'the-account:host:the-host' ],
|
10
|
+
[ 'host/a/quite/long/host/name', 'the-account:host:a/quite/long/host/name' ],
|
11
|
+
[ 'newkind/host/name', 'the-account:newkind:host/name' ],
|
12
|
+
].each do |p|
|
13
|
+
context "'#{p[0]}'" do
|
14
|
+
let(:username) { p[0] }
|
15
|
+
|
16
|
+
describe '#role_name_from_username' do
|
17
|
+
subject { Conjur::API.role_name_from_username username, account }
|
18
|
+
it { is_expected.to eq(p[1]) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,81 +1,73 @@
|
|
1
1
|
require 'simplecov'
|
2
|
-
SimpleCov.start
|
3
|
-
add_filter "/spec/"
|
4
|
-
end
|
2
|
+
SimpleCov.start
|
5
3
|
|
6
4
|
require 'rubygems'
|
7
5
|
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
8
6
|
$:.unshift File.join(File.dirname(__FILE__), "lib")
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
config.before do
|
26
|
-
# test with a clean environment
|
27
|
-
stub_const 'ENV', 'CONJUR_ENV' => 'test'
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
# If you're not using ActiveRecord you should remove these
|
32
|
-
# lines, delete config/database.yml and disable :active_record
|
33
|
-
# in your config/boot.rb
|
34
|
-
#config.use_transactional_fixtures = true
|
35
|
-
#config.use_instantiated_fixtures = false
|
36
|
-
#config.fixture_path = File.join(redmine_root, 'test', 'fixtures')
|
37
|
-
|
38
|
-
# == Fixtures
|
39
|
-
#
|
40
|
-
# You can declare fixtures for each example_group like this:
|
41
|
-
# describe "...." do
|
42
|
-
# fixtures :table_a, :table_b
|
43
|
-
#
|
44
|
-
# Alternatively, if you prefer to declare them only once, you can
|
45
|
-
# do so right here. Just uncomment the next line and replace the fixture
|
46
|
-
# names with your fixtures.
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# If you declare global fixtures, be aware that they will be declared
|
50
|
-
# for all of your examples, even those that don't use them.
|
51
|
-
#
|
52
|
-
# You can also declare which fixtures to use (for example fixtures for test/fixtures):
|
53
|
-
#
|
54
|
-
# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
55
|
-
#
|
56
|
-
# == Mock Framework
|
57
|
-
#
|
58
|
-
# RSpec uses its own mocking framework by default. If you prefer to
|
59
|
-
# use mocha, flexmock or RR, uncomment the appropriate line:
|
60
|
-
#
|
61
|
-
# config.mock_with :mocha
|
62
|
-
# config.mock_with :flexmock
|
63
|
-
# config.mock_with :rr
|
64
|
-
#
|
65
|
-
# == Notes
|
66
|
-
#
|
67
|
-
# For more information take a look at Spec::Runner::Configuration and Spec::Runner
|
7
|
+
|
8
|
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
9
|
+
# from the project root directory.
|
10
|
+
ENV["CONJUR_ENV"] ||= 'test'
|
11
|
+
|
12
|
+
# Allows loading of an environment config based on the environment
|
13
|
+
require 'rspec'
|
14
|
+
require 'securerandom'
|
15
|
+
|
16
|
+
# Uncomment the next line to use webrat's matchers
|
17
|
+
#require 'webrat/integrations/rspec-rails'
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.before do
|
21
|
+
# test with a clean environment
|
22
|
+
stub_const 'ENV', 'CONJUR_ENV' => 'test'
|
68
23
|
end
|
69
|
-
end
|
70
24
|
|
71
|
-
|
72
|
-
#
|
73
|
-
|
74
|
-
#
|
75
|
-
#
|
76
|
-
|
25
|
+
|
26
|
+
# If you're not using ActiveRecord you should remove these
|
27
|
+
# lines, delete config/database.yml and disable :active_record
|
28
|
+
# in your config/boot.rb
|
29
|
+
#config.use_transactional_fixtures = true
|
30
|
+
#config.use_instantiated_fixtures = false
|
31
|
+
#config.fixture_path = File.join(redmine_root, 'test', 'fixtures')
|
32
|
+
|
33
|
+
# == Fixtures
|
34
|
+
#
|
35
|
+
# You can declare fixtures for each example_group like this:
|
36
|
+
# describe "...." do
|
37
|
+
# fixtures :table_a, :table_b
|
38
|
+
#
|
39
|
+
# Alternatively, if you prefer to declare them only once, you can
|
40
|
+
# do so right here. Just uncomment the next line and replace the fixture
|
41
|
+
# names with your fixtures.
|
42
|
+
#
|
43
|
+
#
|
44
|
+
# If you declare global fixtures, be aware that they will be declared
|
45
|
+
# for all of your examples, even those that don't use them.
|
46
|
+
#
|
47
|
+
# You can also declare which fixtures to use (for example fixtures for test/fixtures):
|
48
|
+
#
|
49
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
50
|
+
#
|
51
|
+
# == Mock Framework
|
52
|
+
#
|
53
|
+
# RSpec uses its own mocking framework by default. If you prefer to
|
54
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
55
|
+
#
|
56
|
+
# config.mock_with :mocha
|
57
|
+
# config.mock_with :flexmock
|
58
|
+
# config.mock_with :rr
|
59
|
+
#
|
60
|
+
# == Notes
|
61
|
+
#
|
62
|
+
# For more information take a look at Spec::Runner::Configuration and Spec::Runner
|
77
63
|
end
|
78
64
|
|
65
|
+
# This code will be run each time you run your specs.
|
66
|
+
|
67
|
+
# Requires supporting files with custom matchers and macros, etc,
|
68
|
+
# in ./support/ and its subdirectories.
|
69
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
70
|
+
|
79
71
|
shared_examples_for "http response" do
|
80
72
|
let(:http_response) { double(:response) }
|
81
73
|
|
@@ -100,20 +92,13 @@ OPTIONS={}
|
|
100
92
|
shared_context api: :dummy do
|
101
93
|
let(:username) { "user" }
|
102
94
|
let(:api){ Conjur::API.new_from_key username, 'key' }
|
103
|
-
let(:authz_host) { 'http://authz.example.com' }
|
104
|
-
let(:audit_host) { 'http://audit.example.com' }
|
105
95
|
let(:authn_host) { 'http://authn.example.com' }
|
106
|
-
let(:credentials) { { headers: { authorization: "Token token=\"stub\"" } } } #, username: username } }
|
107
96
|
let(:core_host) { 'http://core.example.com' }
|
97
|
+
let(:credentials) { { headers: { authorization: "Token token=\"stub\"" } } } #, username: username } }
|
108
98
|
let(:account) { 'the-account' }
|
109
99
|
|
110
100
|
before do
|
111
|
-
allow(Conjur
|
112
|
-
allow(Conjur::Authz::API).to receive_messages host: authz_host
|
113
|
-
allow(Conjur::Core::API).to receive_messages host: core_host
|
114
|
-
allow(Conjur::Core::API).to receive_messages conjur_account: account
|
115
|
-
allow(Conjur::Audit::API).to receive_messages host:audit_host
|
116
|
-
Conjur.configuration.set :account, account
|
101
|
+
allow(Conjur.configuration).to receive_messages account: account, core_url: core_host, authn_url: authn_host
|
117
102
|
allow(api).to receive_messages credentials: credentials
|
118
103
|
end
|
119
104
|
end
|
data/spec/ssl_spec.rb
CHANGED
@@ -9,7 +9,7 @@ require 'webrick/https'
|
|
9
9
|
describe 'SSL connection' do
|
10
10
|
context 'with an untrusted certificate' do
|
11
11
|
it 'fails' do
|
12
|
-
expect { Conjur::API.login 'foo', 'bar' }.to \
|
12
|
+
expect { Conjur::API.login 'foo', 'bar', account: "the-account" }.to \
|
13
13
|
raise_one_of(RestClient::SSLCertificateNotVerified, OpenSSL::SSL::SSLError)
|
14
14
|
end
|
15
15
|
end
|
@@ -22,7 +22,7 @@ describe 'SSL connection' do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'works' do
|
25
|
-
expect { Conjur::API.login 'foo', 'bar' }.to raise_error RestClient::ResourceNotFound
|
25
|
+
expect { Conjur::API.login 'foo', 'bar', account: "the-account" }.to raise_error RestClient::ResourceNotFound
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -35,16 +35,14 @@ describe 'SSL connection' do
|
|
35
35
|
let(:port) { server.config[:Port] }
|
36
36
|
|
37
37
|
before do
|
38
|
-
allow(Conjur
|
38
|
+
allow(Conjur.configuration).to receive(:authn_url).and_return "https://localhost:#{port}"
|
39
39
|
end
|
40
40
|
|
41
41
|
around do |example|
|
42
42
|
server_thread = Thread.new do
|
43
43
|
server.start
|
44
44
|
end
|
45
|
-
WebMock.disable!
|
46
45
|
example.run
|
47
|
-
WebMock.enable!
|
48
46
|
server.shutdown
|
49
47
|
server_thread.join
|
50
48
|
end
|
@@ -38,58 +38,4 @@ describe RestClient::Request do
|
|
38
38
|
expect(request.ssl_opts[:cert_store]).to eq(OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE)
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
|
-
def reinit_mime_types!
|
43
|
-
# pretend to initialize MIME::Types from scratch
|
44
|
-
MIME::Types.instance_variable_set :@__types__, nil
|
45
|
-
MIME::Types.send :remove_const, :VERSION # to suppress a warning
|
46
|
-
load 'mime/types.rb'
|
47
|
-
end
|
48
|
-
|
49
|
-
def with_env vals, &block
|
50
|
-
olds = Hash[vals.keys.zip ENV.values_at *vals.keys]
|
51
|
-
ENV.update vals
|
52
|
-
yield if block_given?
|
53
|
-
ENV.update olds
|
54
|
-
end
|
55
|
-
|
56
|
-
around do |ex|
|
57
|
-
with_env 'RUBY_MIME_TYPES_CACHE' => cache,
|
58
|
-
'RUBY_MIME_TYPES_LAZY_LOAD' => lazy.to_s do
|
59
|
-
reinit_mime_types!
|
60
|
-
ex.run
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "with plain MIME::Types config" do
|
65
|
-
let(:cache) { nil }
|
66
|
-
let(:lazy) { false }
|
67
|
-
include_examples :restclient
|
68
|
-
end
|
69
|
-
|
70
|
-
context "with lazy MIME::Types loading" do
|
71
|
-
let(:cache) { nil }
|
72
|
-
let(:lazy) { true }
|
73
|
-
include_examples :restclient
|
74
|
-
end
|
75
|
-
|
76
|
-
context "using MIME::Types cache" do
|
77
|
-
let(:cache) do
|
78
|
-
tf = Tempfile.new('mimecache')
|
79
|
-
path = tf.path
|
80
|
-
|
81
|
-
tf.unlink # delete so mimetypes doesn't try to read it
|
82
|
-
# create the cache
|
83
|
-
with_env 'RUBY_MIME_TYPES_CACHE' => path,
|
84
|
-
'RUBY_MIME_TYPES_LAZY_LOAD' => 'false' do
|
85
|
-
reinit_mime_types!
|
86
|
-
end
|
87
|
-
|
88
|
-
return path
|
89
|
-
end
|
90
|
-
|
91
|
-
after { File.unlink cache }
|
92
|
-
let(:lazy) { false }
|
93
|
-
include_examples :restclient
|
94
|
-
end
|
95
41
|
end
|
data/test.sh
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/bin/bash -e
|
2
|
+
|
3
|
+
function finish {
|
4
|
+
echo 'Removing test environment'
|
5
|
+
echo '---'
|
6
|
+
docker-compose down --rmi 'local' --volumes
|
7
|
+
}
|
8
|
+
trap finish EXIT
|
9
|
+
|
10
|
+
function main() {
|
11
|
+
# Generate reports folders locally
|
12
|
+
mkdir -p spec/reports features/reports
|
13
|
+
|
14
|
+
startConjur
|
15
|
+
runTests
|
16
|
+
}
|
17
|
+
|
18
|
+
function startConjur() {
|
19
|
+
echo 'Starting Conjur environment'
|
20
|
+
echo '-----'
|
21
|
+
docker-compose pull conjur postgres
|
22
|
+
docker-compose build --pull tester
|
23
|
+
docker-compose up -d conjur
|
24
|
+
}
|
25
|
+
|
26
|
+
function runTests() {
|
27
|
+
echo 'waiting for Conjur to come up...'
|
28
|
+
# TODO: remove this once we have HEALTHCHECK in place
|
29
|
+
docker-compose run --rm tester ./ci/wait_for_server.sh
|
30
|
+
|
31
|
+
local api_key=$(docker-compose exec -T conjur rails r "print Credentials['cucumber:user:admin'].api_key")
|
32
|
+
|
33
|
+
echo 'Running tests'
|
34
|
+
echo '-----'
|
35
|
+
docker-compose run --rm \
|
36
|
+
-e CONJUR_AUTHN_API_KEY="$api_key" \
|
37
|
+
tester
|
38
|
+
}
|
39
|
+
|
40
|
+
main
|