summaryrefslogtreecommitdiff
path: root/spec/unit/provider/exec
AgeCommit message (Collapse)AuthorFilesLines
2014-07-17(PUP-2732) Restrict Posix exec tests to POSIX envEthan J. Brown1-7/+6
- Instead of trying to simulate a POSIX environment on the Windows for the sake of tests against a provider that never runs on Windows, exclude the tests when Puppet.features.posix? is not true. - Given that these tests will no longer execute on Windows, the usage of expand_path is no longer necessary, nor are any of the Puppet.features.microsoft_windows? guards
2014-07-17(maint) Use Struct::Passwd instead of Etc::PasswdAndrew Parker1-1/+1
The return type of Etc.getpwent (and friends) is available as Etc::Passwd in ruby 1.9.3 and later. However that constant doesn't exist in ruby 1.8.7. However the docs refer to the type as Struct::Passwd, which turns out to be available on 1.8.7, 1.9.3, 2.0.0, and 2.1.0.
2014-07-16(PUP-2732) Test ignoring of user parameterAndrew Parker1-1/+11
When the user parameter is specified, but it is the same as the current user, there isn't any need to control the user when executing the command. This adds a test in the posix provider for this shared behavior. There don't appear to be many tests for how exec works at all.
2014-07-16(maint) Use real resource for testing shell providerAndrew Parker1-2/+2
The shell provider tests were creating an invalid configuration of objects in order to test. The resource needs to be an instance of the :exec type, not a Puppet::Resource.
2014-07-16(maint) Use parameter matchers in testsAndrew Parker1-7/+6
This uses the mocha parameter matchers in the tests rather than a custom with() block. This is a little shorter and should provide better error messages when it fails.
2013-11-14(#23124) Move ProcessOutput to Puppet::Util::ExecutionAndrew Parker1-3/+3
The ProcessOutput class was lonely over in the puppet/process directory. Not only did it have the wrong name, but it had no friends. This moves it to Puppet::Util::Execution so that it can be with its friends and also gives it some more documentation and a public tag so that others can know how great it is.
2013-11-14(#23124) Fix: Incorrect Exit Codes from Windows ExecRob Reynolds1-3/+3
This fixes the incorrect exitstatus being returned when a process is run on Windows. There is an outstanding bug with Ruby (https://bugs.ruby-lang.org/issues/8083) where it truncates the exit codes to one byte values. Due to this an exit code of 3010 is currently truncated to 194. Puppet accurately receives the exit code but was then ignoring that and only returning the output. $CHILD_STATUS was then being queried, and due to the aforementioned bug, was returning the truncated return code. This means that anything above 256 would be returned incorrectly. This removes the private method Puppet::Util::SUIDManager.run_and_capture() in favor of a more simplified call to Puppet::Util::Execution.execute(). This was done as run_and_capture was only being called by Puppet::Provider::Exec.run(). This also removes the call to $CHILD_STATUS which may clear up some other race conditions with capturing the proper $CHILD_STATUS. Paired with Andrew Parker <andy@puppetlabs.com>
2013-11-14Merge branch 'stable'Rob Reynolds1-3/+3
Conflicts: lib/puppet/provider/package/windows.rb
2013-11-14Revert "(#23124) Merge branch 'ticket/stable/23124-exit_codes_on_windows' ↵Rob Reynolds1-3/+3
into stable" Reverting as this should have been targeted at 3.4.0 (on master). This reverts commit 1f3ea533b06ccf5188f5dd371da722e7c84dc904, reversing changes made to f4c7e8b7a67ae5ae60b0be12b97f12b6c3673291.
2013-11-14Merge branch 'stable'Rob Reynolds1-3/+3
Conflicts: lib/puppet/provider/package/windows.rb
2013-11-14(#23124) Move ProcessOutput to Puppet::Util::ExecutionAndrew Parker1-3/+3
The ProcessOutput class was lonely over in the puppet/process directory. Not only did it have the wrong name, but it had no friends. This moves it to Puppet::Util::Execution so that it can be with its friends and also gives it some more documentation and a public tag so that others can know how great it is.
2013-11-14(#23124) Fix: Incorrect Exit Codes from Windows ExecRob Reynolds1-3/+3
This fixes the incorrect exitstatus being returned when a process is run on Windows. There is an outstanding bug with Ruby (https://bugs.ruby-lang.org/issues/8083) where it truncates the exit codes to one byte values. Due to this an exit code of 3010 is currently truncated to 194. Puppet accurately receives the exit code but was then ignoring that and only returning the output. $CHILD_STATUS was then being queried, and due to the aforementioned bug, was returning the truncated return code. This means that anything above 256 would be returned incorrectly. This removes the private method Puppet::Util::SUIDManager.run_and_capture() in favor of a more simplified call to Puppet::Util::Execution.execute(). This was done as run_and_capture was only being called by Puppet::Provider::Exec.run(). This also removes the call to $CHILD_STATUS which may clear up some other race conditions with capturing the proper $CHILD_STATUS. Paired with Andrew Parker <andy@puppetlabs.com>
2013-09-17(#4424) Add umask parameter to Exec typeJohn Julien1-0/+5
Setting a umask value for execs can be useful when the exec creates files or directories. Relying on the sytem umask can produce unexected results as it may be different from system to system or just not what the user intends..
2013-05-28(#20302) Append .exe to spec "executables" on WindowsJosh Cooper1-0/+1
When running the tests on Windows and Ruby 1.8.7, File.executable? returns true on regardless of the file extension. On Ruby 1.9, it only returns true if the extension is .exe or similar. This commit ensures the "executable" ends with .exe.
2013-03-25Fix posix exec provider spec on systems with /bin/cdNick Lewis1-1/+1
This test was setting path to /bin with the assumption that it didn't contain cd, and therefore the only cd would be a shell built-in. On system which *do* contain /bin/cd, this was failing. Now we just use a bogus path so this will work everywhere.
2012-09-26(Maint) Remove rspec from shebang lineJeff McCune3-3/+3
Without this patch Ruby 1.9 is still complaining loudly about trying to parse the spec files. The previous attempt to clean up this problem in edc3ddf works for Ruby 1.8 but not 1.9. I'd prefer to remove the shebang lines entirely, but doing so will cause encoding errors in Ruby 1.9. This patch strives for a happy middle ground of convincing Ruby it is actually working with Ruby while not confusing it to think it should exec() to rspec. This patch is the result of the following command run against the source tree: find spec -type f -print0 | \ xargs -0 perl -pl -i -e 's,^\#\!\s?/(.*)rspec,\#! /usr/bin/env ruby,'
2012-08-31Merge remote-tracking branch 'upstream/2.7.x' into 3.xJosh Cooper1-4/+5
* upstream/2.7.x: (#16208): Correct spec test to match new failed parameter message Maint: Fix inconsistent expect-should usage Maint: Fix leaked tempfile handle Conflicts: spec/unit/util_spec.rb
2012-08-31Maint: Fix leaked tempfile handleJosh Cooper1-4/+5
This test failed on Windows because we were creating a tempfile, but not closing the underlying file descriptor. So later attempts to cleanup fail on Windows (unlike POSIX). This commit modifies the `.tmpfile` and `#tmpfile` methods on the PuppetSpec::Files module to accept an optional directory in which to create the temp file.
2012-08-31Merge remote-tracking branch 'origin/2.7.x' into 3.xDaniel Pittman1-6/+6
Conflicts: lib/puppet/parser/functions/shellquote.rb lib/puppet/type/package.rb spec/integration/util/file_locking_spec.rb spec/unit/parser/functions/shellquote_spec.rb spec/unit/util/command_line_spec.rb Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-08-31Don't make executables in /tmp in posix_specPatrick Carlisle1-6/+6
The posix specs were creating executable files in /tmp, which caused a warning about an insecure directory in the path. This adds an intermediate safe directory.
2012-08-14(Maint) Fix assertion about locale to correct value.rahul1-3/+3
Previous merge from 3.x to master updated the locales incorrectly and overwrote a change for solaris specs (#15547) : validate locales as sentinel #43d86d40570140918009f2048f8998fb2200f81f. This update corrects it.
2012-07-30(Maint) Fix assertion about localeAndrew Parker1-1/+1
The merge from 3.x to master had an incorrect change that caused the test to fail. I had forgotten to run the tests before pushing and didn't notice until it got to CI. This commit just undoes the one incorrect change.
2012-07-27Merge remote-tracking branch 'upstream/3.x'Andrew Parker1-3/+3
* upstream/3.x: (27 commits) Replace "the short version" with outline (#15547) mock of facter :operatingsystem pending (#15595) Improve message on SSL errors (#15595) Clear up tests around ssl errors use error_message instead of error updates as requested (#15595) Offer better errors for certificate validation errors Update CONTRIBUTING.md (Maint) Remove some more ambiguity Use rspec 2.11 compatible block syntax Revert "Merge branch 'fixpid' of https://github.com/vrthra/puppet into 3.x" Make 3.x specs compatible with rspec 2.11 (#15676) Fix puppet module face SSL acceptance tests to use masters real hostname wip Revert "Merge branch 'non-string-resource-titles' of https://github.com/nicklewis/puppet into 3.x" Fix buggy resource title tests Use rspec 2.11 compatible block syntax (Maint) Be more honest about submission methods (Maint) Clarify that Redmine tickets are mandatory (Maint) Clarify which branches changes should be based on ... Conflicts: spec/unit/provider/exec/posix_spec.rb
2012-07-1715547 : valid locales as sentinel and checkrahul1-4/+4
Using spurious values for LC_ALL and LANG values in solaris causes some commands to barf. Since we are only checking for overrides, we can aswell use a valid locale.
2012-07-1715547 : use a clean env for builtin checkrahul1-1/+1
solaris has /bin/cd as a command to ensure posix compatibility. So we need to avoid using '/bin' in path if we want to ensure that we are looking at shell builtin cd.
2012-07-11Use a valid locale when setting LC_ALL in the exec posix provider testR. Tyler Croy1-2/+2
Fixes #15467
2012-07-02(maint) Standardize on /usr/bin/env ruby -S rspecJeff McCune3-3/+3
Without this patch some spec files are using `ruby -S rspec` and others are using `rspec`. We should standardize on a single form of the interpreter used for spec files. `ruby -S rspec` is the best choice because it correctly informs editors such as Vim with Syntastic that the file is a Ruby file rather than an Rspec file.
2012-04-24Merge 2.7.x into master.Daniel Pittman1-14/+17
This manually fixes up a pile of Puppet Module Tool conflicts by hand, related to overlapping changes with nothing but textual translation. The rest of the merge was smooth and simple. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-04-23(#14060) Fix quoting of commands to interpolate inside the shell.Daniel Pittman1-0/+7
The `shell` exec provider was supposed to emulate the behaviour of 0.25 exec, which was to pass the content through the default shell to get it executed. Unfortunately, it got quoting a bit wrong, and ended up interpolating variables at the wrong point - it used double quotes where single quotes were really what was desired. Thanks to Matthew Byng-Maddick for the report, and a fix to the quoting; in the end we should not be in this position - we shouldn't be using string execution where we can pass an array instead. That avoids any chance that there is more than one round of shell interpolation entirely. As a bonus, this fixes the base exec type to support specifying the command to run that very way, and making it good. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-04-20Modernize the style of the shell exec provider tests.Daniel Pittman1-14/+10
This just whips the content up to the modern standard for tests. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-04-10Merge branch '2.7.x'Patrick Carlisle1-7/+1
* 2.7.x: (maint) Remove unnecessary step from puppet module build help (#13659) Convert fact values to string when searching database (#13649) Restrict module name matching (#13643) Make the use of FileUtils.rm_rf secure (#13642) Move search notice message (#13639) Don't send errors directly to stderr (#13638) Add SemVer#pre function (#3581) Stop forking around: Add fork helper method (#13397) fix gem provider ensure=>latest bug (#12101) Make Puppet::Util::absolute_path? usable in autoloader (#12101) Add shared context for specs to imitate windows or posix Conflicts: lib/puppet/util.rb spec/unit/util_spec.rb
2012-03-28(#12101) Add shared context for specs to imitate windows or posixPatrick Carlisle1-7/+1
Add "windows" and "posix" shared contexts to rspec. If you give :as_platform => :posix or :as_platform => :windows as argument to a describe block, it will automatically stub the relevant facts and path behavior to imitate windows or posix.
2012-02-03(#12309) Fix broken rspecscprice1-3/+3
2012-02-02(#12309) move execution-related methods from Util to Util::ExecutionChris Price1-2/+2
There are still deprecated stubs for execpipe, execfail, and execute in Puppet::Util for backwards compatibility. rspecs are all passing, but would still like to go through and check for deprecation warnings that were triggered by this changeset (and fix them, obviously). get spec tests running against Puppet::Util -> Util::Execution refactor
2012-02-02moved posix-specific constants from Util to Util::POSIXChris Price1-7/+7
2012-01-27(#5224) Unset USER-related env vars during execsChris Price1-1/+50
This bug report was related to the fact that you may end up with very different values for environment variables such as "HOME", "USER", "LOGNAME" depending on how you start puppet (at boot time, via "service", via /etc/init.d, etc.). These variations can have an effect on the behavior of programs / services that are launched by puppet, particularly those that are triggered via Exec resources. Change the behavior such that these environment variables are simply unset by puppet prior to executing commands.
2012-01-26(#11860) Fix specs that fail on windowsChris Price1-1/+1
Previously, the daemon and execute_posix spec tests were failing on Windows, but this functionality is not supported on Windows, and so the tests are skipped on Windows.
2012-01-25(#11860) Add parameter to control locale overrideChris Price1-0/+39
Puppet::Util.execute_posix contained some code that would override some locale-related environment variables in order to force the command being executed to produce well-known, consistent, predictably formatted output so that it could be parsed. However, there are some cases (such as a user-defined "exec" block) where we need to respect the system/user locale settings. Add a boolean parameter to the Puppet::Util.execute method that allows toggling this locale override behavior. The "exec" provider now passes "false" for this value, meaning that we no longer override the locale for user-defined "exec" resources. Users may choose to override the locale themselves by specifying the appropriate locale-related vars in the "environment" section of their resource. All of this is ignored on windows at the moment, but the parameter is passed in to "execute", which is responsible for calling "execute_windows" on windows systems. We could decide to do something with this parameter on windows at some point in the future.
2012-01-24Revert "(#12101) Add shared context for specs to imitate windows or posix"Patrick Carlisle1-1/+7
This reverts commit edc544d73bc8f9f7de07de4b30e344d1f4db3178. This doesn't work with rspec < 2.6.0 and it's breaking continuous integration.
2012-01-24(#12101) Add shared context for specs to imitate windows or posixPatrick Carlisle1-7/+1
Add "windows" and "posix" shared contexts to rspec. If you give :as_platform => :posix or :as_platform => :windows as argument to a describe block, it will automatically stub the relevant facts and path behavior to imitate windows or posix.
2011-11-14maint: Fix failing specs for Windows exec providerNick Lewis1-0/+1
These specs were trying to stub the microsoft_windows feature to enable the Windows exec provider for the test. However, the Windows provider was changed in ad98d47 to use the operatingsystem fact for its confine, rather than the feature, so these failed. This changes them to also stub the operatingsystem fact. Reviewed-by: Josh Cooper <josh@puppetlabs.com>
2011-10-12Maint: Remove duplicate path extension codeJosh Cooper1-8/+1
Previously, the Windows exec provider had incorrect logic for resolving an executable using a hard-coded list of extensions, e.g. '.cmd' wasn't in the list. Recently, Puppet::Util.which was modified to perform path resolution taking into account the PATHEXT environment variable on Windows. See 0258096c474d1b2cbf7e403fc990a853ac277231. As a result, the duplicate logic in the Windows exec provider has been removed.
2011-09-15Fix order dependent spec failure in exec specsNick Lewis1-0/+6
The provider/exec/windows_spec.rb spec was creating exec resources explicitly using the Windows provider as the provider. The Windows provider was being evaluated as suitable and thus the default provider for the type. Then in future specs, it could be used since it was the default, even though it wasn't necessarily suitable, causing failures. Now, we just clear the defaultprovider on the exec type after all the specs in the file have finished, ensuring it will be recalculated appropriately when needed. Reviewed-By: Matt Robinson <matt@puppetlabs.com>
2011-08-24(#8140) Add an exec provider for WindowsNick Lewis1-0/+113
This provider inherits from the Puppet::Provider::Exec class, and is very similar to the posix provider in its behavior. This provider doesn't have the ability to run as a particular user or group and will fail if that is attempted, but does support setting all other parameters, as well as autorequires.
2011-08-24(#8410) Factor out a base class for exec providersNick Lewis1-9/+4
Rather than the shell provider inheriting from the posix provider, they both now inherit from a common Puppet::Provider::Exec class. This new base class and inheritance structure will allow the forthcoming windows provider to also inherit from that class, rather than from the unsuitable posix provider. Also, now that Puppet::Util.execute supports commands as strings in addition to arrays, the command to execute is passed to Puppet::Util::SUIDManager.run_and_capture as a string, rather than a string wrapped in an array. This ensures we will never improperly quote a command with arguments provided as a single string.
2011-08-19Fix posix exec provider spec failures on WindowsNick Lewis1-3/+5
These specs were assuming that paths such as /foo were always absolute, which is not the case on Windows. Thus, when run on Windows, the provider was complaining about receiving relative paths when it expected absolute, rather than succeeding or failing in the intended way. Now we expand all paths we want to be absolute, to guarantee they will be absolute everywhere. Also, some specs were failing because they were trying to test the case where a file isn't executable. That's not something we can reliably check on Windows, so instead just stub the appropriate executable? methods. Reviewed-By: Matt Robinson <matt@puppetlabs.com> (cherry picked from commit e9b558dd35eec6e221aef9de3f300a5843347454)
2011-08-19(#5495) Remove dead Windows-specific code from posix exec providerNick Lewis1-5/+3
Because this provider only applies when the posix feature is present (and thus not the windows feature), it can never be used on Windows. Thus, the Windows-specific command handling is unnecessary and unused. Also added more specific error messages for the cases where a command doesn't exist, isn't a file, and isn't executable. These only apply when the command path is absolute (otherwise the message is simply command not found). Reviewed-By: Matt Robinson <matt@puppetlabs.com> (cherry picked from commit b28bcb031346cfd2026361ec5ffb420c1dcf60d7) Conflicts: spec/unit/provider/exec/posix_spec.rb
2011-08-19(#8663) Disable spec tests for unsupported functionality on WindowsJosh Cooper1-1/+1
The mount, shell, and ssh_authorized_key types are not supported on Windows, so these spec tests have been disabled when running on Windows. One of the compiler spec tests fails on Windows because Puppet::Util.execute attempts to execute a program named "git rev-parse HEAD". This has different semantics than Unix, where the command is splatted, Kernel.exec(*command). Since this truly is a Windows bug, I removed the fails_on_windows tag and updated ticket #8410. Reviewed-by: Jacob Helwig <jacob@puppetlabs.com> (cherry picked from commit d9ce88d10707268fe41c8f3ad1166137fe8e202f)
2011-08-19Maint: Tagged spec tests that are known to fail on WindowsJosh Cooper1-1/+1
Many spec tests fail on Windows because there are no default providers implemented for Windows yet. Several others are failing due to Puppet::Util::Cacher not working correctly, so for now the tests that are known to fail are marked with :fails_on_windows => true. To skip these tests, you can run: rspec --tag ~fails_on_windows spec Reviewed-by: Jacob Helwig <jacob@puppetlabs.com> (cherry picked from commit 255c5b4663bd389d2c87a2d39ec350034421a6f0) Conflicts: spec/unit/resource/catalog_spec.rb
2011-08-16Fix posix exec provider spec failures on WindowsNick Lewis1-3/+5
These specs were assuming that paths such as /foo were always absolute, which is not the case on Windows. Thus, when run on Windows, the provider was complaining about receiving relative paths when it expected absolute, rather than succeeding or failing in the intended way. Now we expand all paths we want to be absolute, to guarantee they will be absolute everywhere. Also, some specs were failing because they were trying to test the case where a file isn't executable. That's not something we can reliably check on Windows, so instead just stub the appropriate executable? methods. Reviewed-By: Matt Robinson <matt@puppetlabs.com>