puppet 2.6.1 → 2.6.2

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.

Files changed (79) hide show
  1. data/CHANGELOG +51 -195
  2. data/LICENSE +2 -2
  3. data/conf/suse/puppet.spec +13 -10
  4. data/install.rb +7 -13
  5. data/lib/puppet.rb +1 -1
  6. data/lib/puppet/application.rb +17 -21
  7. data/lib/puppet/defaults.rb +1 -1
  8. data/lib/puppet/dsl.rb +0 -4
  9. data/lib/puppet/dsl/resource_type_api.rb +16 -10
  10. data/lib/puppet/external/event-loop/event-loop.rb +15 -11
  11. data/lib/puppet/feature/base.rb +2 -1
  12. data/lib/puppet/feature/rails.rb +1 -3
  13. data/lib/puppet/network/http/webrick/rest.rb +1 -0
  14. data/lib/puppet/network/http_pool.rb +0 -12
  15. data/lib/puppet/parser/ast/function.rb +1 -1
  16. data/lib/puppet/parser/ast/resource.rb +1 -5
  17. data/lib/puppet/parser/functions/extlookup.rb +1 -1
  18. data/lib/puppet/parser/functions/versioncmp.rb +3 -3
  19. data/lib/puppet/parser/lexer.rb +1 -1
  20. data/lib/puppet/parser/parser_support.rb +4 -2
  21. data/lib/puppet/parser/resource.rb +8 -0
  22. data/lib/puppet/parser/type_loader.rb +50 -48
  23. data/lib/puppet/provider/nameservice.rb +1 -0
  24. data/lib/puppet/provider/nameservice/objectadd.rb +2 -1
  25. data/lib/puppet/provider/service/freebsd.rb +1 -1
  26. data/lib/puppet/provider/service/launchd.rb +16 -9
  27. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +7 -0
  28. data/lib/puppet/provider/user/hpux.rb +0 -1
  29. data/lib/puppet/provider/user/user_role_add.rb +21 -9
  30. data/lib/puppet/provider/user/useradd.rb +44 -3
  31. data/lib/puppet/rails.rb +3 -3
  32. data/lib/puppet/reference/configuration.rb +7 -12
  33. data/lib/puppet/reference/indirection.rb +2 -2
  34. data/lib/puppet/reference/metaparameter.rb +10 -9
  35. data/lib/puppet/reference/type.rb +6 -6
  36. data/lib/puppet/reports/rrdgraph.rb +1 -1
  37. data/lib/puppet/reports/tagmail.rb +1 -1
  38. data/lib/puppet/ssl/certificate_request.rb +1 -1
  39. data/lib/puppet/sslcertificates/ca.rb +4 -10
  40. data/lib/puppet/type.rb +3 -3
  41. data/lib/puppet/type/cron.rb +1 -1
  42. data/lib/puppet/type/tidy.rb +1 -0
  43. data/lib/puppet/type/user.rb +55 -0
  44. data/lib/puppet/type/whit.rb +4 -0
  45. data/lib/puppet/util.rb +8 -0
  46. data/lib/puppet/util/metric.rb +38 -9
  47. data/lib/puppet/util/rdoc/parser.rb +10 -7
  48. data/lib/puppet/util/reference.rb +4 -4
  49. data/lib/puppet/util/zaml.rb +0 -1
  50. data/spec/fixtures/yaml/report0.25.x.yaml +64 -0
  51. data/spec/fixtures/yaml/report2.6.x.yaml +190 -0
  52. data/spec/integration/application/doc_spec.rb +55 -0
  53. data/spec/integration/defaults_spec.rb +1 -1
  54. data/spec/integration/parser/compiler_spec.rb +21 -0
  55. data/spec/integration/parser/ruby_manifest_spec.rb +128 -0
  56. data/spec/lib/puppet_spec/files.rb +1 -0
  57. data/spec/spec_helper.rb +1 -0
  58. data/spec/unit/application_spec.rb +16 -25
  59. data/spec/unit/dsl/resource_type_api_spec.rb +32 -12
  60. data/spec/unit/indirector/node/active_record_spec.rb +0 -1
  61. data/spec/unit/parser/ast/function_spec.rb +14 -4
  62. data/spec/unit/parser/lexer_spec.rb +8 -0
  63. data/spec/unit/parser/parser_spec.rb +0 -9
  64. data/spec/unit/parser/type_loader_spec.rb +3 -16
  65. data/spec/unit/provider/service/launchd_spec.rb +8 -5
  66. data/spec/unit/provider/user/user_role_add_spec.rb +18 -1
  67. data/spec/unit/provider/user/useradd_spec.rb +19 -0
  68. data/spec/unit/rails_spec.rb +10 -4
  69. data/spec/unit/reports/rrdgraph_spec.rb +31 -0
  70. data/spec/unit/reports/tagmail_spec.rb +1 -0
  71. data/spec/unit/sslcertificates/ca_spec.rb +110 -0
  72. data/spec/unit/type/user_spec.rb +19 -1
  73. data/spec/unit/type/whit_spec.rb +11 -0
  74. data/spec/unit/type_spec.rb +7 -0
  75. data/spec/unit/util/rdoc/parser_spec.rb +18 -14
  76. data/spec/unit/util/zaml_spec.rb +2 -1
  77. metadata +11 -6
  78. data/conf/suse/ruby-env.patch +0 -17
  79. data/test/certmgr/ca.rb +0 -87
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'tempfile'
2
3
 
3
4
  # A support module for testing files.
4
5
  module PuppetSpec::Files
@@ -20,6 +20,7 @@ module PuppetSpec
20
20
  FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
21
21
  end
22
22
 
23
+ require 'spec/lib/puppet_spec/files'
23
24
  require 'monkey_patches/alias_should_to_must'
24
25
  require 'monkey_patches/add_confine_and_runnable_to_rspec_dsl'
25
26
  require 'monkey_patches/publicize_methods'
@@ -191,24 +191,17 @@ describe Puppet::Application do
191
191
  Puppet.settings.stubs(:optparse_addargs).returns([])
192
192
  end
193
193
 
194
- it "should create a new option parser when needed" do
195
- option_parser = stub "option parser"
196
- option_parser.stubs(:on)
197
- OptionParser.expects(:new).returns(option_parser).once
198
- @app.option_parser.should == option_parser
199
- @app.option_parser.should == option_parser
200
- end
201
-
202
194
  it "should pass the banner to the option parser" do
203
195
  option_parser = stub "option parser"
204
196
  option_parser.stubs(:on)
197
+ option_parser.stubs(:parse!)
205
198
  @app.class.instance_eval do
206
199
  banner "banner"
207
200
  end
208
201
 
209
202
  OptionParser.expects(:new).with("banner").returns(option_parser)
210
203
 
211
- @app.option_parser
204
+ @app.parse_options
212
205
  end
213
206
 
214
207
  it "should get options from Puppet.settings.optparse_addargs" do
@@ -219,15 +212,14 @@ describe Puppet::Application do
219
212
 
220
213
  it "should add Puppet.settings options to OptionParser" do
221
214
  Puppet.settings.stubs(:optparse_addargs).returns( [["--option","-o", "Funny Option"]])
222
-
223
- @app.option_parser.expects(:on).with { |*arg| arg == ["--option","-o", "Funny Option"] }
224
-
215
+ Puppet.settings.expects(:handlearg).with("--option", 'true')
216
+ @app.command_line.stubs(:args).returns(["--option"])
225
217
  @app.parse_options
226
218
  end
227
219
 
228
220
  it "should ask OptionParser to parse the command-line argument" do
229
221
  @app.command_line.stubs(:args).returns(%w{ fake args })
230
- @app.option_parser.expects(:parse!).with(%w{ fake args })
222
+ OptionParser.any_instance.expects(:parse!).with(%w{ fake args })
231
223
 
232
224
  @app.parse_options
233
225
  end
@@ -258,31 +250,30 @@ describe Puppet::Application do
258
250
 
259
251
  describe "when dealing with an argument not declared directly by the application" do
260
252
  it "should pass it to handle_unknown if this method exists" do
261
- Puppet.settings.stubs(:optparse_addargs).returns([["--not-handled"]])
262
- @app.option_parser.stubs(:on).yields("value")
253
+ Puppet.settings.stubs(:optparse_addargs).returns([["--not-handled", :REQUIRED]])
263
254
 
264
255
  @app.expects(:handle_unknown).with("--not-handled", "value").returns(true)
265
-
256
+ @app.command_line.stubs(:args).returns(["--not-handled", "value"])
266
257
  @app.parse_options
267
258
  end
268
259
 
269
260
  it "should pass it to Puppet.settings if handle_unknown says so" do
270
- Puppet.settings.stubs(:optparse_addargs).returns([["--topuppet"]])
271
- @app.option_parser.stubs(:on).yields("value")
261
+ Puppet.settings.stubs(:optparse_addargs).returns([["--topuppet", :REQUIRED]])
272
262
 
273
263
  @app.stubs(:handle_unknown).with("--topuppet", "value").returns(false)
274
264
 
275
265
  Puppet.settings.expects(:handlearg).with("--topuppet", "value")
266
+ @app.command_line.stubs(:args).returns(["--topuppet", "value"])
276
267
  @app.parse_options
277
268
  end
278
269
 
279
270
  it "should pass it to Puppet.settings if there is no handle_unknown method" do
280
- Puppet.settings.stubs(:optparse_addargs).returns([["--topuppet"]])
281
- @app.option_parser.stubs(:on).yields("value")
271
+ Puppet.settings.stubs(:optparse_addargs).returns([["--topuppet", :REQUIRED]])
282
272
 
283
273
  @app.stubs(:respond_to?).returns(false)
284
274
 
285
275
  Puppet.settings.expects(:handlearg).with("--topuppet", "value")
276
+ @app.command_line.stubs(:args).returns(["--topuppet", "value"])
286
277
  @app.parse_options
287
278
  end
288
279
 
@@ -310,7 +301,7 @@ describe Puppet::Application do
310
301
 
311
302
  it "should exit if OptionParser raises an error" do
312
303
  $stderr.stubs(:puts)
313
- @app.option_parser.stubs(:parse!).raises(OptionParser::ParseError.new("blah blah"))
304
+ OptionParser.any_instance.stubs(:parse!).raises(OptionParser::ParseError.new("blah blah"))
314
305
 
315
306
  @app.expects(:exit)
316
307
 
@@ -478,7 +469,7 @@ describe Puppet::Application do
478
469
  @app.class.option("--[no-]test3","-t") do
479
470
  end
480
471
 
481
- @app.option_parser
472
+ @app.parse_options
482
473
  end
483
474
 
484
475
  it "should pass a block that calls our defined method" do
@@ -490,7 +481,7 @@ describe Puppet::Application do
490
481
  @app.class.option("--test4","-t") do
491
482
  end
492
483
 
493
- @app.option_parser
484
+ @app.parse_options
494
485
  end
495
486
  end
496
487
 
@@ -501,7 +492,7 @@ describe Puppet::Application do
501
492
 
502
493
  @app.class.option("--test4","-t")
503
494
 
504
- @app.option_parser
495
+ @app.parse_options
505
496
  end
506
497
 
507
498
  it "should give to OptionParser a block that adds the the value to the options array" do
@@ -512,7 +503,7 @@ describe Puppet::Application do
512
503
 
513
504
  @app.class.option("--test4","-t")
514
505
 
515
- @app.option_parser
506
+ @app.parse_options
516
507
  end
517
508
  end
518
509
  end
@@ -4,13 +4,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
5
  require 'puppet/dsl/resource_type_api'
6
6
 
7
- class DSLAPITester
8
- include Puppet::DSL::ResourceTypeAPI
9
- end
10
-
11
7
  describe Puppet::DSL::ResourceTypeAPI do
12
- before do
13
- @api = DSLAPITester.new
8
+ # Run the given block in the context of a new ResourceTypeAPI
9
+ # object.
10
+ def test_api_call(&block)
11
+ Thread.current[:known_resource_types] = Puppet::Resource::TypeCollection.new(:env)
12
+ Puppet::DSL::ResourceTypeAPI.new.instance_eval(&block)
13
+ ensure
14
+ Thread.current[:known_resource_types] = nil
14
15
  end
15
16
 
16
17
  [:definition, :node, :hostclass].each do |type|
@@ -18,29 +19,48 @@ describe Puppet::DSL::ResourceTypeAPI do
18
19
  it "should be able to create a #{type}" do
19
20
  newtype = Puppet::Resource::Type.new(:hostclass, "foo")
20
21
  Puppet::Resource::Type.expects(:new).with { |t, n, args| t == type }.returns newtype
21
- @api.send(method, "myname")
22
+ test_api_call { send(method, "myname") }
22
23
  end
23
24
 
24
25
  it "should use the provided name when creating a #{type}" do
25
26
  type = Puppet::Resource::Type.new(:hostclass, "foo")
26
27
  Puppet::Resource::Type.expects(:new).with { |t, n, args| n == "myname" }.returns type
27
- @api.send(method, "myname")
28
+ test_api_call { send(method, "myname") }
28
29
  end
29
30
 
30
31
  unless type == :definition
31
32
  it "should pass in any provided options" do
32
33
  type = Puppet::Resource::Type.new(:hostclass, "foo")
33
34
  Puppet::Resource::Type.expects(:new).with { |t, n, args| args == {:myarg => :myvalue} }.returns type
34
- @api.send(method, "myname", :myarg => :myvalue)
35
+ test_api_call { send(method, "myname", :myarg => :myvalue) }
35
36
  end
36
37
  end
37
38
 
38
- it "should set any provided block as the type's ruby code"
39
+ it "should set any provided block as the type's ruby code" do
40
+ Puppet::Resource::Type.any_instance.expects(:ruby_code=).with { |blk| blk.call == 'foo' }
41
+ test_api_call { send(method, "myname") { 'foo' } }
42
+ end
39
43
 
40
- it "should add the type to the current environment's known resource types"
44
+ it "should add the type to the current environment's known resource types" do
45
+ begin
46
+ newtype = Puppet::Resource::Type.new(:hostclass, "foo")
47
+ Puppet::Resource::Type.expects(:new).returns newtype
48
+ known_resource_types = Puppet::Resource::TypeCollection.new(:env)
49
+ Thread.current[:known_resource_types] = known_resource_types
50
+ known_resource_types.expects(:add).with(newtype)
51
+ Puppet::DSL::ResourceTypeAPI.new.instance_eval { hostclass "myname" }
52
+ ensure
53
+ Thread.current[:known_resource_types] = nil
54
+ end
55
+ end
41
56
  end
42
57
 
43
58
  describe "when creating a definition" do
44
- it "should use the provided options to define valid arguments for the resource type"
59
+ it "should use the provided options to define valid arguments for the resource type" do
60
+ newtype = Puppet::Resource::Type.new(:definition, "foo")
61
+ Puppet::Resource::Type.expects(:new).returns newtype
62
+ test_api_call { define("myname", :arg1, :arg2) }
63
+ newtype.instance_eval { @arguments }.should == { 'arg1' => nil, 'arg2' => nil }
64
+ end
45
65
  end
46
66
  end
@@ -3,7 +3,6 @@
3
3
  require File.dirname(__FILE__) + '/../../../spec_helper'
4
4
 
5
5
  require 'puppet/node'
6
- require 'spec/lib/puppet_spec/files.rb'
7
6
 
8
7
  describe "Puppet::Node::ActiveRecord" do
9
8
  include PuppetSpec::Files
@@ -61,20 +61,30 @@ describe Puppet::Parser::AST::Function do
61
61
  end
62
62
 
63
63
  it "should call the underlying ruby function" do
64
- argument = stub 'arg', :safeevaluate => "nothing"
64
+ argument = stub 'arg', :safeevaluate => ["nothing"]
65
65
  Puppet::Parser::Functions.stubs(:function).with("exist").returns(true)
66
66
  func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument
67
67
 
68
- @scope.expects(:function_exist).with("nothing")
68
+ @scope.expects(:function_exist).with(["nothing"])
69
+
70
+ func.evaluate(@scope)
71
+ end
72
+
73
+ it "should convert :undef to '' in arguments" do
74
+ argument = stub 'arg', :safeevaluate => ["foo", :undef, "bar"]
75
+ Puppet::Parser::Functions.stubs(:function).with("exist").returns(true)
76
+ func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument
77
+
78
+ @scope.expects(:function_exist).with(["foo", "", "bar"])
69
79
 
70
80
  func.evaluate(@scope)
71
81
  end
72
82
 
73
83
  it "should return the ruby function return for rvalue functions" do
74
- argument = stub 'arg', :safeevaluate => "nothing"
84
+ argument = stub 'arg', :safeevaluate => ["nothing"]
75
85
  Puppet::Parser::Functions.stubs(:function).with("exist").returns(true)
76
86
  func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument
77
- @scope.stubs(:function_exist).with("nothing").returns("returning")
87
+ @scope.stubs(:function_exist).with(["nothing"]).returns("returning")
78
88
 
79
89
  func.evaluate(@scope).should == "returning"
80
90
  end
@@ -30,6 +30,14 @@ describe Puppet::Parser::Lexer do
30
30
 
31
31
  @lexer.line.should == 10
32
32
  end
33
+
34
+ it "should not think the terminator is escaped, when preceeded by an even number of backslashes" do
35
+ @lexer.line = 10
36
+ @lexer.string = "here\nis\nthe\nstring\\\\'with\nextra\njunk"
37
+ @lexer.slurpstring("'")
38
+
39
+ @lexer.line.should == 13
40
+ end
33
41
  end
34
42
  end
35
43
 
@@ -52,15 +52,6 @@ describe Puppet::Parser do
52
52
  @parser.file = "/my/file.rb"
53
53
  @parser.parse
54
54
  end
55
-
56
- describe "in ruby" do
57
- it "should use the ruby interpreter to load the file" do
58
- @parser.file = "/my/file.rb"
59
- @parser.expects(:require).with "/my/file.rb"
60
-
61
- @parser.parse_ruby_file
62
- end
63
- end
64
55
  end
65
56
 
66
57
  describe "when parsing append operator" do
@@ -77,13 +77,6 @@ describe Puppet::Parser::TypeLoader do
77
77
  @loader.load_until(["foo"], "bar") { |f| false }.should be_nil
78
78
  end
79
79
 
80
- it "should know when a given name has been loaded" do
81
- @loader.expects(:name2files).returns %w{file}
82
- @loader.expects(:import).with("file",nil)
83
- @loader.load_until(["foo"], "bar") { |f| true }
84
- @loader.should be_loaded("file")
85
- end
86
-
87
80
  it "should set the module name on any created resource types" do
88
81
  type = Puppet::Resource::Type.new(:hostclass, "mytype")
89
82
 
@@ -113,7 +106,8 @@ describe Puppet::Parser::TypeLoader do
113
106
  describe "when importing" do
114
107
  before do
115
108
  Puppet::Parser::Files.stubs(:find_manifests).returns ["modname", %w{file}]
116
- @loader.stubs(:parse_file)
109
+ Puppet::Parser::Parser.any_instance.stubs(:parse)
110
+ Puppet::Parser::Parser.any_instance.stubs(:file=)
117
111
  end
118
112
 
119
113
  it "should return immediately when imports are being ignored" do
@@ -154,16 +148,9 @@ describe Puppet::Parser::TypeLoader do
154
148
  @loader.import("myfile", "/current/file")
155
149
  end
156
150
 
157
- it "should know when a given file has been imported" do
158
- Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
159
- @loader.import("myfile")
160
-
161
- @loader.should be_imported("/one")
162
- end
163
-
164
151
  it "should not attempt to import files that have already been imported" do
165
152
  Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
166
- @loader.expects(:parse_file).once
153
+ Puppet::Parser::Parser.any_instance.expects(:parse).once
167
154
  @loader.import("myfile")
168
155
 
169
156
  # This will fail if it tries to reimport the file.
@@ -98,19 +98,22 @@ describe provider_class do
98
98
  it "should return true if the job plist says disabled is true and the global overrides says disabled is false" do
99
99
  provider_class.stubs(:get_macosx_version_major).returns("10.6")
100
100
  @provider.stubs(:plist_from_label).returns(["foo", {"Disabled" => true}])
101
- Plist.stubs(:parse_xml).returns({@resource[:name] => {"Disabled" => false}})
101
+ @provider.class.stubs(:read_plist).returns({@resource[:name] => {"Disabled" => false}})
102
+ FileTest.expects(:file?).with(Launchd_Overrides).returns(true)
102
103
  @provider.enabled?.should == :true
103
104
  end
104
105
  it "should return false if the job plist says disabled is false and the global overrides says disabled is true" do
105
106
  provider_class.stubs(:get_macosx_version_major).returns("10.6")
106
107
  @provider.stubs(:plist_from_label).returns(["foo", {"Disabled" => false}])
107
- Plist.stubs(:parse_xml).returns({@resource[:name] => {"Disabled" => true}})
108
+ @provider.class.stubs(:read_plist).returns({@resource[:name] => {"Disabled" => true}})
109
+ FileTest.expects(:file?).with(Launchd_Overrides).returns(true)
108
110
  @provider.enabled?.should == :false
109
111
  end
110
112
  it "should return true if the job plist and the global overrides have no disabled keys" do
111
113
  provider_class.stubs(:get_macosx_version_major).returns("10.6")
112
114
  @provider.stubs(:plist_from_label).returns(["foo", {}])
113
- Plist.stubs(:parse_xml).returns({})
115
+ @provider.class.stubs(:read_plist).returns({})
116
+ FileTest.expects(:file?).with(Launchd_Overrides).returns(true)
114
117
  @provider.enabled?.should == :true
115
118
  end
116
119
  end
@@ -182,7 +185,7 @@ describe provider_class do
182
185
  describe "when enabling the service on OS X 10.6" do
183
186
  it "should write to the global launchd overrides file once" do
184
187
  provider_class.stubs(:get_macosx_version_major).returns("10.6")
185
- Plist.stubs(:parse_xml).returns({})
188
+ @provider.class.stubs(:read_plist).returns({})
186
189
  Plist::Emit.expects(:save_plist).once
187
190
  @provider.enable
188
191
  end
@@ -191,7 +194,7 @@ describe provider_class do
191
194
  describe "when disabling the service on OS X 10.6" do
192
195
  it "should write to the global launchd overrides file once" do
193
196
  provider_class.stubs(:get_macosx_version_major).returns("10.6")
194
- Plist.stubs(:parse_xml).returns({})
197
+ @provider.class.stubs(:read_plist).returns({})
195
198
  Plist::Emit.expects(:save_plist).once
196
199
  @provider.enable
197
200
  end
@@ -56,7 +56,7 @@ describe provider_class do
56
56
  it "should use the add command when the user is not a role" do
57
57
  @provider.stubs(:is_role?).returns(false)
58
58
  @provider.expects(:addcmd).returns("useradd")
59
- @provider.expects(:run)
59
+ @provider.expects(:run).at_least_once
60
60
  @provider.create
61
61
  end
62
62
 
@@ -66,6 +66,15 @@ describe provider_class do
66
66
  @provider.expects(:run)
67
67
  @provider.create
68
68
  end
69
+
70
+ it "should set password age rules" do
71
+ @resource = Puppet::Type.type(:user).new :name => "myuser", :password_min_age => 5, :password_max_age => 10, :provider => :user_role_add
72
+ @provider = provider_class.new(@resource)
73
+ @provider.stubs(:user_attributes)
74
+ @provider.stubs(:execute)
75
+ @provider.expects(:execute).with { |cmd, *args| args == ["-m", 5, "-M", 10, "myuser"] }
76
+ @provider.create
77
+ end
69
78
  end
70
79
 
71
80
  describe "when calling destroy" do
@@ -107,6 +116,7 @@ describe provider_class do
107
116
  before do
108
117
  @resource.expects(:allowdupe?).returns true
109
118
  @provider.stubs(:is_role?).returns(false)
119
+ @provider.stubs(:execute)
110
120
  @provider.expects(:execute).with { |args| args.include?("-o") }
111
121
  end
112
122
 
@@ -246,4 +256,11 @@ describe provider_class do
246
256
  @provider.password=("hashedpassword")
247
257
  end
248
258
  end
259
+
260
+ describe "#shadow_entry" do
261
+ it "should return the line for the right user" do
262
+ File.stubs(:readlines).returns(["someuser:!:10:5:20:7:1::\n", "fakeval:*:20:10:30:7:2::\n", "testuser:*:30:15:40:7:3::\n"])
263
+ @provider.shadow_entry.should == ["fakeval", "*", "20", "10", "30", "7", "2"]
264
+ end
265
+ end
249
266
  end
@@ -15,6 +15,7 @@ describe provider_class do
15
15
  # #1360
16
16
  it "should add -o when allowdupe is enabled and the user is being created" do
17
17
  @resource.expects(:allowdupe?).returns true
18
+ @provider.stubs(:execute)
18
19
  @provider.expects(:execute).with { |args| args.include?("-o") }
19
20
  @provider.create
20
21
  end
@@ -26,6 +27,15 @@ describe provider_class do
26
27
  @provider.uid = 150
27
28
  end
28
29
 
30
+ it "should set password age rules" do
31
+ provider_class.has_feature :manages_password_age
32
+ @resource = Puppet::Type.type(:user).new :name => "myuser", :password_min_age => 5, :password_max_age => 10, :provider => :useradd
33
+ @provider = provider_class.new(@resource)
34
+ @provider.stubs(:execute)
35
+ @provider.expects(:execute).with { |cmd, *args| args == ["-m", 5, "-M", 10, "myuser"] }
36
+ @provider.create
37
+ end
38
+
29
39
  describe "when checking to add allow dup" do
30
40
  it "should check allow dup" do
31
41
  @resource.expects(:allowdupe?)
@@ -109,6 +119,15 @@ describe provider_class do
109
119
  @provider.stubs(:command).with(:add).returns("useradd")
110
120
  @provider.stubs(:add_properties).returns(["-G", "somegroup"])
111
121
  @resource.stubs(:[]).with(:name).returns("someuser")
122
+ @resource.stubs(:[]).with(:expiry).returns("somedate")
123
+ @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", '-e somedate', "someuser"]
124
+ end
125
+
126
+ it "should return an array without -e if expery is undefined full command" do
127
+ @provider.stubs(:command).with(:add).returns("useradd")
128
+ @provider.stubs(:add_properties).returns(["-G", "somegroup"])
129
+ @resource.stubs(:[]).with(:name).returns("someuser")
130
+ @resource.stubs(:[]).with(:expiry).returns nil
112
131
  @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", "someuser"]
113
132
  end
114
133
  end