Sha256: e3c01e356dabb16c56fb0d49136b599047711b643e3bb6cac48e1aece8842567

Contents?: true

Size: 1.73 KB

Versions: 12

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'
require 'puppet/forge'
require 'puppet_spec/https'

describe Puppet::Forge, unless: Puppet::Util::Platform.jruby? do
  include PuppetSpec::Files

  before :all do
    WebMock.disable!
  end

  after :all do
    WebMock.enable!
  end

  before :each do
    # make sure we don't take too long
    Puppet[:http_connect_timeout] = '5s'
  end

  let(:hostname) { '127.0.0.1' }
  let(:wrong_hostname) { 'localhost' }
  let(:server) { PuppetSpec::HTTPSServer.new }
  let(:ssl_provider) { Puppet::SSL::SSLProvider.new }

  let(:http_response) do
    File.read(fixtures('unit/forge/bacula.json'))
  end

  let(:release_response) do
    releases = JSON.parse(http_response)
    releases['results'] = []
    JSON.dump(releases)
  end

  it 'fetching module release entries' do
    # create a temp cacert bundle
    ssl_file = tmpfile('systemstore')
    File.write(ssl_file, server.ca_cert)

    # override path to system cacert bundle, this must be done before
    # the SSLContext is created and the call to X509::Store.set_default_paths
    Puppet::Util.withenv("SSL_CERT_FILE" => ssl_file) do
      response_proc = -> res {
        res.status = 200
        res.body = release_response
      }

      server.start_server(response_proc: response_proc) do |port|
        forge = described_class.new("https://127.0.0.1:#{port}")
        forge.fetch('bacula')
      end
    end
  end

  it 'returns a valid exception when there is an SSL verification problem' do
    server.start_server do |port|
      forge = described_class.new("https://#{wrong_hostname}:#{port}")
      expect {
        forge.fetch('mymodule')
      }.to raise_error Puppet::Forge::Errors::SSLVerifyError, %r{^Unable to verify the SSL certificate at https://#{wrong_hostname}}
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
puppet-6.14.0 spec/integration/module_tool/forge_spec.rb
puppet-6.14.0-x86-mingw32 spec/integration/module_tool/forge_spec.rb
puppet-6.14.0-x64-mingw32 spec/integration/module_tool/forge_spec.rb
puppet-6.14.0-universal-darwin spec/integration/module_tool/forge_spec.rb
puppet-6.13.0 spec/integration/module_tool/forge_spec.rb
puppet-6.13.0-x86-mingw32 spec/integration/module_tool/forge_spec.rb
puppet-6.13.0-x64-mingw32 spec/integration/module_tool/forge_spec.rb
puppet-6.13.0-universal-darwin spec/integration/module_tool/forge_spec.rb
puppet-6.12.0 spec/integration/module_tool/forge_spec.rb
puppet-6.12.0-x86-mingw32 spec/integration/module_tool/forge_spec.rb
puppet-6.12.0-x64-mingw32 spec/integration/module_tool/forge_spec.rb
puppet-6.12.0-universal-darwin spec/integration/module_tool/forge_spec.rb