Sha256: 3150cb59fbc4222622cbb142f88f5519a7d4b099df477919c1ae9991a7e6811e

Contents?: true

Size: 1.46 KB

Versions: 234

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

require 'puppet/network/http'

describe Puppet::Network::HTTP::API::Master::V3::Authorization do
  HTTP = Puppet::Network::HTTP

  let(:response) { HTTP::MemoryResponse.new }
  let(:authz) { HTTP::API::Master::V3::Authorization.new }
  let(:noop_handler) {
    lambda do |request, response|
    end
  }

  it "accepts v3 api requests that match allowed authconfig entries" do
    request = HTTP::Request.from_hash({
      :path => "/v3/environments",
      :method => "GET",
      :params => { :authenticated => true, :node => "testing", :ip => "127.0.0.1" }
    })

    authz.stubs(:authconfig).returns(Puppet::Network::AuthConfigParser.new(<<-AUTH).parse)
path /v3/environments
method find
allow *
    AUTH

    handler = authz.wrap do
      noop_handler
    end

    expect do
      handler.call(request, response)
    end.to_not raise_error
  end

  it "rejects v3 api requests that are disallowed by authconfig entries" do
    request = HTTP::Request.from_hash({
      :path => "/v3/environments",
      :method => "GET",
      :params => { :authenticated => true, :node => "testing", :ip => "127.0.0.1" }
    })

    authz.stubs(:authconfig).returns(Puppet::Network::AuthConfigParser.new(<<-AUTH).parse)
path /v3/environments
method find
auth any
deny testing
    AUTH

    handler = authz.wrap do
      noop_handler
    end

    expect do
      handler.call(request, response)
    end.to raise_error(HTTP::Error::HTTPNotAuthorizedError, /Forbidden request/)
  end
end

Version data entries

234 entries across 234 versions & 1 rubygems

Version Path
puppet-5.3.4 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.4-x86-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.4-x64-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.4-universal-darwin spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-4.10.10 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-4.10.10-x86-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-4.10.10-x64-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-4.10.10-universal-darwin spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-4.10.9 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-4.10.9-x86-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-4.10.9-x64-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-4.10.9-universal-darwin spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.3 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.3-x86-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.3-x64-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.3-universal-darwin spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.2 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.2-x86-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.2-x64-mingw32 spec/unit/network/http/api/master/v3/authorization_spec.rb
puppet-5.3.2-universal-darwin spec/unit/network/http/api/master/v3/authorization_spec.rb