summaryrefslogtreecommitdiff
path: root/spec/unit/util
AgeCommit message (Collapse)AuthorFilesLines
2014-01-06(PUP-716) Fix up all of utilAndrew Parker10-72/+67
2014-01-06(PUP-716) Fix up watcher specAndrew Parker1-4/+1
2014-01-06(PUP-716) Fix up YAML specsAndrew Parker1-2/+2
2013-12-27(maint) Require json for logstash testAndrew Parker1-0/+1
Removal of the hiera2 bindings code exposed the fact that the test for logstash logging doesn't require JSON even though it uses it. This adds a line to require JSON so that it is available when the test runs.
2013-12-20(PUP-1133) Windows tests write config to tempEthan J. Brown1-1/+3
- Previously tests were writing to the shared %ALLUSERSPROFILE%\PuppetLabs\puppet directory, and would blow up if this directory did not exist - Because this directory was shared from one run to the next, failing tests could be masked by data generated / used by a locally installed Puppet - The stubbing of FileSystem::File.exist? to return true was causing some tests to treat files like c:\dev\null\foo to attempt to be loaded, which would cause these tests to fail in isolation, but not when run within the suite - Had to change some doc specs under Ruby 1.9 / OSX to verify a value instead of asserting a method was called, to prevent a stack overflow - In some unit tests, the process of reading / writing settings caused issues with test loading, so Puppet.settings.use has been stubbed
2013-12-12(#23373) Pull apart settings into a few more classesAndrew Parker1-2/+10
The monolithic settings infrastructure is really hard to work with. In order to implement the functionality for puppet config print to reliably be able to print the value of any given section of the configuration I need to be able to split it apart from the very static structure that exists inside puppet. This takes a step in that direction by starting the process of extracting the lookup logic into smaller classes.
2013-12-06Merge branch 'stable'Adrien Thebo1-0/+14
2013-12-06(#23369) Allow caller to override YAML.load_file returning falseJosh Cooper1-0/+14
According to https://github.com/tenderlove/psych/issues/149, Syck and Psych return false when ::YAML.load_file tries to parse an empty file. Since Puppet::Indirector::Yaml#find calls Puppet::Util::Yaml.load_file directly, we can't change the semantics of what it returns. Instead we allow the caller to explicitly specify what the default value should be.
2013-12-04Merge pull request #2097 from adrienthebo/maint-empty-lockfileKylo Ginsberg1-4/+25
(maint) Handle empty or malformed JSON lockfiles
2013-11-26(#11563) Create an explicit ace if the old ace is inheritedJosh Cooper1-0/+22
Given a directory owned by Administrators and group None, and with DACL: NT AUTHORITY\SYSTEM:(I)(OI)(CI) 0x1f01ff BUILTIN\Administrators:(I)(OI)(CI) 0x1f01ff WIN-QP47VOHA2P4\albert:(I)(OI)(CI) 0x1f01ff where the ACE for the owner is inherited (I). If puppet changed the owner to Users, it would copy all of the inherited ACEs as-is. But the new owner would not have any privileges, even though the old owner did. The same is true for group. This commit ensures that if we see an inherited ACE for the old owner, that we prepend a new explicit ACE, whose type (allow or deny), flags and mask grant/deny the same access as the inherited ACE did. Note that not all flags are valid when setting an ACE, e.g. INHERITED_ACE is only something you can read, not set. As a result of this change, when puppet changes the owner from Administrators to Users the dacl will have the following ACE prepended to the list, with the existing inherited ACEs copied as-is: BUILTIN\Users:(OI)(CI) 0x1f01ff Note that the new ACE has the same mask as the old one, and has the object and container inherit flags set.
2013-11-26(#11563) Model Windows security descriptorsJosh Cooper3-0/+295
Creates objects for modeling windows security descriptors, access control lists, and access control entries.
2013-11-20(#23236) Deprecate Puppet::Util::SUIDManager.run_and_captureRob Reynolds1-26/+33
This deprecates run_and_capture from SUIDManager for Puppet::Util::Execution.execute(). Run and capture is returning $CHILDSTATUS where execute returns an exit status as part of output. This means that run and capture could have potential issues when being used, especially with Windows which is known to have issues due to the truncation of exit codes greater than 256.
2013-11-20(maint) Handle empty or malformed JSON lockfilesAdrien Thebo1-4/+25
If a JSON lockfile was empty or had malformed JSON, it would raise a PSON::ParserError and could lead to application failures with an unclear cause. This commit changes the JSON lockfile behavior to treat empty or malformed file contents to be nil and generate warnings when the file contents are malformed JSON.
2013-11-15Merge branch 'stable'Kylo Ginsberg1-8/+10
2013-11-15(#23183) Use FFI to manage pointers in RootCerts moduleJosh Cooper1-8/+10
Previously, we made assumptions about the layout of the CERT_CONTEXT structure, specifically that PCERT_INFO (pointer to CERT_CONTEXT) was an unsigned 32-bit integer ('L'), and magically accessed the size of the returned structure as arr[2]. We were also memcpy 40-bytes which was larger than the size of the CERT_CONTEXT structure in both x86 and x64 and was the cause of infrequent segmentation faults. This commit uses FFI to define the layout of the CERT_CONTEXT structure, uses named fields, e.g. [:cbCertEncoded], to access offsets within the structure, and uses the FFI::Pointer#null? method to check for NULL pointer. Note that we use FFI::Pointer and not MemoryPointer, because the CertEnumCertificatesInStore function is responsible for freeing the previous CERT_CONTEXT pointer, not us. Also in the motto of "don't stub what you don't own" it exercises the Win32 APIs to make the tests more meaningful.
2013-11-14(#23124) Move ProcessOutput to Puppet::Util::ExecutionAndrew Parker1-9/+8
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 Reynolds2-27/+38
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 Reynolds2-11/+28
Conflicts: lib/puppet/provider/package/windows.rb
2013-11-14Revert "(#23124) Merge branch 'ticket/stable/23124-exit_codes_on_windows' ↵Rob Reynolds2-11/+28
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 Reynolds2-28/+11
Conflicts: lib/puppet/provider/package/windows.rb
2013-11-14(#23124) Move ProcessOutput to Puppet::Util::ExecutionAndrew Parker1-9/+8
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(Maint) Remove commented out testsAndrew Parker1-27/+0
The run_and_capture method was removed, so the tests aren't needed anymore.
2013-11-14(#23124) Fix: Incorrect Exit Codes from Windows ExecRob Reynolds2-27/+38
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-13Merge branch 'ticket/master/19447-windows-symlinks-unlink-abstraction'Josh Cooper2-4/+4
* ticket/master/19447-windows-symlinks-unlink-abstraction: (#19447) Puppet::FileSystem::File.unlink Closes GH-2063
2013-11-13Merge pull request #1916 from ↵Andrew Parker1-0/+41
joshcooper/ticket/master/21817-ignore-duplicate-certs (#21817) Ignore duplicate certs
2013-11-13(#19447) Puppet::FileSystem::File.unlinkEthan J. Brown2-4/+4
- 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. Brown8-47/+47
- 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. Brown5-12/+28
- 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-11-04Merge remote-tracking branch 'upstream/stable'Josh Partlow1-2/+2
* upstream/stable: (maint) Fix acceptance harness and tests for windows vcloud templates (#22878) Scope call to CloseHandle
2013-10-31Merge pull request #1922 from joshcooper/ticket/master/21241-priorityJosh Partlow1-0/+41
(#21241) Allow process priority to be specified
2013-10-30(#22878) Scope call to CloseHandleBrandon Wulf1-2/+2
Previously, the win32-process gem used to extend Windows::Handle from the windows-pr gem, so that the Process.CloseHandle method was available. However, newer versions of the win32-process gem that are based on ffi, do not extend Windows::Handle, so the Process.CloseHandle method is not defined. This commit modifies puppet to call a version of CloseHandle which we control, and therefore is guaranteed to exist.
2013-10-30Merge pull request #2008 from pcarlisle/performance/taggingAndrew Parker2-45/+128
improve tag performance
2013-10-25Merge pull request #2009 from ↵Henrik Lindberg2-36/+30
jpartlow/issue/master/22180-fix-rdoc-parsing-on-ruby-1.9 Issue/master/22180 fix rdoc parsing on ruby 1.9
2013-10-25(#22180) Recapture class comments under Ruby 2.0 RDocJosh Partlow1-5/+5
RDoc 2+ has an RDoc::ClassModule.add_comment(comment,location) method which is the preferred method of setting comments for a class. RDoc shipping with Ruby 1.9 seems to fall back to using the @comment, which is how rdoc1 handled this, but Ruby 2.0's rdoc seems to be stricter and requires use of add_comment. This patch overrides the add_comment method in our PuppetModule, PuppetClass, PuppetNode code objects with a version compatible with either rdoc1 or 2. It also tests for module level README comments being incorporated.
2013-10-24(#22180) Fix broken rdoc1 featuresJosh Partlow2-31/+25
There were a number of rdoc1 features (tracking of included, required modules, realized virtual resources, all resources when :document_all setting is true, and global variables) which had not been functioning due to the parser wrapping statements in Puppet::Parser::AST::BlockExpression instances now rather than Puppet::Parser::AST::Array instances. This is now fixed so that these areas are documented when using rdoc1. Only included classes is documented in rdoc2, however. Documenting the remaining elements would require writing a new renderer.
2013-10-23(#22956) Remove temporary TagSet#== implementationPatrick Carlisle2-12/+0
2013-10-23(#22956) Use a set to store tagsPatrick Carlisle2-42/+137
Tags were being stored in an array, which is inefficient as the number of tags grows. This commit changes Puppet::Util::Tagging to store tags in a set. A new class is added, Puppet::Util::TagSet, which subclasses the built in set while allowing it to be compatible with the old serialization format.
2013-10-14Merge branch 'stable'Josh Partlow1-2/+2
* stable: (240 commits) (#22847) Restrict WMI group / user queries (maint) Explicit vcloud paths for pe nodes (#22324) Disable puppet listen on master/agent nodes (docs) Clarify Windows' handling of primary groups (maint) Coppy in the node configurations and pre-suite for pe test runs (maint) Remove stale vagrant support (#22324) Confine external_ca_support test not to run on PE (#22324) Loosen the host regex for package apply test on debian (maint) Fix default secs for destroy preserved hosts task (maint) Default xml output for beaker runs. (maint) Remove typo '3' in module_utils (maint) Check jenkins queueItem as well for a pending job (#22324) Puppet cert generate tests do not clear master ssl dir (#22324) Reports submission test checks puppetdb on pe runs (#22810) Fix rpm provider query method (#22804) Check for encoding support more robustly (#22324) Determine user/group from puppet configuration (#22324) Confine puppet manages own configuration test not to run on pe (#22324) Remove redundant without_installed_modules test (#22324) Fix modules/install/already_installed tests for pe ... Conflicts: acceptance/tests/databinding/hiera/auto_lookup_for_class_parameters.rb acceptance/tests/databinding/hiera/bind_data_with_puppet_backend.rb Resolved in favor of master having removed these tests in 75ab42.
2013-10-11(#22847) Restrict WMI group / user queriesEthan J. Brown1-2/+2
- Querying win32_useraccount or win32_group on a domain can yield a large request to AD for user / group objects, that may number in the tens of thousands in large organizations - This can cause a lot of stress on AD and the network to retrieve all of these results, which are ultimately unused in the existing code anyhow - The solution involves simply restricting the queries to the local machine
2013-10-09Merge branch 'ticket/master/17031-windows-group-provider'Josh Cooper2-12/+189
* ticket/master/17031-windows-group-provider: (#17031) Prefer the domain component from the resolved SID (#17031) Use SIDs to modify ADSI group membership (#17031) Puppet::Util::ADSI.sid_uri (#17031) group type #insync? #is_to_s #should_to_s (#17031) Parse ADSI usernames -> domain / account (#17031) Add SID.name_to_sid_object (#17031) Add SID.octet_string_to_sid_object (maint) .gitignore add .idea
2013-10-09(#17031) Use SIDs to modify ADSI group membershipEthan J. Brown1-17/+80
- New #add_member_sid / #remove_member_sid methods do the heavy lifting inside of Puppet::Util::ADSI::User to add / remove group members instead of relying on string names - Expose a new Puppet::Util::ADSI::User#sid method that returns a Win32::Security::SID instance with account, domain, and raw SID - Puppet::Util::ADSI::User#uri method now uses the #sid account and domain to build a URI - Since #uri now relies on #sid, which converts the binary value from the #native_user.objectSID byte array, the @native_user is initially populated by generating a throwaway uri built by parsing @name. This prevents a circular reference. This effectively means the original given @name is parsed and given to ADSI.connect, and on connect, the raw SID generates a SID object. Alternatively, a SID could have been generated by Win32::Security::SID first, its domain and account values then used to retrieve @native_user. Original semantics around @native_user were kept intact to prevent breaking existing callers. In practice, this should have no effect. - Due to dependence on Windows::Security, some tests are now run only on Windows. This was a trade off where it would have been possible to add an initializer param for @sid to Puppet::Util::ADSI::User, but it seemed cleaner not to
2013-10-09(#17031) Puppet::Util::ADSI.sid_uriEthan J. Brown1-0/+15
- Allow for creation of WinNT://<SID> style uris
2013-10-09(#17031) Parse ADSI usernames -> domain / accountEthan J. Brown1-0/+30
- User names were previously naively accepted without checking if they were qualified with a host or domain
2013-10-09(#17031) Add SID.name_to_sid_objectEthan J. Brown1-0/+30
- Simple wrapper around creating new SID instances - Used to insulate tests from Win32::Security - Existing name_to_sid now delegates to this method
2013-10-03(maint) Refactor Puppet::Util::Docs.scrubNick Fagerlund1-0/+91
It was hard to understand what this method was doing, and once I got it, I noticed it wasn't quite doing what it claimed. (It was cheating -- grabbing the indent of the second line with text and assuming that was the least common indent. This meant you could break it by starting a doc fragment with a line of text, two newlines, and an indented block of example code.) This commit replaces it with something more clear and correct, as well as some comments explaining what we expect it to do. We also trim trailing whitespace, while we're at it; this costs some speed, but should make it even more reliable/useful. We also add tests for scrub in this commit, at spec/unit/util/docs_spec.rb.
2013-10-02(#17031) Add SID.octet_string_to_sid_objectEthan J. Brown1-0/+39
- This will allow a WIN32OLE instance returned by the connect method to convert its objectSID property (an octet stream / array of bytes) to a standard user friendly SID object
2013-09-30(#22662) create a logstash_event loggerrenato arruda1-0/+32
This pull request implements logdest for puppet runs as using a structured log format for logstash (json, eventlog, schema can be found at https://logstash.jira.com/browse/LOGSTASH-675 ).
2013-09-20(#21241) Set process priority if one is specifiedJosh Cooper1-0/+41
This commit adds a Puppet::Util::Limits module for specifying process priority, and mixes the module into Puppet::Util::CommandLine. Since the CommandLine is the application entry point for puppet it seemed sensible to have it set the process priority there, and to have it done as early as possible. Another option would have been to set the priority in the base Application, after the application-specific settings have been initialized. But this would mean you couldn't set the process priority when puppet executes an ExternalSubcommand-based application. As it stands now, it's not possible to have different priorities for different sections, e.g. agent vs master, in puppet's configuration file.
2013-09-18(#21817) Ignore duplicate certsJosh Cooper1-0/+41
Previously, SSL connections initiated by the puppet agent on windows, e.g puppet module install, would cause the agent to terminate if the 'Root' store on Windows contained duplicate certificates. This commit ensures that we only add unique certificates to the X509 store. Also, if we fail to add a certificate to the store, we issue a warning and continue.
2013-09-17Merge remote-tracking branch 'upstream/stable'Josh Cooper1-39/+21
* upstream/stable: (Maint) Stop asserting nothingness (Maint) Don't keep Tempfile open while specs are running (Maint) TestHelper already clears global state