microwave 1.0.4 → 11.400.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTING.md +155 -0
- data/README.md +89 -0
- data/Rakefile +2 -2
- data/bin/chef-apply +25 -0
- data/bin/chef-shell +34 -0
- data/bin/chef-solo +0 -2
- data/bin/shef +6 -5
- data/lib/chef.rb +2 -4
- data/spec/data/big_json.json +2 -1
- data/spec/data/big_json_plus_one.json +2 -1
- data/spec/data/cookbooks/chefignore +2 -0
- data/spec/data/cookbooks/openldap/attributes/default.rb +10 -9
- data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -1
- data/spec/data/git_bundles/sinatra-test-app-with-callback-files.gitbundle +0 -0
- data/spec/data/git_bundles/sinatra-test-app-with-symlinks.gitbundle +0 -0
- data/spec/data/git_bundles/sinatra-test-app.gitbundle +0 -0
- data/spec/data/lwrp/providers/inline_compiler.rb +26 -0
- data/spec/data/nodes/default.rb +3 -3
- data/spec/data/nodes/test.example.com.rb +3 -3
- data/spec/data/nodes/test.rb +3 -3
- data/spec/data/partial_one.erb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +4 -0
- data/spec/data/run_context/cookbooks/circular-dep1/definitions/circular_dep1_res.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep1/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/circular-dep1/metadata.rb +2 -0
- data/spec/data/run_context/cookbooks/circular-dep1/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep1/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/circular-dep1/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +3 -0
- data/spec/data/run_context/cookbooks/circular-dep2/definitions/circular_dep2_res.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep2/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/circular-dep2/metadata.rb +2 -0
- data/spec/data/run_context/cookbooks/circular-dep2/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep2/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/circular-dep2/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -0
- data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -0
- data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +3 -0
- data/spec/data/run_context/cookbooks/dependency1/definitions/dependency1_res.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency1/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/dependency1/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency1/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/dependency1/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +3 -0
- data/spec/data/run_context/cookbooks/dependency2/definitions/dependency2_res.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency2/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/dependency2/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency2/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/dependency2/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +3 -0
- data/spec/data/run_context/cookbooks/no-default-attr/definitions/no_default-attr_res.rb +1 -0
- data/spec/data/run_context/cookbooks/no-default-attr/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/no-default-attr/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/no-default-attr/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +3 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/definitions/test_with-circular-deps_res.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/metadata.rb +2 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +3 -0
- data/spec/data/run_context/cookbooks/test-with-deps/definitions/test_with-deps_res.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-deps/libraries/lib.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-deps/metadata.rb +3 -0
- data/spec/data/run_context/cookbooks/test-with-deps/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-deps/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/test-with-deps/recipes/server.rb +0 -0
- data/spec/data/run_context/cookbooks/test-with-deps/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/test/attributes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/test/attributes/george.rb +1 -1
- data/spec/data/run_context/cookbooks/test/definitions/test_res.rb +1 -0
- data/spec/data/run_context/cookbooks/test/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/test/resources/resource.rb +1 -0
- data/spec/data/shef-config.rb +10 -0
- data/spec/functional/dsl/registry_helper_spec.rb +63 -0
- data/spec/functional/knife/cookbook_delete_spec.rb +0 -2
- data/spec/functional/knife/exec_spec.rb +4 -6
- data/spec/functional/knife/smoke_test.rb +34 -0
- data/spec/functional/knife/ssh_spec.rb +64 -3
- data/spec/functional/resource/cookbook_file_spec.rb +33 -2
- data/spec/functional/resource/deploy_revision_spec.rb +515 -0
- data/spec/functional/resource/directory_spec.rb +4 -0
- data/spec/functional/resource/file_spec.rb +56 -22
- data/spec/functional/resource/link_spec.rb +12 -10
- data/spec/functional/resource/registry_spec.rb +572 -0
- data/spec/functional/resource/remote_directory_spec.rb +142 -36
- data/spec/functional/resource/remote_file_spec.rb +28 -3
- data/spec/functional/resource/template_spec.rb +23 -2
- data/spec/functional/run_lock_spec.rb +238 -0
- data/spec/functional/shell_spec.rb +101 -0
- data/spec/functional/tiny_server_spec.rb +5 -4
- data/spec/functional/win32/registry_helper_spec.rb +632 -0
- data/spec/functional/win32/security_spec.rb +37 -0
- data/spec/spec_helper.rb +15 -3
- data/spec/stress/win32/security_spec.rb +5 -5
- data/spec/support/chef_helpers.rb +14 -3
- data/spec/support/lib/chef/resource/cat.rb +3 -5
- data/spec/support/lib/chef/resource/one_two_three_four.rb +8 -10
- data/spec/support/lib/chef/resource/zen_master.rb +8 -10
- data/spec/support/matchers/leak.rb +1 -1
- data/spec/support/platform_helpers.rb +18 -0
- data/spec/support/shared/functional/directory_resource.rb +85 -23
- data/spec/support/shared/functional/file_resource.rb +198 -53
- data/spec/support/shared/functional/securable_resource.rb +140 -105
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +375 -0
- data/spec/support/shared/unit/file_system_support.rb +110 -0
- data/spec/support/shared/unit/platform_introspector.rb +162 -0
- data/spec/tiny_server.rb +29 -10
- data/spec/unit/api_client/registration_spec.rb +172 -0
- data/spec/unit/api_client_spec.rb +156 -103
- data/spec/unit/application/apply.rb +84 -0
- data/spec/unit/application/knife_spec.rb +5 -0
- data/spec/unit/application_spec.rb +57 -2
- data/spec/unit/chef_fs/diff_spec.rb +329 -0
- data/spec/unit/chef_fs/file_pattern_spec.rb +526 -0
- data/spec/unit/chef_fs/file_system/chef_server_root_dir_spec.rb +237 -0
- data/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb +568 -0
- data/spec/unit/chef_fs/file_system/data_bags_dir_spec.rb +220 -0
- data/spec/unit/chef_fs/file_system_spec.rb +136 -0
- data/spec/unit/client_spec.rb +188 -16
- data/spec/unit/config_spec.rb +54 -4
- data/spec/unit/cookbook/chefignore_spec.rb +2 -1
- data/spec/unit/cookbook/syntax_check_spec.rb +48 -109
- data/spec/unit/cookbook_loader_spec.rb +153 -91
- data/spec/unit/cookbook_manifest_spec.rb +81 -81
- data/spec/unit/cookbook_spec.rb +3 -20
- data/spec/unit/cookbook_version_spec.rb +23 -122
- data/spec/unit/digester_spec.rb +50 -0
- data/spec/unit/dsl/data_query_spec.rb +66 -0
- data/spec/unit/dsl/platform_introspection_spec.rb +130 -0
- data/spec/unit/dsl/regsitry_helper_spec.rb +55 -0
- data/spec/unit/encrypted_data_bag_item_spec.rb +126 -10
- data/spec/unit/environment_spec.rb +0 -130
- data/spec/unit/exceptions_spec.rb +2 -3
- data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +23 -3
- data/spec/unit/json_compat_spec.rb +69 -0
- data/spec/unit/knife/bootstrap_spec.rb +81 -28
- data/spec/unit/knife/client_reregister_spec.rb +23 -22
- data/spec/unit/knife/configure_spec.rb +29 -26
- data/spec/unit/knife/cookbook_metadata_spec.rb +11 -4
- data/spec/unit/knife/cookbook_site_install_spec.rb +12 -2
- data/spec/unit/knife/cookbook_test_spec.rb +1 -0
- data/spec/unit/knife/cookbook_upload_spec.rb +41 -2
- data/spec/unit/knife/core/bootstrap_context_spec.rb +8 -1
- data/spec/unit/knife/core/ui_spec.rb +156 -7
- data/spec/unit/knife/data_bag_create_spec.rb +14 -0
- data/spec/unit/knife/data_bag_edit_spec.rb +14 -4
- data/spec/unit/knife/data_bag_from_file_spec.rb +17 -5
- data/spec/unit/knife/data_bag_show_spec.rb +11 -4
- data/spec/unit/knife/index_rebuild_spec.rb +96 -33
- data/spec/unit/knife/knife_help.rb +7 -7
- data/spec/unit/knife/node_run_list_remove_spec.rb +2 -1
- data/spec/unit/knife/ssh_spec.rb +121 -15
- data/spec/unit/knife/status_spec.rb +2 -2
- data/spec/unit/knife/user_create_spec.rb +86 -0
- data/spec/unit/knife/user_delete_spec.rb +39 -0
- data/spec/unit/knife/user_edit_spec.rb +42 -0
- data/spec/unit/knife/user_list_spec.rb +32 -0
- data/spec/unit/knife/user_reregister_spec.rb +53 -0
- data/spec/unit/knife/user_show_spec.rb +41 -0
- data/spec/unit/knife_spec.rb +53 -0
- data/spec/unit/lwrp_spec.rb +59 -17
- data/spec/unit/mixin/checksum_spec.rb +2 -2
- data/spec/unit/mixin/deep_merge_spec.rb +56 -491
- data/spec/unit/mixin/deprecation_spec.rb +23 -0
- data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +6 -1
- data/spec/unit/mixin/params_validate_spec.rb +4 -2
- data/spec/unit/mixin/securable_spec.rb +5 -3
- data/spec/unit/mixin/template_spec.rb +119 -0
- data/spec/unit/node/attribute_spec.rb +272 -137
- data/spec/unit/node/immutable_collections_spec.rb +139 -0
- data/spec/unit/node_spec.rb +411 -339
- data/spec/unit/platform_spec.rb +8 -8
- data/spec/unit/provider/breakpoint_spec.rb +8 -8
- data/spec/unit/provider/cookbook_file_spec.rb +4 -8
- data/spec/unit/provider/deploy/revision_spec.rb +2 -8
- data/spec/unit/provider/deploy_spec.rb +6 -40
- data/spec/unit/provider/directory_spec.rb +103 -68
- data/spec/unit/provider/erl_call_spec.rb +0 -2
- data/spec/unit/provider/file_spec.rb +69 -59
- data/spec/unit/provider/git_spec.rb +0 -10
- data/spec/unit/provider/group/groupadd_spec.rb +1 -1
- data/spec/unit/provider/group/usermod_spec.rb +2 -2
- data/spec/unit/provider/http_request_spec.rb +28 -69
- data/spec/unit/provider/ifconfig_spec.rb +2 -2
- data/spec/unit/provider/link_spec.rb +1 -1
- data/spec/unit/provider/ohai_spec.rb +4 -4
- data/spec/unit/provider/package/apt_spec.rb +0 -1
- data/spec/unit/provider/package/ips_spec.rb +0 -1
- data/spec/unit/provider/package/rubygems_spec.rb +0 -18
- data/spec/unit/provider/package/yum_spec.rb +79 -15
- data/spec/unit/provider/package_spec.rb +7 -5
- data/spec/unit/provider/registry_key_spec.rb +269 -0
- data/spec/unit/provider/remote_directory_spec.rb +24 -7
- data/spec/unit/provider/remote_file_spec.rb +36 -0
- data/spec/unit/provider/route_spec.rb +3 -6
- data/spec/unit/provider/ruby_block_spec.rb +8 -0
- data/spec/unit/provider/service/arch_service_spec.rb +4 -4
- data/spec/unit/provider/service/debian_service_spec.rb +1 -1
- data/spec/unit/provider/service/freebsd_service_spec.rb +4 -4
- data/spec/unit/provider/service/init_service_spec.rb +26 -3
- data/spec/unit/provider/service/insserv_service_spec.rb +1 -1
- data/spec/unit/provider/service/invokercd_service_spec.rb +3 -3
- data/spec/unit/provider/service/redhat_spec.rb +1 -1
- data/spec/unit/provider/service/simple_service_spec.rb +3 -3
- data/spec/unit/provider/service/upstart_service_spec.rb +7 -7
- data/spec/unit/provider/service_spec.rb +2 -2
- data/spec/unit/provider/subversion_spec.rb +1 -1
- data/spec/unit/provider/template_spec.rb +35 -11
- data/spec/unit/provider/user/dscl_spec.rb +57 -31
- data/spec/unit/provider/user_spec.rb +7 -16
- data/spec/unit/provider_spec.rb +4 -3
- data/spec/unit/recipe_spec.rb +10 -8
- data/spec/unit/registry_helper_spec.rb +376 -0
- data/spec/unit/resource/log_spec.rb +9 -0
- data/spec/unit/resource/registry_key_spec.rb +171 -0
- data/spec/unit/resource/remote_file_spec.rb +21 -23
- data/spec/unit/resource/ruby_block_spec.rb +7 -3
- data/spec/unit/resource/service_spec.rb +11 -0
- data/spec/unit/resource_spec.rb +27 -4
- data/spec/unit/rest/auth_credentials_spec.rb +2 -14
- data/spec/unit/rest_spec.rb +122 -187
- data/spec/unit/run_context/cookbook_compiler_spec.rb +181 -0
- data/spec/unit/run_context_spec.rb +18 -4
- data/spec/unit/run_list_spec.rb +0 -209
- data/spec/unit/run_lock_spec.rb +37 -0
- data/spec/unit/runner_spec.rb +101 -2
- data/spec/unit/scan_access_control_spec.rb +4 -4
- data/spec/unit/{shef → shell}/model_wrapper_spec.rb +5 -5
- data/spec/unit/{shef/shef_ext_spec.rb → shell/shell_ext_spec.rb} +21 -21
- data/spec/unit/{shef/shef_session_spec.rb → shell/shell_session_spec.rb} +12 -12
- data/spec/unit/shell_out_spec.rb +18 -0
- data/spec/unit/{shef_spec.rb → shell_spec.rb} +20 -20
- data/spec/unit/user_spec.rb +255 -0
- metadata +162 -157
- data/README.rdoc +0 -177
- data/spec/unit/certificate_spec.rb +0 -76
- data/spec/unit/checksum_cache_spec.rb +0 -209
- data/spec/unit/checksum_spec.rb +0 -94
- data/spec/unit/couchdb_spec.rb +0 -274
- data/spec/unit/index_queue_spec.rb +0 -391
- data/spec/unit/json_compat_spect.rb +0 -53
- data/spec/unit/mixin/language_spec.rb +0 -305
- data/spec/unit/openid_registration_spec.rb +0 -153
- data/spec/unit/solr_query/query_transform_spec.rb +0 -454
- data/spec/unit/solr_query/solr_http_request_spec.rb +0 -244
- data/spec/unit/solr_query_spec.rb +0 -203
- data/spec/unit/webui_user_spec.rb +0 -238
@@ -75,8 +75,22 @@ describe Chef::Knife::DataBagCreate do
|
|
75
75
|
@knife.should_receive(:create_object).and_yield(@plain_data)
|
76
76
|
data_bag_item = Chef::DataBagItem.from_hash(@enc_data)
|
77
77
|
data_bag_item.data_bag("sudoing_admins")
|
78
|
+
|
79
|
+
# Random IV is used each time the data bag item is encrypted, so values
|
80
|
+
# will not be equal if we re-encrypt.
|
81
|
+
Chef::EncryptedDataBagItem.should_receive(:encrypt_data_bag_item).and_return(@enc_data)
|
82
|
+
|
78
83
|
@rest.should_receive(:post_rest).with("data", {'name' => 'sudoing_admins'}).ordered
|
79
84
|
@rest.should_receive(:post_rest).with("data/sudoing_admins", data_bag_item).ordered
|
85
|
+
|
86
|
+
@secret_file = Tempfile.new("encrypted_data_bag_secret_file_test")
|
87
|
+
@secret_file.puts(@secret)
|
88
|
+
@secret_file.flush
|
89
|
+
end
|
90
|
+
|
91
|
+
after do
|
92
|
+
@secret_file.close
|
93
|
+
@secret_file.unlink
|
80
94
|
end
|
81
95
|
|
82
96
|
it "creates an encrypted data bag item via --secret" do
|
@@ -59,6 +59,19 @@ describe Chef::Knife::DataBagEdit do
|
|
59
59
|
@enc_edited_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(@edited_data,
|
60
60
|
@secret)
|
61
61
|
Chef::DataBagItem.stub!(:load).with('bag_name', 'item_name').and_return(@enc_data)
|
62
|
+
|
63
|
+
# Random IV is used each time the data bag item is encrypted, so values
|
64
|
+
# will not be equal if we encrypt same value twice.
|
65
|
+
Chef::EncryptedDataBagItem.should_receive(:encrypt_data_bag_item).and_return(@enc_edited_data)
|
66
|
+
|
67
|
+
@secret_file = Tempfile.new("encrypted_data_bag_secret_file_test")
|
68
|
+
@secret_file.puts(@secret)
|
69
|
+
@secret_file.flush
|
70
|
+
end
|
71
|
+
|
72
|
+
after do
|
73
|
+
@secret_file.close
|
74
|
+
@secret_file.unlink
|
62
75
|
end
|
63
76
|
|
64
77
|
it "decrypts and encrypts via --secret" do
|
@@ -70,10 +83,7 @@ describe Chef::Knife::DataBagEdit do
|
|
70
83
|
end
|
71
84
|
|
72
85
|
it "decrypts and encrypts via --secret_file" do
|
73
|
-
secret_file
|
74
|
-
secret_file.puts(@secret)
|
75
|
-
secret_file.flush
|
76
|
-
@knife.stub!(:config).and_return({:secret_file => secret_file.path})
|
86
|
+
@knife.stub!(:config).and_return({:secret_file => @secret_file.path})
|
77
87
|
@knife.should_receive(:edit_data).with(@plain_data).and_return(@edited_data)
|
78
88
|
@rest.should_receive(:put_rest).with("data/bag_name/item_name", @enc_edited_data).ordered
|
79
89
|
|
@@ -142,6 +142,19 @@ describe Chef::Knife::DataBagFromFile do
|
|
142
142
|
@secret = "abc123SECRET"
|
143
143
|
@enc_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(@plain_data,
|
144
144
|
@secret)
|
145
|
+
|
146
|
+
# Random IV is used each time the data bag item is encrypted, so values
|
147
|
+
# will not be equal if we re-encrypt.
|
148
|
+
Chef::EncryptedDataBagItem.should_receive(:encrypt_data_bag_item).and_return(@enc_data)
|
149
|
+
|
150
|
+
@secret_file = Tempfile.new("encrypted_data_bag_secret_file_test")
|
151
|
+
@secret_file.puts(@secret)
|
152
|
+
@secret_file.flush
|
153
|
+
end
|
154
|
+
|
155
|
+
after do
|
156
|
+
@secret_file.close
|
157
|
+
@secret_file.unlink
|
145
158
|
end
|
146
159
|
|
147
160
|
it "encrypts values when given --secret" do
|
@@ -157,10 +170,7 @@ describe Chef::Knife::DataBagFromFile do
|
|
157
170
|
end
|
158
171
|
|
159
172
|
it "encrypts values when given --secret_file" do
|
160
|
-
secret_file
|
161
|
-
secret_file.puts(@secret)
|
162
|
-
secret_file.flush
|
163
|
-
@knife.stub!(:config).and_return({:secret_file => secret_file.path})
|
173
|
+
@knife.stub!(:config).and_return({:secret_file => @secret_file.path})
|
164
174
|
|
165
175
|
@knife.loader.stub!(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data)
|
166
176
|
dbag = Chef::DataBagItem.new
|
@@ -177,7 +187,9 @@ describe Chef::Knife::DataBagFromFile do
|
|
177
187
|
it "prints help if given no arguments" do
|
178
188
|
@knife.instance_variable_set(:@name_args, [])
|
179
189
|
lambda { @knife.run }.should raise_error(SystemExit)
|
180
|
-
|
190
|
+
help_text = "knife data bag from file BAG FILE|FOLDER [FILE|FOLDER..] (options)"
|
191
|
+
help_text_regex = Regexp.new("^#{Regexp.escape(help_text)}")
|
192
|
+
@stdout.string.should match(help_text_regex)
|
181
193
|
end
|
182
194
|
end
|
183
195
|
|
@@ -57,6 +57,7 @@ describe Chef::Knife::DataBagShow do
|
|
57
57
|
|
58
58
|
@knife.run
|
59
59
|
Chef::JSONCompat.from_json(@stdout.string).should == data_item.raw_data
|
60
|
+
|
60
61
|
end
|
61
62
|
|
62
63
|
describe "encrypted data bag items" do
|
@@ -70,6 +71,15 @@ describe Chef::Knife::DataBagShow do
|
|
70
71
|
@enc_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(@plain_data,
|
71
72
|
@secret)
|
72
73
|
@knife.instance_variable_set(:@name_args, ['bag_name', 'item_name'])
|
74
|
+
|
75
|
+
@secret_file = Tempfile.new("encrypted_data_bag_secret_file_test")
|
76
|
+
@secret_file.puts(@secret)
|
77
|
+
@secret_file.flush
|
78
|
+
end
|
79
|
+
|
80
|
+
after do
|
81
|
+
@secret_file.close
|
82
|
+
@secret_file.unlink
|
73
83
|
end
|
74
84
|
|
75
85
|
it "prints the decrypted contents of an item when given --secret" do
|
@@ -82,10 +92,7 @@ describe Chef::Knife::DataBagShow do
|
|
82
92
|
end
|
83
93
|
|
84
94
|
it "prints the decrypted contents of an item when given --secret_file" do
|
85
|
-
secret_file
|
86
|
-
secret_file.puts(@secret)
|
87
|
-
secret_file.flush
|
88
|
-
@knife.stub!(:config).and_return({:secret_file => secret_file.path})
|
95
|
+
@knife.stub!(:config).and_return({:secret_file => @secret_file.path})
|
89
96
|
Chef::EncryptedDataBagItem.should_receive(:load).
|
90
97
|
with('bag_name', 'item_name', @secret).
|
91
98
|
and_return(Chef::EncryptedDataBagItem.new(@enc_data, @secret))
|
@@ -19,47 +19,110 @@
|
|
19
19
|
require 'spec_helper'
|
20
20
|
|
21
21
|
describe Chef::Knife::IndexRebuild do
|
22
|
-
before do
|
23
|
-
Chef::Config[:node_name] = "webmonkey.example.com"
|
24
|
-
@knife = Chef::Knife::IndexRebuild.new
|
25
|
-
@rest_client = mock("Chef::REST (mock)", :post_rest => { :result => :true })
|
26
|
-
@knife.ui.stub!(:output)
|
27
|
-
@knife.stub!(:rest).and_return(@rest_client)
|
28
|
-
|
29
|
-
@out = StringIO.new
|
30
|
-
@knife.ui.stub!(:stdout).and_return(@out)
|
31
|
-
end
|
32
22
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@out.string.should match(/yes\/no/)
|
23
|
+
let(:knife){Chef::Knife::IndexRebuild.new}
|
24
|
+
let(:rest_client){mock(Chef::REST)}
|
25
|
+
|
26
|
+
let(:stub_rest!) do
|
27
|
+
knife.should_receive(:rest).and_return(rest_client)
|
39
28
|
end
|
40
29
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@knife.run
|
45
|
-
@out.string.should match(/yes\/no/)
|
30
|
+
before :each do
|
31
|
+
# This keeps the test output clean
|
32
|
+
knife.ui.stub!(:stdout).and_return(StringIO.new)
|
46
33
|
end
|
47
34
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
35
|
+
context "#grab_api_info" do
|
36
|
+
let(:http_not_found_response) do
|
37
|
+
e = Net::HTTPNotFound.new("1.1", 404, "blah")
|
38
|
+
e.stub(:[]).with("x-ops-api-info").and_return(api_header_value)
|
39
|
+
e
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:http_server_exception) do
|
43
|
+
Net::HTTPServerException.new("404: Not Found", http_not_found_response)
|
44
|
+
end
|
45
|
+
|
46
|
+
before(:each) do
|
47
|
+
stub_rest!
|
48
|
+
rest_client.stub(:get_rest).and_raise(http_server_exception)
|
49
|
+
end
|
50
|
+
|
51
|
+
context "against a Chef 11 server" do
|
52
|
+
let(:api_header_value){"flavor=osc;version=11.0.0;erchef=1.2.3"}
|
53
|
+
it "retrieves API information" do
|
54
|
+
knife.grab_api_info.should == {"flavor" => "osc", "version" => "11.0.0", "erchef" => "1.2.3"}
|
55
|
+
end
|
56
|
+
end # Chef 11
|
57
|
+
|
58
|
+
context "against a Chef 10 server" do
|
59
|
+
let(:api_header_value){nil}
|
60
|
+
it "finds no API information" do
|
61
|
+
knife.grab_api_info.should == {}
|
62
|
+
end
|
63
|
+
end # Chef 10
|
64
|
+
end # grab_api_info
|
65
|
+
|
66
|
+
context "#unsupported_version?" do
|
67
|
+
context "with Chef 11 API metadata" do
|
68
|
+
it "is unsupported" do
|
69
|
+
knife.unsupported_version?({"version" => "11.0.0", "flavor" => "osc", "erchef" => "1.2.3"}).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "only truly relies on the version being non-nil" do
|
73
|
+
knife.unsupported_version?({"version" => "1", "flavor" => "osc", "erchef" => "1.2.3"}).should be_true
|
74
|
+
end
|
54
75
|
end
|
55
76
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
77
|
+
context "with Chef 10 API metadata" do
|
78
|
+
it "is supported" do
|
79
|
+
# Chef 10 will have no metadata
|
80
|
+
knife.unsupported_version?({}).should be_false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end # unsupported_version?
|
84
|
+
|
85
|
+
context "Simulating a 'knife index rebuild' run" do
|
86
|
+
|
87
|
+
before :each do
|
88
|
+
knife.should_receive(:grab_api_info).and_return(api_info)
|
89
|
+
server_specific_stubs!
|
90
|
+
end
|
91
|
+
|
92
|
+
context "against a Chef 11 server" do
|
93
|
+
let(:api_info) do
|
94
|
+
{"flavor" => "osc",
|
95
|
+
"version" => "11.0.0",
|
96
|
+
"erchef" => "1.2.3"
|
97
|
+
}
|
98
|
+
end
|
99
|
+
let(:server_specific_stubs!) do
|
100
|
+
knife.should_receive(:unsupported_server_message).with(api_info)
|
101
|
+
knife.should_receive(:exit).with(1)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not be allowed" do
|
105
|
+
knife.run
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "against a Chef 10 server" do
|
110
|
+
let(:api_info){ {} }
|
111
|
+
let(:server_specific_stubs!) do
|
112
|
+
stub_rest!
|
113
|
+
rest_client.should_receive(:post_rest).with("/search/reindex", {}).and_return("representative output")
|
114
|
+
knife.should_not_receive(:unsupported_server_message)
|
115
|
+
knife.should_receive(:deprecated_server_message)
|
116
|
+
knife.should_receive(:nag)
|
117
|
+
knife.should_receive(:output).with("representative output")
|
118
|
+
end
|
119
|
+
it "should be allowed" do
|
120
|
+
knife.run
|
121
|
+
end
|
62
122
|
end
|
63
123
|
end
|
64
124
|
|
65
125
|
end
|
126
|
+
|
127
|
+
|
128
|
+
|
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -21,7 +21,7 @@ require 'spec_helper'
|
|
21
21
|
describe Chef::Knife::Help do
|
22
22
|
before(:each) do
|
23
23
|
# Perilously use the build in list even though it is dynamic so we don't get warnings about the constant
|
24
|
-
# HELP_TOPICS = [ "foo", "bar", "knife-kittens", "ceiling-cat", "
|
24
|
+
# HELP_TOPICS = [ "foo", "bar", "knife-kittens", "ceiling-cat", "shell" ]
|
25
25
|
@knife = Chef::Knife::Help.new
|
26
26
|
end
|
27
27
|
|
@@ -30,8 +30,8 @@ describe Chef::Knife::Help do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should run man for you" do
|
33
|
-
@knife.name_args = [ "
|
34
|
-
@knife.should_receive(:exec).with(/^man \/.*\/
|
33
|
+
@knife.name_args = [ "shell" ]
|
34
|
+
@knife.should_receive(:exec).with(/^man \/.*\/shell.1$/)
|
35
35
|
@knife.run
|
36
36
|
end
|
37
37
|
|
@@ -47,9 +47,9 @@ describe Chef::Knife::Help do
|
|
47
47
|
|
48
48
|
describe "find_manpage_path" do
|
49
49
|
it "should find the man page in the gem" do
|
50
|
-
@knife.find_manpage_path("
|
50
|
+
@knife.find_manpage_path("shell").should =~ /distro\/common\/man\/man1\/chef-shell.1$/
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should provide the man page name if not in the gem" do
|
54
54
|
@knife.find_manpage_path("foo").should == "foo"
|
55
55
|
end
|
@@ -25,6 +25,7 @@ describe Chef::Knife::NodeRunListRemove do
|
|
25
25
|
@knife.config[:print_after] = nil
|
26
26
|
@knife.name_args = [ "adam", "role[monkey]" ]
|
27
27
|
@node = Chef::Node.new()
|
28
|
+
@node.name("knifetest-node")
|
28
29
|
@node.run_list << "role[monkey]"
|
29
30
|
@node.stub!(:save).and_return(true)
|
30
31
|
|
@@ -52,7 +53,7 @@ describe Chef::Knife::NodeRunListRemove do
|
|
52
53
|
|
53
54
|
it "should print the run list" do
|
54
55
|
@knife.config[:print_after] = true
|
55
|
-
@knife.ui.should_receive(:output).with({ 'run_list' => [] })
|
56
|
+
@knife.ui.should_receive(:output).with({ "knifetest-node" => { 'run_list' => [] } })
|
56
57
|
@knife.run
|
57
58
|
end
|
58
59
|
|
data/spec/unit/knife/ssh_spec.rb
CHANGED
@@ -34,14 +34,14 @@ describe Chef::Knife::Ssh do
|
|
34
34
|
|
35
35
|
before do
|
36
36
|
@knife = Chef::Knife::Ssh.new
|
37
|
-
@knife.
|
37
|
+
@knife.merge_configs
|
38
38
|
@knife.config[:attribute] = "fqdn"
|
39
|
-
@node_foo = Chef::Node.new
|
40
|
-
@node_foo[:fqdn] = "foo.example.org"
|
41
|
-
@node_foo[:ipaddress] = "10.0.0.1"
|
42
|
-
@node_bar = Chef::Node.new
|
43
|
-
@node_bar[:fqdn] = "bar.example.org"
|
44
|
-
@node_bar[:ipaddress] = "10.0.0.2"
|
39
|
+
@node_foo = Chef::Node.new
|
40
|
+
@node_foo.automatic_attrs[:fqdn] = "foo.example.org"
|
41
|
+
@node_foo.automatic_attrs[:ipaddress] = "10.0.0.1"
|
42
|
+
@node_bar = Chef::Node.new
|
43
|
+
@node_bar.automatic_attrs[:fqdn] = "bar.example.org"
|
44
|
+
@node_bar.automatic_attrs[:ipaddress] = "10.0.0.2"
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "#configure_session" do
|
@@ -64,7 +64,7 @@ describe Chef::Knife::Ssh do
|
|
64
64
|
@knife.should_receive(:session_from_list).with(['10.0.0.1', '10.0.0.2'])
|
65
65
|
@knife.configure_session
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "returns an array of the attributes specified on the command line even when a config value is set" do
|
69
69
|
@knife.config[:attribute] = "config_file" # this value will be the config file
|
70
70
|
@knife.config[:override_attribute] = "ipaddress" # this is the value of the command line via #configure_attribute
|
@@ -84,10 +84,8 @@ describe Chef::Knife::Ssh do
|
|
84
84
|
|
85
85
|
context "when cloud hostnames are available" do
|
86
86
|
before do
|
87
|
-
@node_foo[:cloud] =
|
88
|
-
@node_bar[:cloud] =
|
89
|
-
@node_foo[:cloud][:public_hostname] = "ec2-10-0-0-1.compute-1.amazonaws.com"
|
90
|
-
@node_bar[:cloud][:public_hostname] = "ec2-10-0-0-2.compute-1.amazonaws.com"
|
87
|
+
@node_foo.automatic_attrs[:cloud][:public_hostname] = "ec2-10-0-0-1.compute-1.amazonaws.com"
|
88
|
+
@node_bar.automatic_attrs[:cloud][:public_hostname] = "ec2-10-0-0-2.compute-1.amazonaws.com"
|
91
89
|
end
|
92
90
|
|
93
91
|
it "returns an array of cloud public hostnames" do
|
@@ -109,8 +107,8 @@ describe Chef::Knife::Ssh do
|
|
109
107
|
context "when there are some hosts found but they do not have an attribute to connect with" do
|
110
108
|
before do
|
111
109
|
@query.stub!(:search).and_return([[@node_foo, @node_bar]])
|
112
|
-
@node_foo[:fqdn] = nil
|
113
|
-
@node_bar[:fqdn] = nil
|
110
|
+
@node_foo.automatic_attrs[:fqdn] = nil
|
111
|
+
@node_bar.automatic_attrs[:fqdn] = nil
|
114
112
|
Chef::Search::Query.stub!(:new).and_return(@query)
|
115
113
|
end
|
116
114
|
|
@@ -180,5 +178,113 @@ describe Chef::Knife::Ssh do
|
|
180
178
|
end
|
181
179
|
end
|
182
180
|
|
183
|
-
|
181
|
+
describe "#session_from_list" do
|
182
|
+
before :each do
|
183
|
+
@knife.instance_variable_set(:@longest, 0)
|
184
|
+
ssh_config = {:timeout => 50, :user => "locutus", :port => 23 }
|
185
|
+
Net::SSH.stub!(:configuration_for).with('the.b.org').and_return(ssh_config)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "uses the port from an ssh config file" do
|
189
|
+
@knife.session_from_list(['the.b.org'])
|
190
|
+
@knife.session.servers[0].port.should == 23
|
191
|
+
end
|
192
|
+
|
193
|
+
it "uses the user from an ssh config file" do
|
194
|
+
@knife.session_from_list(['the.b.org'])
|
195
|
+
@knife.session.servers[0].user.should == "locutus"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "#ssh_command" do
|
200
|
+
let(:execution_channel) { double(:execution_channel, :on_data => nil) }
|
201
|
+
let(:session_channel) { double(:session_channel, :request_pty => nil)}
|
202
|
+
|
203
|
+
let(:execution_channel2) { double(:execution_channel, :on_data => nil) }
|
204
|
+
let(:session_channel2) { double(:session_channel, :request_pty => nil)}
|
205
|
+
|
206
|
+
let(:session) { double(:session, :loop => nil) }
|
207
|
+
|
208
|
+
let(:command) { "false" }
|
209
|
+
|
210
|
+
before do
|
211
|
+
execution_channel.
|
212
|
+
should_receive(:on_request).
|
213
|
+
and_yield(nil, double(:data_stream, :read_long => exit_status))
|
214
|
+
|
215
|
+
session_channel.
|
216
|
+
should_receive(:exec).
|
217
|
+
with(command).
|
218
|
+
and_yield(execution_channel, true)
|
219
|
+
|
220
|
+
execution_channel2.
|
221
|
+
should_receive(:on_request).
|
222
|
+
and_yield(nil, double(:data_stream, :read_long => exit_status2))
|
223
|
+
|
224
|
+
session_channel2.
|
225
|
+
should_receive(:exec).
|
226
|
+
with(command).
|
227
|
+
and_yield(execution_channel2, true)
|
228
|
+
|
229
|
+
session.
|
230
|
+
should_receive(:open_channel).
|
231
|
+
and_yield(session_channel).
|
232
|
+
and_yield(session_channel2)
|
233
|
+
end
|
234
|
+
|
235
|
+
context "both connections return 0" do
|
236
|
+
let(:exit_status) { 0 }
|
237
|
+
let(:exit_status2) { 0 }
|
238
|
+
|
239
|
+
it "returns a 0 exit code" do
|
240
|
+
@knife.ssh_command(command, session).should == 0
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "the first connection returns 1 and the second returns 0" do
|
245
|
+
let(:exit_status) { 1 }
|
246
|
+
let(:exit_status2) { 0 }
|
247
|
+
|
248
|
+
it "returns a non-zero exit code" do
|
249
|
+
@knife.ssh_command(command, session).should == 1
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context "the first connection returns 1 and the second returns 2" do
|
254
|
+
let(:exit_status) { 1 }
|
255
|
+
let(:exit_status2) { 2 }
|
256
|
+
|
257
|
+
it "returns a non-zero exit code" do
|
258
|
+
@knife.ssh_command(command, session).should == 2
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "#run" do
|
264
|
+
before do
|
265
|
+
@query = Chef::Search::Query.new
|
266
|
+
@query.should_receive(:search).and_return([[@node_foo]])
|
267
|
+
Chef::Search::Query.stub!(:new).and_return(@query)
|
268
|
+
@knife.stub(:ssh_command).and_return(exit_code)
|
269
|
+
@knife.name_args = ['*:*', 'false']
|
270
|
+
end
|
271
|
+
|
272
|
+
context "with an error" do
|
273
|
+
let(:exit_code) { 1 }
|
274
|
+
|
275
|
+
it "should exit with a non-zero exit code" do
|
276
|
+
@knife.should_receive(:exit).with(exit_code)
|
277
|
+
@knife.run
|
278
|
+
end
|
279
|
+
end
|
184
280
|
|
281
|
+
context "with no error" do
|
282
|
+
let(:exit_code) { 0 }
|
283
|
+
|
284
|
+
it "should not exit" do
|
285
|
+
@knife.should_not_receive(:exit)
|
286
|
+
@knife.run
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|