berkshelf 5.2.0 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +10 -2
- data/CONTRIBUTING.md +5 -1
- data/Gemfile.lock +17 -17
- data/README.md +1 -1
- data/berkshelf.gemspec +1 -1
- data/lib/berkshelf.rb +14 -2
- data/lib/berkshelf/config.rb +3 -0
- data/lib/berkshelf/downloader.rb +9 -1
- data/lib/berkshelf/source.rb +10 -1
- data/lib/berkshelf/ssl_policies.rb +40 -0
- data/lib/berkshelf/version.rb +1 -1
- data/spec/data/trusted_certs/example.crt +22 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/berkshelf/downloader_spec.rb +106 -33
- data/spec/unit/berkshelf/ssl_policies_spec.rb +75 -0
- data/spec/unit/berkshelf/uploader_spec.rb +25 -1
- metadata +14 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca3e18fe34db1ef6247c982bfcdee59145909ace
|
4
|
+
data.tar.gz: 2349d6fd268fe58dd5f28096bbd16aa57f8a4d57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 670473789eb3606bc9e867fbb6f28ce2858bfa1ef0092862627043008ffb7b807580bcfa06c3a01fb111a847144f9ff262041f93e0cc103e3b2db2a944101ecf
|
7
|
+
data.tar.gz: 0beb850938db36494f3ed5b272c6974706c57731cacc74ec62578a5c9f821fad1737dadbdd91a5f30f28be791b0b9781de9c685bcc73b121ad2202c1d7f3698e
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [5.
|
4
|
-
[Full Changelog](https://github.com/berkshelf/berkshelf/compare/v5.
|
3
|
+
## [5.3.0](https://github.com/berkshelf/berkshelf/tree/5.3.0) (2016-12-15)
|
4
|
+
[Full Changelog](https://github.com/berkshelf/berkshelf/compare/v5.2.0...5.3.0)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Add SSLPolicy class that will use chefdk trusted certs path [\#1640](https://github.com/berkshelf/berkshelf/pull/1640) ([afiune](https://github.com/afiune))
|
9
|
+
- Add alternative way to run tests [\#1626](https://github.com/berkshelf/berkshelf/pull/1626) ([gliptak](https://github.com/gliptak))
|
10
|
+
|
11
|
+
## [v5.2.0](https://github.com/berkshelf/berkshelf/tree/v5.2.0) (2016-11-07)
|
12
|
+
[Full Changelog](https://github.com/berkshelf/berkshelf/compare/v5.1.0...v5.2.0)
|
5
13
|
|
6
14
|
**Merged pull requests:**
|
7
15
|
|
data/CONTRIBUTING.md
CHANGED
@@ -36,10 +36,14 @@ Bundler will install all gems and their dependencies required for testing and de
|
|
36
36
|
|
37
37
|
### Running unit (RSpec) and acceptance (Cucumber) tests
|
38
38
|
|
39
|
-
We use Chef Zero - an in-memory Chef Server for running tests. It is automatically managed by the Specs and Cukes.
|
39
|
+
We use Chef Zero - an in-memory Chef Server for running tests. It is automatically managed by the Specs and Cukes. Run:
|
40
40
|
|
41
41
|
$ bundle exec guard start
|
42
42
|
|
43
|
+
or
|
44
|
+
|
45
|
+
$ bundle exec thor spec:ci
|
46
|
+
|
43
47
|
See [here](https://github.com/tdegrunt/vagrant-chef-server-bootstrap) for a
|
44
48
|
quick way to get a testing chef server up.
|
45
49
|
|
data/Gemfile.lock
CHANGED
@@ -20,7 +20,7 @@ GIT
|
|
20
20
|
PATH
|
21
21
|
remote: .
|
22
22
|
specs:
|
23
|
-
berkshelf (5.
|
23
|
+
berkshelf (5.3.0)
|
24
24
|
addressable (~> 2.3, >= 2.3.4)
|
25
25
|
berkshelf-api-client (>= 2.0.2, < 4.0)
|
26
26
|
buff-config (~> 2.0)
|
@@ -35,7 +35,7 @@ PATH
|
|
35
35
|
retryable (~> 2.0)
|
36
36
|
ridley (~> 5.0)
|
37
37
|
solve (> 2.0, < 4.0)
|
38
|
-
thor (~> 0.19)
|
38
|
+
thor (~> 0.19, < 0.19.2)
|
39
39
|
|
40
40
|
GEM
|
41
41
|
remote: https://rubygems.org/
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
addressable (2.4.0)
|
50
50
|
archive (0.0.6)
|
51
51
|
ffi (~> 1.9.3)
|
52
|
-
artifactory (2.5.
|
52
|
+
artifactory (2.5.1)
|
53
53
|
aruba (0.14.2)
|
54
54
|
childprocess (~> 0.5.6)
|
55
55
|
contracts (~> 0.9)
|
@@ -80,7 +80,7 @@ GEM
|
|
80
80
|
celluloid-io (0.16.2)
|
81
81
|
celluloid (>= 0.16.0)
|
82
82
|
nio4r (>= 1.1.0)
|
83
|
-
chef-config (12.
|
83
|
+
chef-config (12.16.42)
|
84
84
|
addressable
|
85
85
|
fuzzyurl
|
86
86
|
mixlib-config (~> 2.0)
|
@@ -187,10 +187,10 @@ GEM
|
|
187
187
|
guard (~> 2.0)
|
188
188
|
guard-compat (~> 1.0)
|
189
189
|
spork (>= 0.8.4)
|
190
|
-
hashdiff (0.3.
|
190
|
+
hashdiff (0.3.1)
|
191
191
|
hashie (3.4.6)
|
192
192
|
hitimes (1.2.4)
|
193
|
-
http (2.0
|
193
|
+
http (2.1.0)
|
194
194
|
addressable (~> 2.3)
|
195
195
|
http-cookie (~> 1.0)
|
196
196
|
http-form_data (~> 1.0.1)
|
@@ -219,7 +219,7 @@ GEM
|
|
219
219
|
mixlib-authentication (1.4.1)
|
220
220
|
mixlib-log
|
221
221
|
mixlib-config (2.2.4)
|
222
|
-
mixlib-install (2.1.
|
222
|
+
mixlib-install (2.1.7)
|
223
223
|
artifactory
|
224
224
|
mixlib-shellout
|
225
225
|
mixlib-versioning
|
@@ -227,7 +227,7 @@ GEM
|
|
227
227
|
mixlib-log (1.7.1)
|
228
228
|
mixlib-shellout (2.2.7)
|
229
229
|
mixlib-versioning (1.1.0)
|
230
|
-
molinillo (0.5.
|
230
|
+
molinillo (0.5.4)
|
231
231
|
msgpack (1.0.2)
|
232
232
|
multi_json (1.12.1)
|
233
233
|
multi_test (0.1.2)
|
@@ -253,12 +253,12 @@ GEM
|
|
253
253
|
multi_json (~> 1.3)
|
254
254
|
multi_xml (~> 0.5)
|
255
255
|
rack (>= 1.2, < 3)
|
256
|
-
octokit (4.
|
257
|
-
sawyer (~> 0.
|
256
|
+
octokit (4.6.2)
|
257
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
258
258
|
overcommit (0.37.0)
|
259
259
|
childprocess (~> 0.5.8)
|
260
260
|
iniparse (~> 1.4)
|
261
|
-
parser (2.3.
|
261
|
+
parser (2.3.3.0)
|
262
262
|
ast (~> 2.2)
|
263
263
|
powerpack (0.1.1)
|
264
264
|
pry (0.10.4)
|
@@ -320,17 +320,17 @@ GEM
|
|
320
320
|
ruby-progressbar (1.8.1)
|
321
321
|
ruby_dep (1.5.0)
|
322
322
|
safe_yaml (1.0.4)
|
323
|
-
sawyer (0.
|
324
|
-
addressable (>= 2.3.5, < 2.
|
325
|
-
faraday (~> 0.8, < 0
|
323
|
+
sawyer (0.8.1)
|
324
|
+
addressable (>= 2.3.5, < 2.6)
|
325
|
+
faraday (~> 0.8, < 1.0)
|
326
326
|
semverse (2.0.0)
|
327
327
|
shellany (0.0.1)
|
328
328
|
slop (3.6.0)
|
329
|
-
solve (3.0
|
330
|
-
molinillo (
|
329
|
+
solve (3.1.0)
|
330
|
+
molinillo (>= 0.5)
|
331
331
|
semverse (>= 1.1, < 3.0)
|
332
332
|
spork (0.9.2)
|
333
|
-
test-kitchen (1.
|
333
|
+
test-kitchen (1.14.0)
|
334
334
|
mixlib-install (>= 1.2, < 3.0)
|
335
335
|
mixlib-shellout (>= 1.2, < 3.0)
|
336
336
|
net-scp (~> 1.1)
|
data/README.md
CHANGED
data/berkshelf.gemspec
CHANGED
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.add_dependency 'retryable', '~> 2.0'
|
43
43
|
s.add_dependency 'ridley', '~> 5.0'
|
44
44
|
s.add_dependency 'solve', '> 2.0', '< 4.0'
|
45
|
-
s.add_dependency 'thor', '~> 0.19'
|
45
|
+
s.add_dependency 'thor', '~> 0.19', '< 0.19.2'
|
46
46
|
s.add_dependency 'octokit', '~> 4.0'
|
47
47
|
s.add_dependency 'mixlib-archive', '~> 0.1'
|
48
48
|
end
|
data/lib/berkshelf.rb
CHANGED
@@ -118,14 +118,25 @@ module Berkshelf
|
|
118
118
|
@formatter ||= HumanFormatter.new
|
119
119
|
end
|
120
120
|
|
121
|
+
def ssl_policy
|
122
|
+
@ssl_policy ||= SSLPolicy.new
|
123
|
+
end
|
124
|
+
|
121
125
|
# @raise [Berkshelf::ChefConnectionError]
|
122
126
|
def ridley_connection(options = {}, &block)
|
123
|
-
|
127
|
+
ssl_options = {}
|
128
|
+
ssl_options[:verify] = if options[:ssl_verify].nil?
|
129
|
+
Berkshelf.config.ssl.verify
|
130
|
+
else
|
131
|
+
options[:ssl_verify]
|
132
|
+
end
|
133
|
+
ssl_options[:cert_store] = ssl_policy.store if ssl_policy.store
|
124
134
|
|
135
|
+
ridley_options = options.slice(:ssl)
|
125
136
|
ridley_options[:server_url] = options[:server_url] || Berkshelf.config.chef.chef_server_url
|
126
137
|
ridley_options[:client_name] = options[:client_name] || Berkshelf.config.chef.node_name
|
127
138
|
ridley_options[:client_key] = options[:client_key] || Berkshelf.config.chef.client_key
|
128
|
-
ridley_options[:ssl] =
|
139
|
+
ridley_options[:ssl] = ssl_options
|
129
140
|
|
130
141
|
unless ridley_options[:server_url].present?
|
131
142
|
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.server_url'
|
@@ -207,6 +218,7 @@ require_relative 'berkshelf/resolver'
|
|
207
218
|
require_relative 'berkshelf/source'
|
208
219
|
require_relative 'berkshelf/source_uri'
|
209
220
|
require_relative 'berkshelf/validator'
|
221
|
+
require_relative 'berkshelf/ssl_policies'
|
210
222
|
|
211
223
|
Ridley.logger = Berkshelf.logger
|
212
224
|
Berkshelf.logger.level = Logger::WARN
|
data/lib/berkshelf/config.rb
CHANGED
@@ -106,6 +106,9 @@ module Berkshelf
|
|
106
106
|
attribute 'chef.node_name',
|
107
107
|
type: String,
|
108
108
|
default: Berkshelf.chef_config.node_name
|
109
|
+
attribute 'chef.trusted_certs_dir',
|
110
|
+
type: String,
|
111
|
+
default: Berkshelf.chef_config.trusted_certs_dir
|
109
112
|
attribute 'cookbook.copyright',
|
110
113
|
type: String,
|
111
114
|
default: Berkshelf.chef_config.cookbook_copyright
|
data/lib/berkshelf/downloader.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'mixlib/archive'
|
3
|
+
require 'berkshelf/ssl_policies'
|
3
4
|
|
4
5
|
module Berkshelf
|
5
6
|
class Downloader
|
@@ -14,6 +15,10 @@ module Berkshelf
|
|
14
15
|
@berksfile = berksfile
|
15
16
|
end
|
16
17
|
|
18
|
+
def ssl_policy
|
19
|
+
@ssl_policy ||= SSLPolicy.new
|
20
|
+
end
|
21
|
+
|
17
22
|
# Download the given Berkshelf::Dependency. If the optional block is given,
|
18
23
|
# the temporary path to the cookbook is yielded and automatically deleted
|
19
24
|
# when the block returns. If no block is given, it is the responsibility of
|
@@ -61,11 +66,14 @@ module Berkshelf
|
|
61
66
|
CommunityREST.new(remote_cookbook.location_path).download(name, version)
|
62
67
|
when :chef_server
|
63
68
|
# @todo Dynamically get credentials for remote_cookbook.location_path
|
69
|
+
ssl_options = {verify: Berkshelf::Config.instance.ssl.verify}
|
70
|
+
ssl_options[:cert_store] = ssl_policy.store if ssl_policy.store
|
71
|
+
|
64
72
|
credentials = {
|
65
73
|
server_url: remote_cookbook.location_path,
|
66
74
|
client_name: Berkshelf::Config.instance.chef.node_name,
|
67
75
|
client_key: Berkshelf::Config.instance.chef.client_key,
|
68
|
-
ssl:
|
76
|
+
ssl: ssl_options
|
69
77
|
}
|
70
78
|
# @todo Something scary going on here - getting an instance of Kitchen::Logger from test-kitchen
|
71
79
|
# https://github.com/opscode/test-kitchen/blob/master/lib/kitchen.rb#L99
|
data/lib/berkshelf/source.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'berkshelf/api-client'
|
2
|
+
require 'berkshelf/ssl_policies'
|
3
|
+
require 'openssl'
|
2
4
|
|
3
5
|
module Berkshelf
|
4
6
|
class Source
|
@@ -12,11 +14,18 @@ module Berkshelf
|
|
12
14
|
@universe = nil
|
13
15
|
end
|
14
16
|
|
17
|
+
def ssl_policy
|
18
|
+
@ssl_policy ||= SSLPolicy.new
|
19
|
+
end
|
20
|
+
|
15
21
|
def api_client
|
16
22
|
@api_client ||= begin
|
23
|
+
ssl_options = {verify: Berkshelf::Config.instance.ssl.verify}
|
24
|
+
ssl_options[:cert_store] = ssl_policy.store if ssl_policy.store
|
25
|
+
|
17
26
|
if source == :chef_server
|
18
27
|
APIClient.chef_server(
|
19
|
-
ssl:
|
28
|
+
ssl: ssl_options,
|
20
29
|
timeout: api_timeout,
|
21
30
|
open_timeout: [(api_timeout / 10), 3].max,
|
22
31
|
client_name: Berkshelf::Config.instance.chef.node_name,
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module Berkshelf
|
4
|
+
class SSLPolicy
|
5
|
+
|
6
|
+
# @return [Store]
|
7
|
+
# Holds trusted CA certificates used to verify peer certificates
|
8
|
+
attr_reader :store
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@store = OpenSSL::X509::Store.new.tap do |store|
|
12
|
+
store.set_default_paths
|
13
|
+
end
|
14
|
+
|
15
|
+
set_custom_certs if ::File.exist?(trusted_certs_dir)
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_trusted_cert(cert)
|
19
|
+
@store.add_cert(cert)
|
20
|
+
rescue OpenSSL::X509::StoreError => e
|
21
|
+
raise e unless e.message == 'cert already in hash table'
|
22
|
+
end
|
23
|
+
|
24
|
+
def trusted_certs_dir
|
25
|
+
config_dir = Berkshelf.config.chef.trusted_certs_dir.to_s
|
26
|
+
if config_dir.empty? || !::File.exist?(config_dir)
|
27
|
+
File.join(ENV['HOME'], '.chef', 'trusted_certs')
|
28
|
+
else
|
29
|
+
config_dir
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_custom_certs
|
34
|
+
::Dir.glob("#{trusted_certs_dir}/" "{*.crt,*.pem}").each do |cert|
|
35
|
+
cert = OpenSSL::X509::Certificate.new(IO.read(cert))
|
36
|
+
add_trusted_cert(cert)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/berkshelf/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDkjCCAnoCCQDihI8kxGYTFTANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMC
|
3
|
+
VVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMRAwDgYDVQQKEwdZb3VD
|
4
|
+
b3JwMRMwEQYDVQQLEwpPcGVyYXRpb25zMRYwFAYDVQQDEw1leGFtcGxlLmxvY2Fs
|
5
|
+
MR0wGwYJKoZIhvcNAQkBFg5tZUBleGFtcGxlLmNvbTAeFw0xMzEwMTcxODAxMzVa
|
6
|
+
Fw0yMzEwMTUxODAxMzVaMIGKMQswCQYDVQQGEwJVUzELMAkGA1UECBMCV0ExEDAO
|
7
|
+
BgNVBAcTB1NlYXR0bGUxEDAOBgNVBAoTB1lvdUNvcnAxEzARBgNVBAsTCk9wZXJh
|
8
|
+
dGlvbnMxFjAUBgNVBAMTDWV4YW1wbGUubG9jYWwxHTAbBgkqhkiG9w0BCQEWDm1l
|
9
|
+
QGV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKBo
|
10
|
+
U+Bdni0xZK/NCzdLdi2X+TyW5eahbYMx+r1GDcVqCICvrthBCVLVFsQ8rvOHwTPi
|
11
|
+
AxQJGxb9TLSXRgXQSlH6FLjIUceuOtpan3qYVJ1v7AxY4DgNvYBpbtJz5MQedJnT
|
12
|
+
g2F+rXzkwaD6CWBqWHeGU0oP3r7bq1AMD6XEsK2w2/zHtG7TEnL45ARv1PsyrU5M
|
13
|
+
ZAW/XyoMyq1k2Lpv7YR5kAvTq1+4RSt/it2RFE7R0AVbaQ0MeAnllfySiHHHlaOT
|
14
|
+
FVd/qPSiGISxsUmmzA3Z08+0sfJwkrnJXbLscCBYndd7gMGgtczGjJtul0Ch3GFa
|
15
|
+
/Pn5McjwF272+usJ1wIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQCzPePWifWNECsG
|
16
|
+
nL8on1AtFMkczE1/pdRS4YUl/Tc926MpezptSja8rL31+4Bom37/wYPG7HygtAQl
|
17
|
+
R4FHpAtuqJKPOfjUmDNsIXRFnytrnflTpctDu/Nbj4PDCy01k/sTDUQt+s+lEBL8
|
18
|
+
M8ArmfLZ8PCfAwnXmJQ5rggDFKqegjt6z1RsSglbMiASE7+KkpBnzaqH6fET6IQz
|
19
|
+
WgAjv6WdRfwgfJjOTSX4XMpCSet9KaWmXExKrxiVng2Uu6E+ShVAyKaGMuc1B7VA
|
20
|
+
oxnnVaVapFv5lOWucQr4KkC7EgaUZnyt8duOc8+Yvd+y3Xd2dcHUnmegRxly4jRV
|
21
|
+
/lXbFAUb
|
22
|
+
-----END CERTIFICATE-----
|
data/spec/spec_helper.rb
CHANGED
@@ -1,43 +1,116 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
describe "#try_download" do
|
12
|
-
let(:remote_cookbook) { double('remote-cookbook') }
|
13
|
-
let(:source) do
|
14
|
-
source = double('source')
|
15
|
-
allow(source).to receive(:cookbook) { remote_cookbook }
|
16
|
-
source
|
17
|
-
end
|
18
|
-
let(:name) { "fake" }
|
19
|
-
let(:version) { "1.0.0" }
|
20
|
-
|
21
|
-
it "supports the 'opscode' location type" do
|
22
|
-
allow(remote_cookbook).to receive(:location_type) { :opscode }
|
23
|
-
allow(remote_cookbook).to receive(:location_path) { "http://api.opscode.com" }
|
24
|
-
rest = double('community-rest')
|
25
|
-
expect(Berkshelf::CommunityREST).to receive(:new).with("http://api.opscode.com") { rest }
|
26
|
-
expect(rest).to receive(:download).with(name, version)
|
27
|
-
subject.try_download(source, name, version)
|
3
|
+
module Berkshelf
|
4
|
+
describe Downloader do
|
5
|
+
let(:berksfile) do
|
6
|
+
double(Berksfile,
|
7
|
+
lockfile: lockfile,
|
8
|
+
dependencies: [],
|
9
|
+
)
|
28
10
|
end
|
29
11
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
expect(Berkshelf::CommunityREST).to receive(:new).with("http://api.supermarket.com") { rest }
|
35
|
-
expect(rest).to receive(:download).with(name, version)
|
36
|
-
subject.try_download(source, name, version)
|
12
|
+
let(:lockfile) do
|
13
|
+
double(Lockfile,
|
14
|
+
graph: graph
|
15
|
+
)
|
37
16
|
end
|
38
17
|
|
39
|
-
|
18
|
+
let(:graph) { double(Lockfile::Graph, locks: {}) }
|
19
|
+
let(:self_signed_crt_path) { File.join(BERKS_SPEC_DATA, 'trusted_certs') }
|
20
|
+
let(:self_signed_crt) { OpenSSL::X509::Certificate.new(IO.read("#{self_signed_crt_path}/example.crt")) }
|
21
|
+
let(:cert_store) { OpenSSL::X509::Store.new.add_cert(self_signed_crt) }
|
22
|
+
let(:ssl_policy) { double(SSLPolicy, store: cert_store) }
|
23
|
+
|
24
|
+
subject { described_class.new(berksfile) }
|
25
|
+
|
26
|
+
describe "#download" do
|
40
27
|
skip
|
41
28
|
end
|
29
|
+
|
30
|
+
describe "#try_download" do
|
31
|
+
let(:remote_cookbook) { double('remote-cookbook') }
|
32
|
+
let(:source) do
|
33
|
+
source = double('source')
|
34
|
+
allow(source).to receive(:cookbook) { remote_cookbook }
|
35
|
+
source
|
36
|
+
end
|
37
|
+
let(:name) { "fake" }
|
38
|
+
let(:version) { "1.0.0" }
|
39
|
+
|
40
|
+
it "supports the 'opscode' location type" do
|
41
|
+
allow(remote_cookbook).to receive(:location_type) { :opscode }
|
42
|
+
allow(remote_cookbook).to receive(:location_path) { "http://api.opscode.com" }
|
43
|
+
rest = double('community-rest')
|
44
|
+
expect(CommunityREST).to receive(:new).with("http://api.opscode.com") { rest }
|
45
|
+
expect(rest).to receive(:download).with(name, version)
|
46
|
+
subject.try_download(source, name, version)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "supports the 'supermarket' location type" do
|
50
|
+
allow(remote_cookbook).to receive(:location_type) { :supermarket }
|
51
|
+
allow(remote_cookbook).to receive(:location_path) { "http://api.supermarket.com" }
|
52
|
+
rest = double('community-rest')
|
53
|
+
expect(CommunityREST).to receive(:new).with("http://api.supermarket.com") { rest }
|
54
|
+
expect(rest).to receive(:download).with(name, version)
|
55
|
+
subject.try_download(source, name, version)
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'chef_server location type' do
|
59
|
+
let(:chef_server_url) { 'http://configured-chef-server/' }
|
60
|
+
let(:ridley_client) do
|
61
|
+
double(Ridley::Client,
|
62
|
+
cookbook: double('cookbook', download: "fake")
|
63
|
+
)
|
64
|
+
end
|
65
|
+
let(:chef_config) do
|
66
|
+
double(Ridley::Chef::Config,
|
67
|
+
node_name: 'fake-client',
|
68
|
+
client_key: 'client-key',
|
69
|
+
chef_server_url: chef_server_url,
|
70
|
+
validation_client_name: 'validator',
|
71
|
+
validation_key: 'validator.pem',
|
72
|
+
cookbook_copyright: 'user',
|
73
|
+
cookbook_email: 'user@example.com',
|
74
|
+
cookbook_license: 'apachev2',
|
75
|
+
trusted_certs_dir: self_signed_crt_path,
|
76
|
+
knife: {
|
77
|
+
chef_guard: false
|
78
|
+
}
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
let(:berkshelf_config) do
|
83
|
+
double(Config,
|
84
|
+
ssl: double(verify: true),
|
85
|
+
chef: chef_config
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
before do
|
90
|
+
allow(Berkshelf).to receive(:config).and_return(berkshelf_config)
|
91
|
+
allow(subject).to receive(:ssl_policy).and_return(ssl_policy)
|
92
|
+
allow(remote_cookbook).to receive(:location_type) { :chef_server }
|
93
|
+
allow(remote_cookbook).to receive(:location_path) { chef_server_url }
|
94
|
+
end
|
95
|
+
|
96
|
+
it "uses the berkshelf config and provides a custom cert_store" do
|
97
|
+
credentials = {
|
98
|
+
server_url: chef_server_url,
|
99
|
+
client_name: chef_config.node_name,
|
100
|
+
client_key: chef_config.client_key,
|
101
|
+
ssl: {
|
102
|
+
verify: berkshelf_config.ssl.verify,
|
103
|
+
cert_store: cert_store
|
104
|
+
}
|
105
|
+
}
|
106
|
+
expect(Ridley).to receive(:open).with(credentials) { ridley_client }
|
107
|
+
subject.try_download(source, name, version)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it "supports the 'file_store' location type" do
|
112
|
+
skip
|
113
|
+
end
|
114
|
+
end
|
42
115
|
end
|
43
116
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Berkshelf::SSLPolicy do
|
4
|
+
let(:self_signed_crt_path) { File.join(BERKS_SPEC_DATA, 'trusted_certs') }
|
5
|
+
|
6
|
+
let(:chef_config) do
|
7
|
+
double(Ridley::Chef::Config,
|
8
|
+
node_name: 'fake-client',
|
9
|
+
client_key: 'client-key',
|
10
|
+
chef_server_url: 'http://configured-chef-server/',
|
11
|
+
validation_client_name: 'validator',
|
12
|
+
validation_key: 'validator.pem',
|
13
|
+
cookbook_copyright: 'user',
|
14
|
+
cookbook_email: 'user@example.com',
|
15
|
+
cookbook_license: 'apachev2',
|
16
|
+
trusted_certs_dir: self_signed_crt_path,
|
17
|
+
knife: {
|
18
|
+
chef_guard: false
|
19
|
+
}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:berkshelf_config) do
|
24
|
+
double(Berkshelf::Config,
|
25
|
+
ssl: double(verify: true),
|
26
|
+
chef: chef_config
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
subject do
|
31
|
+
Berkshelf::SSLPolicy.new()
|
32
|
+
end
|
33
|
+
|
34
|
+
before do
|
35
|
+
allow(Berkshelf).to receive(:config).and_return(berkshelf_config)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#initialize' do
|
39
|
+
it 'sets up the store' do
|
40
|
+
expect(subject.store.class).to be(OpenSSL::X509::Store)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'sets up custom certificates for chef' do
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#trusted_certs_dir' do
|
48
|
+
it 'uses the trusted_certs_dir from Berkshelf config' do
|
49
|
+
expect(subject.trusted_certs_dir).to eq(self_signed_crt_path)
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'trusted_certs_dir in Berkshelf' do
|
53
|
+
|
54
|
+
context 'config is not set' do
|
55
|
+
before { allow(chef_config).to receive_messages(trusted_certs_dir: nil) }
|
56
|
+
|
57
|
+
it 'defaults to ~/.chef/trusted_certs' do
|
58
|
+
expect(subject.trusted_certs_dir).to eq(
|
59
|
+
File.join(ENV['HOME'], '.chef', 'trusted_certs')
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'config is seti but does not exist' do
|
65
|
+
before { allow(chef_config).to receive_messages(trusted_certs_dir: '/fake') }
|
66
|
+
|
67
|
+
it 'defaults to ~/.chef/trusted_certs' do
|
68
|
+
expect(subject.trusted_certs_dir).to eq(
|
69
|
+
File.join(ENV['HOME'], '.chef', 'trusted_certs')
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -16,6 +16,10 @@ module Berkshelf
|
|
16
16
|
end
|
17
17
|
|
18
18
|
let(:graph) { double(Lockfile::Graph, locks: {}) }
|
19
|
+
let(:self_signed_crt_path) { File.join(BERKS_SPEC_DATA, 'trusted_certs') }
|
20
|
+
let(:self_signed_crt) { OpenSSL::X509::Certificate.new(IO.read("#{self_signed_crt_path}/example.crt")) }
|
21
|
+
let(:cert_store) { OpenSSL::X509::Store.new.add_cert(self_signed_crt) }
|
22
|
+
let(:ssl_policy) { double(SSLPolicy, store: cert_store) }
|
19
23
|
|
20
24
|
subject { Uploader.new(berksfile) }
|
21
25
|
|
@@ -56,6 +60,7 @@ module Berkshelf
|
|
56
60
|
cookbook_copyright: 'user',
|
57
61
|
cookbook_email: 'user@example.com',
|
58
62
|
cookbook_license: 'apachev2',
|
63
|
+
trusted_certs_dir: self_signed_crt_path,
|
59
64
|
knife: {
|
60
65
|
chef_guard: false
|
61
66
|
}
|
@@ -81,6 +86,7 @@ module Berkshelf
|
|
81
86
|
|
82
87
|
before do
|
83
88
|
allow(Berkshelf).to receive(:config).and_return(berkshelf_config)
|
89
|
+
allow(Berkshelf).to receive(:ssl_policy).and_return(ssl_policy)
|
84
90
|
end
|
85
91
|
|
86
92
|
context 'when there is no value for :chef_server_url' do
|
@@ -123,7 +129,25 @@ module Berkshelf
|
|
123
129
|
client_name: chef_config.node_name,
|
124
130
|
client_key: chef_config.client_key,
|
125
131
|
ssl: {
|
126
|
-
verify: berkshelf_config.ssl.verify
|
132
|
+
verify: berkshelf_config.ssl.verify,
|
133
|
+
cert_store: cert_store
|
134
|
+
}
|
135
|
+
)
|
136
|
+
subject.run
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'when ssl_verify: false is passed as an option' do
|
141
|
+
subject { Uploader.new(berksfile, ssl_verify: false) }
|
142
|
+
|
143
|
+
it 'uses the passed option' do
|
144
|
+
expect(Ridley).to receive(:open).with(
|
145
|
+
server_url: chef_config.chef_server_url,
|
146
|
+
client_name: chef_config.node_name,
|
147
|
+
client_key: chef_config.client_key,
|
148
|
+
ssl: {
|
149
|
+
verify: false,
|
150
|
+
cert_store: cert_store
|
127
151
|
}
|
128
152
|
)
|
129
153
|
subject.run
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berkshelf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Winsor
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2016-
|
15
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: addressable
|
@@ -213,6 +213,9 @@ dependencies:
|
|
213
213
|
- - "~>"
|
214
214
|
- !ruby/object:Gem::Version
|
215
215
|
version: '0.19'
|
216
|
+
- - "<"
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: 0.19.2
|
216
219
|
type: :runtime
|
217
220
|
prerelease: false
|
218
221
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -220,6 +223,9 @@ dependencies:
|
|
220
223
|
- - "~>"
|
221
224
|
- !ruby/object:Gem::Version
|
222
225
|
version: '0.19'
|
226
|
+
- - "<"
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: 0.19.2
|
223
229
|
- !ruby/object:Gem::Dependency
|
224
230
|
name: octokit
|
225
231
|
requirement: !ruby/object:Gem::Requirement
|
@@ -373,6 +379,7 @@ files:
|
|
373
379
|
- lib/berkshelf/shell.rb
|
374
380
|
- lib/berkshelf/source.rb
|
375
381
|
- lib/berkshelf/source_uri.rb
|
382
|
+
- lib/berkshelf/ssl_policies.rb
|
376
383
|
- lib/berkshelf/thor.rb
|
377
384
|
- lib/berkshelf/thor_ext.rb
|
378
385
|
- lib/berkshelf/thor_ext/hash_with_indifferent_access.rb
|
@@ -383,6 +390,7 @@ files:
|
|
383
390
|
- spec/config/berkshelf.pem
|
384
391
|
- spec/config/knife.rb
|
385
392
|
- spec/config/validator.pem
|
393
|
+
- spec/data/trusted_certs/example.crt
|
386
394
|
- spec/fixtures/Berksfile
|
387
395
|
- spec/fixtures/berksfiles/default
|
388
396
|
- spec/fixtures/cookbook-path/jenkins-config/metadata.rb
|
@@ -445,6 +453,7 @@ files:
|
|
445
453
|
- spec/unit/berkshelf/shell_spec.rb
|
446
454
|
- spec/unit/berkshelf/source_spec.rb
|
447
455
|
- spec/unit/berkshelf/source_uri_spec.rb
|
456
|
+
- spec/unit/berkshelf/ssl_policies_spec.rb
|
448
457
|
- spec/unit/berkshelf/uploader_spec.rb
|
449
458
|
- spec/unit/berkshelf/validator_spec.rb
|
450
459
|
- spec/unit/berkshelf/visualizer_spec.rb
|
@@ -469,7 +478,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
469
478
|
version: 2.0.0
|
470
479
|
requirements: []
|
471
480
|
rubyforge_project:
|
472
|
-
rubygems_version: 2.
|
481
|
+
rubygems_version: 2.6.8
|
473
482
|
signing_key:
|
474
483
|
specification_version: 4
|
475
484
|
summary: Manages a Cookbook's, or an Application's, Cookbook dependencies
|
@@ -515,6 +524,7 @@ test_files:
|
|
515
524
|
- spec/config/berkshelf.pem
|
516
525
|
- spec/config/knife.rb
|
517
526
|
- spec/config/validator.pem
|
527
|
+
- spec/data/trusted_certs/example.crt
|
518
528
|
- spec/fixtures/Berksfile
|
519
529
|
- spec/fixtures/berksfiles/default
|
520
530
|
- spec/fixtures/cookbook-path/jenkins-config/metadata.rb
|
@@ -577,6 +587,7 @@ test_files:
|
|
577
587
|
- spec/unit/berkshelf/shell_spec.rb
|
578
588
|
- spec/unit/berkshelf/source_spec.rb
|
579
589
|
- spec/unit/berkshelf/source_uri_spec.rb
|
590
|
+
- spec/unit/berkshelf/ssl_policies_spec.rb
|
580
591
|
- spec/unit/berkshelf/uploader_spec.rb
|
581
592
|
- spec/unit/berkshelf/validator_spec.rb
|
582
593
|
- spec/unit/berkshelf/visualizer_spec.rb
|