summaryrefslogtreecommitdiffstats
path: root/acceptance
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppetlabs.com>2011-08-10 16:20:00 -0700
committerJosh Cooper <josh@puppetlabs.com>2011-08-11 15:02:45 -0700
commitd7c9c765dbf28df3631e709832c44c343569cb53 (patch)
tree06c36a680865cc7c4bd70dc41bc57637f7fea1f5 /acceptance
parentc209f6279563faa863644641a85c9b554900d227 (diff)
downloadpuppet-d7c9c765dbf28df3631e709832c44c343569cb53.tar.gz
puppet-d7c9c765dbf28df3631e709832c44c343569cb53.tar.xz
puppet-d7c9c765dbf28df3631e709832c44c343569cb53.zip
(#8740) Do not enumerate files in the root directory.
Previously the command 'puppet resource file' would enumerate all files in the root directory, and generate an exception if the file type was not a directory, file, or link. Worse, it would also do this when a file or directory was specified, e.g. 'puppet resource file /etc/hosts'. Ideally, the find method of the ral terminus should not need to call the type's instances class method, instead just creating an instance of the type with the specified name and parameters. However, some types, like package, depend on this behavior. The type walks all providers and all instances that they provide, checking to see if the provider provides an instance with that name, and also warning if another provider provides an instance with the same name. Also, ideally, puppet should not blow up when encountering an unsupported file type, e.g. Unix domain socket, but that would be too big of a change for 2.6.x. This commit changes 'puppet resource file' to return a message saying that the operation is not supported: Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc The change is bit of a hack, as ideally, the file type's instances method could raise an exception when called in a 'search' context, but return an empty array in a 'find' context. But that also would be too big of a change for 2.6.x. This commit also adds spec tests for the resource application and file type, as well as an acceptance test, which creates a Unix domain socket in the root directory, while running 'puppet resource file'. Paired-with: Nick Lewis <nick@puppetlabs.com> Reviewed-by: Jacob Helwig <jacob@puppetlabs.com>
Diffstat (limited to 'acceptance')
-rw-r--r--acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb b/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb
new file mode 100644
index 000000000..5763a3c98
--- /dev/null
+++ b/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb
@@ -0,0 +1,32 @@
+test_name "#8740: should not enumerate root directory"
+
+target = "/test-socket-#{$$}"
+
+step "clean up the system before we begin"
+on(agents, "rm -f #{target}")
+
+step "create UNIX domain socket"
+on(agents, %Q{ruby -e "require 'socket'; UNIXServer::new('#{target}').close"})
+
+step "query for all files, which should return nothing"
+on(agents, puppet_resource('file'), :acceptable_exit_codes => [1]) do
+ assert_match(%r{Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc}, stderr)
+end
+
+["/", "/etc"].each do |file|
+ step "query '#{file}' directory, which should return single entry"
+ on(agents, puppet_resource('file', file)) do
+ files = stdout.scan(/^file \{ '([^']+)'/).flatten
+
+ assert_equal(1, files.size, "puppet returned multiple files: #{files.join(', ')}")
+ assert_match(file, files[0], "puppet did not return file")
+ end
+end
+
+step "query file that does not exist, which should report the file is absent"
+on(agents, puppet_resource('file', '/this/does/notexist')) do
+ assert_match(/ensure\s+=>\s+'absent'/, stdout)
+end
+
+step "remove UNIX domain socket"
+on(agents, "rm -f #{target}")