summaryrefslogtreecommitdiff
path: root/spec/unit/util/windows/string_spec.rb
AgeCommit message (Collapse)AuthorFilesLines
2014-05-22(PUP-836) FFI Puppet::Util::Windows::UserEthan J. Brown1-0/+4
- LogonUserW, LoadUserProfile, UnloadUserProfile and PROFILEINFO have been converted from manually packing params with Win32API.new to automatically managed with FFI definitions. - Use MemoryPointer where appropriate. - Note that wide character LogonUserW is used rather than platform varying LogonUser as FFI is unable to use that. The pointer widths of PROFILEINFO vary depending on platform, which is handled by using :pointer. With LogonUserW the string pointed to is always wide character, which is properly handled by using wide_string. - Add FFI::MemoryPointer helper read_handle - Add FFI::MemoryPointer.from_wide_string and corresponding tests that ensure that a properly terminated UTF-16LE string is passed in - Add FFI::MemoryPointer#read_wide_string that reads a wide string buffer into a Ruby string with Encoding.default_external and corresponding tests - Add additional tests around User methods that make native Win32 API calls that will intentionally fail - Fix wide_string helper to return nil when given nil so that can be passed directly to Win32 as a null pointer
2014-01-17(PUP-1389) Embed the extra NULL within the stringJosh Cooper1-30/+14
Previously, we were appending a NULL to the wide encoded string to work around a ruby bug fixed in 2.1. However, we were calling `String#strip`, which makes a copy of the string, and in the process only preserves the first NULL. This commit embeds a NULL within the string itself, e.g. "bob\0". Since the NULL is part of the string data, ruby will preserve it. Also, `String#+` cannot combine strings with different encodings, e.g. "a".encode('UTF-16LE') + "\0" results in: incompatible character encodings: UTF-16LE and US-ASCII which is why we need to encode the terminator. The actual message depends on the default encoding, e.g. US-ASCII, UTF-8.
2014-01-14(PUP-1389) ReplaceFile to FFI / move wide_stringRob Reynolds1-0/+70
Puppet::Util::Windows::File.replace_file now calls FFI to replace files in place on Windows. Puppet::Util::Windows::File.wide_string has now been moved to Puppet::Util::Windows::String.wide_string. This moves wide_string to lib/puppet/ubilt/windows/string.rb, adds specs concerning different encodings. In addition, we've removed Windows::API::WideString usages from everywhere it was found as it is known to cause issues with Windows 2012. Puppet::Util::Windows::Process.lookup_privilege_value in particular was changed to use LookupPrivilegeValueA (ANSI) as we control the privilege name being passed to it. Paired with Josh Cooper <josh@puppetlabs.com>