puppet 0.25.0 → 0.25.1

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 (138) hide show
  1. data/CHANGELOG +4772 -19114
  2. data/README +1 -1
  3. data/Rakefile +7 -25
  4. data/{sbin → bin}/puppetca +0 -0
  5. data/{sbin → bin}/puppetd +0 -0
  6. data/{sbin → bin}/puppetmasterd +0 -0
  7. data/{sbin → bin}/puppetqd +0 -0
  8. data/{sbin → bin}/puppetrun +0 -0
  9. data/conf/osx/createpackage.sh +1 -1
  10. data/conf/redhat/client.init +6 -3
  11. data/conf/redhat/puppet.spec +26 -14
  12. data/conf/redhat/server.init +3 -2
  13. data/ext/vim/syntax/puppet.vim +4 -1
  14. data/install.rb +25 -7
  15. data/lib/puppet.rb +1 -1
  16. data/lib/puppet/agent.rb +2 -2
  17. data/lib/puppet/application/puppet.rb +3 -3
  18. data/lib/puppet/application/puppetd.rb +0 -7
  19. data/lib/puppet/application/puppetdoc.rb +1 -0
  20. data/lib/puppet/application/puppetmasterd.rb +2 -2
  21. data/lib/puppet/configurer.rb +6 -1
  22. data/lib/puppet/configurer/fact_handler.rb +2 -2
  23. data/lib/puppet/defaults.rb +2 -2
  24. data/lib/puppet/external/nagios/base.rb +4 -3
  25. data/lib/puppet/external/pson/common.rb +367 -0
  26. data/lib/puppet/external/pson/pure.rb +77 -0
  27. data/lib/puppet/external/pson/pure/generator.rb +429 -0
  28. data/lib/puppet/external/pson/pure/parser.rb +269 -0
  29. data/lib/puppet/external/pson/version.rb +8 -0
  30. data/lib/puppet/feature/pson.rb +6 -0
  31. data/lib/puppet/feature/rails.rb +1 -5
  32. data/lib/puppet/file_serving/configuration.rb +2 -2
  33. data/lib/puppet/indirector/certificate/rest.rb +6 -0
  34. data/lib/puppet/indirector/facts/facter.rb +1 -1
  35. data/lib/puppet/indirector/ldap.rb +1 -1
  36. data/lib/puppet/indirector/queue.rb +3 -3
  37. data/lib/puppet/indirector/rest.rb +1 -1
  38. data/lib/puppet/network/authstore.rb +34 -53
  39. data/lib/puppet/network/formats.rb +59 -9
  40. data/lib/puppet/network/http/mongrel/rest.rb +10 -9
  41. data/lib/puppet/network/http/webrick.rb +8 -1
  42. data/lib/puppet/network/http/webrick/rest.rb +2 -5
  43. data/lib/puppet/network/http_server/webrick.rb +1 -4
  44. data/lib/puppet/parser/ast/leaf.rb +1 -3
  45. data/lib/puppet/parser/collector.rb +14 -8
  46. data/lib/puppet/parser/compiler.rb +7 -0
  47. data/lib/puppet/parser/functions/fqdn_rand.rb +4 -10
  48. data/lib/puppet/parser/functions/regsubst.rb +44 -30
  49. data/lib/puppet/parser/functions/require.rb +18 -3
  50. data/lib/puppet/parser/functions/versioncmp.rb +1 -1
  51. data/lib/puppet/parser/interpreter.rb +1 -1
  52. data/lib/puppet/parser/lexer.rb +29 -31
  53. data/lib/puppet/parser/loaded_code.rb +4 -0
  54. data/lib/puppet/parser/parser_support.rb +5 -2
  55. data/lib/puppet/parser/resource.rb +31 -6
  56. data/lib/puppet/property.rb +3 -2
  57. data/lib/puppet/provider/macauthorization/macauthorization.rb +14 -14
  58. data/lib/puppet/provider/package/dpkg.rb +1 -1
  59. data/lib/puppet/provider/package/portage.rb +15 -5
  60. data/lib/puppet/provider/package/rug.rb +1 -1
  61. data/lib/puppet/provider/package/up2date.rb +1 -1
  62. data/lib/puppet/provider/package/urpmi.rb +1 -1
  63. data/lib/puppet/provider/service/daemontools.rb +7 -10
  64. data/lib/puppet/provider/service/runit.rb +7 -17
  65. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +7 -47
  66. data/lib/puppet/provider/zone/solaris.rb +12 -3
  67. data/lib/puppet/relationship.rb +12 -12
  68. data/lib/puppet/reports/rrdgraph.rb +1 -1
  69. data/lib/puppet/reports/store.rb +2 -2
  70. data/lib/puppet/reports/tagmail.rb +5 -16
  71. data/lib/puppet/resource.rb +15 -20
  72. data/lib/puppet/resource/catalog.rb +40 -29
  73. data/lib/puppet/ssl/certificate_revocation_list.rb +0 -2
  74. data/lib/puppet/ssl/host.rb +2 -3
  75. data/lib/puppet/sslcertificates/ca.rb +0 -5
  76. data/lib/puppet/type/cron.rb +1 -1
  77. data/lib/puppet/type/file/owner.rb +7 -4
  78. data/lib/puppet/type/resources.rb +17 -17
  79. data/lib/puppet/type/yumrepo.rb +10 -3
  80. data/lib/puppet/util.rb +6 -11
  81. data/lib/puppet/util/inifile.rb +8 -0
  82. data/lib/puppet/util/log.rb +2 -2
  83. data/lib/puppet/util/monkey_patches.rb +0 -43
  84. data/lib/puppet/util/{json.rb → pson.rb} +6 -6
  85. data/lib/puppet/util/rdoc.rb +5 -3
  86. data/lib/puppet/util/selinux.rb +12 -6
  87. data/lib/puppet/util/settings.rb +25 -16
  88. data/lib/puppet/util/settings/file_setting.rb +4 -2
  89. data/spec/integration/application/puppet.rb +4 -4
  90. data/spec/integration/defaults.rb +2 -2
  91. data/spec/integration/indirector/catalog/queue.rb +5 -5
  92. data/spec/integration/indirector/certificate/rest.rb +3 -1
  93. data/spec/integration/network/formats.rb +36 -36
  94. data/spec/integration/parser/functions/require.rb +5 -3
  95. data/spec/integration/provider/mailalias/aliases.rb +4 -4
  96. data/spec/integration/resource/catalog.rb +4 -4
  97. data/spec/unit/application/puppet.rb +16 -15
  98. data/spec/unit/application/puppetd.rb +1 -1
  99. data/spec/unit/application/puppetdoc.rb +6 -0
  100. data/spec/unit/application/puppetmasterd.rb +6 -6
  101. data/spec/unit/configurer/fact_handler.rb +3 -3
  102. data/spec/unit/file_serving/configuration.rb +16 -2
  103. data/spec/unit/indirector/certificate/rest.rb +34 -0
  104. data/spec/unit/indirector/queue.rb +15 -15
  105. data/spec/unit/indirector/rest.rb +31 -9
  106. data/spec/unit/network/authstore.rb +105 -26
  107. data/spec/unit/network/formats.rb +124 -39
  108. data/spec/unit/parser/ast/leaf.rb +15 -0
  109. data/spec/unit/parser/collector.rb +20 -9
  110. data/spec/unit/parser/compiler.rb +19 -0
  111. data/spec/unit/parser/functions/fqdn_rand.rb +62 -0
  112. data/spec/unit/parser/functions/regsubst.rb +80 -0
  113. data/spec/unit/parser/functions/require.rb +19 -7
  114. data/spec/unit/parser/interpreter.rb +2 -2
  115. data/spec/unit/parser/lexer.rb +32 -7
  116. data/spec/unit/parser/loaded_code.rb +18 -1
  117. data/spec/unit/parser/parser.rb +10 -2
  118. data/spec/unit/parser/resource.rb +53 -2
  119. data/spec/unit/parser/scope.rb +1 -1
  120. data/spec/unit/property.rb +14 -4
  121. data/spec/unit/provider/package/dpkg.rb +7 -0
  122. data/spec/unit/provider/service/daemontools.rb +19 -2
  123. data/spec/unit/provider/service/redhat.rb +2 -0
  124. data/spec/unit/provider/service/runit.rb +15 -4
  125. data/spec/unit/provider/ssh_authorized_key/parsed.rb +32 -55
  126. data/spec/unit/relationship.rb +21 -46
  127. data/spec/unit/resource.rb +30 -39
  128. data/spec/unit/resource/catalog.rb +66 -51
  129. data/spec/unit/ssl/certificate_revocation_list.rb +0 -12
  130. data/spec/unit/type/cron.rb +33 -0
  131. data/spec/unit/type/file/owner.rb +10 -4
  132. data/spec/unit/util/json.rb +9 -9
  133. data/spec/unit/util/log.rb +36 -0
  134. data/spec/unit/util/settings.rb +6 -0
  135. data/test/data/providers/ssh_authorized_key/parsed/authorized_keys2 +1 -0
  136. data/test/lib/puppettest/support/utils.rb +8 -16
  137. metadata +36 -13
  138. data/lib/puppet/feature/json.rb +0 -2
@@ -10,6 +10,7 @@ describe "the require function" do
10
10
  @compiler = Puppet::Parser::Compiler.new(@node, @parser)
11
11
 
12
12
  @compiler.send(:evaluate_main)
13
+ @compiler.catalog.client_version = "0.25"
13
14
  @scope = @compiler.topscope
14
15
  # preload our functions
15
16
  Puppet::Parser::Functions.function(:include)
@@ -20,10 +21,11 @@ describe "the require function" do
20
21
  @parser.newclass("requiredclass")
21
22
 
22
23
  @scope.function_require("requiredclass")
23
-
24
- @compiler.catalog.edge?(@scope.resource,@compiler.findresource(:class,"requiredclass")).should be_true
24
+ @scope.resource["require"].should_not be_nil
25
+ ref = @scope.resource["require"]
26
+ ref.type.should == "Class"
27
+ ref.title.should == "requiredclass"
25
28
  end
26
-
27
29
  end
28
30
 
29
31
  describe "the include function" do
@@ -17,9 +17,9 @@ describe provider_class do
17
17
  end
18
18
 
19
19
  # #1560
20
- it "should be able to parse each example" do
21
- fakedata("data/providers/mailalias/aliases").each { |file|
20
+ PuppetTest.fakedata("data/providers/mailalias/aliases").each { |file|
21
+ it "should be able to parse the examples in #{file}" do
22
22
  fakedataparse(file)
23
- }
24
- end
23
+ end
24
+ }
25
25
  end
@@ -6,10 +6,10 @@
6
6
  require File.dirname(__FILE__) + '/../../spec_helper'
7
7
 
8
8
  describe Puppet::Resource::Catalog do
9
- describe "when json is available" do
10
- confine "JSON library is missing" => Puppet.features.json?
11
- it "should support json" do
12
- Puppet::Resource::Catalog.supported_formats.should be_include(:json)
9
+ describe "when pson is available" do
10
+ confine "PSON library is missing" => Puppet.features.pson?
11
+ it "should support pson" do
12
+ Puppet::Resource::Catalog.supported_formats.should be_include(:pson)
13
13
  end
14
14
  end
15
15
 
@@ -143,6 +143,7 @@ describe "Puppet" do
143
143
  @interpreter = stub_everything
144
144
  Puppet.stubs(:err)
145
145
  @puppet.stubs(:exit)
146
+ @puppet.options.stubs(:[]).with(:code).returns "some code"
146
147
  Puppet::Parser::Interpreter.stubs(:new).returns(@interpreter)
147
148
  end
148
149
 
@@ -331,17 +332,17 @@ describe "Puppet" do
331
332
  end
332
333
 
333
334
  describe "the 'apply' command" do
334
- confine "JSON library is missing; cannot test applying catalogs" => Puppet.features.json?
335
+ confine "PSON library is missing; cannot test applying catalogs" => Puppet.features.pson?
335
336
 
336
337
  before do
337
- #Puppet::Resource::Catalog.stubs(:json_create).returns Puppet::Resource::Catalog.new
338
- JSON.stubs(:parse).returns Puppet::Resource::Catalog.new
338
+ #Puppet::Resource::Catalog.stubs(:pson_create).returns Puppet::Resource::Catalog.new
339
+ PSON.stubs(:parse).returns Puppet::Resource::Catalog.new
339
340
  end
340
341
 
341
342
  it "should read the catalog in from disk if a file name is provided" do
342
- @puppet.options[:catalog] = "/my/catalog.json"
343
+ @puppet.options[:catalog] = "/my/catalog.pson"
343
344
 
344
- File.expects(:read).with("/my/catalog.json").returns "something"
345
+ File.expects(:read).with("/my/catalog.pson").returns "something"
345
346
 
346
347
  @puppet.apply
347
348
  end
@@ -354,41 +355,41 @@ describe "Puppet" do
354
355
  @puppet.apply
355
356
  end
356
357
 
357
- it "should deserialize the catalog from json" do
358
- @puppet.options[:catalog] = "/my/catalog.json"
358
+ it "should deserialize the catalog from pson" do
359
+ @puppet.options[:catalog] = "/my/catalog.pson"
359
360
 
360
361
  File.expects(:read).returns "something"
361
- JSON.expects(:parse).with("something").returns Puppet::Resource::Catalog.new
362
+ PSON.expects(:parse).with("something").returns Puppet::Resource::Catalog.new
362
363
 
363
364
  @puppet.apply
364
365
  end
365
366
 
366
367
  it "should fail helpfully if deserializing fails" do
367
- @puppet.options[:catalog] = "/my/catalog.json"
368
+ @puppet.options[:catalog] = "/my/catalog.pson"
368
369
 
369
370
  File.expects(:read).returns "something"
370
- JSON.expects(:parse).raises ArgumentError
371
+ PSON.expects(:parse).raises ArgumentError
371
372
 
372
373
  lambda { @puppet.apply }.should raise_error(Puppet::Error)
373
374
  end
374
375
 
375
376
  it "should convert plain data structures into a catalog if deserialization does not do so" do
376
- @puppet.options[:catalog] = "/my/catalog.json"
377
+ @puppet.options[:catalog] = "/my/catalog.pson"
377
378
 
378
379
  File.expects(:read).returns "something"
379
- JSON.expects(:parse).with("something").returns({:foo => "bar"})
380
- Puppet::Resource::Catalog.expects(:json_create).with({:foo => "bar"}).returns(Puppet::Resource::Catalog.new)
380
+ PSON.expects(:parse).with("something").returns({:foo => "bar"})
381
+ Puppet::Resource::Catalog.expects(:pson_create).with({:foo => "bar"}).returns(Puppet::Resource::Catalog.new)
381
382
 
382
383
  @puppet.apply
383
384
  end
384
385
 
385
386
  it "should convert the catalog to a RAL catalog and use a Configurer instance to apply it" do
386
- @puppet.options[:catalog] = "/my/catalog.json"
387
+ @puppet.options[:catalog] = "/my/catalog.pson"
387
388
 
388
389
  File.expects(:read).returns "something"
389
390
 
390
391
  catalog = Puppet::Resource::Catalog.new
391
- JSON.expects(:parse).returns catalog
392
+ PSON.expects(:parse).returns catalog
392
393
 
393
394
  catalog.expects(:to_ral).returns "mycatalog"
394
395
 
@@ -40,7 +40,7 @@ describe "puppetd" do
40
40
 
41
41
  describe "in preinit" do
42
42
  before :each do
43
- @pupetd.stubs(:trap)
43
+ @puppetd.stubs(:trap)
44
44
  end
45
45
 
46
46
  it "should catch INT" do
@@ -320,6 +320,12 @@ describe "puppetdoc" do
320
320
  @puppetdoc.rdoc
321
321
  end
322
322
 
323
+ it "should call Puppet::Util::RDoc.rdoc in full mode with outputdir set to doc if no --outputdir" do
324
+ @puppetdoc.options.expects(:[]).with(:outputdir).returns(false)
325
+ Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests'])
326
+ @puppetdoc.rdoc
327
+ end
328
+
323
329
  it "should call Puppet::Util::RDoc.manifestdoc in manifest mode" do
324
330
  @puppetdoc.manifest = true
325
331
  Puppet::Util::RDoc.expects(:manifestdoc)
@@ -294,11 +294,11 @@ describe "PuppetMaster" do
294
294
  Puppet.stubs(:err)
295
295
  @puppetmasterd.stubs(:exit)
296
296
  Puppet::Parser::Interpreter.stubs(:new).returns(@interpreter)
297
- Puppet.features.stubs(:json?).returns true
297
+ Puppet.features.stubs(:pson?).returns true
298
298
  end
299
299
 
300
- it "should fail if json isn't available" do
301
- Puppet.features.expects(:json?).returns false
300
+ it "should fail if pson isn't available" do
301
+ Puppet.features.expects(:pson?).returns false
302
302
  lambda { @puppetmasterd.compile }.should raise_error
303
303
  end
304
304
 
@@ -310,13 +310,13 @@ describe "PuppetMaster" do
310
310
  @puppetmasterd.compile
311
311
  end
312
312
 
313
- it "should render the catalog to json and print the output" do
313
+ it "should render the catalog to pson and print the output" do
314
314
  @puppetmasterd.options[:node] = "foo"
315
315
  catalog = Puppet::Resource::Catalog.new
316
- catalog.expects(:render).with(:json).returns "myjson"
316
+ catalog.expects(:render).with(:pson).returns "mypson"
317
317
  Puppet::Resource::Catalog.expects(:find).returns catalog
318
318
 
319
- $stdout.expects(:puts).with("myjson")
319
+ $stdout.expects(:puts).with("mypson")
320
320
  @puppetmasterd.compile
321
321
  end
322
322
 
@@ -102,7 +102,7 @@ describe Puppet::Configurer::FactHandler do
102
102
 
103
103
  @facthandler.expects(:find_facts).returns facts
104
104
 
105
- @facthandler.facts_for_uploading.should == {:facts_format => :yaml, :facts => text}
105
+ @facthandler.facts_for_uploading.should == {:facts_format => :b64_zlib_yaml, :facts => text}
106
106
  end
107
107
 
108
108
  it "should properly accept facts containing a '+'" do
@@ -112,12 +112,12 @@ describe Puppet::Configurer::FactHandler do
112
112
 
113
113
  @facthandler.expects(:find_facts).returns facts
114
114
 
115
- @facthandler.facts_for_uploading.should == {:facts_format => :yaml, :facts => text}
115
+ @facthandler.facts_for_uploading.should == {:facts_format => :b64_zlib_yaml, :facts => text}
116
116
  end
117
117
 
118
118
  it "should hard-code yaml as the serialization" do
119
119
  facts = stub 'facts'
120
- facts.expects(:render).with(:yaml).returns "my text"
120
+ facts.expects(:render).with(:b64_zlib_yaml).returns "my text"
121
121
  text = CGI.escape("my text")
122
122
 
123
123
  @facthandler.expects(:find_facts).returns facts
@@ -104,17 +104,31 @@ describe Puppet::FileServing::Configuration do
104
104
 
105
105
  it "should allow all access to modules and plugins if no fileserver.conf exists" do
106
106
  FileTest.expects(:exists?).returns false # the file doesn't exist
107
- modules = stub 'modules'
107
+ modules = stub 'modules', :empty? => true
108
108
  Puppet::FileServing::Mount::Modules.stubs(:new).returns(modules)
109
109
  modules.expects(:allow).with('*')
110
110
 
111
- plugins = stub 'plugins'
111
+ plugins = stub 'plugins', :empty? => true
112
112
  Puppet::FileServing::Mount::Plugins.stubs(:new).returns(plugins)
113
113
  plugins.expects(:allow).with('*')
114
114
 
115
115
  Puppet::FileServing::Configuration.create
116
116
  end
117
117
 
118
+ it "should not allow access from all to modules and plugins if the fileserver.conf provided some rules" do
119
+ FileTest.expects(:exists?).returns false # the file doesn't exist
120
+
121
+ modules = stub 'modules', :empty? => false
122
+ Puppet::FileServing::Mount::Modules.stubs(:new).returns(modules)
123
+ modules.expects(:allow).with('*').never
124
+
125
+ plugins = stub 'plugins', :empty? => false
126
+ Puppet::FileServing::Mount::Plugins.stubs(:new).returns(plugins)
127
+ plugins.expects(:allow).with('*').never
128
+
129
+ Puppet::FileServing::Configuration.create
130
+ end
131
+
118
132
  it "should add modules and plugins mounts even if they are not returned by the parser" do
119
133
  @parser.expects(:parse).returns("one" => mock("mount"))
120
134
  FileTest.expects(:exists?).returns true # the file doesn't exist
@@ -20,4 +20,38 @@ describe Puppet::SSL::Certificate::Rest do
20
20
  it "should set port_setting to :ca_port" do
21
21
  Puppet::SSL::Certificate::Rest.port_setting.should == :ca_port
22
22
  end
23
+
24
+ it "should make sure found certificates have their names set to the search string" do
25
+ terminus = Puppet::SSL::Certificate::Rest.new
26
+
27
+ # This has 'boo.com' in the CN
28
+ cert_string = "-----BEGIN CERTIFICATE-----
29
+ MIICPzCCAaigAwIBAgIBBDANBgkqhkiG9w0BAQUFADAWMRQwEgYDVQQDDAtidWNr
30
+ eS5sb2NhbDAeFw0wOTA5MTcxNzI1MzJaFw0xNDA5MTYxNzI1MzJaMBIxEDAOBgNV
31
+ BAMMB2Jvby5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKG9B+DkTCNh
32
+ F5xHchNDfnbC9NzWKM600oxrr84pgUVAG6B2wAZcdfoEtXszhsY9Jzpwqkvxk4Mx
33
+ AbYqo9+TCi4UoiH6e+vAKOOJD3DHrlf+/RW4hGtyaI41DBhf4+B4/oFz5PH9mvKe
34
+ NSfHFI/yPW+1IXYjxKLQNwF9E7q3JbnzAgMBAAGjgaAwgZ0wOAYJYIZIAYb4QgEN
35
+ BCsWKVB1cHBldCBSdWJ5L09wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMAwG
36
+ A1UdEwEB/wQCMAAwHQYDVR0OBBYEFJOxEUeyf4cNOBmf9zIaE1JTuNdLMAsGA1Ud
37
+ DwQEAwIFoDAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwME
38
+ MA0GCSqGSIb3DQEBBQUAA4GBAFTJxKprMg6tfhGnvEvURPmlJrINn9c2b5Y4AGYp
39
+ tO86PFFkWw/EIJvvJzbj3s+Butr+eUo//+f1xxX7UCwwGqGxKqjtVS219oU/wkx8
40
+ h7rW4Xk7MrLl0auSS1p4wLcAMm+ZImf94+j8Cj+tkr8eGozZceRV13b8+EkdaE3S
41
+ rn/G
42
+ -----END CERTIFICATE-----
43
+ "
44
+
45
+ network = stub 'network'
46
+ terminus.stubs(:network).returns network
47
+
48
+ response = stub 'response', :code => "200", :body => cert_string
49
+ response.stubs(:[]).with('content-type').returns "text/plain"
50
+ network.expects(:get).returns response
51
+
52
+ request = Puppet::Indirector::Request.new(:certificate, :find, "foo.com")
53
+ result = terminus.find(request)
54
+ result.should_not be_nil
55
+ result.name.should == "foo.com"
56
+ end
23
57
  end
@@ -9,25 +9,25 @@ end
9
9
  class FooExampleData
10
10
  attr_accessor :name
11
11
 
12
- def self.json_create(json)
13
- new(json['data'].to_sym)
12
+ def self.pson_create(pson)
13
+ new(pson['data'].to_sym)
14
14
  end
15
15
 
16
16
  def initialize(name = nil)
17
17
  @name = name if name
18
18
  end
19
19
 
20
- def render(format = :json)
21
- to_json
20
+ def render(format = :pson)
21
+ to_pson
22
22
  end
23
23
 
24
- def to_json(*args)
25
- {:json_class => self.class.to_s, :data => name}.to_json(*args)
24
+ def to_pson(*args)
25
+ {:type => self.class.to_s, :data => name}.to_pson(*args)
26
26
  end
27
27
  end
28
28
 
29
29
  describe Puppet::Indirector::Queue do
30
- confine "JSON library is missing; cannot test queueing" => Puppet.features.json?
30
+ confine "PSON library is missing; cannot test queueing" => Puppet.features.pson?
31
31
 
32
32
  before :each do
33
33
  @model = mock 'model'
@@ -51,8 +51,8 @@ describe Puppet::Indirector::Queue do
51
51
  @request = stub 'request', :key => :me, :instance => @subject
52
52
  end
53
53
 
54
- it "should require JSON" do
55
- Puppet.features.expects(:json?).returns false
54
+ it "should require PSON" do
55
+ Puppet.features.expects(:pson?).returns false
56
56
 
57
57
  lambda { @store_class.new }.should raise_error(ArgumentError)
58
58
  end
@@ -63,16 +63,16 @@ describe Puppet::Indirector::Queue do
63
63
  end
64
64
 
65
65
  describe "when saving" do
66
- it 'should render the instance using json' do
67
- @subject.expects(:render).with(:json)
66
+ it 'should render the instance using pson' do
67
+ @subject.expects(:render).with(:pson)
68
68
  @store.client.stubs(:send_message)
69
69
  @store.save(@request)
70
70
  end
71
71
 
72
72
  it "should send the rendered message to the appropriate queue on the client" do
73
- @subject.expects(:render).returns "myjson"
73
+ @subject.expects(:render).returns "mypson"
74
74
 
75
- @store.client.expects(:send_message).with(:my_queue, "myjson")
75
+ @store.client.expects(:send_message).with(:my_queue, "mypson")
76
76
 
77
77
  @store.save(@request)
78
78
  end
@@ -89,8 +89,8 @@ describe Puppet::Indirector::Queue do
89
89
  @store_class.stubs(:model).returns @model
90
90
  end
91
91
 
92
- it "should use the model's Format support to intern the message from json" do
93
- @model.expects(:convert_from).with(:json, "mymessage")
92
+ it "should use the model's Format support to intern the message from pson" do
93
+ @model.expects(:convert_from).with(:pson, "mymessage")
94
94
 
95
95
  @store_class.client.expects(:subscribe).yields("mymessage")
96
96
  @store_class.subscribe {|o| o }
@@ -90,15 +90,37 @@ describe Puppet::Indirector::REST do
90
90
  @searcher.deserialize(response).should be_nil
91
91
  end
92
92
 
93
- it "should fail if the response code is not in the 200s" do
94
- @model.expects(:convert_from).never
95
-
96
- response = mock 'response'
97
- response.stubs(:code).returns "300"
98
- response.stubs(:message).returns "There was a problem"
99
-
100
- lambda { @searcher.deserialize(response) }.should raise_error(Net::HTTPError)
101
- end
93
+ [300,400,403,405,500,501,502,503,504].each { |rc|
94
+ describe "when the response code is #{rc}" do
95
+ before :each do
96
+ @model.expects(:convert_from).never
97
+
98
+ @response = mock 'response'
99
+ @response.stubs(:code).returns rc.to_s
100
+ @response.stubs(:message).returns "There was a problem (header)"
101
+ end
102
+
103
+ it "should fail" do
104
+ @response.stubs(:body).returns nil
105
+ lambda { @searcher.deserialize(@response) }.should raise_error(Net::HTTPError)
106
+ end
107
+
108
+ it "should take the error message from the body, if present" do
109
+ @response.stubs(:body).returns "There was a problem (body)"
110
+ lambda { @searcher.deserialize(@response) }.should raise_error(Net::HTTPError,"Error #{rc} on SERVER: There was a problem (body)")
111
+ end
112
+
113
+ it "should take the error message from the response header if the body is empty" do
114
+ @response.stubs(:body).returns ""
115
+ lambda { @searcher.deserialize(@response) }.should raise_error(Net::HTTPError,"Error #{rc} on SERVER: There was a problem (header)")
116
+ end
117
+
118
+ it "should take the error message from the response header if the body is absent" do
119
+ @response.stubs(:body).returns nil
120
+ lambda { @searcher.deserialize(@response) }.should raise_error(Net::HTTPError,"Error #{rc} on SERVER: There was a problem (header)")
121
+ end
122
+ end
123
+ }
102
124
 
103
125
  it "should return the results of converting from the format specified by the content-type header if the response code is in the 200s" do
104
126
  @model.expects(:convert_from).with("myformat", "mydata").returns "myobject"
@@ -4,27 +4,78 @@ require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
5
  require 'puppet/network/authconfig'
6
6
 
7
- describe Puppet::Network::AuthStore::Declaration do
8
-
9
- describe "when the pattern is simple numeric IP" do
7
+ describe Puppet::Network::AuthStore do
8
+ describe "when checking if the acl has some entries" do
10
9
  before :each do
11
- @ip = '100.101.99.98'
12
- @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,@ip)
10
+ @authstore = Puppet::Network::AuthStore.new
13
11
  end
14
- it "should match the specified IP" do
15
- @declaration.should be_match('www.testsite.org',@ip)
12
+
13
+ it "should be empty if no ACE have been entered" do
14
+ @authstore.should be_empty
16
15
  end
17
- it "should not match other IPs" do
18
- @declaration.should_not be_match('www.testsite.org','200.101.99.98')
16
+
17
+ it "should not be empty if it is a global allow" do
18
+ @authstore.allow('*')
19
+
20
+ @authstore.should_not be_empty
21
+ end
22
+
23
+ it "should not be empty if at least one allow has been entered" do
24
+ @authstore.allow('1.1.1.*')
25
+
26
+ @authstore.should_not be_empty
27
+ end
28
+
29
+ it "should not be empty if at least one deny has been entered" do
30
+ @authstore.deny('1.1.1.*')
31
+
32
+ @authstore.should_not be_empty
19
33
  end
20
34
  end
35
+ end
36
+
37
+ describe Puppet::Network::AuthStore::Declaration do
38
+
39
+ ['100.101.99.98','100.100.100.100','1.2.3.4','11.22.33.44'].each { |ip|
40
+ describe "when the pattern is a simple numeric IP such as #{ip}" do
41
+ before :each do
42
+ @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,ip)
43
+ end
44
+ it "should match the specified IP" do
45
+ @declaration.should be_match('www.testsite.org',ip)
46
+ end
47
+ it "should not match other IPs" do
48
+ @declaration.should_not be_match('www.testsite.org','200.101.99.98')
49
+ end
50
+ end
51
+
52
+ (1..3).each { |n|
53
+ describe "when the pattern is a IP mask with #{n} numeric segments and a *" do
54
+ before :each do
55
+ @ip_pattern = ip.split('.')[0,n].join('.')+'.*'
56
+ @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,@ip_pattern)
57
+ end
58
+ it "should match an IP in the range" do
59
+ @declaration.should be_match('www.testsite.org',ip)
60
+ end
61
+ it "should not match other IPs" do
62
+ @declaration.should_not be_match('www.testsite.org','200.101.99.98')
63
+ end
64
+ it "should not match IPs that differ in the last non-wildcard segment" do
65
+ other = ip.split('.')
66
+ other[n-1].succ!
67
+ @declaration.should_not be_match('www.testsite.org',other.join('.'))
68
+ end
69
+ end
70
+ }
71
+ }
21
72
 
22
73
  describe "when the pattern is a numeric IP with a back reference" do
23
74
  before :each do
24
75
  @ip = '100.101.$1'
25
76
  @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,@ip).interpolate('12.34'.match(/(.*)/))
26
77
  end
27
- it "should match an IP with the apropriate interpolation" do
78
+ it "should match an IP with the appropriate interpolation" do
28
79
  @declaration.should be_match('www.testsite.org',@ip.sub(/\$1/,'12.34'))
29
80
  end
30
81
  it "should not match other IPs" do
@@ -32,20 +83,25 @@ describe Puppet::Network::AuthStore::Declaration do
32
83
  end
33
84
  end
34
85
 
35
- describe "when the pattern is a PQDN" do
36
- before :each do
37
- @host = 'spirit.mars.nasa.gov'
38
- @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,@host)
39
- end
40
- it "should match the specified PQDN" do
41
- pending "FQDN consensus"
42
- @declaration.should be_match(@host,'200.101.99.98')
43
- end
44
- it "should not match a similar FQDN" do
45
- pending "FQDN consensus"
46
- @declaration.should_not be_match(@host+'.','200.101.99.98')
47
- end
48
- end
86
+ {
87
+ 'spirit.mars.nasa.gov' => 'a PQDN',
88
+ 'ratchet.2ndsiteinc.com' => 'a PQDN with digits',
89
+ 'a.c.ru' => 'a PQDN with short segments',
90
+ }.each {|pqdn,desc|
91
+ describe "when the pattern is #{desc}" do
92
+ before :each do
93
+ @host = pqdn
94
+ @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,@host)
95
+ end
96
+ it "should match the specified PQDN" do
97
+ @declaration.should be_match(@host,'200.101.99.98')
98
+ end
99
+ it "should not match a similar FQDN" do
100
+ pending "FQDN consensus"
101
+ @declaration.should_not be_match(@host+'.','200.101.99.98')
102
+ end
103
+ end
104
+ }
49
105
 
50
106
  describe "when the pattern is a FQDN" do
51
107
  before :each do
@@ -57,7 +113,6 @@ describe Puppet::Network::AuthStore::Declaration do
57
113
  @declaration.should be_match(@host,'200.101.99.98')
58
114
  end
59
115
  it "should not match a similar PQDN" do
60
- #pending "FQDN consensus"
61
116
  @declaration.should_not be_match(@host[0..-2],'200.101.99.98')
62
117
  end
63
118
  end
@@ -70,7 +125,31 @@ describe Puppet::Network::AuthStore::Declaration do
70
125
  @pattern = %{^/catalog/([^/]+)$}
71
126
  @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,'$1')
72
127
  end
73
- it "should match an IP with the apropriate interpolation" do
128
+ it "should match an IP with the appropriate interpolation" do
129
+ @declaration.interpolate(@item.match(@pattern)).should be_match(@host,'10.0.0.5')
130
+ end
131
+ end
132
+
133
+ describe "when the pattern is an opaque string with a back reference and the matched data contains dots" do
134
+ before :each do
135
+ @host = 'admin.mgmt.nym1'
136
+ @item = "/catalog/#{@host}"
137
+ @pattern = %{^/catalog/([^/]+)$}
138
+ @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,'$1')
139
+ end
140
+ it "should match a name with the appropriate interpolation" do
141
+ @declaration.interpolate(@item.match(@pattern)).should be_match(@host,'10.0.0.5')
142
+ end
143
+ end
144
+
145
+ describe "when the pattern is an opaque string with a back reference and the matched data contains dots with an initial prefix that looks like an IP address" do
146
+ before :each do
147
+ @host = '01.admin.mgmt.nym1'
148
+ @item = "/catalog/#{@host}"
149
+ @pattern = %{^/catalog/([^/]+)$}
150
+ @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,'$1')
151
+ end
152
+ it "should match a name with the appropriate interpolation" do
74
153
  @declaration.interpolate(@item.match(@pattern)).should be_match(@host,'10.0.0.5')
75
154
  end
76
155
  end