chef-vault-testfixtures 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/Guardfile +1 -0
- data/History.md +4 -0
- data/README.md +82 -3
- data/Rakefile +3 -0
- data/chef-vault-testfixtures.gemspec +13 -4
- data/lib/chef-vault/test_fixtures.rb +86 -17
- data/spec/lib/chef-vault/test_fixtures_spec.rb +13 -30
- data/spec/spec_helper.rb +11 -0
- metadata +45 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 644e9c5bbb5372faf29af5d11bc7d7580d07fdca
|
4
|
+
data.tar.gz: 42a949fc8bea10c3a4f3d6b63f2a4d811110a7ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e2eb02210c2483adb5a57e12f0ba1e879eb9fc1aa6f89fd2771e165081dae3b50adc2ac5244b81c848ac7244a5b085deb96a50a505e7384117410ac9015ff91
|
7
|
+
data.tar.gz: 0d9d7006e1a92c22993a1b130e275f24521399de3ab84728403a2a12e000929c53a0a6bef3811f17ccbc98ecc27dddec89e19178eb89642cb78f5ac3d71b6fef
|
data/.rubocop.yml
CHANGED
@@ -2,6 +2,7 @@ AllCops:
|
|
2
2
|
Exclude:
|
3
3
|
- '**/Gemfile'
|
4
4
|
- '**/*.gemspec'
|
5
|
+
- 'pkg/**/*'
|
5
6
|
|
6
7
|
Style/RegexpLiteral:
|
7
8
|
Exclude:
|
@@ -12,3 +13,6 @@ Style/Documentation:
|
|
12
13
|
- 'spec/**/*.rb'
|
13
14
|
- lib/chef-vault/test_fixtures/version.rb
|
14
15
|
- lib/hoe/markdown.rb
|
16
|
+
|
17
|
+
Metrics/CyclomaticComplexity:
|
18
|
+
Max: 7
|
data/Guardfile
CHANGED
@@ -10,6 +10,7 @@ guard :rubocop, all_on_start: true, cli: ['-D'] do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
guard :rspec, all_on_start: true, cmd: 'bundle exec rspec' do
|
13
|
+
watch(%r{^spec/recipes/.+_spec\.rb$})
|
13
14
|
watch(%r{^spec/(.+)_spec\.rb$})
|
14
15
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
15
16
|
watch(%r{^spec/spec_helper.*\.rb$}) { 'spec' }
|
data/History.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog for chef-vault-testfixtures
|
2
2
|
|
3
|
+
## 0.5.0
|
4
|
+
|
5
|
+
* breaking change: by default, only stub calls to `ChefVault::Item.load(bag, item)` and `Chef::DataBag.load(bag).key?(item_keys)`. This allows people who are using the JSON files in test/integration/data_bags to stub unencrypted data bag to do so. See the README for details of how to continue to stub `ChefVault::DataBagItem.load(bag, item)` and return a fake hash. Reported by [Dru Goradia](https://github.com/dgoradia-atlas))
|
6
|
+
|
3
7
|
## 0.4.1
|
4
8
|
|
5
9
|
* fix bug where only the last item for a given vault was stubbed
|
data/README.md
CHANGED
@@ -79,9 +79,88 @@ encrypted data, then checking for the existence of the `_keys` data bag
|
|
79
79
|
item to go along with the normal item. The [sensu cookbook](https://github.com/sensu/sensu-chef/blob/35ee3aa6fa4ad578cdf751fe6822e3d2b3890d94/libraries/sensu_helpers.rb#L39-55) is a good example
|
80
80
|
of this:
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
```
|
83
|
+
raw_hash = Chef::DataBagItem.load(data_bag_name, item)
|
84
|
+
encrypted = raw_hash.detect do |key, value|
|
85
|
+
if value.is_a?(Hash)
|
86
|
+
value.has_key?("encrypted_data")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
if encrypted
|
90
|
+
if Chef::DataBag.load(data_bag_name).key? "#{item}_keys"
|
91
|
+
chef_vault_item(data_bag_name, item)
|
92
|
+
else
|
93
|
+
secret = Chef::EncryptedDataBagItem.load_secret
|
94
|
+
Chef::EncryptedDataBagItem.new(raw_hash, secret)
|
95
|
+
end
|
96
|
+
else
|
97
|
+
raw_hash
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
chef-vault-testfixtures also stubs `Chef::DataBag` so that for every JSON
|
102
|
+
file in your test directory, it will think that there is a side-along
|
103
|
+
item suffixed with `_keys`. This satisfies the probes that the chef-vault
|
104
|
+
cookbook helper uses. To address the check for the `encrypted_data` key
|
105
|
+
that the sensu cookbook uses, pass a true value to `rspec_shared_context`:
|
106
|
+
|
107
|
+
```
|
108
|
+
RSpec.describe 'my_cookbook::default' do
|
109
|
+
include ChefVault::TestFixtures.rspec_shared_context(true)
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
Now, when your recipe calls `Chef::DataBagItem.load`, it will
|
114
|
+
get back a hash with the same keys as the JSON file, but values which are
|
115
|
+
hashes of the form:
|
116
|
+
|
117
|
+
```
|
118
|
+
{
|
119
|
+
encrypted_data => '...'
|
120
|
+
}
|
121
|
+
```
|
122
|
+
|
123
|
+
This is not a valid data bag obviously, but it will satisfy the probe
|
124
|
+
and cause code like that in the sensu cookbook to call `ChefVault::Item.load`,
|
125
|
+
which is stubbed to return valid data.
|
126
|
+
|
127
|
+
## STUBBING UNENCRYPTED DATA BAGS
|
128
|
+
|
129
|
+
This technique is not a part of this gem, but was brought to my attention
|
130
|
+
in an issue. Credit to Dru Goradia for the approach. This will let you
|
131
|
+
populate an unencrypted data bag from the same JSON files:
|
132
|
+
|
133
|
+
In `spec/spec_helper.rb`:
|
134
|
+
|
135
|
+
```
|
136
|
+
require 'chef-vault/test_fixtures'
|
137
|
+
require 'json'
|
138
|
+
|
139
|
+
def parse_data_bag (path)
|
140
|
+
data_bags_path = File.expand_path(File.join(File.dirname(__FILE__), '../test/integration/data_bags'))
|
141
|
+
return JSON.parse(File.read("#{data_bags_path}/#{path}"))
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
145
|
+
In your test:
|
146
|
+
|
147
|
+
```
|
148
|
+
describe 'my_cookbook::default' do
|
149
|
+
include ChefVault::TestFixtures.rspec_shared_context
|
150
|
+
|
151
|
+
let(:chef_run) do
|
152
|
+
ChefSpec::ServerRunner.new() do |node, server|
|
153
|
+
server.create_data_bag('foo', {
|
154
|
+
'bar' => parse_data_bag('foo/bar.json')
|
155
|
+
})
|
156
|
+
end.converge(described_recipe)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should converge' do
|
160
|
+
expect(chef_run).to include_recipe(described_recipe)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
```
|
85
164
|
|
86
165
|
## DEPENDENCIES
|
87
166
|
|
data/Rakefile
CHANGED
@@ -12,6 +12,7 @@ begin
|
|
12
12
|
license 'apache2'
|
13
13
|
extra_deps << ['rspec', '~> 3.1']
|
14
14
|
extra_deps << ['chef-vault', '~> 2.5']
|
15
|
+
extra_deps << ['hashie', '~> 2.1']
|
15
16
|
extra_dev_deps << ['chef', '~> 12.0']
|
16
17
|
extra_dev_deps << ['hoe', '~> 3.13']
|
17
18
|
extra_dev_deps << ['hoe-gemspec', '~> 1.0']
|
@@ -21,6 +22,8 @@ begin
|
|
21
22
|
extra_dev_deps << ['guard-rspec', '~> 4.2']
|
22
23
|
extra_dev_deps << ['guard-rake', '~> 0.0']
|
23
24
|
extra_dev_deps << ['guard-rubocop', '~> 1.2']
|
25
|
+
extra_dev_deps << ['chefspec', '~> 4.2']
|
26
|
+
extra_dev_deps << ['berkshelf', '~> 3.2']
|
24
27
|
extra_dev_deps << ['rubocop', '~> 0.29']
|
25
28
|
extra_dev_deps << ['simplecov', '~> 0.9']
|
26
29
|
extra_dev_deps << ['simplecov-console', '~> 0.2']
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: chef-vault-testfixtures 0.4.
|
2
|
+
# stub: chef-vault-testfixtures 0.4.2.20150505160823 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "chef-vault-testfixtures"
|
6
|
-
s.version = "0.4.
|
6
|
+
s.version = "0.4.2.20150505160823"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["James FitzGibbon"]
|
11
|
-
s.date = "2015-
|
11
|
+
s.date = "2015-05-05"
|
12
12
|
s.description = "chef-vault-testfixtures provides an RSpec shared context that\nstubs access to chef-vault encrypted data bags using the same\nfallback mechanism as the `chef_vault_item` helper from the\n[chef-vault cookbook](https://supermarket.chef.io/cookbooks/chef-vault)"
|
13
13
|
s.email = ["james.i.fitzgibbon@nordstrom.com"]
|
14
14
|
s.extra_rdoc_files = ["History.md", "Manifest.txt", "README.md"]
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.homepage = "https://github.com/Nordstrom/chef-vault-testfixtures"
|
17
17
|
s.licenses = ["apache2"]
|
18
18
|
s.rdoc_options = ["--main", "README.md"]
|
19
|
-
s.rubygems_version = "2.4.
|
19
|
+
s.rubygems_version = "2.4.4"
|
20
20
|
s.summary = "chef-vault-testfixtures provides an RSpec shared context that stubs access to chef-vault encrypted data bags using the same fallback mechanism as the `chef_vault_item` helper from the [chef-vault cookbook](https://supermarket.chef.io/cookbooks/chef-vault)"
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
26
|
s.add_runtime_dependency(%q<rspec>, ["~> 3.1"])
|
27
27
|
s.add_runtime_dependency(%q<chef-vault>, ["~> 2.5"])
|
28
|
+
s.add_runtime_dependency(%q<hashie>, ["~> 2.1"])
|
28
29
|
s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
|
29
30
|
s.add_development_dependency(%q<chef>, ["~> 12.0"])
|
30
31
|
s.add_development_dependency(%q<hoe>, ["~> 3.13"])
|
@@ -34,6 +35,8 @@ Gem::Specification.new do |s|
|
|
34
35
|
s.add_development_dependency(%q<guard-rspec>, ["~> 4.2"])
|
35
36
|
s.add_development_dependency(%q<guard-rake>, ["~> 0.0"])
|
36
37
|
s.add_development_dependency(%q<guard-rubocop>, ["~> 1.2"])
|
38
|
+
s.add_development_dependency(%q<chefspec>, ["~> 4.2"])
|
39
|
+
s.add_development_dependency(%q<berkshelf>, ["~> 3.2"])
|
37
40
|
s.add_development_dependency(%q<rubocop>, ["~> 0.29"])
|
38
41
|
s.add_development_dependency(%q<simplecov>, ["~> 0.9"])
|
39
42
|
s.add_development_dependency(%q<simplecov-console>, ["~> 0.2"])
|
@@ -41,6 +44,7 @@ Gem::Specification.new do |s|
|
|
41
44
|
else
|
42
45
|
s.add_dependency(%q<rspec>, ["~> 3.1"])
|
43
46
|
s.add_dependency(%q<chef-vault>, ["~> 2.5"])
|
47
|
+
s.add_dependency(%q<hashie>, ["~> 2.1"])
|
44
48
|
s.add_dependency(%q<rdoc>, ["~> 4.0"])
|
45
49
|
s.add_dependency(%q<chef>, ["~> 12.0"])
|
46
50
|
s.add_dependency(%q<hoe>, ["~> 3.13"])
|
@@ -50,6 +54,8 @@ Gem::Specification.new do |s|
|
|
50
54
|
s.add_dependency(%q<guard-rspec>, ["~> 4.2"])
|
51
55
|
s.add_dependency(%q<guard-rake>, ["~> 0.0"])
|
52
56
|
s.add_dependency(%q<guard-rubocop>, ["~> 1.2"])
|
57
|
+
s.add_dependency(%q<chefspec>, ["~> 4.2"])
|
58
|
+
s.add_dependency(%q<berkshelf>, ["~> 3.2"])
|
53
59
|
s.add_dependency(%q<rubocop>, ["~> 0.29"])
|
54
60
|
s.add_dependency(%q<simplecov>, ["~> 0.9"])
|
55
61
|
s.add_dependency(%q<simplecov-console>, ["~> 0.2"])
|
@@ -58,6 +64,7 @@ Gem::Specification.new do |s|
|
|
58
64
|
else
|
59
65
|
s.add_dependency(%q<rspec>, ["~> 3.1"])
|
60
66
|
s.add_dependency(%q<chef-vault>, ["~> 2.5"])
|
67
|
+
s.add_dependency(%q<hashie>, ["~> 2.1"])
|
61
68
|
s.add_dependency(%q<rdoc>, ["~> 4.0"])
|
62
69
|
s.add_dependency(%q<chef>, ["~> 12.0"])
|
63
70
|
s.add_dependency(%q<hoe>, ["~> 3.13"])
|
@@ -67,6 +74,8 @@ Gem::Specification.new do |s|
|
|
67
74
|
s.add_dependency(%q<guard-rspec>, ["~> 4.2"])
|
68
75
|
s.add_dependency(%q<guard-rake>, ["~> 0.0"])
|
69
76
|
s.add_dependency(%q<guard-rubocop>, ["~> 1.2"])
|
77
|
+
s.add_dependency(%q<chefspec>, ["~> 4.2"])
|
78
|
+
s.add_dependency(%q<berkshelf>, ["~> 3.2"])
|
70
79
|
s.add_dependency(%q<rubocop>, ["~> 0.29"])
|
71
80
|
s.add_dependency(%q<simplecov>, ["~> 0.9"])
|
72
81
|
s.add_dependency(%q<simplecov-console>, ["~> 0.2"])
|
@@ -1,14 +1,17 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'json'
|
3
|
+
require 'hashie/extensions/method_access'
|
3
4
|
|
4
5
|
require 'rspec'
|
5
6
|
require 'rspec/core/shared_context'
|
6
7
|
require 'chef-vault'
|
7
8
|
|
9
|
+
# chef-vault helps manage encrypted data bags using a node's public key
|
8
10
|
class ChefVault
|
9
11
|
# dynamic RSpec contexts for cookbooks that use chef-vault
|
10
12
|
class TestFixtures
|
11
|
-
|
13
|
+
# the version of the gem
|
14
|
+
VERSION = '0.5.0'
|
12
15
|
|
13
16
|
# dynamically creates a memoized RSpec shared context
|
14
17
|
# that when included into an example group will stub
|
@@ -17,42 +20,75 @@ class ChefVault
|
|
17
20
|
# @return [Module] the RSpec shared context
|
18
21
|
class << self
|
19
22
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
20
|
-
|
23
|
+
|
24
|
+
# created a shared RSpec context that stubs calls to ChefVault::Item.load
|
25
|
+
# @param stub_encrypted_data [Boolean] whether to also stub calls to
|
26
|
+
# Chef::DataBagItem.load
|
27
|
+
# @return [Module] a shared context to include in your example groups
|
28
|
+
def rspec_shared_context(stub_encrypted_data = false)
|
21
29
|
@context ||= begin
|
22
30
|
Module.new do
|
23
31
|
extend RSpec::Core::SharedContext
|
24
32
|
|
25
|
-
before { find_vaults }
|
33
|
+
before { find_vaults(stub_encrypted_data) }
|
26
34
|
|
27
35
|
private
|
28
36
|
|
29
|
-
|
37
|
+
# finds all the directories in test/integration/data_bags, stubbing
|
38
|
+
# each as a vault
|
39
|
+
# @param stub_encrypted_data [Boolean] whether to also stub calls to
|
40
|
+
# Chef::DataBagItem.load
|
41
|
+
# return [void]
|
42
|
+
# @api private
|
43
|
+
def find_vaults(stub_encrypted_data)
|
30
44
|
dbdir = Pathname.new('test') + 'integration' + 'data_bags'
|
31
45
|
dbdir.each_child do |vault|
|
32
46
|
next unless vault.directory?
|
33
|
-
stub_vault(vault)
|
47
|
+
stub_vault(stub_encrypted_data, vault)
|
34
48
|
end
|
35
49
|
end
|
36
50
|
|
37
|
-
|
51
|
+
# stubs a vault with the contents of JSON files in a directory.
|
52
|
+
# Finds all files in the vault path ending in .json and stubs
|
53
|
+
# each as a vault item.
|
54
|
+
# @param stub_encrypted_data [Boolean] whether to also stub calls to
|
55
|
+
# Chef::DataBagItem.load
|
56
|
+
# @param vault [Pathname] the path to the directory that will be
|
57
|
+
# stubbed as a vault
|
58
|
+
# @return [void]
|
59
|
+
# @api private
|
60
|
+
def stub_vault(stub_encrypted_data, vault)
|
38
61
|
db = {}
|
39
62
|
vault.each_child do |e|
|
40
63
|
next unless e.file?
|
41
64
|
m = e.basename.to_s.downcase.match(/(.+)\.json/i)
|
42
|
-
|
65
|
+
next unless m
|
66
|
+
content = JSON.parse(e.read)
|
67
|
+
vaultname = vault.basename.to_s
|
68
|
+
stub_vault_item(vaultname, m[1], content, db)
|
69
|
+
if stub_encrypted_data
|
70
|
+
stub_vault_item_encrypted_data(vaultname, m[1], content)
|
71
|
+
end
|
43
72
|
end
|
44
73
|
end
|
45
74
|
|
46
|
-
|
47
|
-
|
75
|
+
# stubs a vault item with the contents of a parsed JSON string.
|
76
|
+
# If the class-level setting `encrypted_data_stub` is true, then
|
77
|
+
# Chef::DataBagItem.load
|
78
|
+
# @param vault [String] the name of the vault data bag
|
79
|
+
# @param item [String] the name of the vault item
|
80
|
+
# @param content [String] the JSON-encoded contents to populate the
|
81
|
+
# fake vault with
|
82
|
+
# @param db [Hash] the fake data bag item that contains the item
|
83
|
+
# @return [void]
|
84
|
+
# @api private
|
85
|
+
def stub_vault_item(vault, item, content, db)
|
48
86
|
db["#{item}_keys"] = true
|
49
|
-
dbi = {}
|
50
87
|
vi = make_fakevault(vault, item)
|
51
88
|
|
52
|
-
# stub lookup of each of the vault item keys
|
89
|
+
# stub vault lookup of each of the vault item keys
|
53
90
|
content.each do |k, v|
|
54
91
|
next if 'id' == k
|
55
|
-
dbi[k] = { 'encrypted_data' => '...' }
|
56
92
|
allow(vi).to receive(:[]).with(k).and_return(v)
|
57
93
|
end
|
58
94
|
|
@@ -64,11 +100,6 @@ class ChefVault
|
|
64
100
|
.with(dbname, item)
|
65
101
|
.and_return(vi)
|
66
102
|
)
|
67
|
-
allow(Chef::DataBagItem).to(
|
68
|
-
receive(:load)
|
69
|
-
.with(dbname, item)
|
70
|
-
.and_return(dbi)
|
71
|
-
)
|
72
103
|
allow(Chef::DataBag).to(
|
73
104
|
receive(:load)
|
74
105
|
.with(dbname)
|
@@ -77,6 +108,39 @@ class ChefVault
|
|
77
108
|
end
|
78
109
|
end
|
79
110
|
|
111
|
+
# stubs Chef::DataBagItem.load to return a fake hash in which
|
112
|
+
# each key of the content returns a hash with single
|
113
|
+
# `encrypted_data` key, which fools some attempts to determine
|
114
|
+
# whether a data bag is a vault
|
115
|
+
# @param vault [String] the name of the vault data bag
|
116
|
+
# @param item [String] the name of the vault item
|
117
|
+
# @param content [String] the JSON-encoded contents to populate the
|
118
|
+
# fake vault with
|
119
|
+
# @return [void]
|
120
|
+
# @api private
|
121
|
+
def stub_vault_item_encrypted_data(vault, item, content)
|
122
|
+
# stub data bag lookup of each of the vault item keys
|
123
|
+
dbi = ChefVault::TestFixtureDataBagItem.new
|
124
|
+
dbi['raw_data'] = content
|
125
|
+
content.each_key do |k|
|
126
|
+
next if 'id' == k
|
127
|
+
dbi[k] = { 'encrypted_data' => '...' }
|
128
|
+
end
|
129
|
+
|
130
|
+
[vault, vault.to_sym].each do |dbname|
|
131
|
+
allow(Chef::DataBagItem).to(
|
132
|
+
receive(:load)
|
133
|
+
.with(dbname, item)
|
134
|
+
.and_return(dbi)
|
135
|
+
)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# returns an RSpec double that acts like a vault item
|
140
|
+
# @param vault [String] the name of the vault data bag
|
141
|
+
# @param item [String] the name of the vault item
|
142
|
+
# @return [RSpec::Mocks::Double] the vault double
|
143
|
+
# @api private
|
80
144
|
def make_fakevault(vault, item)
|
81
145
|
fakevault = double "vault item #{vault}/#{item}"
|
82
146
|
allow(fakevault).to receive(:[]=).with(String, Object)
|
@@ -90,4 +154,9 @@ class ChefVault
|
|
90
154
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
91
155
|
end
|
92
156
|
end
|
157
|
+
|
158
|
+
# a hash with method access to stand in for a Chef::DataBagItem
|
159
|
+
class TestFixtureDataBagItem < Hash
|
160
|
+
include Hashie::Extensions::MethodAccess
|
161
|
+
end
|
93
162
|
end
|
@@ -1,28 +1,10 @@
|
|
1
1
|
require 'chef-vault/test_fixtures'
|
2
2
|
|
3
|
-
# same with ChefVault::TestFixtures
|
4
|
-
class ChefVault
|
5
|
-
class TestFixtures
|
6
|
-
class << self
|
7
|
-
def clear_context
|
8
|
-
@context = nil
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
3
|
RSpec.describe ChefVault::TestFixtures do
|
15
|
-
|
16
|
-
|
17
|
-
before do
|
4
|
+
describe 'without the encrypted_data stub' do
|
18
5
|
ChefVault::TestFixtures.clear_context
|
19
|
-
|
20
|
-
|
21
|
-
after do
|
22
|
-
ChefVault::TestFixtures.clear_context
|
23
|
-
end
|
6
|
+
include ChefVault::TestFixtures.rspec_shared_context(false)
|
24
7
|
|
25
|
-
describe 'Generic functionality' do
|
26
8
|
it 'can create an RSpec shared context' do
|
27
9
|
sc = ChefVault::TestFixtures.rspec_shared_context
|
28
10
|
expect(sc).to be_a(Module)
|
@@ -34,9 +16,7 @@ RSpec.describe ChefVault::TestFixtures do
|
|
34
16
|
mod2 = ChefVault::TestFixtures.rspec_shared_context
|
35
17
|
expect(mod2).to be(mod1)
|
36
18
|
end
|
37
|
-
end
|
38
19
|
|
39
|
-
describe 'stub ChefVault::Item.load' do
|
40
20
|
it 'should stub the foo/bar vault item' do
|
41
21
|
baz = ChefVault::Item.load('foo', 'bar')['baz']
|
42
22
|
expect(baz).to eq(2)
|
@@ -78,9 +58,19 @@ RSpec.describe ChefVault::TestFixtures do
|
|
78
58
|
item = ChefVault::Item.load('bar', 'foo')
|
79
59
|
item.save
|
80
60
|
end
|
61
|
+
|
62
|
+
it 'should stub the _keys data bag item' do
|
63
|
+
db = Chef::DataBag.load('foo')
|
64
|
+
expect(db.key?('bar_keys')).to be_truthy
|
65
|
+
end
|
81
66
|
end
|
67
|
+
end
|
68
|
+
|
69
|
+
RSpec.describe ChefVault::TestFixtures do
|
70
|
+
describe 'with the encrypted_data stub' do
|
71
|
+
ChefVault::TestFixtures.clear_context
|
72
|
+
include ChefVault::TestFixtures.rspec_shared_context(true)
|
82
73
|
|
83
|
-
describe 'stub Chef::DataBagItem.load' do
|
84
74
|
it 'should present the foo/bar data bag item as encrypted' do
|
85
75
|
dbi = Chef::DataBagItem.load('foo', 'bar')
|
86
76
|
encrypted = dbi.detect do |_, v|\
|
@@ -89,11 +79,4 @@ RSpec.describe ChefVault::TestFixtures do
|
|
89
79
|
expect(encrypted).to be_truthy
|
90
80
|
end
|
91
81
|
end
|
92
|
-
|
93
|
-
describe 'stub Chef::DataBag.load' do
|
94
|
-
it 'should fake the foo/bar_keys data bag item' do
|
95
|
-
db = Chef::DataBag.load('foo')
|
96
|
-
expect(db.key?('bar_keys')).to be_truthy
|
97
|
-
end
|
98
|
-
end
|
99
82
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,3 +21,14 @@ RSpec.configure do |config|
|
|
21
21
|
config.order = :random
|
22
22
|
Kernel.srand config.seed
|
23
23
|
end
|
24
|
+
|
25
|
+
# a helper to clear the context between examples
|
26
|
+
class ChefVault
|
27
|
+
class TestFixtures
|
28
|
+
class << self
|
29
|
+
def clear_context
|
30
|
+
@context = nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-vault-testfixtures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James FitzGibbon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hashie
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rdoc
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +178,34 @@ dependencies:
|
|
164
178
|
- - "~>"
|
165
179
|
- !ruby/object:Gem::Version
|
166
180
|
version: '1.2'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: chefspec
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '4.2'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '4.2'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: berkshelf
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '3.2'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '3.2'
|
167
209
|
- !ruby/object:Gem::Dependency
|
168
210
|
name: rubocop
|
169
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -270,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
312
|
version: '0'
|
271
313
|
requirements: []
|
272
314
|
rubyforge_project:
|
273
|
-
rubygems_version: 2.4.
|
315
|
+
rubygems_version: 2.4.4
|
274
316
|
signing_key:
|
275
317
|
specification_version: 4
|
276
318
|
summary: chef-vault-testfixtures provides an RSpec shared context that stubs access
|