chef-vault 3.4.0.pre.pre419 → 3.4.0.pre.pre420

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. metadata +1 -45
  3. data/.github/CODEOWNERS +0 -2
  4. data/.gitignore +0 -33
  5. data/.rspec +0 -2
  6. data/.rubocop.yml +0 -6
  7. data/.simplecov +0 -6
  8. data/.travis.yml +0 -19
  9. data/Changelog.md +0 -141
  10. data/DEMO.md +0 -60
  11. data/Gemfile +0 -12
  12. data/KNIFE_EXAMPLES.md +0 -256
  13. data/README.md +0 -333
  14. data/Rakefile +0 -50
  15. data/THEORY.md +0 -363
  16. data/UPGRADE.md +0 -55
  17. data/appveyor.yml +0 -32
  18. data/chef-vault.gemspec +0 -54
  19. data/features/clean.feature +0 -23
  20. data/features/clean_on_refresh.feature +0 -27
  21. data/features/clean_unknown_clients.feature +0 -45
  22. data/features/detect_and_warn_v1_vault.feature +0 -14
  23. data/features/isvault.feature +0 -29
  24. data/features/itemtype.feature +0 -24
  25. data/features/step_definitions/chef-databag.rb +0 -9
  26. data/features/step_definitions/chef-repo.rb +0 -72
  27. data/features/step_definitions/chef-vault.rb +0 -151
  28. data/features/step_definitions/chef_databagitem.rb +0 -9
  29. data/features/support/env.rb +0 -14
  30. data/features/vault_create.feature +0 -63
  31. data/features/vault_list.feature +0 -31
  32. data/features/vault_show.feature +0 -45
  33. data/features/vault_show_vaultname.feature +0 -21
  34. data/features/vault_update.feature +0 -18
  35. data/features/verify_id_matches.feature +0 -10
  36. data/features/wrong_private_key.feature +0 -13
  37. data/hooks/pre-commit +0 -43
  38. data/spec/chef-vault/actor_spec.rb +0 -247
  39. data/spec/chef-vault/certificate_spec.rb +0 -37
  40. data/spec/chef-vault/chef_api_spec.rb +0 -39
  41. data/spec/chef-vault/item_keys_spec.rb +0 -263
  42. data/spec/chef-vault/item_spec.rb +0 -360
  43. data/spec/chef-vault/user_spec.rb +0 -36
  44. data/spec/chef-vault_spec.rb +0 -65
  45. data/spec/spec_helper.rb +0 -91
  46. data/tasks/github_changelog_generator.rb +0 -30
@@ -1,9 +0,0 @@
1
- Given(/^I create a data bag item '(.+)\/(.+)' containing the JSON '(.+)'$/) do |databag, _, json|
2
- write_file "item.json", json
3
- run_simple "knife data bag from file #{databag} item.json -z -c knife.rb", false
4
- end
5
-
6
- Given(/^I create an encrypted data bag item '(.+)\/(.+)' containing the JSON '(.+)' with the secret '(.+)'$/) do |databag, _, json, secret|
7
- write_file "item.json", json
8
- run_simple "knife data bag from file #{databag} item.json -s #{secret} -z -c knife.rb", false
9
- end
@@ -1,14 +0,0 @@
1
- if ENV["COVERAGE"]
2
- require "simplecov"
3
- end
4
-
5
- require "aruba/cucumber"
6
-
7
- # Travis runs tests in a limited environment which takes a long time to invoke
8
- # the knife command. Up the timeout when we're in a travis build based on the
9
- # environment variable set in .travis.yml
10
- #if ENV['TRAVIS_BUILD']
11
- Before do
12
- @aruba_timeout_seconds = 15
13
- end
14
- #end
@@ -1,63 +0,0 @@
1
- Feature: knife vault create
2
- 'knife vault create' creates two Chef data bag items: an
3
- encrypted data bag item encrypted with a randomized shared
4
- secret, and a side-along data bag item suffixed with _keys
5
- that contains an set of asymmetrically encrypted copies of
6
- the shared secret using the public keys of a set of admins
7
- and/or clients
8
-
9
- Scenario: create vault with all known clients
10
- Given a local mode chef repo with nodes 'one,two,three'
11
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
12
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
13
- And 'one,two,three' should be a client for the vault item 'test/item'
14
-
15
- Scenario: create vault with all unknown clients
16
- Given a local mode chef repo with nodes 'two,three'
17
- And I delete clients 'two,three' from the Chef server
18
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'two,three'
19
- Then the vault item 'test/item' should not be encrypted for 'one,two,three'
20
- And the output should contain "node 'two' has no private key; skipping"
21
- And the output should contain "node 'three' has no private key; skipping"
22
- And 'two,three' should not be a client for the vault item 'test/item'
23
-
24
- Scenario: create vault with mix of known and unknown clients
25
- Given a local mode chef repo with nodes 'one,two,three'
26
- And I delete client 'three' from the Chef server
27
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
28
- Then the vault item 'test/item' should be encrypted for 'one,two'
29
- And the output should contain "node 'three' has no private key; skipping"
30
- And 'one,two' should be a client for the vault item 'test/item'
31
- And 'three' should not be a client for the vault item 'test/item'
32
-
33
- Scenario: create vault with mix of known and unknown nodes
34
- Given a local mode chef repo with nodes 'one,two'
35
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
36
- Then the vault item 'test/item' should be encrypted for 'one,two'
37
- And 'one,two' should be a client for the vault item 'test/item'
38
- And 'three' should not be a client for the vault item 'test/item'
39
-
40
- Scenario: create vault with several admins
41
- Given a local mode chef repo with nodes 'one,two' with admins 'alice,bob'
42
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three' with 'alice' as admin
43
- Then the vault item 'test/item' should be encrypted for 'one,two'
44
- And 'one,two' should be a client for the vault item 'test/item'
45
- And 'three' should not be a client for the vault item 'test/item'
46
- And 'alice' should be an admin for the vault item 'test/item'
47
- And 'bob' should not be an admin for the vault item 'test/item'
48
-
49
- Scenario: create vault with several admins in sparse mode
50
- Given a local mode chef repo with nodes 'one,two' with admins 'alice,bob'
51
- And I create a vault item 'test/item' with keys in sparse mode containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three' with 'alice' as admin
52
- Then the vault item 'test/item' should be encrypted for 'one,two' with keys in sparse mode
53
- And the vault item 'test/item' should not be encrypted for 'three' with keys in sparse mode
54
- And 'one,two' should be a client for the vault item 'test/item'
55
- And 'three' should not be a client for the vault item 'test/item'
56
- And 'alice' should be an admin for the vault item 'test/item'
57
- And 'bob' should not be an admin for the vault item 'test/item'
58
-
59
- Scenario: create vault with an unknown admin
60
- Given a local mode chef repo with nodes 'one,two'
61
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three' with 'alice' as admin
62
- Then the exit status should not be 0
63
- And the output should contain "FATAL: Could not find default key for alice in users or clients!"
@@ -1,31 +0,0 @@
1
- Feature: list data bags that are vaults
2
- knife vault list should list all data bags that appear to
3
- be vaults. This is not an exact science; we assume that
4
- any data bag containing an even number of items and for
5
- which all items are pairs of thing/thing_keys is a vault
6
-
7
- Scenario: List bags that are vaults
8
- Given a local mode chef repo with nodes 'one,two,three'
9
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
10
- And I list the vaults
11
- Then the output should match /(?m:^test$)/
12
-
13
- Scenario: List bags that are vaults with keys in sparse mode
14
- Given a local mode chef repo with nodes 'one,two,three'
15
- And I create a vault item 'test/item' with keys in sparse mode containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
16
- And I list the vaults
17
- Then the output should match /(?m:^test$)/
18
-
19
- Scenario: Skip data bags that are not vaults
20
- Given a local mode chef repo with nodes 'one,two,three'
21
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
22
- And I create a data bag 'lessthantwokeys' containing the JSON '{"id": "item", "foo": "bar"}'
23
- And I create a data bag 'oddnumberofkeys' containing the JSON '{"id": "item", "one": 1, "two": 2, "three":3}'
24
- And I create a data bag 'unbalanced' containing the JSON '{"id": "item", "one": 1, "one_keys": 1, "two_keys": 1, "three_keys": 1}'
25
- And I create a data bag 'mismatched' containing the JSON '{"id": "item", "one": 1, "one_keys": 1, "two_keys": 1, "three": 1}'
26
- And I list the vaults
27
- Then the output should match /(?m:^test$)/
28
- And the output should not match /(?m:^lessthantwokeys$)/
29
- And the output should not match /(?m:^oddnumberofkeys$)/
30
- And the output should not match /(?m:^unbalanced$)/
31
- And the output should not match /(?m:^mismatched$)/
@@ -1,45 +0,0 @@
1
- Feature: knife vault show
2
- 'knife vault show' displays the contents of a Chef encrypted
3
- data bag by fetching the asymmetrically encrypted shared
4
- secret and decrypting it using the private key of the user
5
- or node
6
-
7
- Scenario: successful decrypt as admin
8
- Given a local mode chef repo with nodes 'one,two,three' with admins 'alice,bob'
9
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three' with 'alice' as admin
10
- Then the vault item 'test/item' should be encrypted for 'one,two,three,alice'
11
- And 'one,two,three' should be a client for the vault item 'test/item'
12
- And 'alice' should be an admin for the vault item 'test/item'
13
- And 'bob' should not be an admin for the vault item 'test/item'
14
- And I can decrypt the vault item 'test/item' as 'alice'
15
- And the output should match /^foo: bar$/
16
-
17
- Scenario: successful decrypt as node
18
- Given a local mode chef repo with nodes 'one,two,three' with admins 'alice,bob'
19
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three' with 'alice' as admin
20
- Then the vault item 'test/item' should be encrypted for 'one,two,three,alice'
21
- And 'one,two,three' should be a client for the vault item 'test/item'
22
- And 'alice' should be an admin for the vault item 'test/item'
23
- And 'bob' should not be an admin for the vault item 'test/item'
24
- And I can decrypt the vault item 'test/item' as 'two'
25
- And the output should match /^foo: bar$/
26
-
27
- Scenario: failed decrypt as admin
28
- Given a local mode chef repo with nodes 'one,two,three' with admins 'alice,bob'
29
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three' with 'alice' as admin
30
- Then the vault item 'test/item' should be encrypted for 'one,two,three,alice'
31
- And 'one,two,three' should be a client for the vault item 'test/item'
32
- And 'alice' should be an admin for the vault item 'test/item'
33
- And 'bob' should not be an admin for the vault item 'test/item'
34
- And I can't decrypt the vault item 'test/item' as 'bob'
35
- And the output should contain "test/item is not encrypted with your public key"
36
-
37
- Scenario: failed decrypt as node
38
- Given a local mode chef repo with nodes 'one,two,three' with admins 'alice,bob'
39
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two' with 'alice' as admin
40
- Then the vault item 'test/item' should be encrypted for 'one,two,alice'
41
- And 'one,two' should be a client for the vault item 'test/item'
42
- And 'alice' should be an admin for the vault item 'test/item'
43
- And 'bob' should not be an admin for the vault item 'test/item'
44
- And I can't decrypt the vault item 'test/item' as 'three'
45
- And the output should contain "test/item is not encrypted with your public key"
@@ -1,21 +0,0 @@
1
- Feature: knife vault show [VAULTNAME]
2
- 'knife vault show [VAULTNAME]' displays the keys of a vault
3
- (i.e. the items that are not suffixed with _keys)
4
-
5
- Scenario: show keys of a vault
6
- Given a local mode chef repo with nodes 'one,two,three'
7
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
8
- And I create a vault item 'test/item2' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
9
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
10
- And 'one,two,three' should be a client for the vault item 'test/item'
11
- And I show the keys of the vault 'test'
12
- Then the output should match /(?m:^item$)/
13
- And the output should match /(?m:^item2$)/
14
- And the output should not match /(?m:^item_keys$)/
15
- And the output should not match /(?m:^item2_keys$)/
16
-
17
- Scenario: show keys of a data bag that is not a vault
18
- Given a local mode chef repo with nodes 'one,two,three'
19
- And I create a data bag 'notavault' containing the JSON '{"id": "item", "foo": "bar"}'
20
- And I show the keys of the vault 'notavault'
21
- Then the output should match /data bag notavault is not a chef-vault/
@@ -1,18 +0,0 @@
1
- Feature: knife vault update
2
- 'knife vault update' is used to add clients, or administrators
3
- and to re-run the search query and update the vault's item values.
4
-
5
- Scenario: add admin to a vault
6
- Given a local mode chef repo with nodes 'one,two,three' with admins 'alice,bob'
7
- When I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three' with 'alice' as admin
8
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
9
- And 'one,two,three' should be a client for the vault item 'test/item'
10
- And 'alice' should be an admin for the vault item 'test/item'
11
- And I can decrypt the vault item 'test/item' as 'alice'
12
- But I can't decrypt the vault item 'test/item' as 'bob'
13
- And I can save the JSON object of the encrypted data bag for the vault item 'test/item'
14
- When I add 'bob' as an admin for the vault item 'test/item'
15
- Then 'alice,bob' should be an admin for the vault item 'test/item'
16
- And I can decrypt the vault item 'test/item' as 'alice'
17
- And I can decrypt the vault item 'test/item' as 'bob'
18
- And the data bag of the vault item 'test/item' has not been re-encrypted
@@ -1,10 +0,0 @@
1
- Feature: knife vault create with mismatched ID
2
- 'knife vault create' creates a vault. A JSON file can be passed
3
- on the command line. If the vault ID specified on the command line
4
- does not match the value of the 'id' key in the JSON file, knife
5
- should throw an error
6
-
7
- Scenario: create vault from JSON file with mismatched ID
8
- Given a local mode chef repo with nodes 'one,two,three'
9
- And I create a vault item 'test/item' containing the JSON '{"id": "eyetem"}' encrypted for 'one,two,three'
10
- Then the output should match /id mismatch - input JSON has id 'eyetem' but vault item has id 'item'/
@@ -1,13 +0,0 @@
1
- Feature: Wrong private key during decrypt
2
- https://github.com/Nordstrom/chef-vault/issues/43
3
- If a vault is encrypted for a node and then the node's private
4
- key is regenerated, the error that comes back from chef-vault
5
- should be informative, not a lower-level error from OpenSSL
6
- like 'OpenSSL::PKey::RSAError: padding check failed'
7
-
8
- Scenario: Regenerate node key and attempt decrypt
9
- Given a local mode chef repo with nodes 'one,two'
10
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two'
11
- And I regenerate the client key for the node 'one'
12
- And I try to decrypt the vault item 'test/item' as 'one'
13
- Then the output should match /is encrypted for you, but your private key failed to decrypt the contents/
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env ruby
2
- output = `bundle exec chefstyle -a`
3
- if !$?.success?
4
- puts "pre-commit hook: Tried to run `bundle exec chefstyle -a` to autocleanup errors, but it failed with output:"
5
- puts output
6
- end
7
-
8
- detected = /(\d+) offenses detected/.match(output)
9
- corrected = /(\d+) offenses corrected/.match(output)
10
-
11
- # no errors detected by chefstyle
12
- exit 0 if detected.nil?
13
-
14
- # chefstyle found errors
15
- if !detected.nil?
16
- # get the first result from the capture group that isn't the whole capture
17
- num_detected = detected.to_a[1].to_i
18
- num_corrected = if corrected.nil?
19
- 0
20
- else
21
- corrected.to_a[1].to_i
22
- end
23
- if num_detected == num_corrected
24
- puts <<EOF
25
- pre-commit hook: Ran `bundle exec chefstyle -a` to autocleanup errors if any existed and
26
- #{num_detected} were detected, but all were cleaned up. `git add` all files that were
27
- autoupdated and try commiting again. New git status:
28
-
29
- EOF
30
- puts `git status`
31
- else
32
- puts <<EOF
33
- pre-commit hook: Ran `bundle exec chefstyle -a` to autocleanup errors if any existed and
34
- #{num_detected} were detected, but #{num_detected - num_corrected} could not be cleaned up
35
- automatically. Run:
36
-
37
- bundle exec chefstyle -a
38
-
39
- to see remaining errors to clean up by hand, add all updated files, and try commiting again.
40
- EOF
41
- end
42
- exit 1
43
- end
@@ -1,247 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe ChefVault::Actor do
4
- let(:actor_name) { "actor" }
5
- let(:public_key_string) do
6
- "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyMXT9IOV9pkQsxsnhSx8\n8RX6GW3caxkjcXFfHg6E7zUVBFAsfw4B1D+eHAks3qrDB7UrUxsmCBXwU4dQHaQy\ngAn5Sv0Jc4CejDNL2EeCBLZ4TF05odHmuzyDdPkSZP6utpR7+uF7SgVQedFGySIB\nih86aM+HynhkJqgJYhoxkrdo/JcWjpk7YEmWb6p4esnvPWOpbcjIoFs4OjavWBOF\niTfpkS0SkygpLi/iQu9RQfd4hDMWCc6yh3Th/1nVMUd+xQCdUK5wxluAWSv8U0zu\nhiIlZNazpCGHp+3QdP3f6rebmQA8pRM8qT5SlOvCYPk79j+IMUVSYrR4/DTZ+VM+\naQIDAQAB\n-----END PUBLIC KEY-----\n"
7
- end
8
-
9
- let(:key_response) do
10
- {
11
- "name" => "default",
12
- "public_key" => "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyMXT9IOV9pkQsxsnhSx8\n8RX6GW3caxkjcXFfHg6E7zUVBFAsfw4B1D+eHAks3qrDB7UrUxsmCBXwU4dQHaQy\ngAn5Sv0Jc4CejDNL2EeCBLZ4TF05odHmuzyDdPkSZP6utpR7+uF7SgVQedFGySIB\nih86aM+HynhkJqgJYhoxkrdo/JcWjpk7YEmWb6p4esnvPWOpbcjIoFs4OjavWBOF\niTfpkS0SkygpLi/iQu9RQfd4hDMWCc6yh3Th/1nVMUd+xQCdUK5wxluAWSv8U0zu\nhiIlZNazpCGHp+3QdP3f6rebmQA8pRM8qT5SlOvCYPk79j+IMUVSYrR4/DTZ+VM+\naQIDAQAB\n-----END PUBLIC KEY-----\n",
13
- "expiration_date" => "infinity",
14
- }
15
- end
16
-
17
- let(:http_response_code) do
18
- "404"
19
- end
20
-
21
- let(:http_error) do
22
- http_response = double("http error")
23
- allow(http_response).to receive(:code).and_return(http_response_code)
24
- Net::HTTPServerException.new("http error message", http_response)
25
- end
26
-
27
- let(:api) { double("api") }
28
-
29
- subject(:chef_key) { described_class.new(actor_type, actor_name) }
30
-
31
- describe "#new" do
32
- context "when something besides 'clients' or 'users' is passed" do
33
- let(:actor_type) { "charmander" }
34
- it "throws an error" do
35
- expect { described_class.new("charmander", actor_name) }.to raise_error(RuntimeError)
36
- end
37
- end
38
-
39
- context "when 'clients' is passed" do
40
- it "requests a client key" do
41
- expect_any_instance_of(described_class).to receive(:get_client_key)
42
- described_class.new("clients", actor_name).key
43
- end
44
- end
45
-
46
- context "when 'admins' is passed" do
47
- it "requests a admin key" do
48
- expect_any_instance_of(described_class).to receive(:get_admin_key)
49
- described_class.new("admins", actor_name).key
50
- end
51
- end
52
- end
53
-
54
- shared_examples_for "get_key_handling" do
55
- context "when the default key exists for the requested client" do
56
- it "sets up a valid key" do
57
- expect(chef_key).to receive(:get_key).with(request_actor_type).and_return(public_key_string)
58
- expect(chef_key.send(method)).to eq(public_key_string)
59
- end
60
- end
61
-
62
- context "when get_key returns an http error" do
63
- before do
64
- allow(chef_key).to receive(:get_key).with(request_actor_type).and_raise(http_error)
65
- end
66
-
67
- context "when the error code is not 404 or 403" do
68
- let(:http_response_code) { "500" }
69
-
70
- it "raises the original error" do
71
- expect { chef_key.send(method) }.to raise_error(http_error)
72
- end
73
- end
74
-
75
- context "when the error code is 403" do
76
- let(:http_response_code) { "403" }
77
-
78
- it "prints information for the user to resolve the issue and raises the original error" do
79
- expect(chef_key).to receive(:print_forbidden_error)
80
- expect { chef_key.send(method) }.to raise_error(http_error)
81
- end
82
- end
83
- end
84
- end
85
-
86
- describe "#get_client_key" do
87
- let(:request_actor_type) { "clients" }
88
- let(:actor_type) { "clients" }
89
- let(:method) { :get_client_key }
90
-
91
- it_should_behave_like "get_key_handling"
92
-
93
- context "when get_key returns an http error" do
94
- before do
95
- allow(chef_key).to receive(:get_key).with(actor_type).and_raise(http_error)
96
- end
97
-
98
- context "when the error code is 404" do
99
- let(:http_response_code) { "404" }
100
-
101
- it "raises ChefVault::Exceptions::ClientNotFound" do
102
- expect { chef_key.get_client_key }.to raise_error(ChefVault::Exceptions::ClientNotFound)
103
- end
104
- end
105
- end
106
- end # get_client_key
107
-
108
- describe "#get_admin_key" do
109
- let(:request_actor_type) { "users" }
110
- let(:actor_type) { "admins" }
111
- let(:method) { :get_admin_key }
112
-
113
- it_should_behave_like "get_key_handling"
114
-
115
- context "when the first get_key for users returns an http error" do
116
- before do
117
- allow(chef_key).to receive(:get_key).with(request_actor_type).and_raise(http_error)
118
- end
119
-
120
- context "when the error code from the users get is a 404" do
121
- let(:http_response_code) { "404" }
122
-
123
- context "when the second get_key for clients returns an http error" do
124
-
125
- let(:http_error_2) do
126
- http_response = double("http error")
127
- allow(http_response).to receive(:code).and_return(http_response_code_2)
128
- Net::HTTPServerException.new("http error message", http_response)
129
- end
130
-
131
- before do
132
- allow(chef_key).to receive(:get_key).with("clients").and_raise(http_error_2)
133
- end
134
-
135
- context "when it is a 404" do
136
- let(:http_response_code_2) { "404" }
137
-
138
- it "rasies ChefVault::Exceptions::AdminNotFound" do
139
- expect { chef_key.get_admin_key }.to raise_error(ChefVault::Exceptions::AdminNotFound)
140
- end
141
- end
142
-
143
- context "when it is a 403" do
144
- let(:http_response_code_2) { "403" }
145
-
146
- it "raises the original error" do
147
- expect { chef_key.get_admin_key }.to raise_error(http_error_2)
148
- end
149
- end
150
-
151
- context "when it is not a 404" do
152
- let(:http_response_code_2) { "500" }
153
-
154
- it "raises the original error" do
155
- expect { chef_key.get_admin_key }.to raise_error(http_error_2)
156
- end
157
- end
158
- end # when the second get_key for clients returns an http error
159
-
160
- context "when the second get_key for clients exists with the same name as the admin requested" do
161
- it "strangely returns the client key as an admin key" do
162
- expect(chef_key).to receive(:get_key).with(request_actor_type).and_return(public_key_string)
163
- expect(chef_key.send(method)).to eq(public_key_string)
164
- end
165
- end
166
- end # when the first get_key for users returns an http erro
167
- end
168
- end # get_admin_key
169
-
170
- describe "#get_key" do
171
-
172
- shared_examples_for "a properly retrieved and error handled key fetch" do
173
- # mock out the API
174
- before do
175
- allow(chef_key).to receive(:api).and_return(api)
176
- [:rest_v0, :rest_v1, :org_scoped_rest_v0, :org_scoped_rest_v1].each do |method|
177
- allow(api).to receive(method)
178
- end
179
- end
180
-
181
- context "when keys/default returns 200 for org scoped endpoint" do
182
- before do
183
- allow(api.org_scoped_rest_v1).to receive(:get).with("#{request_actor_type}/#{actor_name}/keys/default").and_return(key_response)
184
- end
185
-
186
- it "returns the public_key" do
187
- expect(chef_key.get_key(request_actor_type)).to eql(public_key_string)
188
- end
189
-
190
- it "hits the proper endpoint" do
191
- expect(api.org_scoped_rest_v1).to receive(:get).with("#{request_actor_type}/#{actor_name}/keys/default")
192
- chef_key.get_key(request_actor_type)
193
- end
194
- end
195
-
196
- context "when a 500 is returned" do
197
- let(:http_response_code) { "500" }
198
- before do
199
- allow(api.org_scoped_rest_v1).to receive(:get).with("#{request_actor_type}/#{actor_name}/keys/default").and_raise(http_error)
200
- end
201
-
202
- it "raises the http error" do
203
- expect { chef_key.get_key(request_actor_type) }.to raise_error(http_error)
204
- end
205
- end
206
-
207
- context "when keys/default returns 404" do
208
- let(:http_response_code) { "404" }
209
- let(:chef_object) { double("chef object") }
210
-
211
- before do
212
- allow(api.org_scoped_rest_v1).to receive(:get).with("#{request_actor_type}/#{actor_name}/keys/default").and_raise(http_error)
213
- allow(chef_object_type).to receive(:load).with(actor_name).and_return(chef_object)
214
- allow(chef_object).to receive(:public_key).and_return(public_key_string)
215
- end
216
-
217
- it "tries to load the object via Chef::<object>_v1" do
218
- expect(chef_object_type).to receive(:load).with(actor_name)
219
- chef_key.get_key(request_actor_type)
220
- end
221
-
222
- context "when the Chef::<object>_v1 object loads properly" do
223
- it "returns the public key" do
224
- expect(chef_key.get_key(request_actor_type)).to eql(public_key_string)
225
- end
226
- end
227
- end
228
- end # shared_examples_for
229
-
230
- context "when a client is passed" do
231
- let(:request_actor_type) { "clients" }
232
- let(:actor_type) { "clients" }
233
- let(:chef_object_type) { Chef::ApiClient }
234
-
235
- it_behaves_like "a properly retrieved and error handled key fetch"
236
- end
237
-
238
- context "when an admin is passed" do
239
- let(:request_actor_type) { "users" }
240
- let(:actor_type) { "admins" }
241
- let(:chef_object_type) { Chef::User }
242
-
243
- it_behaves_like "a properly retrieved and error handled key fetch"
244
- end
245
-
246
- end
247
- end