PUP-1494 - Remove Windows iconv from colors.rb

  - We no longer support / ship Ruby 1.8 on Windows, so iconv support
    is not necessary
(maint) Puppet fails to properly surface backtraces

 - In many cases, exceptions are handled with Ruby and rethrown in
   a manner that loses the original exceptions backtrace. This often
   masks the real backtrace associated with an error, and can be the
   source of misleading errors or fishing expeditions.
 - Where appropriate, pass along the backtrace, or use the initializer
   of the raised Error to wrap / extract the backtrace from the existing
   exception.
 - Puppet::Util::Windows::Error is given a new initializer that allows
   passing in the original Exception
 - Puppet::Util::Errors.fail adds a new overload that allows for the
   original Exception to be passed in
 - To summarize, calls structured like this preserve backtraces:
   rescue ArgumentError => e
     raise
     raise e, e.message, e.backtrace
     raise e
   rescue
     raise
     raise $!
     raise $!, "bad arg yo -- part 2", $!.backtrace
     raise $!, $!.message, $!.backtrace
     raise Puppet::Error.new("new msg / ex type", detail)
 - To summarize, calls structured like this will eat backtraces:
   rescue
     raise $!, "Just smoked the backtrace on existing exception"
     raise "Just smoked the backtrace and changed to RuntimeError"
     raise RuntimeError.new($!)
Adds support for building puppet on RHEL7 via spec.
Add initial support for building in a RHEL 7 mock

Building in an x86_64 mock, since RHEL has not provided a 32-bit release.
(PUP-1278) Windows Puppet Agent Service gracefully terminates after succesfully being put into a Paused state

Removed redundant return statement
Added in logic to only start the Puppet Agent if the service is in a Running or Idle state
PUP-1494 Guard against Win32 memory corruption

 - Ruby's .encode(UTF-16LE) call on String may generate a string that
   not properly terminated with 2 NULLs, which may result in garbage
   bytes read from the memory pointer passed into the Win32 API. This
   can cause memory instability which results in failures in later
   Win32 calls.  These calls have been replaced with an internal
   helper that properly NULl terminates the string.  Note that this
   bug is fixed in Ruby 2.1:
   http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?revision=41920&view=revision
 - Don't include the wide NULL character when calculating number of
   characters to write to the console to properly indent Puppets stdout
   output (without the -1 calculation, it's indented with two spaces).
 - Includes a test to ensure that we can detect when `string_encode` is
   updated in the future, when we move to a version of Ruby where the
   String#encode bug is fixed for encodings with multi-byte terminators

Paired-with Josh Cooper <josh@puppetlabs.com>
(maint) Don't duplicate hash keys in rspec tests

RSpec examples can be restricted by using `:if`: and `:unless` values in
the example metadata. However these are hash keys, and defining two
`:if` statements will cause the latter definition to overwrite the
first. This commit resolves this issue by defining a single expression
evaluated by `:if` instead of having two separate clauses.
Merge branch 'maint/windows/rspec-duplicate-key'
Merge pull request #2293 from Iristyle/maint/master/properly-return-backtraces

(maint) Puppet fails to properly surface backtraces
Merge branch 'ticket/master/PUP-1494/remove-native-ruby-encode-UTF-16-windows'

* ticket/master/PUP-1494/remove-native-ruby-encode-UTF-16-windows:
  PUP-1494 Guard against Win32 memory corruption
  PUP-1494 - Remove Windows iconv from colors.rb
(maint) Fix another broken rspec restriction
Merge pull request #2303 from kylog/maint/fix-rspec-key

(maint) Fix another broken rspec restriction
Revert "Merge branch 'pull-2137'"

This reverts commit a20b16bb70446d43c51340f72c821fc3a93c7cb6, reversing
changes made to 00579976264da4b2b8492bb664291b9ba0d5987c.

Unfortunately this change introduced a number of problems that need to
be addressed before this code can be released.

1) The yum provider is always holdable

The package type detects the ability to hold packages based on the
presence of the #hold method. Even though there is a guarding clause
around the `has_feature :holdable` in the provider it's bypassed when it
fails since the provider defines the #hold method.

This ties into:

2) Holding a package without the yum-plugin-versionlock raises errors

Since the plugin isn't available but the provider looks like it's
holdable, applying a resource like:

    package { 'bash':
      ensure => held,
    }

results in a backtrace since `yum versionlock` returns 1, and a
Puppet::ExecutionFailure is raised.

3) Held packages are not idempotent

When the yum versionlock plugin is installed, the resulting resource is
not idempotent because the ensure value is always being changed from
$version to 'held':

    [root@localhost puppet]# puppet resource package bash ensure=held
    Notice: /Package[bash]/ensure: ensure changed '4.1.2-15.el6_4' to 'held'
    package { 'bash':
      ensure => '4.1.2-15.el6_4',
    }
    [root@localhost puppet]# puppet resource package bash ensure=held
    Notice: /Package[bash]/ensure: ensure changed '4.1.2-15.el6_4' to 'held'
    package { 'bash':
      ensure => '4.1.2-15.el6_4',
    }
(maint) Adding .ruby-version and .ruby-gemset to .gitignore for RVM users.
(maint) Fix acceptance test failure caused by backtrace preservation
change (GH-2293).
We should not be accessing the exception object from the else clause of
the begin/rescue/else.
(PUP-1411) Initialize OpenSSL before starting TCP connection

Ruby's Net::HTTP#connect method makes a TCP connection before it creates
the OpenSSL::SSL::SSLContext and invokes the SSLSocket#connect method:

    def connect
      s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }
      if use_ssl?
        ...
        @ssl_context = OpenSSL::SSL::SSLContext.new
        s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
        ...
      end
      ...
      timeout(@open_timeout) { s.connect }

Between the time that the TCP connection is established (TCPSocket.open)
and when the client starts the SSL handshake (SSLSocket#connect), the server
must hold the TCP connection open[1].

The first time this code path is taken on the client, the call to
SSLContext.new causes the openssl library to be initialized. This can
take a non-trivial amount of time and is highly platform dependent, e.g.
openssl will initialize the cryptographically strong pseudo-random
number generator. On Windows, this typically calls CryptGenRandom among
other things.

In our CI environment, we are seeing this call take upwards of 7
seconds on Windows agents. If the agent connects to a webrick
puppetmaster, then the server will only hold the connection open for 6.2
seconds. See redmine #4762 and commit 711344836. This can lead to the
puppetmaster closing the connection, to protect against DoS attacks.

This commit ensures that we initialize the openssl library prior to
establishing the TCP connection. This reduces the amount of time the
server needs to wait for the client to send the CLIENT_HELLO message and
decreases the likelihood that the server will timeout the connection
unnecessarily.

[1] https://bugs.ruby-lang.org/issues/9459
(PUP-1411) Increase CLIENT_HELLO timeout

Previously, if a client established a TCP connection to the webrick server,
but the server did not receive any data within 6.2 seconds, the server
would close the connection, and report that the client disconnected.

The error message is actually misleading, because if the client did
actively disconnect, e.g. sent FIN or RST, then IO.select would report that the
socket is ready and timeout would not be reached.

This commit increases the timeout to 10 seconds and updates the error
message to more clearly say that the client did not send any data
before the timeout expired.

Note that we perform this check, because OpenSSL's SSL_accept will block
indefinitely, since the underlying socket is blocking by default.
Merge pull request #2305 from joshcooper/issue/stable/PUP-1411-SSL_connect_timeout

(PUP-1411) Protect against SSL_connect errors
(PUP-1118) Add acceptance test for using directory envs

This checks that an environment that comes from the environmentdir
setting is usable as an environment.
(PUP-1118) Stop using Environment.new

Instead of creating environments directly, we need to go through the
configured environment loaders, otherwise environments can't come from
other places.