summaryrefslogtreecommitdiffstats
path: root/spec/unit/type/macauthorization_spec.rb
blob: 8785984fe3289b605f2c77453e0d070d47423929 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../spec_helper'

macauth_type = Puppet::Type.type(:macauthorization)

describe Puppet::Type.type(:macauthorization), "when checking macauthorization objects" do

    before do
        authplist = {}
        authplist["rules"] = { "foorule" => "foo" }
        authplist["rights"] = { "fooright" => "foo" }
        provider_class = macauth_type.provider(macauth_type.providers[0])
        Plist.stubs(:parse_xml).with("/etc/authorization").returns(authplist)
        macauth_type.stubs(:defaultprovider).returns provider_class
        @resource = macauth_type.new(:name => 'foo')
    end

    describe "when validating attributes" do

        parameters = [:name,]
        properties = [:auth_type, :allow_root, :authenticate_user, :auth_class,
                      :comment, :group, :k_of_n, :mechanisms, :rule,
                      :session_owner, :shared, :timeout, :tries]

        parameters.each do |parameter|
            it "should have a %s parameter" % parameter do
                macauth_type.attrclass(parameter).ancestors.should be_include(Puppet::Parameter)
            end

            it "should have documentation for its %s parameter" % parameter do
                macauth_type.attrclass(parameter).doc.should be_instance_of(String)
            end
        end

        properties.each do |property|
            it "should have a %s property" % property do
                macauth_type.attrclass(property).ancestors.should be_include(Puppet::Property)
            end

            it "should have documentation for its %s property" % property do
                macauth_type.attrclass(property).doc.should be_instance_of(String)
            end
        end

    end

    describe "when validating properties" do

        it "should have a default provider inheriting from Puppet::Provider" do
            macauth_type.defaultprovider.ancestors.should be_include(Puppet::Provider)
        end

        it "should be able to create an instance" do
            lambda {
                macauth_type.new(:name => 'foo')
            }.should_not raise_error
        end

        it "should support :present as a value to :ensure" do
            lambda {
                macauth_type.new(:name => "foo", :ensure => :present)
            }.should_not raise_error
        end

        it "should support :absent as a value to :ensure" do
            lambda {
                macauth_type.new(:name => "foo", :ensure => :absent)
            }.should_not raise_error
        end

    end

    [:k_of_n, :timeout, :tries].each do |property|
        describe "when managing the #{property} property" do
            it "should convert number-looking strings into actual numbers" do
                prop = macauth_type.attrclass(property).new(:resource => @resource)
                prop.should = "300"
                prop.should.must == 300
            end
            it "should support integers as a value" do
                prop = macauth_type.attrclass(property).new(:resource => @resource)
                prop.should = 300
                prop.should.must == 300
            end
            it "should raise an error for non-integer values" do
                prop = macauth_type.attrclass(property).new(:resource => @resource)
                lambda { prop.should = "foo" }.should raise_error(Puppet::Error)
            end
        end
    end

    [:allow_root, :authenticate_user, :session_owner, :shared].each do |property|
        describe "when managing the #{property} property" do
            it "should convert boolean-looking false strings into actual booleans" do
                prop = macauth_type.attrclass(property).new(:resource => @resource)
                prop.should = "false"
                prop.should.must == :false
            end
            it "should convert boolean-looking true strings into actual booleans" do
                prop = macauth_type.attrclass(property).new(:resource => @resource)
                prop.should = "true"
                prop.should.must == :true
            end
            it "should raise an error for non-boolean values" do
                prop = macauth_type.attrclass(property).new(:resource => @resource)
                lambda { prop.should = "foo" }.should raise_error(Puppet::Error)
            end
        end
    end
end