~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to test/ral/type/sshkey.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
require 'facter'
7
7
 
8
8
class TestSSHKey < Test::Unit::TestCase
9
 
        include PuppetTest
 
9
    include PuppetTest
10
10
    def setup
11
11
        super
12
12
        # god i'm lazy
13
 
        @sshkeytype = Puppet.type(:sshkey)
 
13
        @sshkeytype = Puppet::Type.type(:sshkey)
14
14
 
15
15
        @provider = @sshkeytype.defaultprovider
16
16
 
17
 
        # Make sure they aren't using something funky like netinfo
 
17
        # Make sure they are using the parsed provider
18
18
        unless @provider.name == :parsed
19
19
            @sshkeytype.defaultprovider = @sshkeytype.provider(:parsed)
20
20
        end
48
48
 
49
49
        @catalog ||= mk_catalog
50
50
 
51
 
        assert_nothing_raised {
52
 
            key = @sshkeytype.create(
53
 
                :name => "host%s.madstop.com" % @kcount,
54
 
                :key => "%sAAAAB3NzaC1kc3MAAACBAMnhSiku76y3EGkNCDsUlvpO8tRgS9wL4Eh54WZfQ2lkxqfd2uT/RTT9igJYDtm/+UHuBRdNGpJYW1Nw2i2JUQgQEEuitx4QKALJrBotejGOAWxxVk6xsh9xA0OW8Q3ZfuX2DDitfeC8ZTCl4xodUMD8feLtP+zEf8hxaNamLlt/AAAAFQDYJyf3vMCWRLjTWnlxLtOyj/bFpwAAAIEAmRxxXb4jjbbui9GYlZAHK00689DZuX0EabHNTl2yGO5KKxGC6Esm7AtjBd+onfu4Rduxut3jdI8GyQCIW8WypwpJofCIyDbTUY4ql0AQUr3JpyVytpnMijlEyr41FfIb4tnDqnRWEsh2H7N7peW+8DWZHDFnYopYZJ9Yu4/jHRYAAACAERG50e6aRRb43biDr7Ab9NUCgM9bC0SQscI/xdlFjac0B/kSWJYTGVARWBDWug705hTnlitY9cLC5Ey/t/OYOjylTavTEfd/bh/8FkAYO+pWdW3hx6p97TBffK0b6nrc6OORT2uKySbbKOn0681nNQh4a6ueR3JRppNkRPnTk5c=" % @kcount,
55
 
                :type => "ssh-dss",
56
 
                :alias => ["192.168.0.%s" % @kcount],
57
 
                :catalog => @catalog
58
 
            )
59
 
        }
 
51
        key = @sshkeytype.new(
 
52
            :name => "host%s.madstop.com" % @kcount,
 
53
            :key => "%sAAAAB3NzaC1kc3MAAACBAMnhSiku76y3EGkNCDsUlvpO8tRgS9wL4Eh54WZfQ2lkxqfd2uT/RTT9igJYDtm/+UHuBRdNGpJYW1Nw2i2JUQgQEEuitx4QKALJrBotejGOAWxxVk6xsh9xA0OW8Q3ZfuX2DDitfeC8ZTCl4xodUMD8feLtP+zEf8hxaNamLlt/AAAAFQDYJyf3vMCWRLjTWnlxLtOyj/bFpwAAAIEAmRxxXb4jjbbui9GYlZAHK00689DZuX0EabHNTl2yGO5KKxGC6Esm7AtjBd+onfu4Rduxut3jdI8GyQCIW8WypwpJofCIyDbTUY4ql0AQUr3JpyVytpnMijlEyr41FfIb4tnDqnRWEsh2H7N7peW+8DWZHDFnYopYZJ9Yu4/jHRYAAACAERG50e6aRRb43biDr7Ab9NUCgM9bC0SQscI/xdlFjac0B/kSWJYTGVARWBDWug705hTnlitY9cLC5Ey/t/OYOjylTavTEfd/bh/8FkAYO+pWdW3hx6p97TBffK0b6nrc6OORT2uKySbbKOn0681nNQh4a6ueR3JRppNkRPnTk5c=" % @kcount,
 
54
            :type => "ssh-dss",
 
55
            :alias => ["192.168.0.%s" % @kcount],
 
56
            :catalog => @catalog
 
57
        )
 
58
 
 
59
        @catalog.add_resource(key)
60
60
 
61
61
        return key
62
62
    end
63
63
 
64
64
    def test_instances
 
65
        list = nil
65
66
        assert_nothing_raised {
66
 
            Puppet.type(:sshkey).instances
 
67
            list = Puppet::Type.type(:sshkey).instances
67
68
        }
68
69
 
69
70
        count = 0
70
 
        @sshkeytype.each do |h|
 
71
        list.each do |h|
71
72
            count += 1
72
73
        end
73
74
 
81
82
        key[:provider] = :parsed
82
83
 
83
84
        assert_apply(key)
84
 
        
 
85
 
85
86
        assert_events([], key, "created events on in-sync key")
86
 
        
 
87
 
87
88
        assert(key.provider.exists?, "Key did not get created")
88
 
        
 
89
 
89
90
        # Now create a new key object
90
91
        name = key.name
91
92
        key = nil
92
 
        @sshkeytype.clear
93
 
        
94
 
        key = @sshkeytype.create :name => name, :target => file, :provider => :parsed
 
93
 
 
94
        key = @sshkeytype.new :name => name, :target => file, :provider => :parsed
95
95
        key.retrieve
96
 
        
 
96
 
97
97
        assert(key.provider.exists?, "key thinks it does not exist")
98
 
        
 
98
 
99
99
    end
100
100
 
101
101
    def test_moddingkey
102
102
        key = mkkey()
103
103
 
104
 
        assert_events([:sshkey_created], key)
 
104
        @catalog.apply
105
105
 
106
106
        key.retrieve
107
107
 
108
108
        aliases = %w{madstop kirby yayness}
109
109
        key[:alias] = aliases
110
110
 
111
 
        params = key.instance_variable_get("@parameters")
112
 
        assert_events([:sshkey_changed], key)
 
111
        @catalog.apply
113
112
 
114
113
        aliases.each do |name|
115
 
            assert_equal(key, key.class[name],
116
 
                "alias was not set")
 
114
            assert_equal(key.object_id, @catalog.resource(:sshkey, name).object_id, "alias %s was not set" % name)
117
115
        end
118
116
    end
119
117
 
135
133
            key[:alias] = "testing"
136
134
        }
137
135
 
138
 
        same = key.class["testing"]
 
136
        key.finish
 
137
 
 
138
        same = @catalog.resource(:sshkey, "testing")
139
139
        assert(same, "Could not retrieve by alias")
140
140
    end
141
141
 
169
169
        }
170
170
        assert_apply(*keys)
171
171
        keys.clear
172
 
        Puppet.type(:sshkey).clear
 
172
 
 
173
        @catalog.clear(true)
 
174
        @catalog = nil
 
175
 
173
176
        newkey = mkkey()
174
177
        #newkey[:ensure] = :present
175
178
        names << newkey.name
177
180
 
178
181
        # Verify we can retrieve that info
179
182
        assert_nothing_raised("Could not retrieve after second write") {
180
 
            newkey.provider.class.prefetch
181
 
            newkey.retrieve
 
183
            newkey.provider.prefetch
182
184
        }
183
185
 
184
 
        # And verify that we have data for everything
185
 
        names.each { |name|
186
 
            key = Puppet.type(:sshkey)[name] ||
187
 
                Puppet.type(:sshkey).create(:name => name)
188
 
            assert(key, "Could not retrieve key for %s" % name)
189
 
            assert(key.provider.exists?, "key %s is missing" % name)
190
 
        }
 
186
        assert(newkey.provider.exists?, "Did not see key in file")
191
187
    end
192
188
end
193