summaryrefslogtreecommitdiff
path: root/spec/unit/util_spec.rb
AgeCommit message (Collapse)AuthorFilesLines
2014-01-06(PUP-761) Make most FileSystem API change related test passHenrik Lindberg1-7/+7
2013-11-13(#19447) Puppet::FileSystem::File.unlinkEthan J. Brown1-2/+2
- All previous File.unlink calls go through the new FileSystem::File abstraction so that the implementation can later be swapped for a Windows specific one to support symlinks
2013-11-08(#19447) Puppet::FileSystem::File.exist?Ethan J. Brown1-4/+4
- All previous File and FileTest calls to exist? or exists? go through the new FileSystem::File abstraction so that the implementation can later be swapped for a Windows specific one to support symlinks
2013-11-08(#19447) Puppet::FileSystem::File#stat / lstatEthan J. Brown1-3/+3
- All calls to File class stat / lstat go through the new FileSystem::File abstraction so that the implementation can later be swapped for a Windows specific one to support symlinks
2013-09-06(maint) Windows failing spec fixesIristyle1-0/+1
- The usage of Dir.getwd in tests has been simplified to File.expand_path to properly handle mixed case CWD - util_spec.rb ensures 'FOO' Env var cleared before test starts - Windows SID checks should be performed as a regex match to properly handle all accounts starting with S-1-5-*, which denotes accounts with an identifier authority of SECURITY_NT_AUTHORITY instead of hardcoding S-1-5-32-544, the Administrators group
2013-06-25(#20607) support symbolic file mode in Puppet::Util#replace_fileBrice Figureau1-0/+16
In order to fix #20607 (where incorrect 'settings specified' file permissions were crashing P::U#replace_file), this patch enhance P::U#replace_file default_mode behavior. Now P::U#replace_file supports symbolic file mode, along with octal numerical string, and pure octal integers. It also now fails if the given mode is incorrect. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
2013-05-29(#20302) File.expand_file('~') fails differently in Ruby19Josh Cooper1-1/+4
In ruby 1.8, calling File.expand_path('~') when HOME is undefined would raise ArgumentError on both Unix and Windows. The same test in ruby 1.9 does not raise on Windows, because ruby also looks at HOMEDRIVE and USERPROFILE. Only if all three are undefined does ruby raise ArgumentError as expected. This commit ensures all 3 environment variables are undefined in util_spec. It also only tests the platform specific RunMode functionality on the appropriate platforms, and adds tests that were missing on the Windows side.
2013-04-11(Maint) Provide JUnit output for jenkinsAndrew Parker1-0/+3
Without JUnit style output we don't have a good way of seeing test failures within jenkins. This adds a new rake task ci:spec that will run with junit output, descriptive output and spec order logging. It turns out that some of the tests would call safe_posix_fork which ended up closing all open file handles. This ended up also closing the file handle that rspec would hold open for the junit output formatter. Those tests have been modified to ensure that the file descripters are not actually closed.
2013-03-20(#15791) isolate deterministic random functionPeter Meier1-0/+25
We should not fiddle with the global seed, as other people might still depend on Kernel.rand() not being that deterministic as it is the idea with the fqdn_rand function. However, as ruby < 1.9.2 does not provide such a nice solution, as a dedicated Random class we simply call Kernel.srand() again on ruby < 1.9.2 -> Reinitialize with a less deterministic seed.
2012-11-15(#17007) Restore pre-3.0 execute semantics when calling deprecated methodJosh Cooper1-0/+17
Previously, Puppet::Util.execute(command) had different semantics than Puppet::Util::Executor.execute(command) due to the `arguments` parameter defaulting to an empty hash. As a result, the former defaulted failonfail and combine to false, whereas the latter defaulted them to true. This commit changes the Puppet::Util.execute method to pass its arguments directly through. The only difference between the two is that the former issues a deprecation warning.
2012-09-10(#16027) Restore function context to backtracesDaniel Pittman1-0/+17
The changed implementation of `pretty_backtrace` was indeed prettier, but it also lost information: the function context was dropped from the trace. Since this is a debugging tool, and knowing the method tree is quite valuable to understanding a problem, this restores it - and any extra context that Ruby later decided it should add to the picture. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-07-13Eliminate `symbolize` everywhere, and remove it.Daniel Pittman1-8/+0
The whole `symbolize` API was confusing and complex: because it didn't do any type enforcement, just passed through arbitrary data, we had very unclear API in a whole pile of places. This replaces that method entirely with a more rigid definition: we intern in a bunch of places, add the occasional clear failure mode, and then delete the original definition. This eliminates one point of complexity from the codebase. (These other uses have no notable performance penalty, just code complexity and clarity issues.) Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-05-01Merge branch '2.7.x'Patrick Carlisle1-0/+11
* 2.7.x: Revert "Fix incorrect argument handling for expire in NodeExpirer" Fix #14123 for Windows Fix incorrect argument handling for expire in NodeExpirer Fix filebucket specs on Windows (#8778) Make '' == undef commutative in the DSL (#14173) Enforce that filebucket paths must be absolute (#14127) Add integration tests for ssh_authorized_key maint: refactor integration specs for ssh_authorized_key (#14127) ssh_authorized_keys grammer fails on blank lines. (#14123) Puppet shouldn't explode if PATH contains ~nonexistent_user Conflicts: lib/puppet/provider/ssh_authorized_key/parsed.rb lib/puppet/util.rb
2012-04-30Fix #14123 for WindowsPatrick Carlisle1-1/+1
Windows raised a different exception when a home directory doesn't exist, so we catch that too.
2012-04-23(#14123) Puppet shouldn't explode if PATH contains ~nonexistent_userDaniel Pittman1-0/+11
As reported in http://bugs.debian.org/669650, when the PATH contained an expansion for a user that doesn't exist, Puppet handled it the same way Ruby does - to raise an exception, and explode. Leaving aside the sanity of literal tilde in the PATH, we shouldn't explode in that case - we should just skip that entry and carry on to the next element in the path instead. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-04-18Use Win32 API atomic replace in `replace_file`Daniel Pittman1-6/+9
The changes to enable Windows support in `replace_file` were not actually complete, and it didn't work when the file didn't exist - because of limitations of the emulation done on our side, rather than anything else. Windows has a bunch of quirks, and Ruby doesn't actually abstract over the underlying platform a great deal. We can use the Windows API ReplaceFile, and MoveFileEx, to achieve the desired behaviour though. This adds even more conditional code inside the `replace_file` method to handle multiple platforms - but it really isn't very clean. Better to get this working now, then refactor, though. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-04-10Merge branch '2.7.x'Patrick Carlisle1-11/+45
* 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-04-09Merge pull request #611 from pcarlisle/ticket/2.7.x/12101-reapply-autoloadDaniel Pittman1-11/+11
Ticket/2.7.x/12101 reapply autoload
2012-04-09Merge pull request #620 from ↵Daniel Pittman1-9/+32
kelseyhightower/kelseyhightower/ticket/2.7.x/3581_fork_that (#3581) Stop forking around: Add fork helper method
2012-04-09Merge branch '2.7.x'Patrick Carlisle1-0/+20
* 2.7.x: (#9167) Do not send email when nothing changes [#13686] Fix directoryservices ShadowHashData code Fixup tests to work on CentOS 5 fix bug in Util#symbolizehash! (#13567) Fix create_resources name parameter bug (#13636) Update Module Face copyright date (#13737) Swap build_tree and format_tree method names (#9167) Do not send email when nothing changes Add Module Tool Make core changes needed for the puppet module tool (#13367) Patch SemVer to permit ranges including pre-release components. Monkey patch FileUtils.mv in Ruby 1.8.5 (#1076) Show warning if an empty group is specified Maint: Remove unused mock objects in user spec Maint: Use real objects in user spec Maint: Add a real provider class to user spec Maint: Remove unused variable in user spec Conflicts: lib/puppet/util/monkey_patches.rb spec/unit/type/resources_spec.rb spec/unit/type/user_spec.rb
2012-04-05fix bug in Util#symbolizehash!Chris Price1-0/+20
The method Puppet::Util.symbolizehash! was modifying a hash during iteration; this is (sanely, thankfully) not legal in ruby 1.9. This has been broken in our code for quite some time, but we hadn't noticed because nothing was calling this method. A recent commit introduced code that calls it, highlighting the bug, which is fixed by this commit.
2012-04-03(#3581) Stop forking around: Add fork helper methodKelsey Hightower1-9/+32
Without this patch we are forking all over the place. All this forking around is problematic when it comes to things like ActiveRecord and database connections. It turns out that forking has a nasty side effect of aggressively closing database connections and spewing errors all over the place. This patch introduces a new `Puppet::Util#safe_posix_fork` method that does forking the right way (closing file descriptors, and resetting stdin, stdout, and stderr). Tagmail, Puppet kick, and `Puppet::Util#execute_posix` have been updated to make use of this new functionality. In the future, `Puppet::Util#safe_posix_fork` should be used in-place of direct calls to `Kernel#fork`. This patch includes related spec tests.
2012-03-30Revert "Disable replace_file on Windows"Daniel Pittman1-81/+71
This reverts commit 4272d1f7674911c15da3ff6516d5827646a6bda6. To quote: Our current approach of setting owner/mode in the Puppet way risks losing any extra permissions beyond owner/group/everyone, which is significant enough that it is better to simply not support this operation until we have a better solution. replace_file isn't used in any code which actually runs on Windows at the moment, so this is a benign change. ...except that it isn't so benign as all that: various other parts of the code open-code the same method, poorly, and with various different bugs. They will all, without question, lose permissions in exactly the same way on Windows. At least by routing them through a central path we can start to unify their behaviour and get to a place where fixing one point in the code fixes all the faulty permission transfers that we previously had. We win an overall net reduction in bug count, and an increase in predictability of bugs, from this change.
2012-03-28(#12101) Add shared context for specs to imitate windows or posixPatrick Carlisle1-11/+11
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-23Merge branch '2.7.x'Patrick Carlisle1-0/+140
* 2.7.x: (63 commits) Maint: Fix bad copy and paste (#12725) Fix puppet agent --listen on Windows (#11740) Wait on the handle from the PROCESS_INFORMATION structure (#12564) Stub CHILDSTATUS in all test cases, not just failure cases. Updating CHANGELOG and lib/puppet.rb for 2.7.11 (#12412) Mark symbolic file modes test as pending on Windows Symbolic file mode test fixes when no mode change happens. Fix spec ordering failure on environment Updating CHANGELOG and lib/puppet.rb for 2.7.11 Disable specs that use replace_file on Windows Disable replace_file on Windows Remove unnecessary fallbacks in change_{user,group} Document uid/gid-related methods in Puppet::Util Copy owner/group in replace_file (#12463) eliminate `secure_open` in favour of `replace_file` (#12460) use `replace_file` for the .k5login file (#12462) user_role_add: use `replace_file` for /etc/shadow (#12463) add secure `replace_file` to Puppet::Util (#12459) drop supplementary groups when permanently dropping UID (#12458) default to users primary group, not root, in `asuser` ... Conflicts: lib/puppet/application/queue.rb lib/puppet/provider/package/openbsd.rb lib/puppet/util.rb spec/unit/network/http/webrick_spec.rb spec/unit/util_spec.rb test/lib/puppettest/servertest.rb
2012-02-23Merge tag '2.7.11' into 2.7.xNick Lewis1-0/+147
2012-02-21Merge pull request #520 from joshcooper/ticket/2.7.x/11740-handle-is-invalidJeff McCune1-30/+47
(#11740) Wait on the handle from the PROCESS_INFORMATION structure
2012-02-20(#11740) Wait on the handle from the PROCESS_INFORMATION structureJosh Cooper1-30/+47
Previously, the `Puppet::Util.execute` method was using `waitpid2` to wait for the child process to exit and retrieve its exit status. On Windows, this method (as implemented by the win32-process gem) opens a handle to the process with the given pid, and then calls `WaitForSingleObject` and `GetExitCodeProcess` on the process handle. However, the pid-to-handle lookup will raise an exception if the child process has exited. As a result there was a race condition whereby puppet could sometimes fail to retrieve the exit status of child processes. The normal way of getting the exit code for a child process on Windows is to use the child process handle contained in the `PROCESS_INFORMATION` structure returned by `CreateProcess`. This works regardless of whether the child process is currently executing or not. This commit reworks the `Puppet::Util.execute_windows` method to wait on the child process handle contained in the process information structure. This requires that we pass the `:close_handles => false` option to the win32-process gem so that it doesn't close the handles. This commit also re-enables tests that were previously being skipped due to this bug.
2012-02-20(#12564) Stub CHILDSTATUS in all test cases, not just failure cases.Daniel Pittman1-0/+2
On my machine, $CHILDSTATUS is always "success", so I didn't notice the failure to stub out the first couple of tests correctly. Now, with them stubbed, it is no longer possible that a previous test can leave global state dangling that will break their assumptions. Signed-off-by: Daniel Pittman <daniel@rimspace.net>
2012-02-20Disable replace_file on WindowsNick Lewis1-71/+81
Our current approach of setting owner/mode in the Puppet way risks losing any extra permissions beyond owner/group/everyone, which is significant enough that it is better to simply not support this operation until we have a better solution. replace_file isn't used in any code which actually runs on Windows at the moment, so this is a benign change.
2012-02-20(#12463) add secure `replace_file` to Puppet::UtilDaniel Pittman1-0/+116
There is some complex logic around replacing an existing file safely, and it used to be scattered all over the tree - making the whole system much harder to use nicely and pleasantly. It is much better that we provide a central, and easy to use, method for achieving that specific and common goal in a consistent, secure, and easy to audit fashion. Based on code submitted by me on 2010-04-08. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-02-13(#12564) Paste execpipe commands together with spaces.Daniel Pittman1-0/+33
Previously the `execpipe` method would create a command from an array by pasting the content together as strings. This was all well and good, but it required the caller to add whitespace manually when invoking the command. Instead, we can paste together with a space character - leading to a better external experience, and less repetitious code. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-02-09(#12490) fixing windows spec testscprice1-2/+4
This should fix the failures in exec_spec.rb and util_spec.rb. Has been tested on Win2k3.
2012-02-07(#12336) Util::'which' may fail if user's path contains a tildecprice1-0/+7
In certain circumstances (user's HOME environment variable is not set, or has been unset during ruby execution, plus PATH contains a literal ~ character), Util::w hich would raise an ArgumentError. Handle this error by logging a warning (one time only) and ignoring this element of the PATH.
2012-02-02(#12309) move execution-related methods from Util to Util::ExecutionChris Price1-439/+42
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-12/+12
2012-01-30Merge pull request #418 from ↵Daniel Pittman1-0/+57
cprice-puppet/bug/master/5224-user-env-vars-during-Exec (#5224) Unset USER-related env vars during execs
2012-01-29Merge remote-tracking branch 'origin/2.7.x'Daniel Pittman1-15/+0
Conflicts: spec/unit/daemon_spec.rb Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-01-27(#5224) Unset USER-related env vars during execsChris Price1-0/+57
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-3/+3
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) Minor cleanup as per pull request commentsChris Price1-2/+6
(#11860) Minor cleanup as per pull request comments (#11860) Minor cleanup as per pull request comments (#11860) Minor cleanup as per pull request comments (#11860) Minor cleanup as per pull request comments (#11860) Minor cleanup as per pull request comments (#11860) Minor cleanup as per pull request comments (#11860) Minor cleanup as per pull request comments (#11860) Minor cleanup as per pull request comments
2012-01-25(#11860) Add parameter to control locale overrideChris Price1-4/+88
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-11/+11
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-11/+11
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-01-23(#11955) Refactor to use IO.binreadJosh Cooper1-15/+0
Previously, I had created a utility method `Puppet::Util.binread`, since `IO.binread` was added in ruby 1.9. This commit monkey patches the method, if it's not defined, to make the transition to ruby 1.9 seamless. And while I was at it, I add the corresponding `IO.binwrite` method. The motivation for these methods is that, in general, we should always be using binary mode when performing file I/O. However, text mode is the default on Windows, and using text mode can corrupt binary data, e.g. executables. So use binary mode, unless you know what text mode is and why you need to use it. Conflicts: spec/unit/file_serving/content_spec.rb
2011-11-01(#9983) Add method for reading binary filesJosh Cooper1-0/+17
The method IO#binread is not available prior to ruby 1.9, so this commit adds a method Puppet::Util.binread that does just that.
2011-10-13Merge remote-tracking branch ↵Jacob Helwig1-1/+4
'josh/ticket/2.7.x/9636-onlyif-unless-windows-exec' into 2.7.x * josh/ticket/2.7.x/9636-onlyif-unless-windows-exec: Maint: Remove duplicate path extension code (#9636) Always set $CHILD_STATUS when executing on Windows (#9636) Fix PATHEXT resolution for paths other than system32
2011-10-12(#9636) Fix PATHEXT resolution for paths other than system32Josh Cooper1-1/+4
Previously, Puppet::Util.which could only resolve executables that were located in the first PATH directory entry, typically c:\windows\system32. This was introduced in 0258096c4 due to the inner loop overwriting the 'bin' variable that was used in the outer loop. And it wasn't noticed during testing, because I was always using executables from c:\windows\system32, e.g. cmd.exe. This commit changes that the inner loop to use a different variable so as to not clobber the 'bin' variable. It also updates the spec test.
2011-10-12(#9996) Restore functionality for multi-line commands in exec resourcesJacob Helwig1-0/+6
Originally we were relying on the behavior that Array.new would call #to_a on its argument, which is a no-op if the object is already an array. When #to_a is called on a string, it does not always return [original_string]. Because string.to_a is effectively equivalent to string.each_line.to_a (at least in Ruby 1.8.7) we were breaking commands with embedded newlines. Manually wrapping the passed in command in an array, and calling #flatten is much safer since it will not "helpfully" split up the command string for us.
2011-10-06(#9461) Resolve executables using PATHEXT on WindowsJosh Cooper1-0/+95
Previously, 'puppet resource package' fails on Windows when attempting to invoke the 'gem' executable, because on Windows, 'gem' is a ruby script which must be executed by calling the batch wrapper, 'gem.bat'. This commit modifies Puppet::Util.which such that if a non-absolute path is given, then for each directory in PATH, and each extension in PATHEXT, it returns the first file that exists and is executable. If the PATHEXT environment variable is not defined, then it defaults to the same values that cmd.exe uses and are known to work across all Windows versions.