conjur-api 4.15.0 → 4.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/conjur-api/version.rb +1 -1
- data/lib/conjur/configuration.rb +37 -0
- data/spec/lib/configuration_spec.rb +86 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1774efca45d1103cedf13423ce1934f6c3a516e2
|
4
|
+
data.tar.gz: 028c735666d90ab39cc214e22f9e4013195b3894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 885c346828a875234c194bbd27f5a06b353e1b894d2dfc4cdca2dbfcbae27404176211417f968b8f9ca5854d627670d64c6c8a716d5a2f9b2db26f41eca3e802
|
7
|
+
data.tar.gz: 54bcfbb2d74a8f6e7c2079074716051d90369248b175a7f1a6fff434a808a4d2d4e41da24b484729b745012a751d3c982eb56f06ec3df24765a2cd0e55c87feb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# v4.16.0
|
2
|
+
* Add ssl_certificate option to allow certs to be provided as strings (helpful in heroku)
|
3
|
+
* Add `Conjur::Configuration#apply_cert_config!` method to add certs from `#cert_file` and `#ssl_certificate`
|
4
|
+
to the default cert store.
|
1
5
|
# v4.15.0
|
2
6
|
* Extensive documentation improvements
|
3
7
|
* A few additional methoods, for example `Conjur::API#public_key_names`.
|
data/lib/conjur-api/version.rb
CHANGED
data/lib/conjur/configuration.rb
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
19
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
20
|
#
|
21
|
+
|
22
|
+
require 'set'
|
21
23
|
module Conjur
|
22
24
|
|
23
25
|
class << self
|
@@ -388,8 +390,42 @@ module Conjur
|
|
388
390
|
# @return [String, nil] path to the certificate file, or nil if you aren't using one.
|
389
391
|
add_option :cert_file
|
390
392
|
|
393
|
+
# @!attribute ssl_certificate
|
394
|
+
#
|
395
|
+
# Contents of a certificate file. This can be used instead of :cert_file in environments like Heroku where you
|
396
|
+
# can't use a certificate file.
|
397
|
+
#
|
398
|
+
# This option overrides the value of {#cert_file} if both are given, and issues a warning.
|
399
|
+
#
|
400
|
+
# @see cert_file
|
401
|
+
add_option :ssl_certificate
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
# Add the certificate configured by the {#ssl_certificate} and {#cert_file} options to the certificate
|
406
|
+
# store used by Conjur clients.
|
407
|
+
#
|
408
|
+
# @param [OpenSSL::X509::Store] store the certificate store that the certificate will be installed in.
|
409
|
+
# @return [Boolean] whether a certificate was added to the store.
|
410
|
+
def apply_cert_config! store=OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE
|
411
|
+
if ssl_certificate
|
412
|
+
add_cert_string store, ssl_certificate
|
413
|
+
elsif cert_file
|
414
|
+
store.add_file cert_file
|
415
|
+
else
|
416
|
+
return false
|
417
|
+
end
|
418
|
+
true
|
419
|
+
end
|
420
|
+
|
391
421
|
private
|
392
422
|
|
423
|
+
def add_cert_string store, str
|
424
|
+
store.add_cert OpenSSL::X509::Certificate.new str
|
425
|
+
rescue OpenSSL::X509::StoreError => ex
|
426
|
+
raise ex unless ex.message == 'cert already in hash table'
|
427
|
+
end
|
428
|
+
|
393
429
|
def global_service_url(service_name, service_port_offset)
|
394
430
|
if appliance_url
|
395
431
|
URI.join(appliance_url + '/', service_name).to_s
|
@@ -428,5 +464,6 @@ module Conjur
|
|
428
464
|
def herokuize name
|
429
465
|
name.downcase.gsub(/[^a-z0-9\-]/, '-')
|
430
466
|
end
|
467
|
+
|
431
468
|
end
|
432
469
|
end
|
@@ -213,4 +213,90 @@ describe Conjur::Configuration do
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
end
|
216
|
+
|
217
|
+
describe "apply_cert_config!" do
|
218
|
+
subject{ Conjur.configuration.apply_cert_config! }
|
219
|
+
|
220
|
+
let(:store){ double('default store') }
|
221
|
+
|
222
|
+
|
223
|
+
before do
|
224
|
+
stub_const 'OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE', store
|
225
|
+
allow_any_instance_of(Conjur::Configuration).to receive(:ssl_certificate).and_return ssl_certificate
|
226
|
+
allow_any_instance_of(Conjur::Configuration).to receive(:cert_file).and_return cert_file
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
context "when neither cert_file or ssl_certificate is present" do
|
231
|
+
let(:cert_file){ nil }
|
232
|
+
let(:ssl_certificate){ nil }
|
233
|
+
|
234
|
+
it 'does nothing to the store' do
|
235
|
+
expect(store).to_not receive(:add_file)
|
236
|
+
expect(store).to_not receive(:add_cert)
|
237
|
+
expect(subject).to be_falsey
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'when both are given' do
|
242
|
+
let(:cert_file){ '/path/to/cert.pem' }
|
243
|
+
let(:ssl_certificate){ 'certificate contents' }
|
244
|
+
let(:cert){ double('certificate') }
|
245
|
+
it 'calls store.add_cert with a certificate created from ssl_certificate' do
|
246
|
+
expect(OpenSSL::X509::Certificate).to receive(:new).with(ssl_certificate).once.and_return cert
|
247
|
+
expect(store).to receive(:add_cert).once.with(cert)
|
248
|
+
expect(subject).to be_truthy
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context 'when cert_file is given and ssl_certificate is not' do
|
253
|
+
let(:cert_file){ '/path/to/cert.pem' }
|
254
|
+
let(:ssl_certificate){ nil }
|
255
|
+
it 'calls store.add_file with cert_file' do
|
256
|
+
expect(store).to receive(:add_file).with(cert_file).once
|
257
|
+
expect(subject).to be_truthy
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context 'when ssl_certificate is given' do
|
262
|
+
let(:cert_file){ nil }
|
263
|
+
let(:ssl_certificate){ 'certificate contents' }
|
264
|
+
let(:cert){ double('cert') }
|
265
|
+
|
266
|
+
before do
|
267
|
+
expect(OpenSSL::X509::Certificate).to receive(:new).with(ssl_certificate).at_least(:once).and_return cert
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'calls store.add_cert with a certificate created from ssl_certificate' do
|
271
|
+
expect(store).to receive(:add_cert).with(cert).once
|
272
|
+
expect(subject).to be_truthy
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'rescues from a StoreError with message "cert already in hash tabble"' do
|
276
|
+
expect(store).to receive(:add_cert).with(cert).once.and_raise(OpenSSL::X509::StoreError.new('cert already in hash table'))
|
277
|
+
expect(subject).to be_truthy
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
it 'does not rescue from other exceptions' do
|
282
|
+
expect(store).to receive(:add_cert).with(cert).once.and_raise(OpenSSL::X509::StoreError.new('some other message'))
|
283
|
+
expect{subject}.to raise_exception
|
284
|
+
expect(store).to receive(:add_cert).with(cert).once.and_raise(ArgumentError.new('bad news'))
|
285
|
+
expect{subject}.to raise_exception
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
context 'when given a store argument' do
|
290
|
+
let(:cert_file){ '/path/to/cert.pem' }
|
291
|
+
let(:ssl_certificate){ nil }
|
292
|
+
let(:alt_store){ double('alt store') }
|
293
|
+
subject{ Conjur.configuration.apply_cert_config! alt_store }
|
294
|
+
|
295
|
+
it 'uses that store instead' do
|
296
|
+
expect(alt_store).to receive(:add_file).with(cert_file).once
|
297
|
+
expect(subject).to be_truthy
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
216
302
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conjur-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafal Rzepecki
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-04-
|
12
|
+
date: 2015-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|