~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to .pc/2.7.18-CVE-Rollup.patch/spec/unit/network/rest_authconfig_spec.rb

  • Committer: Package Import Robot
  • Author(s): Robie Basak
  • Date: 2013-04-08 15:03:25 UTC
  • mfrom: (3.1.46 sid)
  • Revision ID: package-import@ubuntu.com-20130408150325-4o91hljzz2zca5fi
Tags: 2.7.18-4ubuntu1
* Merge from Debian unstable. This merges the vim addon fix in 2.7.18-2
  (LP: #1163927). Remaining changes:
  - debian/puppetmaster-passenger.postinst: Make sure we error if puppet
    config print doesn't work
  - debian/puppetmaster-passenger.postinst: Ensure upgrades from
    <= 2.7.11-1 fixup passenger apache configuration.
  - Drop Build-Depends on ruby-rspec (in universe):
    + debian/control: remove ruby-rspec from Build-Depends
    + debian/patches/no-rspec.patch: make Rakefile work anyway if rspec
      isn't installed so we can use it in debian/rules.
* Drop upstreamed patches:
  - debian/patches/security-mar-2013.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env rspec
 
2
require 'spec_helper'
 
3
 
 
4
require 'puppet/network/rest_authconfig'
 
5
 
 
6
describe Puppet::Network::RestAuthConfig do
 
7
 
 
8
  DEFAULT_ACL = Puppet::Network::RestAuthConfig::DEFAULT_ACL
 
9
 
 
10
  before :each do
 
11
    FileTest.stubs(:exists?).returns(true)
 
12
    File.stubs(:stat).returns(stub('stat', :ctime => :now))
 
13
    Time.stubs(:now).returns Time.now
 
14
 
 
15
    @authconfig = Puppet::Network::RestAuthConfig.new("dummy", false)
 
16
    @authconfig.stubs(:read)
 
17
 
 
18
    @acl = stub_everything 'rights'
 
19
    @authconfig.rights = @acl
 
20
  end
 
21
 
 
22
  it "should use the puppet default rest authorization file" do
 
23
    Puppet.expects(:[]).with(:rest_authconfig).returns("dummy")
 
24
 
 
25
    Puppet::Network::RestAuthConfig.new(nil, false)
 
26
  end
 
27
 
 
28
  it "should ask for authorization to the ACL subsystem" do
 
29
    params = {:ip => "127.0.0.1", :node => "me", :environment => :env, :authenticated => true}
 
30
    @acl.expects(:is_request_forbidden_and_why?).with("path", :save, "to/resource", params).returns(nil)
 
31
 
 
32
    @authconfig.check_authorization("path", :save, "to/resource", params)
 
33
  end
 
34
 
 
35
  describe "when defining an acl with mk_acl" do
 
36
    it "should create a new right for each default acl" do
 
37
      @acl.expects(:newright).with(:path)
 
38
      @authconfig.mk_acl(:acl => :path)
 
39
    end
 
40
 
 
41
    it "should allow everyone for each default right" do
 
42
      @acl.expects(:allow).with(:path, "*")
 
43
      @authconfig.mk_acl(:acl => :path)
 
44
    end
 
45
 
 
46
    it "should restrict the ACL to a method" do
 
47
      @acl.expects(:restrict_method).with(:path, :method)
 
48
      @authconfig.mk_acl(:acl => :path, :method => :method)
 
49
    end
 
50
 
 
51
    it "should restrict the ACL to a specific authentication state" do
 
52
      @acl.expects(:restrict_authenticated).with(:path, :authentication)
 
53
      @authconfig.mk_acl(:acl => :path, :authenticated => :authentication)
 
54
    end
 
55
  end
 
56
 
 
57
  describe "when parsing the configuration file" do
 
58
    it "should check for missing ACL after reading the authconfig file" do
 
59
      File.stubs(:open)
 
60
 
 
61
      @authconfig.expects(:insert_default_acl)
 
62
 
 
63
      @authconfig.parse
 
64
    end
 
65
  end
 
66
 
 
67
  DEFAULT_ACL.each do |acl|
 
68
    it "should insert #{acl[:acl]} if not present" do
 
69
      @authconfig.rights.stubs(:[]).returns(true)
 
70
      @authconfig.rights.stubs(:[]).with(acl[:acl]).returns(nil)
 
71
 
 
72
      @authconfig.expects(:mk_acl).with { |h| h[:acl] == acl[:acl] }
 
73
 
 
74
      @authconfig.insert_default_acl
 
75
    end
 
76
 
 
77
    it "should not insert #{acl[:acl]} if present" do
 
78
      @authconfig.rights.stubs(:[]).returns(true)
 
79
      @authconfig.rights.stubs(:[]).with(acl).returns(true)
 
80
 
 
81
      @authconfig.expects(:mk_acl).never
 
82
 
 
83
      @authconfig.insert_default_acl
 
84
    end
 
85
  end
 
86
 
 
87
  it "should create default ACL entries if no file have been read" do
 
88
    Puppet::Network::RestAuthConfig.any_instance.stubs(:exists?).returns(false)
 
89
 
 
90
    Puppet::Network::RestAuthConfig.any_instance.expects(:insert_default_acl)
 
91
 
 
92
    Puppet::Network::RestAuthConfig.main
 
93
  end
 
94
 
 
95
  describe "when adding default ACLs" do
 
96
 
 
97
    DEFAULT_ACL.each do |acl|
 
98
      it "should create a default right for #{acl[:acl]}" do
 
99
        @authconfig.stubs(:mk_acl)
 
100
        @authconfig.expects(:mk_acl).with(acl)
 
101
        @authconfig.insert_default_acl
 
102
      end
 
103
    end
 
104
 
 
105
    it "should log at info loglevel" do
 
106
      Puppet.expects(:info).at_least_once
 
107
      @authconfig.insert_default_acl
 
108
    end
 
109
 
 
110
    it "should create a last catch-all deny all rule" do
 
111
      @authconfig.stubs(:mk_acl)
 
112
      @acl.expects(:newright).with("/")
 
113
      @authconfig.insert_default_acl
 
114
    end
 
115
 
 
116
    it "should create a last catch-all deny all rule for any authenticated request state" do
 
117
      @authconfig.stubs(:mk_acl)
 
118
      @acl.stubs(:newright).with("/")
 
119
 
 
120
      @acl.expects(:restrict_authenticated).with("/", :any)
 
121
 
 
122
      @authconfig.insert_default_acl
 
123
    end
 
124
 
 
125
  end
 
126
 
 
127
end