puppet 2.7.1 → 2.7.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +225 -1
- data/CONTRIBUTING.md +299 -0
- data/README.md +0 -1
- data/conf/redhat/puppet.spec +132 -25
- data/conf/solaris/pkginfo +1 -1
- data/conf/suse/puppet.spec +5 -2
- data/ext/envpuppet +56 -3
- data/ext/vim/README +2 -1
- data/ext/vim/ftplugin/puppet.vim +94 -0
- data/ext/vim/indent/puppet.vim +76 -0
- data/lib/puppet.rb +2 -3
- data/lib/puppet/application/agent.rb +7 -7
- data/lib/puppet/application/apply.rb +20 -8
- data/lib/puppet/application/ca.rb +5 -0
- data/lib/puppet/application/cert.rb +2 -1
- data/lib/puppet/application/certificate.rb +0 -5
- data/lib/puppet/application/device.rb +4 -4
- data/lib/puppet/application/doc.rb +23 -12
- data/lib/puppet/application/face_base.rb +2 -1
- data/lib/puppet/application/inspect.rb +5 -2
- data/lib/puppet/configurer.rb +60 -56
- data/lib/puppet/configurer/fact_handler.rb +6 -1
- data/lib/puppet/defaults.rb +20 -1
- data/lib/puppet/face/ca.rb +233 -0
- data/lib/puppet/face/certificate.rb +15 -11
- data/lib/puppet/face/certificate_request.rb +9 -11
- data/lib/puppet/face/certificate_revocation_list.rb +5 -7
- data/lib/puppet/face/node/clean.rb +154 -0
- data/lib/puppet/face/status.rb +1 -0
- data/lib/puppet/file_serving/configuration/parser.rb +6 -13
- data/lib/puppet/indirector/exec.rb +3 -3
- data/lib/puppet/indirector/face.rb +17 -7
- data/lib/puppet/indirector/report/processor.rb +29 -16
- data/lib/puppet/indirector/rest.rb +42 -7
- data/lib/puppet/indirector/yaml.rb +5 -0
- data/lib/puppet/interface.rb +7 -2
- data/lib/puppet/interface/action.rb +57 -23
- data/lib/puppet/interface/action_manager.rb +10 -5
- data/lib/puppet/interface/face_collection.rb +43 -52
- data/lib/puppet/interface/option.rb +19 -0
- data/lib/puppet/interface/option_builder.rb +13 -0
- data/lib/puppet/interface/option_manager.rb +2 -1
- data/lib/puppet/metatype/manager.rb +7 -20
- data/lib/puppet/module.rb +4 -1
- data/lib/puppet/network/authconfig.rb +3 -1
- data/lib/puppet/network/authstore.rb +14 -5
- data/lib/puppet/network/handler/fileserver.rb +3 -0
- data/lib/puppet/network/http/webrick.rb +1 -1
- data/lib/puppet/network/rest_authconfig.rb +6 -1
- data/lib/puppet/network/rest_authorization.rb +1 -1
- data/lib/puppet/parser/compiler.rb +8 -11
- data/lib/puppet/parser/functions.rb +1 -6
- data/lib/puppet/parser/functions/create_resources.rb +6 -5
- data/lib/puppet/parser/functions/regsubst.rb +26 -0
- data/lib/puppet/parser/functions/shellquote.rb +26 -0
- data/lib/puppet/parser/functions/sprintf.rb +26 -0
- data/lib/puppet/parser/grammar.ra +34 -60
- data/lib/puppet/parser/lexer.rb +5 -5
- data/lib/puppet/parser/parser.rb +913 -1196
- data/lib/puppet/parser/resource.rb +18 -1
- data/lib/puppet/parser/scope.rb +2 -2
- data/lib/puppet/provider/augeas/augeas.rb +42 -17
- data/lib/puppet/provider/mount/parsed.rb +19 -1
- data/lib/puppet/provider/naginator.rb +9 -1
- data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
- data/lib/puppet/provider/network_device.rb +1 -1
- data/lib/puppet/provider/package/aptitude.rb +1 -0
- data/lib/puppet/provider/package/pacman.rb +94 -0
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
- data/lib/puppet/rails/host.rb +7 -0
- data/lib/puppet/reports/store.rb +15 -0
- data/lib/puppet/resource/catalog.rb +15 -6
- data/lib/puppet/ssl/certificate.rb +6 -0
- data/lib/puppet/ssl/inventory.rb +2 -0
- data/lib/puppet/transaction.rb +9 -17
- data/lib/puppet/transaction/report.rb +3 -3
- data/lib/puppet/type.rb +13 -24
- data/lib/puppet/type/file.rb +8 -2
- data/lib/puppet/type/file/source.rb +2 -2
- data/lib/puppet/type/service.rb +20 -24
- data/lib/puppet/type/ssh_authorized_key.rb +12 -0
- data/lib/puppet/type/user.rb +8 -0
- data/lib/puppet/util.rb +0 -1
- data/lib/puppet/util/network_device.rb +3 -3
- data/lib/puppet/util/settings.rb +1 -1
- data/lib/puppet/util/settings/file_setting.rb +1 -0
- data/lib/semver.rb +65 -0
- data/spec/integration/defaults_spec.rb +23 -1
- data/spec/integration/network/rest_authconfig_spec.rb +145 -0
- data/spec/integration/node/facts_spec.rb +1 -1
- data/spec/integration/parser/functions_spec.rb +1 -1
- data/spec/integration/parser/parser_spec.rb +31 -0
- data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
- data/spec/integration/type_spec.rb +11 -0
- data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
- data/spec/lib/puppet/face/huzzah.rb +1 -0
- data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
- data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
- data/spec/unit/application/agent_spec.rb +2 -2
- data/spec/unit/application/apply_spec.rb +74 -56
- data/spec/unit/application/cert_spec.rb +10 -0
- data/spec/unit/application/device_spec.rb +2 -3
- data/spec/unit/application/face_base_spec.rb +1 -0
- data/spec/unit/application/facts_spec.rb +1 -0
- data/spec/unit/application/inspect_spec.rb +5 -0
- data/spec/unit/configurer/fact_handler_spec.rb +45 -37
- data/spec/unit/configurer_spec.rb +405 -327
- data/spec/unit/face/ca_spec.rb +355 -0
- data/spec/unit/face/certificate_spec.rb +16 -4
- data/spec/unit/face/node_spec.rb +261 -1
- data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
- data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
- data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
- data/spec/unit/indirector/exec_spec.rb +4 -4
- data/spec/unit/indirector/face_spec.rb +3 -1
- data/spec/unit/indirector/facts/couch_spec.rb +2 -2
- data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
- data/spec/unit/indirector/node/exec_spec.rb +1 -1
- data/spec/unit/indirector/report/processor_spec.rb +31 -8
- data/spec/unit/indirector/rest_spec.rb +53 -5
- data/spec/unit/indirector/yaml_spec.rb +18 -0
- data/spec/unit/interface/action_spec.rb +112 -8
- data/spec/unit/interface/face_collection_spec.rb +46 -36
- data/spec/unit/interface/option_spec.rb +44 -0
- data/spec/unit/interface_spec.rb +11 -6
- data/spec/unit/module_spec.rb +38 -9
- data/spec/unit/network/authconfig_spec.rb +23 -0
- data/spec/unit/network/authstore_spec.rb +36 -4
- data/spec/unit/network/handler/fileserver_spec.rb +32 -0
- data/spec/unit/network/rest_authconfig_spec.rb +1 -1
- data/spec/unit/node_spec.rb +1 -0
- data/spec/unit/parser/compiler_spec.rb +8 -46
- data/spec/unit/parser/lexer_spec.rb +27 -17
- data/spec/unit/parser/resource_spec.rb +61 -3
- data/spec/unit/parser/scope_spec.rb +5 -1
- data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
- data/spec/unit/provider/cisco_spec.rb +3 -4
- data/spec/unit/provider/interface/cisco_spec.rb +1 -2
- data/spec/unit/provider/mount/parsed_spec.rb +41 -0
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
- data/spec/unit/provider/network_device_spec.rb +1 -2
- data/spec/unit/provider/package/pacman_spec.rb +237 -0
- data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
- data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
- data/spec/unit/rails/host_spec.rb +8 -0
- data/spec/unit/resource/catalog_spec.rb +55 -8
- data/spec/unit/semver_spec.rb +187 -0
- data/spec/unit/ssl/certificate_spec.rb +25 -0
- data/spec/unit/transaction/report_spec.rb +3 -3
- data/spec/unit/transaction_spec.rb +8 -2
- data/spec/unit/type/file_spec.rb +57 -0
- data/spec/unit/type/interface_spec.rb +1 -2
- data/spec/unit/type/schedule_spec.rb +73 -42
- data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
- data/spec/unit/type/user_spec.rb +8 -0
- data/spec/unit/type/vlan_spec.rb +1 -2
- data/spec/unit/type_spec.rb +66 -0
- data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
- data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
- data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
- data/spec/unit/util/network_device/config_spec.rb +3 -4
- data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
- data/spec/unit/util/network_device_spec.rb +2 -2
- data/spec/unit/util/settings/file_setting_spec.rb +4 -0
- data/spec/unit/util/settings_spec.rb +11 -0
- data/test/lib/puppettest/railstesting.rb +0 -34
- metadata +19 -4
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'puppet/network/rest_authconfig'
|
4
|
+
|
5
|
+
RSpec::Matchers.define :allow do |params|
|
6
|
+
|
7
|
+
match do |auth|
|
8
|
+
begin
|
9
|
+
auth.check_authorization(params[0], params[1], params[2], params[3])
|
10
|
+
true
|
11
|
+
rescue Puppet::Network::AuthorizationError
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
failure_message_for_should do |instance|
|
17
|
+
"expected #{params[3][:node]}/#{params[3][:ip]} to be allowed"
|
18
|
+
end
|
19
|
+
|
20
|
+
failure_message_for_should_not do |instance|
|
21
|
+
"expected #{params[3][:node]}/#{params[3][:ip]} to be forbidden"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Puppet::Network::RestAuthConfig do
|
26
|
+
include PuppetSpec::Files
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
Puppet[:rest_authconfig] = tmpfile('auth.conf')
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_rule(rule)
|
33
|
+
File.open(Puppet[:rest_authconfig],"w+") do |f|
|
34
|
+
f.print "path /test\n#{rule}\n"
|
35
|
+
end
|
36
|
+
@auth = Puppet::Network::RestAuthConfig.new(Puppet[:rest_authconfig], true)
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_regex_rule(regex, rule)
|
40
|
+
File.open(Puppet[:rest_authconfig],"w+") do |f|
|
41
|
+
f.print "path ~ #{regex}\n#{rule}\n"
|
42
|
+
end
|
43
|
+
@auth = Puppet::Network::RestAuthConfig.new(Puppet[:rest_authconfig], true)
|
44
|
+
end
|
45
|
+
|
46
|
+
def request(args = {})
|
47
|
+
{ :ip => '10.1.1.1', :node => 'host.domain.com', :key => 'key', :authenticated => true }.each do |k,v|
|
48
|
+
args[k] ||= v
|
49
|
+
end
|
50
|
+
['test', :find, args[:key], args]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should support IPv4 address" do
|
54
|
+
add_rule("allow 10.1.1.1")
|
55
|
+
|
56
|
+
@auth.should allow(request)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should support CIDR IPv4 address" do
|
60
|
+
add_rule("allow 10.0.0.0/8")
|
61
|
+
|
62
|
+
@auth.should allow(request)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should support wildcard IPv4 address" do
|
66
|
+
add_rule("allow 10.1.1.*")
|
67
|
+
|
68
|
+
@auth.should allow(request)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should support IPv6 address" do
|
72
|
+
add_rule("allow 2001:DB8::8:800:200C:417A")
|
73
|
+
|
74
|
+
@auth.should allow(request(:ip => '2001:DB8::8:800:200C:417A'))
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should support hostname" do
|
78
|
+
add_rule("allow host.domain.com")
|
79
|
+
|
80
|
+
@auth.should allow(request)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should support wildcard host" do
|
84
|
+
add_rule("allow *.domain.com")
|
85
|
+
|
86
|
+
@auth.should allow(request)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should support hostname backreferences" do
|
90
|
+
add_regex_rule('^/test/([^/]+)$', "allow $1.domain.com")
|
91
|
+
|
92
|
+
@auth.should allow(request(:key => 'host'))
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should support opaque strings" do
|
96
|
+
add_rule("allow this-is-opaque@or-not")
|
97
|
+
|
98
|
+
@auth.should allow(request(:node => 'this-is-opaque@or-not'))
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should support opaque strings and backreferences" do
|
102
|
+
add_regex_rule('^/test/([^/]+)$', "allow $1")
|
103
|
+
|
104
|
+
@auth.should allow(request(:key => 'this-is-opaque@or-not', :node => 'this-is-opaque@or-not'))
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should support hostname ending with '.'" do
|
108
|
+
pending('bug #7589')
|
109
|
+
add_rule("allow host.domain.com.")
|
110
|
+
|
111
|
+
@auth.should allow(request(:node => 'host.domain.com.'))
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should support hostname ending with '.' and backreferences" do
|
115
|
+
pending('bug #7589')
|
116
|
+
add_regex_rule('^/test/([^/]+)$',"allow $1")
|
117
|
+
|
118
|
+
@auth.should allow(request(:node => 'host.domain.com.'))
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should support trailing whitespace" do
|
122
|
+
add_rule('allow host.domain.com ')
|
123
|
+
|
124
|
+
@auth.should allow(request)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should support inlined comments" do
|
128
|
+
add_rule('allow host.domain.com # will it work?')
|
129
|
+
|
130
|
+
@auth.should allow(request)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should deny non-matching host" do
|
134
|
+
add_rule("allow inexistant")
|
135
|
+
|
136
|
+
@auth.should_not allow(request)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should deny denied hosts" do
|
140
|
+
add_rule("deny host.domain.com")
|
141
|
+
|
142
|
+
@auth.should_not allow(request)
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
@@ -7,7 +7,7 @@ require 'spec_helper'
|
|
7
7
|
|
8
8
|
describe Puppet::Node::Facts do
|
9
9
|
describe "when using the indirector" do
|
10
|
-
after { Puppet::Util::Cacher.expire }
|
10
|
+
after(:each) { Puppet::Util::Cacher.expire }
|
11
11
|
|
12
12
|
it "should expire any cached node instances when it is saved" do
|
13
13
|
Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Puppet::Parser::Functions do
|
5
5
|
before :each do
|
6
|
-
Puppet::Parser::Functions.rmfunction("template") if Puppet::Parser::Functions.
|
6
|
+
Puppet::Parser::Functions.rmfunction("template") if Puppet::Parser::Functions.functions.include?("template")
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should support multiple threads autoloading the same function" do
|
@@ -117,5 +117,36 @@ describe Puppet::Parser::Parser do
|
|
117
117
|
$out = $hash['a']['b']['c']
|
118
118
|
}.should parse_with { |v| v.value.is_a?(Puppet::Parser::AST::ASTHash) }
|
119
119
|
end
|
120
|
+
|
121
|
+
it "should fail if asked to parse '$foo::::bar'" do
|
122
|
+
expect { @parser.parse("$foo::::bar") }.should raise_error(Puppet::ParseError, /Syntax error at ':'/)
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "function calls" do
|
126
|
+
it "should be able to pass an array to a function" do
|
127
|
+
"my_function([1,2,3])".should parse_with { |fun|
|
128
|
+
fun.is_a?(Puppet::Parser::AST::Function) &&
|
129
|
+
fun.arguments[0].evaluate(stub 'scope') == ['1','2','3']
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should be able to pass a hash to a function" do
|
134
|
+
"my_function({foo => bar})".should parse_with { |fun|
|
135
|
+
fun.is_a?(Puppet::Parser::AST::Function) &&
|
136
|
+
fun.arguments[0].evaluate(stub 'scope') == {'foo' => 'bar'}
|
137
|
+
}
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "collections" do
|
142
|
+
it "should find resources according to an expression" do
|
143
|
+
%q{
|
144
|
+
File <| mode == 0700 + 0050 + 0050 |>
|
145
|
+
}.should parse_with { |coll|
|
146
|
+
coll.is_a?(Puppet::Parser::AST::Collection) &&
|
147
|
+
coll.query.evaluate(stub 'scope').first == "param_values.value = '528' and param_names.name = 'mode'"
|
148
|
+
}
|
149
|
+
end
|
150
|
+
end
|
120
151
|
end
|
121
152
|
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'puppet/file_bucket/dipper'
|
5
|
+
|
6
|
+
describe "ssh_authorized_key provider (integration)" do
|
7
|
+
include PuppetSpec::Files
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@fake_userfile = tmpfile('authorized_keys.user')
|
11
|
+
@fake_rootfile = tmpfile('authorized_keys.root')
|
12
|
+
|
13
|
+
# few testkeys generated with ssh-keygen
|
14
|
+
@sample_rsa_keys = [
|
15
|
+
'AAAAB3NzaC1yc2EAAAADAQABAAAAgQCi18JBZOq10X3w4f67nVhO0O3s5Y1vHH4UgMSM3ZnQwbC5hjGyYSi9UULOoQQoQynI/a0I9NL423/Xk/XJVIKCHcS8q6V2Wmjd+fLNelOjxxoW6mbIytEt9rDvwgq3Mof3/m21L3t2byvegR00a+ikKbmInPmKwjeWZpexCIsHzQ==', # 1024 bit
|
16
|
+
'AAAAB3NzaC1yc2EAAAADAQABAAAAgQDLClyvi3CsJw5Id6khZs2/+s11qOH4Gdp6iDioDsrIp0m8kSiPr71VGyQYAfPzzvHemHS7Xg0NkG1Kc8u9tRqBQfTvz7ubq0AT/g01+4P2hQ/soFkuwlUG/HVnnaYb6N0Qp5SHWvD5vBE2nFFQVpP5GrSctPtHSjzJq/i+6LYhmQ==', # 1024 bit
|
17
|
+
'AAAAB3NzaC1yc2EAAAADAQABAAABAQDLygAO6txXkh9FNV8xSsBkATeqLbHzS7sFjGI3gt0Dx6q3LjyKwbhQ1RLf28kd5G6VWiXmClU/RtiPdUz8nrGuun++2mrxzrXrvpR9dq1lygLQ2wn2cI35dN5bjRMtXy3decs6HUhFo9MoNwX250rUWfdCyNPhGIp6OOfmjdy+UeLGNxq9wDx6i4bT5tVVSqVRtsEfw9+ICXchzl85QudjneVVpP+thriPZXfXA5eaGwAo/dmoKOIhUwF96gpdLqzNtrGQuxPbV80PTbGv9ZtAtTictxaDz8muXO7he9pXmchUpxUKtMFjHkL0FAZ9tRPmv3RA30sEr2fZ8+LKvnE50w0' #2048 Bit
|
18
|
+
]
|
19
|
+
@sample_dsa_keys = [
|
20
|
+
'AAAAB3NzaC1kc3MAAACBAOPck2O8MIDSqxPSnvENt6tzRrKJ5oOhB6Nc6oEcWm+VEH1gvuxdiRqwoMgRwyEf1yUd+UAcLw3a6Jn+EtFyEBN/5WF+4Tt4xTxZ0Pfik2Wc5uqHbQ2dkmOoXiAOYPiD3JUQ1Xwm/J0CgetjitoLfzAGdCNhMqguqAuHcVJ78ZZbAAAAFQCIBKFYZ+I18I+dtgteirXh+VVEEwAAAIEAs1yvQ/wnLLrRCM660pF4kBiw3D6dJfMdCXWQpn0hZmkBQSIzZv4Wuk3giei5luxscDxNc+y3CTXtnyG4Kt1Yi2sOdvhRI3rX8tD+ejn8GHazM05l5VIo9uu4AQPIE32iV63IqgApSBbJ6vDJW91oDH0J492WdLCar4BS/KE3cRwAAACBAN0uSDyJqYLRsfYcFn4HyVf6TJxQm1IcwEt6GcJVzgjri9VtW7FqY5iBqa9B9Zdh5XXAYJ0XLsWQCcrmMHM2XGHGpA4gL9VlCJ/0QvOcXxD2uK7IXwAVUA7g4V4bw8EVnFv2Flufozhsp+4soo1xiYc5jiFVHwVlk21sMhAtKAeF' # 1024 Bit
|
21
|
+
]
|
22
|
+
|
23
|
+
@sample_lines = [
|
24
|
+
"ssh-rsa #{@sample_rsa_keys[1]} root@someotherhost",
|
25
|
+
"ssh-dss #{@sample_dsa_keys[0]} root@anywhere",
|
26
|
+
"ssh-rsa #{@sample_rsa_keys[2]} paul"
|
27
|
+
]
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
after :each do
|
32
|
+
Puppet::Type::Ssh_authorized_key::ProviderParsed.clear # Work around bug #6628
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_fake_key(username, content)
|
36
|
+
filename = (username == :root ? @fake_rootfile : @fake_userfile )
|
37
|
+
File.open(filename, 'w') do |f|
|
38
|
+
content.each do |line|
|
39
|
+
f.puts line
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def check_fake_key(username, expected_content)
|
45
|
+
filename = (username == :root ? @fake_rootfile : @fake_userfile )
|
46
|
+
content = File.readlines(filename).map(&:chomp).sort.reject{ |x| x =~ /^#|^$/ }
|
47
|
+
content.join("\n").should == expected_content.sort.join("\n")
|
48
|
+
end
|
49
|
+
|
50
|
+
def run_in_catalog(*resources)
|
51
|
+
Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # Don't backup to the filebucket
|
52
|
+
catalog = Puppet::Resource::Catalog.new
|
53
|
+
catalog.host_config = false
|
54
|
+
resources.each do |resource|
|
55
|
+
resource.expects(:err).never
|
56
|
+
catalog.add_resource(resource)
|
57
|
+
end
|
58
|
+
catalog.apply
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "when managing one resource" do
|
62
|
+
|
63
|
+
before :each do
|
64
|
+
# We are not running as root so chown/chmod is not possible
|
65
|
+
File.stubs(:chown)
|
66
|
+
File.stubs(:chmod)
|
67
|
+
Puppet::Util::SUIDManager.stubs(:asuser).yields
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "with ensure set to absent" do
|
71
|
+
|
72
|
+
before :each do
|
73
|
+
@example = Puppet::Type.type(:ssh_authorized_key).new(
|
74
|
+
:name => 'root@hostname',
|
75
|
+
:type => :rsa,
|
76
|
+
:key => @sample_rsa_keys[0],
|
77
|
+
:target => @fake_rootfile,
|
78
|
+
:user => 'root',
|
79
|
+
:ensure => :absent
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should not modify root's keyfile if resource is currently not present" do
|
84
|
+
create_fake_key(:root, @sample_lines)
|
85
|
+
run_in_catalog(@example)
|
86
|
+
check_fake_key(:root, @sample_lines)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "remove the key from root's keyfile if resource is currently present" do
|
90
|
+
create_fake_key(:root, @sample_lines + ["ssh-rsa #{@sample_rsa_keys[0]} root@hostname"])
|
91
|
+
run_in_catalog(@example)
|
92
|
+
check_fake_key(:root, @sample_lines)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "when ensure is present" do
|
98
|
+
|
99
|
+
before :each do
|
100
|
+
@example = Puppet::Type.type(:ssh_authorized_key).new(
|
101
|
+
:name => 'root@hostname',
|
102
|
+
:type => :rsa,
|
103
|
+
:key => @sample_rsa_keys[0],
|
104
|
+
:target => @fake_rootfile,
|
105
|
+
:user => 'root',
|
106
|
+
:ensure => :present
|
107
|
+
)
|
108
|
+
|
109
|
+
# just a dummy so the parsedfile provider is aware
|
110
|
+
# of the user's authorized_keys file
|
111
|
+
@dummy = Puppet::Type.type(:ssh_authorized_key).new(
|
112
|
+
:name => 'dummy',
|
113
|
+
:target => @fake_userfile,
|
114
|
+
:user => 'nobody',
|
115
|
+
:ensure => :absent
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should add the key if it is not present" do
|
120
|
+
create_fake_key(:root, @sample_lines)
|
121
|
+
run_in_catalog(@example)
|
122
|
+
check_fake_key(:root, @sample_lines + ["ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should modify the type if type is out of sync" do
|
126
|
+
create_fake_key(:root,@sample_lines + [ "ssh-dss #{@sample_rsa_keys[0]} root@hostname" ])
|
127
|
+
run_in_catalog(@example)
|
128
|
+
check_fake_key(:root, @sample_lines + [ "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should modify the key if key is out of sync" do
|
132
|
+
create_fake_key(:root,@sample_lines + [ "ssh-rsa #{@sample_rsa_keys[1]} root@hostname" ])
|
133
|
+
run_in_catalog(@example)
|
134
|
+
check_fake_key(:root, @sample_lines + [ "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should remove the key from old file if target is out of sync" do
|
138
|
+
create_fake_key(:user, [ @sample_lines[0], "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
|
139
|
+
create_fake_key(:root, [ @sample_lines[1], @sample_lines[2] ])
|
140
|
+
run_in_catalog(@example, @dummy)
|
141
|
+
check_fake_key(:user, [ @sample_lines[0] ])
|
142
|
+
#check_fake_key(:root, [ @sample_lines[1], @sample_lines[2], "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should add the key to new file if target is out of sync" do
|
146
|
+
create_fake_key(:user, [ @sample_lines[0], "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
|
147
|
+
create_fake_key(:root, [ @sample_lines[1], @sample_lines[2] ])
|
148
|
+
run_in_catalog(@example, @dummy)
|
149
|
+
#check_fake_key(:user, [ @sample_lines[0] ])
|
150
|
+
check_fake_key(:root, [ @sample_lines[1], @sample_lines[2], "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should modify options if options are out of sync" do
|
154
|
+
@example[:options]=[ 'from="correct.domain.com"', 'no-port-forwarding', 'no-pty' ]
|
155
|
+
create_fake_key(:root, @sample_lines + [ "from=\"incorrect.domain.com\",no-port-forwarding,no-pty ssh-rsa #{@sample_rsa_keys[0]} root@hostname"])
|
156
|
+
run_in_catalog(@example)
|
157
|
+
check_fake_key(:root, @sample_lines + [ "from=\"correct.domain.com\",no-port-forwarding,no-pty ssh-rsa #{@sample_rsa_keys[0]} root@hostname"] )
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "when managing two resource" do
|
165
|
+
|
166
|
+
before :each do
|
167
|
+
# We are not running as root so chown/chmod is not possible
|
168
|
+
File.stubs(:chown)
|
169
|
+
File.stubs(:chmod)
|
170
|
+
Puppet::Util::SUIDManager.stubs(:asuser).yields
|
171
|
+
@example_one = Puppet::Type.type(:ssh_authorized_key).new(
|
172
|
+
:name => 'root@hostname',
|
173
|
+
:type => :rsa,
|
174
|
+
:key => @sample_rsa_keys[0],
|
175
|
+
:target => @fake_rootfile,
|
176
|
+
:user => 'root',
|
177
|
+
:ensure => :present
|
178
|
+
)
|
179
|
+
|
180
|
+
@example_two = Puppet::Type.type(:ssh_authorized_key).new(
|
181
|
+
:name => 'user@hostname',
|
182
|
+
:key => @sample_rsa_keys[1],
|
183
|
+
:type => :rsa,
|
184
|
+
:target => @fake_userfile,
|
185
|
+
:user => 'nobody',
|
186
|
+
:ensure => :present
|
187
|
+
)
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "and both keys are absent" do
|
191
|
+
|
192
|
+
before :each do
|
193
|
+
create_fake_key(:root, @sample_lines)
|
194
|
+
create_fake_key(:user, @sample_lines)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should add both keys" do
|
198
|
+
run_in_catalog(@example_one, @example_two)
|
199
|
+
check_fake_key(:root, @sample_lines + [ "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
|
200
|
+
check_fake_key(:user, @sample_lines + [ "ssh-rsa #{@sample_rsa_keys[1]} user@hostname" ])
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
@@ -18,4 +18,15 @@ describe Puppet::Type do
|
|
18
18
|
|
19
19
|
type.provider(:myprovider).should equal(provider)
|
20
20
|
end
|
21
|
+
|
22
|
+
it "should not lose its provider parameter when it is reloaded" do
|
23
|
+
type = Puppet::Type.newtype(:reload_test_type)
|
24
|
+
|
25
|
+
provider = type.provide(:test_provider)
|
26
|
+
|
27
|
+
# reload it
|
28
|
+
type = Puppet::Type.newtype(:reload_test_type)
|
29
|
+
|
30
|
+
type.parameters.should include(:provider)
|
31
|
+
end
|
21
32
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'puppet/face'
|
2
|
+
Puppet::Face.define(:huzzah, '1.0.0') do
|
3
|
+
copyright "Puppet Labs", 2011
|
4
|
+
license "Apache 2 license; see COPYING"
|
5
|
+
summary "life is a thing for celebration"
|
6
|
+
script :obsolete_in_core do |_| "you are in obsolete core now!" end
|
7
|
+
script :call_newer do |_| method_on_newer end
|
8
|
+
end
|