Sha256: 2db01d4ab837276f4d70afa75f0c21ecfe18114d59347cb2212dcabd891875e2

Contents?: true

Size: 1.47 KB

Versions: 57

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

require 'puppet/network/http'

describe Puppet::Network::HTTP::API::V2::Authorization do
  HTTP = Puppet::Network::HTTP

  let(:response) { HTTP::MemoryResponse.new }
  let(:authz) { HTTP::API::V2::Authorization.new }

  it "only authorizes GET requests" do
    request = HTTP::Request.from_hash({
      :method => "POST"
    })

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

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

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

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

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

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

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

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
puppet-3.8.7 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.6 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.5 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.4 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.3 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.2 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.1 spec/unit/network/http/api/v2/authorization_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/network/http/api/v2/authorization_spec.rb