summaryrefslogtreecommitdiffstats
path: root/test/server/authconfig.rb
blob: 3944369c18d820ab0f90a317982940726ab40e42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby

$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/

require 'puppet'
require 'puppet/server/authconfig'
require 'puppettest'

class TestAuthConfig < Test::Unit::TestCase
	include PuppetTest

    def test_parsingconfigfile
        file = tempfile()
        assert(Puppet[:authconfig], "No config path")

        Puppet[:authconfig] = file

        File.open(file, "w") { |f|
            f.puts "[pelementserver.describe]
    allow *.madstop.com
    deny 10.10.1.1

[fileserver]
    allow *.madstop.com
    deny 10.10.1.1

[fileserver.list]
    allow 10.10.1.1
"
        }

        config = nil
        assert_nothing_raised {
            config = Puppet::Server::AuthConfig.new(file)
        }

        assert_nothing_raised {
            assert(config.allowed?("pelementserver.describe",
                "culain.madstop.com", "1.1.1.1"), "Did not allow host")
            assert(! config.allowed?("pelementserver.describe",
                "culain.madstop.com", "10.10.1.1"), "Allowed host")
            assert(config.allowed?("fileserver.yay",
                "culain.madstop.com", "10.1.1.1"), "Did not allow host to fs")
            assert(! config.allowed?("fileserver.yay",
                "culain.madstop.com", "10.10.1.1"), "Allowed host to fs")
            assert(config.allowed?("fileserver.list",
                "culain.madstop.com", "10.10.1.1"), "Did not allow host to fs.list")
        }
    end
end

# $Id$