puppet 0.24.6 → 0.24.7
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 +115 -0
- data/Rakefile +43 -14
- data/bin/puppetca +6 -5
- data/bin/puppetdoc +109 -15
- data/bin/ralsh +3 -1
- data/conf/redhat/puppet.spec +74 -48
- data/examples/mcx_dock_absent.pp +4 -0
- data/examples/mcx_dock_default.pp +118 -0
- data/examples/mcx_dock_full.pp +125 -0
- data/examples/mcx_dock_invalid.pp +9 -0
- data/examples/mcx_nogroup.pp +118 -0
- data/examples/mcx_notexists_absent.pp +4 -0
- data/ext/emacs/puppet-mode.el +1 -1
- data/lib/puppet.rb +1 -1
- data/lib/puppet/external/nagios/base.rb +114 -71
- data/lib/puppet/feature/base.rb +6 -0
- data/lib/puppet/indirector/yaml.rb +12 -3
- data/lib/puppet/module.rb +1 -1
- data/lib/puppet/network/client/master.rb +1 -1
- data/lib/puppet/network/xmlrpc/client.rb +3 -1
- data/lib/puppet/parameter.rb +1 -1
- data/lib/puppet/parser/ast.rb +15 -0
- data/lib/puppet/parser/ast/astarray.rb +1 -2
- data/lib/puppet/parser/ast/casestatement.rb +2 -0
- data/lib/puppet/parser/ast/collection.rb +2 -0
- data/lib/puppet/parser/ast/comparison_operator.rb +4 -0
- data/lib/puppet/parser/ast/definition.rb +2 -0
- data/lib/puppet/parser/ast/else.rb +3 -0
- data/lib/puppet/parser/ast/function.rb +19 -12
- data/lib/puppet/parser/ast/hostclass.rb +9 -1
- data/lib/puppet/parser/ast/ifstatement.rb +3 -0
- data/lib/puppet/parser/ast/node.rb +3 -0
- data/lib/puppet/parser/ast/resource.rb +3 -0
- data/lib/puppet/parser/ast/resource_defaults.rb +2 -0
- data/lib/puppet/parser/ast/resource_override.rb +3 -0
- data/lib/puppet/parser/ast/vardef.rb +3 -0
- data/lib/puppet/parser/functions.rb +14 -0
- data/lib/puppet/parser/functions/inline_template.rb +21 -0
- data/lib/puppet/parser/functions/template.rb +3 -2
- data/lib/puppet/parser/lexer.rb +56 -7
- data/lib/puppet/parser/parser.rb +114 -98
- data/lib/puppet/parser/parser_support.rb +24 -4
- data/lib/puppet/parser/resource/reference.rb +4 -3
- data/lib/puppet/parser/templatewrapper.rb +30 -22
- data/lib/puppet/property.rb +1 -1
- data/lib/puppet/property/list.rb +7 -2
- data/lib/puppet/property/ordered_list.rb +22 -0
- data/lib/puppet/provider/augeas/augeas.rb +189 -0
- data/lib/puppet/provider/computer/computer.rb +22 -0
- data/lib/puppet/provider/confine.rb +4 -1
- data/lib/puppet/provider/confine/variable.rb +13 -2
- data/lib/puppet/provider/confine_collection.rb +4 -1
- data/lib/puppet/provider/confiner.rb +1 -1
- data/lib/puppet/provider/group/directoryservice.rb +6 -3
- data/lib/puppet/provider/group/groupadd.rb +5 -2
- data/lib/puppet/provider/group/ldap.rb +11 -9
- data/lib/puppet/provider/group/netinfo.rb +8 -4
- data/lib/puppet/provider/group/pw.rb +5 -1
- data/lib/puppet/provider/host/netinfo.rb +5 -2
- data/lib/puppet/provider/macauthorization/macauthorization.rb +315 -0
- data/lib/puppet/provider/mcx/mcxcontent.rb +201 -0
- data/lib/puppet/provider/nameservice/directoryservice.rb +210 -107
- data/lib/puppet/provider/nameservice/netinfo.rb +7 -2
- data/lib/puppet/provider/package/appdmg.rb +0 -3
- data/lib/puppet/provider/package/apt.rb +6 -0
- data/lib/puppet/provider/package/rpm.rb +2 -0
- data/lib/puppet/provider/package/yum.rb +5 -1
- data/lib/puppet/provider/package/yumhelper.py +9 -0
- data/lib/puppet/provider/service/base.rb +9 -6
- data/lib/puppet/provider/service/daemontools.rb +25 -15
- data/lib/puppet/provider/service/debian.rb +6 -2
- data/lib/puppet/provider/service/freebsd.rb +5 -2
- data/lib/puppet/provider/service/gentoo.rb +6 -3
- data/lib/puppet/provider/service/init.rb +31 -21
- data/lib/puppet/provider/service/launchd.rb +195 -0
- data/lib/puppet/provider/service/redhat.rb +5 -2
- data/lib/puppet/provider/service/runit.rb +30 -20
- data/lib/puppet/provider/service/smf.rb +7 -4
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +21 -1
- data/lib/puppet/provider/user/directoryservice.rb +1 -0
- data/lib/puppet/provider/user/netinfo.rb +9 -3
- data/lib/puppet/provider/user/user_role_add.rb +43 -6
- data/lib/puppet/provider/zfs/solaris.rb +45 -0
- data/lib/puppet/provider/zone/solaris.rb +8 -4
- data/lib/puppet/provider/zpool/solaris.rb +116 -0
- data/lib/puppet/rails/database/003_add_environment_to_host.rb +9 -0
- data/lib/puppet/rails/database/schema.rb +1 -0
- data/lib/puppet/rails/host.rb +4 -0
- data/lib/puppet/reference/configuration.rb +1 -1
- data/lib/puppet/reports/tagmail.rb +15 -6
- data/lib/puppet/transaction/change.rb +3 -5
- data/lib/puppet/transportable.rb +1 -0
- data/lib/puppet/type/augeas.rb +155 -0
- data/lib/puppet/type/computer.rb +62 -0
- data/lib/puppet/type/exec.rb +2 -1
- data/lib/puppet/type/file.rb +1 -1
- data/lib/puppet/type/file/ensure.rb +8 -5
- data/lib/puppet/type/file/mode.rb +0 -14
- data/lib/puppet/type/file/owner.rb +32 -64
- data/lib/puppet/type/file/selcontext.rb +3 -8
- data/lib/puppet/type/group.rb +27 -45
- data/lib/puppet/type/k5login.rb +1 -1
- data/lib/puppet/type/macauthorization.rb +141 -0
- data/lib/puppet/type/mcx.rb +115 -0
- data/lib/puppet/type/mount.rb +1 -1
- data/lib/puppet/type/nagios_hostdependency.rb +3 -0
- data/lib/puppet/type/ssh_authorized_key.rb +16 -0
- data/lib/puppet/type/tidy.rb +43 -14
- data/lib/puppet/type/user.rb +25 -1
- data/lib/puppet/type/zfs.rb +51 -0
- data/lib/puppet/type/zone.rb +8 -0
- data/lib/puppet/type/zpool.rb +93 -0
- data/lib/puppet/util.rb +17 -38
- data/lib/puppet/util/file_locking.rb +44 -0
- data/lib/puppet/util/filetype.rb +3 -3
- data/lib/puppet/util/log.rb +1 -16
- data/lib/puppet/util/metric.rb +0 -5
- data/lib/puppet/util/rdoc.rb +85 -0
- data/lib/puppet/util/rdoc/code_objects.rb +219 -0
- data/lib/puppet/util/rdoc/generators/puppet_generator.rb +829 -0
- data/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb +1051 -0
- data/lib/puppet/util/rdoc/parser.rb +437 -0
- data/lib/puppet/util/selinux.rb +135 -63
- data/lib/puppet/util/settings.rb +136 -126
- data/lib/puppet/util/storage.rb +4 -2
- data/spec/Rakefile +91 -0
- data/spec/integration/checksum.rb +47 -0
- data/spec/integration/defaults.rb +47 -0
- data/spec/integration/file_serving/configuration.rb +43 -0
- data/spec/integration/file_serving/content.rb +18 -0
- data/spec/integration/file_serving/metadata.rb +18 -0
- data/spec/integration/indirector/direct_file_server.rb +80 -0
- data/spec/integration/indirector/file_content/file_server.rb +18 -0
- data/spec/integration/indirector/file_metadata/file_server.rb +18 -0
- data/spec/integration/indirector/module_files.rb +57 -0
- data/spec/integration/indirector/node/ldap.rb +15 -0
- data/spec/integration/indirector/rest.rb +464 -0
- data/spec/integration/network/server/mongrel.rb +48 -0
- data/spec/integration/network/server/webrick.rb +48 -0
- data/spec/integration/node.rb +93 -0
- data/spec/integration/node/catalog.rb +54 -0
- data/spec/integration/node/facts.rb +45 -0
- data/spec/integration/provider/package.rb +26 -0
- data/spec/integration/provider/service/init.rb +32 -0
- data/spec/integration/reference/providers.rb +17 -0
- data/spec/integration/reports.rb +14 -0
- data/spec/integration/transaction/report.rb +26 -0
- data/spec/integration/type/package.rb +22 -0
- data/spec/integration/util/file_locking.rb +36 -0
- data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +46 -0
- data/spec/monkey_patches/alias_should_to_must.rb +5 -0
- data/spec/shared_behaviours/file_server_terminus.rb +42 -0
- data/spec/shared_behaviours/file_serving.rb +64 -0
- data/spec/shared_behaviours/memory_terminus.rb +32 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/unit/executables/client/certhandler.rb +122 -0
- data/spec/unit/file_serving/configuration.rb +224 -0
- data/spec/unit/file_serving/configuration/parser.rb +135 -0
- data/spec/unit/file_serving/content.rb +71 -0
- data/spec/unit/file_serving/file_base.rb +124 -0
- data/spec/unit/file_serving/fileset.rb +239 -0
- data/spec/unit/file_serving/indirection_hooks.rb +124 -0
- data/spec/unit/file_serving/metadata.rb +187 -0
- data/spec/unit/file_serving/mount.rb +143 -0
- data/spec/unit/file_serving/terminus_helper.rb +76 -0
- data/spec/unit/indirector.rb +152 -0
- data/spec/unit/indirector/catalog/compiler.rb +156 -0
- data/spec/unit/indirector/catalog/yaml.rb +25 -0
- data/spec/unit/indirector/checksum/file.rb +139 -0
- data/spec/unit/indirector/code.rb +33 -0
- data/spec/unit/indirector/direct_file_server.rb +89 -0
- data/spec/unit/indirector/envelope.rb +47 -0
- data/spec/unit/indirector/exec.rb +51 -0
- data/spec/unit/indirector/facts/facter.rb +76 -0
- data/spec/unit/indirector/facts/yaml.rb +26 -0
- data/spec/unit/indirector/file.rb +154 -0
- data/spec/unit/indirector/file_content/file.rb +18 -0
- data/spec/unit/indirector/file_content/file_server.rb +18 -0
- data/spec/unit/indirector/file_content/modules.rb +18 -0
- data/spec/unit/indirector/file_content/rest.rb +11 -0
- data/spec/unit/indirector/file_metadata/file.rb +52 -0
- data/spec/unit/indirector/file_metadata/file_server.rb +18 -0
- data/spec/unit/indirector/file_metadata/modules.rb +42 -0
- data/spec/unit/indirector/file_metadata/rest.rb +9 -0
- data/spec/unit/indirector/file_server.rb +184 -0
- data/spec/unit/indirector/indirection.rb +731 -0
- data/spec/unit/indirector/ldap.rb +143 -0
- data/spec/unit/indirector/memory.rb +29 -0
- data/spec/unit/indirector/module_files.rb +259 -0
- data/spec/unit/indirector/node/exec.rb +69 -0
- data/spec/unit/indirector/node/ldap.rb +424 -0
- data/spec/unit/indirector/node/memory.rb +19 -0
- data/spec/unit/indirector/node/plain.rb +19 -0
- data/spec/unit/indirector/node/rest.rb +13 -0
- data/spec/unit/indirector/node/yaml.rb +25 -0
- data/spec/unit/indirector/plain.rb +29 -0
- data/spec/unit/indirector/report/processor.rb +81 -0
- data/spec/unit/indirector/request.rb +87 -0
- data/spec/unit/indirector/rest.rb +372 -0
- data/spec/unit/indirector/ssl_rsa/file.rb +116 -0
- data/spec/unit/indirector/terminus.rb +245 -0
- data/spec/unit/indirector/yaml.rb +145 -0
- data/spec/unit/module.rb +247 -0
- data/spec/unit/network/client.rb +45 -0
- data/spec/unit/network/client/master.rb +442 -0
- data/spec/unit/network/handler/fileserver.rb +179 -0
- data/spec/unit/network/http.rb +35 -0
- data/spec/unit/network/http/mongrel.rb +117 -0
- data/spec/unit/network/http/mongrel/rest.rb +377 -0
- data/spec/unit/network/http/mongrel/xmlrpc.rb +0 -0
- data/spec/unit/network/http/webrick.rb +127 -0
- data/spec/unit/network/http/webrick/rest.rb +323 -0
- data/spec/unit/network/http/webrick/xmlrpc.rb +0 -0
- data/spec/unit/network/http_pool.rb +238 -0
- data/spec/unit/network/server.rb +316 -0
- data/spec/unit/network/xmlrpc/client.rb +13 -0
- data/spec/unit/node.rb +167 -0
- data/spec/unit/node/catalog.rb +864 -0
- data/spec/unit/node/environment.rb +37 -0
- data/spec/unit/node/facts.rb +44 -0
- data/spec/unit/other/checksum.rb +92 -0
- data/spec/unit/other/pgraph.rb +210 -0
- data/spec/unit/other/transaction.rb +33 -0
- data/spec/unit/other/transbucket.rb +172 -0
- data/spec/unit/other/transobject.rb +92 -0
- data/spec/unit/parameter.rb +24 -0
- data/spec/unit/parser/ast.rb +37 -0
- data/spec/unit/parser/ast/arithmetic_operator.rb +73 -0
- data/spec/unit/parser/ast/astarray.rb +66 -0
- data/spec/unit/parser/ast/boolean_operator.rb +53 -0
- data/spec/unit/parser/ast/collexpr.rb +92 -0
- data/spec/unit/parser/ast/comparison_operator.rb +92 -0
- data/spec/unit/parser/ast/definition.rb +195 -0
- data/spec/unit/parser/ast/function.rb +77 -0
- data/spec/unit/parser/ast/hostclass.rb +148 -0
- data/spec/unit/parser/ast/minus.rb +36 -0
- data/spec/unit/parser/ast/node.rb +125 -0
- data/spec/unit/parser/ast/nop.rb +20 -0
- data/spec/unit/parser/ast/not.rb +30 -0
- data/spec/unit/parser/ast/resource_override.rb +51 -0
- data/spec/unit/parser/ast/resource_reference.rb +63 -0
- data/spec/unit/parser/ast/vardef.rb +47 -0
- data/spec/unit/parser/collector.rb +426 -0
- data/spec/unit/parser/compiler.rb +561 -0
- data/spec/unit/parser/functions.rb +83 -0
- data/spec/unit/parser/functions/inline_template.rb +59 -0
- data/spec/unit/parser/functions/template.rb +62 -0
- data/spec/unit/parser/interpreter.rb +138 -0
- data/spec/unit/parser/lexer.rb +646 -0
- data/spec/unit/parser/parser.rb +228 -0
- data/spec/unit/parser/resource.rb +336 -0
- data/spec/unit/parser/resource/reference.rb +95 -0
- data/spec/unit/parser/scope.rb +87 -0
- data/spec/unit/parser/templatewrapper.rb +129 -0
- data/spec/unit/property.rb +35 -0
- data/spec/unit/property/keyvalue.rb +168 -0
- data/spec/unit/property/list.rb +156 -0
- data/spec/unit/property/ordered_list.rb +64 -0
- data/spec/unit/provider/augeas/augeas.rb +238 -0
- data/spec/unit/provider/confine.rb +78 -0
- data/spec/unit/provider/confine/exists.rb +81 -0
- data/spec/unit/provider/confine/false.rb +53 -0
- data/spec/unit/provider/confine/feature.rb +60 -0
- data/spec/unit/provider/confine/true.rb +53 -0
- data/spec/unit/provider/confine/variable.rb +107 -0
- data/spec/unit/provider/confine_collection.rb +134 -0
- data/spec/unit/provider/confiner.rb +63 -0
- data/spec/unit/provider/group/groupadd.rb +31 -0
- data/spec/unit/provider/group/ldap.rb +105 -0
- data/spec/unit/provider/ldap.rb +248 -0
- data/spec/unit/provider/macauthorization.rb +147 -0
- data/spec/unit/provider/mcx/mcxcontent.rb +175 -0
- data/spec/unit/provider/mount.rb +130 -0
- data/spec/unit/provider/mount/parsed.rb +185 -0
- data/spec/unit/provider/package/apt.rb +138 -0
- data/spec/unit/provider/package/dpkg.rb +163 -0
- data/spec/unit/provider/package/gem.rb +87 -0
- data/spec/unit/provider/package/hpux.rb +52 -0
- data/spec/unit/provider/selboolean.rb +37 -0
- data/spec/unit/provider/selmodule-example.pp +0 -0
- data/spec/unit/provider/selmodule.rb +66 -0
- data/spec/unit/provider/service/daemontools.rb +124 -0
- data/spec/unit/provider/service/launchd.rb +134 -0
- data/spec/unit/provider/service/runit.rb +117 -0
- data/spec/unit/provider/ssh_authorized_key/parsed.rb +102 -0
- data/spec/unit/provider/user/hpux.rb +25 -0
- data/spec/unit/provider/user/ldap.rb +279 -0
- data/spec/unit/provider/user/user_role_add.rb +249 -0
- data/spec/unit/provider/user/useradd.rb +115 -0
- data/spec/unit/provider/zfs/solaris.rb +87 -0
- data/spec/unit/provider/zone/solaris.rb +42 -0
- data/spec/unit/provider/zpool/solaris.rb +179 -0
- data/spec/unit/rails.rb +125 -0
- data/spec/unit/relationship.rb +149 -0
- data/spec/unit/reports.rb +61 -0
- data/spec/unit/resource_reference.rb +73 -0
- data/spec/unit/simple_graph.rb +280 -0
- data/spec/unit/transaction/change.rb +187 -0
- data/spec/unit/transaction/event.rb +25 -0
- data/spec/unit/transaction/report.rb +40 -0
- data/spec/unit/type.rb +64 -0
- data/spec/unit/type/augeas.rb +113 -0
- data/spec/unit/type/computer.rb +82 -0
- data/spec/unit/type/exec.rb +91 -0
- data/spec/unit/type/file.rb +155 -0
- data/spec/unit/type/file/ensure.rb +21 -0
- data/spec/unit/type/file/group.rb +118 -0
- data/spec/unit/type/file/owner.rb +132 -0
- data/spec/unit/type/file/selinux.rb +82 -0
- data/spec/unit/type/group.rb +40 -0
- data/spec/unit/type/macauthorization.rb +78 -0
- data/spec/unit/type/mcx.rb +108 -0
- data/spec/unit/type/mount.rb +219 -0
- data/spec/unit/type/nagios.rb +63 -0
- data/spec/unit/type/noop_metaparam.rb +38 -0
- data/spec/unit/type/package.rb +246 -0
- data/spec/unit/type/resources.rb +27 -0
- data/spec/unit/type/schedule.rb +339 -0
- data/spec/unit/type/selboolean.rb +47 -0
- data/spec/unit/type/selmodule.rb +18 -0
- data/spec/unit/type/service.rb +254 -0
- data/spec/unit/type/ssh_authorized_key.rb +106 -0
- data/spec/unit/type/tidy.rb +68 -0
- data/spec/unit/type/user.rb +260 -0
- data/spec/unit/type/zfs.rb +45 -0
- data/spec/unit/type/zone.rb +20 -0
- data/spec/unit/type/zpool.rb +110 -0
- data/spec/unit/util/checksums.rb +99 -0
- data/spec/unit/util/constant_inflector.rb +70 -0
- data/spec/unit/util/file_locking.rb +115 -0
- data/spec/unit/util/ldap/connection.rb +169 -0
- data/spec/unit/util/ldap/generator.rb +54 -0
- data/spec/unit/util/ldap/manager.rb +654 -0
- data/spec/unit/util/loadedfile.rb +65 -0
- data/spec/unit/util/log.rb +107 -0
- data/spec/unit/util/metric.rb +95 -0
- data/spec/unit/util/nagios_maker.rb +128 -0
- data/spec/unit/util/posix.rb +256 -0
- data/spec/unit/util/resource_template.rb +58 -0
- data/spec/unit/util/selinux.rb +219 -0
- data/spec/unit/util/settings.rb +847 -0
- data/spec/unit/util/storage.rb +248 -0
- data/spec/unit/util/tagging.rb +92 -0
- data/spec/unit/util/uri_helper.rb +41 -0
- data/spec/unit/util/user_attr.rb +47 -0
- data/spec/unit/util/warnings.rb +35 -0
- data/test/certmgr/support.rb +0 -6
- data/test/data/providers/ssh_authorized_key/parsed/authorized_keys +1 -0
- data/test/data/snippets/multilinecomments.pp +6 -0
- data/test/data/snippets/multipleclass.pp +9 -0
- data/test/language/functions.rb +11 -1
- data/test/language/snippets.rb +16 -0
- data/test/lib/puppettest/runnable_test.rb +1 -1
- data/test/network/handler/fileserver.rb +5 -0
- data/test/other/report.rb +0 -4
- data/test/ral/type/resources.rb +2 -19
- data/test/util/settings.rb +4 -4
- data/test/util/storage.rb +0 -24
- data/test/util/utiltest.rb +0 -33
- metadata +319 -26
- data/conf/debian/README.source +0 -2
- data/conf/debian/TODO.Debian +0 -1
- data/conf/debian/changelog +0 -257
- data/conf/debian/compat +0 -1
- data/conf/debian/control +0 -45
- data/conf/debian/copyright +0 -17
- data/conf/debian/docs +0 -1
- data/conf/debian/fileserver.conf +0 -12
- data/conf/debian/puppet.NEWS +0 -63
- data/conf/debian/puppet.conf +0 -8
- data/conf/debian/puppet.dirs +0 -7
- data/conf/debian/puppet.files +0 -6
- data/conf/debian/puppet.init +0 -64
- data/conf/debian/puppet.logrotate +0 -11
- data/conf/debian/puppet.postinst +0 -9
- data/conf/debian/puppet.postrm +0 -21
- data/conf/debian/puppet.preinst +0 -25
- data/conf/debian/puppetmaster.files +0 -4
- data/conf/debian/puppetmaster.init +0 -58
- data/conf/debian/rules +0 -115
- data/conf/debian/watch +0 -2
- data/lib/puppet/type/nagios_hostgroupescalation.rb +0 -3
@@ -0,0 +1,179 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
4
|
+
|
5
|
+
require 'puppet/network/handler/fileserver'
|
6
|
+
|
7
|
+
|
8
|
+
describe Puppet::Network::Handler::FileServer do
|
9
|
+
require 'tmpdir'
|
10
|
+
|
11
|
+
def create_file(filename)
|
12
|
+
File.open(filename, "w") { |f| f.puts filename}
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_nested_file()
|
16
|
+
dirname = File.join(@basedir, "nested_dir")
|
17
|
+
Dir.mkdir(dirname)
|
18
|
+
file = File.join(dirname, "nested_dir_file")
|
19
|
+
create_file(file)
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
@basedir = File.join(Dir.tmpdir(), "test_network_handler")
|
24
|
+
Dir.mkdir(@basedir)
|
25
|
+
@file = File.join(@basedir, "aFile")
|
26
|
+
@link = File.join(@basedir, "aLink")
|
27
|
+
create_file(@file)
|
28
|
+
@mount = Puppet::Network::Handler::FileServer::Mount.new("some_path", @basedir)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should list a single directory" do
|
32
|
+
@mount.list("/", false, false).should == [["/", "directory"]]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should list a file within a directory when given the file path" do
|
36
|
+
@mount.list("/aFile", false, "false").should == [["/", "file"]]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should list a file within a directory when given the file path with recursion" do
|
40
|
+
@mount.list("/aFile", true, "false").should == [["/", "file"]]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return nil for a non-existent path" do
|
44
|
+
@mount.list("/no_such_file", false, false).should be(nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should list a symbolic link as a file when given the link path" do
|
48
|
+
File.symlink(@file, @link)
|
49
|
+
@mount.list("/aLink", false, false).should == [["/", "file"]]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return nil for a dangling symbolic link when given the link path" do
|
53
|
+
File.symlink("/some/where", @link)
|
54
|
+
@mount.list("/aLink", false, false).should be(nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should list directory contents of a flat directory structure when asked to recurse" do
|
58
|
+
list = @mount.list("/", true, false)
|
59
|
+
list.should include(["/aFile", "file"])
|
60
|
+
list.should include(["/", "directory"])
|
61
|
+
list.should have(2).items
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should list the contents of a nested directory" do
|
65
|
+
create_nested_file()
|
66
|
+
list = @mount.list("/", true, false)
|
67
|
+
list.sort.should == [ ["/aFile", "file"], ["/", "directory"] ,
|
68
|
+
["/nested_dir", "directory"], ["/nested_dir/nested_dir_file", "file"]].sort
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should list the contents of a directory ignoring files that match" do
|
72
|
+
create_nested_file()
|
73
|
+
list = @mount.list("/", true, "*File")
|
74
|
+
list.sort.should == [ ["/", "directory"] ,
|
75
|
+
["/nested_dir", "directory"], ["/nested_dir/nested_dir_file", "file"]].sort
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should list the contents of a directory ignoring directories that match" do
|
79
|
+
create_nested_file()
|
80
|
+
list = @mount.list("/", true, "*nested_dir")
|
81
|
+
list.sort.should == [ ["/aFile", "file"], ["/", "directory"] ].sort
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should list the contents of a directory ignoring all ignore patterns that match" do
|
85
|
+
create_nested_file()
|
86
|
+
list = @mount.list("/", true, ["*File" , "*nested_dir"])
|
87
|
+
list.should == [ ["/", "directory"] ]
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should list the directory when recursing to a depth of zero" do
|
91
|
+
create_nested_file()
|
92
|
+
list = @mount.list("/", 0, false)
|
93
|
+
list.should == [["/", "directory"]]
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should list the base directory and files and nested directory to a depth of one" do
|
97
|
+
create_nested_file()
|
98
|
+
list = @mount.list("/", 1, false)
|
99
|
+
list.sort.should == [ ["/aFile", "file"], ["/nested_dir", "directory"], ["/", "directory"] ].sort
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should list the base directory and files and nested directory to a depth of two" do
|
103
|
+
create_nested_file()
|
104
|
+
list = @mount.list("/", 2, false)
|
105
|
+
list.sort.should == [ ["/aFile", "file"], ["/", "directory"] ,
|
106
|
+
["/nested_dir", "directory"], ["/nested_dir/nested_dir_file", "file"]].sort
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should list the base directory and files and nested directory to a depth greater than the directory structure" do
|
110
|
+
create_nested_file()
|
111
|
+
list = @mount.list("/", 42, false)
|
112
|
+
list.sort.should == [ ["/aFile", "file"], ["/", "directory"] ,
|
113
|
+
["/nested_dir", "directory"], ["/nested_dir/nested_dir_file", "file"]].sort
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should list a valid symbolic link as a file when recursing base dir" do
|
117
|
+
File.symlink(@file, @link)
|
118
|
+
list = @mount.list("/", true, false)
|
119
|
+
list.sort.should == [ ["/", "directory"], ["/aFile", "file"], ["/aLink", "file"] ].sort
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should not error when a dangling symlink is present" do
|
123
|
+
File.symlink("/some/where", @link)
|
124
|
+
lambda { @mount.list("/", true, false) }.should_not raise_error
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return the directory contents of valid entries when a dangling symlink is present" do
|
128
|
+
File.symlink("/some/where", @link)
|
129
|
+
list = @mount.list("/", true, false)
|
130
|
+
list.sort.should == [ ["/aFile", "file"], ["/", "directory"] ].sort
|
131
|
+
end
|
132
|
+
|
133
|
+
describe Puppet::Network::Handler::FileServer::PluginMount do
|
134
|
+
PLUGINS = Puppet::Network::Handler::FileServer::PLUGINS
|
135
|
+
|
136
|
+
# create a module plugin hierarchy
|
137
|
+
def create_plugin(mod, plugin)
|
138
|
+
dirname = File.join(@basedir, mod)
|
139
|
+
Dir.mkdir(dirname)
|
140
|
+
plugins = File.join(dirname, PLUGINS)
|
141
|
+
Dir.mkdir(plugins)
|
142
|
+
facter = File.join(plugins, plugin)
|
143
|
+
Dir.mkdir(facter)
|
144
|
+
create_file(File.join(facter,"fact.rb"))
|
145
|
+
end
|
146
|
+
|
147
|
+
before :each do
|
148
|
+
@modules = ["one","two"]
|
149
|
+
Puppet::Module.stubs(:all).returns(@modules.collect{ |p| File.join(@basedir,p)} )
|
150
|
+
@modules.each { |m| create_plugin(m, "facter") }
|
151
|
+
|
152
|
+
@modules.each do |p|
|
153
|
+
File.stubs(:directory?).with(File.join(@basedir,p,PLUGINS)).returns(true)
|
154
|
+
end
|
155
|
+
|
156
|
+
@mount = Puppet::Network::Handler::FileServer::PluginMount.new(PLUGINS)
|
157
|
+
@mount.allow("*")
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should list a file within a directory when given the file path with recursion" do
|
161
|
+
@mount.list("facter/fact.rb", true, "false").should == [["/", "file"], ["/", "file"]]
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should return a merged view of all plugins for all modules" do
|
165
|
+
list = @mount.list("facter",true,false)
|
166
|
+
list.should == [["/", "directory"], ["/fact.rb", "file"], ["/", "directory"], ["/fact.rb", "file"]]
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should not fail for inexistant plugins type" do
|
170
|
+
lambda { @mount.list("puppet/parser",true,false) }.should_not raise_error
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
after do
|
176
|
+
FileUtils.rm_rf(@basedir)
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Rick Bradley on 2007-10-03.
|
4
|
+
# Copyright (c) 2007. All rights reserved.
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
7
|
+
|
8
|
+
require 'puppet/network/http'
|
9
|
+
|
10
|
+
describe Puppet::Network::HTTP do
|
11
|
+
it "should return the webrick HTTP server class when asked for a webrick server" do
|
12
|
+
Puppet::Network::HTTP.server_class_by_type(:webrick).should be(Puppet::Network::HTTP::WEBrick)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "when asked for a mongrel server" do
|
16
|
+
if Puppet.features.mongrel?
|
17
|
+
it "should return the mongrel server class" do
|
18
|
+
Puppet::Network::HTTP.server_class_by_type(:mongrel).should be(Puppet::Network::HTTP::Mongrel)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
it "should fail" do
|
22
|
+
lambda { Puppet::Network::HTTP.server_class_by_type(:mongrel) }.should raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should fail to return the mongrel HTTP server class if mongrel is not available " do
|
28
|
+
Puppet.features.expects(:mongrel?).returns(false)
|
29
|
+
Proc.new { Puppet::Network::HTTP.server_class_by_type(:mongrel) }.should raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return an error when asked for an unknown server" do
|
33
|
+
Proc.new { Puppet::Network::HTTP.server_class_by_type :foo }.should raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Rick Bradley on 2007-10-15.
|
4
|
+
# Copyright (c) 2007. All rights reserved.
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
7
|
+
require 'puppet/network/http'
|
8
|
+
|
9
|
+
describe "Puppet::Network::HTTP::Mongrel", "after initializing" do
|
10
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
11
|
+
|
12
|
+
it "should not be listening" do
|
13
|
+
require 'puppet/network/http/mongrel'
|
14
|
+
|
15
|
+
Puppet::Network::HTTP::Mongrel.new.should_not be_listening
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do
|
20
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
21
|
+
|
22
|
+
before do
|
23
|
+
require 'puppet/network/http/mongrel'
|
24
|
+
|
25
|
+
@server = Puppet::Network::HTTP::Mongrel.new
|
26
|
+
@mock_mongrel = mock('mongrel')
|
27
|
+
@mock_mongrel.stubs(:run)
|
28
|
+
@mock_mongrel.stubs(:register)
|
29
|
+
Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel)
|
30
|
+
@listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :catalog ], :protocols => [ :rest ] }
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should fail if already listening" do
|
34
|
+
@server.listen(@listen_params)
|
35
|
+
Proc.new { @server.listen(@listen_params) }.should raise_error(RuntimeError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should require at least one handler" do
|
39
|
+
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :handlers == k}) }.should raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should require at least one protocol" do
|
43
|
+
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :protocols == k}) }.should raise_error(ArgumentError)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should require a listening address to be specified" do
|
47
|
+
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :address == k})}.should raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should require a listening port to be specified" do
|
51
|
+
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :port == k})}.should raise_error(ArgumentError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should order a mongrel server to start" do
|
55
|
+
@mock_mongrel.expects(:run)
|
56
|
+
@server.listen(@listen_params)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should tell mongrel to listen on the specified address and port" do
|
60
|
+
Mongrel::HttpServer.expects(:new).with("127.0.0.1", 31337).returns(@mock_mongrel)
|
61
|
+
@server.listen(@listen_params)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be listening" do
|
65
|
+
Mongrel::HttpServer.expects(:new).returns(@mock_mongrel)
|
66
|
+
@server.listen(@listen_params)
|
67
|
+
@server.should be_listening
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should instantiate a handler for each protocol+handler pair to configure web server routing" do
|
71
|
+
@listen_params[:protocols].each do |protocol|
|
72
|
+
@listen_params[:handlers].each do |handler|
|
73
|
+
@mock_mongrel.expects(:register)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
@server.listen(@listen_params)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should use a Mongrel + REST class to configure Mongrel when REST services are requested" do
|
80
|
+
@server.expects(:class_for_protocol).with(:rest).at_least_once.returns(Puppet::Network::HTTP::MongrelREST)
|
81
|
+
@server.listen(@listen_params)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should fail if services from an unknown protocol are requested" do
|
85
|
+
Proc.new { @server.listen(@listen_params.merge(:protocols => [ :foo ]))}.should raise_error(ArgumentError)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "Puppet::Network::HTTP::Mongrel", "when turning off listening" do
|
90
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
91
|
+
|
92
|
+
before do
|
93
|
+
@mock_mongrel = mock('mongrel httpserver')
|
94
|
+
@mock_mongrel.stubs(:run)
|
95
|
+
@mock_mongrel.stubs(:register)
|
96
|
+
Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel)
|
97
|
+
@server = Puppet::Network::HTTP::Mongrel.new
|
98
|
+
@listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :catalog ], :protocols => [ :rest ] }
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should fail unless listening" do
|
102
|
+
Proc.new { @server.unlisten }.should raise_error(RuntimeError)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should order mongrel server to stop" do
|
106
|
+
@server.listen(@listen_params)
|
107
|
+
@mock_mongrel.expects(:stop)
|
108
|
+
@server.unlisten
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should not be listening" do
|
112
|
+
@server.listen(@listen_params)
|
113
|
+
@mock_mongrel.stubs(:stop)
|
114
|
+
@server.unlisten
|
115
|
+
@server.should_not be_listening
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,377 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../spec_helper'
|
4
|
+
require 'puppet/network/http'
|
5
|
+
|
6
|
+
describe "Puppet::Network::HTTP::MongrelREST", "when initializing" do
|
7
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
8
|
+
|
9
|
+
before do
|
10
|
+
require 'puppet/network/http/mongrel/rest'
|
11
|
+
|
12
|
+
@mock_mongrel = mock('Mongrel server')
|
13
|
+
@mock_mongrel.stubs(:register)
|
14
|
+
@mock_model = mock('indirected model')
|
15
|
+
Puppet::Indirector::Indirection.stubs(:model).with(:foo).returns(@mock_model)
|
16
|
+
@params = { :server => @mock_mongrel, :handler => :foo }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should require access to a Mongrel server" do
|
20
|
+
Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params.delete_if {|k,v| :server == k })}.should raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should require an indirection name" do
|
24
|
+
Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params.delete_if {|k,v| :handler == k })}.should raise_error(ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should look up the indirection model from the indirection name" do
|
28
|
+
Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(@mock_model)
|
29
|
+
Puppet::Network::HTTP::MongrelREST.new(@params)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should fail if the indirection is not known" do
|
33
|
+
Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(nil)
|
34
|
+
Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params) }.should raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "Puppet::Network::HTTP::MongrelREST", "when receiving a request" do
|
39
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
40
|
+
|
41
|
+
before do
|
42
|
+
@mock_request = stub('mongrel http request')
|
43
|
+
@mock_head = stub('response head')
|
44
|
+
@mock_body = stub('response body', :write => true)
|
45
|
+
@mock_response = stub('mongrel http response')
|
46
|
+
@mock_response.stubs(:start).yields(@mock_head, @mock_body)
|
47
|
+
@mock_model_class = stub('indirected model class')
|
48
|
+
@mock_mongrel = stub('mongrel http server', :register => true)
|
49
|
+
Puppet::Indirector::Indirection.stubs(:model).with(:foo).returns(@mock_model_class)
|
50
|
+
@handler = Puppet::Network::HTTP::MongrelREST.new(:server => @mock_mongrel, :handler => :foo)
|
51
|
+
end
|
52
|
+
|
53
|
+
def setup_find_request(params = {})
|
54
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET',
|
55
|
+
Mongrel::Const::REQUEST_PATH => '/foo/key',
|
56
|
+
'QUERY_STRING' => ''}.merge(params))
|
57
|
+
@mock_model_class.stubs(:find)
|
58
|
+
end
|
59
|
+
|
60
|
+
def setup_search_request(params = {})
|
61
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET',
|
62
|
+
Mongrel::Const::REQUEST_PATH => '/foos',
|
63
|
+
'QUERY_STRING' => '' }.merge(params))
|
64
|
+
@mock_model_class.stubs(:search).returns([])
|
65
|
+
end
|
66
|
+
|
67
|
+
def setup_destroy_request(params = {})
|
68
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'DELETE',
|
69
|
+
Mongrel::Const::REQUEST_PATH => '/foo/key',
|
70
|
+
'QUERY_STRING' => '' }.merge(params))
|
71
|
+
@mock_model_class.stubs(:destroy)
|
72
|
+
end
|
73
|
+
|
74
|
+
def setup_save_request(params = {})
|
75
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'PUT',
|
76
|
+
Mongrel::Const::REQUEST_PATH => '/foo',
|
77
|
+
'QUERY_STRING' => '' }.merge(params))
|
78
|
+
@mock_request.stubs(:body).returns('this is a fake request body')
|
79
|
+
@mock_model_instance = stub('indirected model instance', :save => true)
|
80
|
+
@mock_model_class.stubs(:from_yaml).returns(@mock_model_instance)
|
81
|
+
end
|
82
|
+
|
83
|
+
def setup_bad_request
|
84
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'POST', Mongrel::Const::REQUEST_PATH => '/foos'})
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should call the model find method if the request represents a singular HTTP GET" do
|
88
|
+
setup_find_request
|
89
|
+
@mock_model_class.expects(:find).with { |key, args| key == 'key' }
|
90
|
+
@handler.process(@mock_request, @mock_response)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should call the model search method if the request represents a plural HTTP GET" do
|
94
|
+
setup_search_request
|
95
|
+
@mock_model_class.expects(:search).returns([])
|
96
|
+
@handler.process(@mock_request, @mock_response)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should call the model destroy method if the request represents an HTTP DELETE" do
|
100
|
+
setup_destroy_request
|
101
|
+
@mock_model_class.expects(:destroy).with { |key, args| key == 'key' }
|
102
|
+
@handler.process(@mock_request, @mock_response)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should call the model save method if the request represents an HTTP PUT" do
|
106
|
+
setup_save_request
|
107
|
+
@mock_model_instance.expects(:save)
|
108
|
+
@handler.process(@mock_request, @mock_response)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should fail if the HTTP method isn't supported" do
|
112
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'POST', Mongrel::Const::REQUEST_PATH => '/foo'})
|
113
|
+
@mock_response.expects(:start).with(404)
|
114
|
+
@handler.process(@mock_request, @mock_response)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should fail if the request's pluralization is wrong" do
|
118
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'DELETE', Mongrel::Const::REQUEST_PATH => '/foos/key'})
|
119
|
+
@mock_response.expects(:start).with(404)
|
120
|
+
@handler.process(@mock_request, @mock_response)
|
121
|
+
|
122
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'PUT', Mongrel::Const::REQUEST_PATH => '/foos/key'})
|
123
|
+
@mock_response.expects(:start).with(404)
|
124
|
+
@handler.process(@mock_request, @mock_response)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should fail if the request is for an unknown path" do
|
128
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET',
|
129
|
+
Mongrel::Const::REQUEST_PATH => '/bar/key',
|
130
|
+
'QUERY_STRING' => '' })
|
131
|
+
@mock_response.expects(:start).with(404)
|
132
|
+
@handler.process(@mock_request, @mock_response)
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "and determining the request parameters", :shared => true do
|
136
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
137
|
+
|
138
|
+
before do
|
139
|
+
@mock_request.stubs(:params).returns({})
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should include the HTTP request parameters" do
|
143
|
+
@mock_request.expects(:params).returns('QUERY_STRING' => 'foo=baz&bar=xyzzy')
|
144
|
+
result = @handler.params(@mock_request)
|
145
|
+
result["foo"].should == "baz"
|
146
|
+
result["bar"].should == "xyzzy"
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should pass the client's ip address to model find" do
|
150
|
+
@mock_request.stubs(:params).returns("REMOTE_ADDR" => "ipaddress")
|
151
|
+
@handler.params(@mock_request)[:ip].should == "ipaddress"
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should use the :ssl_client_header to determine the parameter when looking for the certificate" do
|
155
|
+
Puppet.settings.stubs(:value).returns "eh"
|
156
|
+
Puppet.settings.expects(:value).with(:ssl_client_header).returns "myheader"
|
157
|
+
@mock_request.stubs(:params).returns("myheader" => "/CN=host.domain.com")
|
158
|
+
@handler.params(@mock_request)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should retrieve the hostname by matching the certificate parameter" do
|
162
|
+
Puppet.settings.stubs(:value).returns "eh"
|
163
|
+
Puppet.settings.expects(:value).with(:ssl_client_header).returns "myheader"
|
164
|
+
@mock_request.stubs(:params).returns("myheader" => "/CN=host.domain.com")
|
165
|
+
@handler.params(@mock_request)[:node].should == "host.domain.com"
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should use the :ssl_client_header to determine the parameter for checking whether the host certificate is valid" do
|
169
|
+
Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
|
170
|
+
Puppet.settings.expects(:value).with(:ssl_client_verify_header).returns "myheader"
|
171
|
+
@mock_request.stubs(:params).returns("myheader" => "SUCCESS", "certheader" => "/CN=host.domain.com")
|
172
|
+
@handler.params(@mock_request)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should consider the host authenticated if the validity parameter contains 'SUCCESS'" do
|
176
|
+
Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
|
177
|
+
Puppet.settings.stubs(:value).with(:ssl_client_verify_header).returns "myheader"
|
178
|
+
@mock_request.stubs(:params).returns("myheader" => "SUCCESS", "certheader" => "/CN=host.domain.com")
|
179
|
+
@handler.params(@mock_request)[:authenticated].should be_true
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should consider the host unauthenticated if the validity parameter does not contain 'SUCCESS'" do
|
183
|
+
Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
|
184
|
+
Puppet.settings.stubs(:value).with(:ssl_client_verify_header).returns "myheader"
|
185
|
+
@mock_request.stubs(:params).returns("myheader" => "whatever", "certheader" => "/CN=host.domain.com")
|
186
|
+
@handler.params(@mock_request)[:authenticated].should be_false
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should consider the host unauthenticated if no certificate information is present" do
|
190
|
+
Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
|
191
|
+
Puppet.settings.stubs(:value).with(:ssl_client_verify_header).returns "myheader"
|
192
|
+
@mock_request.stubs(:params).returns("myheader" => nil, "certheader" => "SUCCESS")
|
193
|
+
@handler.params(@mock_request)[:authenticated].should be_false
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should not pass a node name to model method if no certificate information is present" do
|
197
|
+
Puppet.settings.stubs(:value).returns "eh"
|
198
|
+
Puppet.settings.expects(:value).with(:ssl_client_header).returns "myheader"
|
199
|
+
@mock_request.stubs(:params).returns("myheader" => nil)
|
200
|
+
@handler.params(@mock_request).should_not be_include(:node)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "when finding a model instance" do |variable|
|
205
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
206
|
+
|
207
|
+
it "should fail to find model if key is not specified" do
|
208
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET', Mongrel::Const::REQUEST_PATH => '/foo'})
|
209
|
+
@mock_response.expects(:start).with(404)
|
210
|
+
@handler.process(@mock_request, @mock_response)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should use a common method for determining the request parameters" do
|
214
|
+
setup_find_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
|
215
|
+
@handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy)
|
216
|
+
@mock_model_class.expects(:find).with do |key, args|
|
217
|
+
args[:foo] == :baz and args[:bar] == :xyzzy
|
218
|
+
end
|
219
|
+
@handler.process(@mock_request, @mock_response)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should generate a 200 response when a model find call succeeds" do
|
223
|
+
setup_find_request
|
224
|
+
@mock_response.expects(:start).with(200)
|
225
|
+
@handler.process(@mock_request, @mock_response)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should return a serialized object when a model find call succeeds" do
|
229
|
+
setup_find_request
|
230
|
+
@mock_model_instance = stub('model instance')
|
231
|
+
@mock_model_instance.expects(:to_yaml)
|
232
|
+
@mock_model_class.stubs(:find).returns(@mock_model_instance)
|
233
|
+
@handler.process(@mock_request, @mock_response)
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should serialize a controller exception when an exception is thrown by find" do
|
237
|
+
setup_find_request
|
238
|
+
@mock_model_class.expects(:find).raises(ArgumentError)
|
239
|
+
@mock_response.expects(:start).with(404)
|
240
|
+
@handler.process(@mock_request, @mock_response)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "when destroying a model instance" do |variable|
|
245
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
246
|
+
|
247
|
+
it "should fail to destroy model if key is not specified" do
|
248
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'DELETE', Mongrel::Const::REQUEST_PATH => '/foo'})
|
249
|
+
@mock_response.expects(:start).with(404)
|
250
|
+
@handler.process(@mock_request, @mock_response)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should use a common method for determining the request parameters" do
|
254
|
+
setup_destroy_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
|
255
|
+
@handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy)
|
256
|
+
@mock_model_class.expects(:destroy).with do |key, args|
|
257
|
+
args[:foo] == :baz and args[:bar] == :xyzzy
|
258
|
+
end
|
259
|
+
@handler.process(@mock_request, @mock_response)
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should pass HTTP request parameters to model destroy" do
|
263
|
+
setup_destroy_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
|
264
|
+
@mock_model_class.expects(:destroy).with do |key, args|
|
265
|
+
key == 'key' and args['foo'] == 'baz' and args['bar'] == 'xyzzy'
|
266
|
+
end
|
267
|
+
@handler.process(@mock_request, @mock_response)
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should generate a 200 response when a model destroy call succeeds" do
|
271
|
+
setup_destroy_request
|
272
|
+
@mock_response.expects(:start).with(200)
|
273
|
+
@handler.process(@mock_request, @mock_response)
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should return a serialized success result when a model destroy call succeeds" do
|
277
|
+
setup_destroy_request
|
278
|
+
@mock_model_class.stubs(:destroy).returns(true)
|
279
|
+
@mock_body.expects(:write).with("--- true\n")
|
280
|
+
@handler.process(@mock_request, @mock_response)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should serialize a controller exception when an exception is thrown by destroy" do
|
284
|
+
setup_destroy_request
|
285
|
+
@mock_model_class.expects(:destroy).raises(ArgumentError)
|
286
|
+
@mock_response.expects(:start).with(404)
|
287
|
+
@handler.process(@mock_request, @mock_response)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "when saving a model instance" do |variable|
|
292
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
293
|
+
|
294
|
+
it "should fail to save model if data is not specified" do
|
295
|
+
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'PUT', Mongrel::Const::REQUEST_PATH => '/foo'})
|
296
|
+
@mock_request.stubs(:body).returns('')
|
297
|
+
@mock_response.expects(:start).with(404)
|
298
|
+
@handler.process(@mock_request, @mock_response)
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should use a common method for determining the request parameters" do
|
302
|
+
setup_save_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
|
303
|
+
@handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy)
|
304
|
+
@mock_model_instance.expects(:save).with do |args|
|
305
|
+
args[:foo] == :baz and args[:bar] == :xyzzy
|
306
|
+
end
|
307
|
+
@handler.process(@mock_request, @mock_response)
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should generate a 200 response when a model save call succeeds" do
|
311
|
+
setup_save_request
|
312
|
+
@mock_response.expects(:start).with(200)
|
313
|
+
@handler.process(@mock_request, @mock_response)
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should return a serialized object when a model save call succeeds" do
|
317
|
+
setup_save_request
|
318
|
+
@mock_model_instance.stubs(:save).returns(@mock_model_instance)
|
319
|
+
@mock_model_instance.expects(:to_yaml).returns('foo')
|
320
|
+
@handler.process(@mock_request, @mock_response)
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should serialize a controller exception when an exception is thrown by save" do
|
324
|
+
setup_save_request
|
325
|
+
@mock_model_instance.expects(:save).raises(ArgumentError)
|
326
|
+
@mock_response.expects(:start).with(404)
|
327
|
+
@handler.process(@mock_request, @mock_response)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
describe "when searching for model instances" do |variable|
|
332
|
+
confine "Mongrel is not available" => Puppet.features.mongrel?
|
333
|
+
|
334
|
+
it "should use a common method for determining the request parameters" do
|
335
|
+
setup_search_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
|
336
|
+
@handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy)
|
337
|
+
@mock_model_class.expects(:search).with do |args|
|
338
|
+
args[:foo] == :baz and args[:bar] == :xyzzy
|
339
|
+
end
|
340
|
+
@handler.process(@mock_request, @mock_response)
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should pass HTTP request parameters to model search" do
|
344
|
+
setup_search_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
|
345
|
+
@mock_model_class.expects(:search).with do |args|
|
346
|
+
args['foo'] == 'baz' and args['bar'] == 'xyzzy'
|
347
|
+
end.returns([])
|
348
|
+
@handler.process(@mock_request, @mock_response)
|
349
|
+
end
|
350
|
+
|
351
|
+
it "should generate a 200 response when a model search call succeeds" do
|
352
|
+
setup_search_request
|
353
|
+
@mock_response.expects(:start).with(200)
|
354
|
+
@handler.process(@mock_request, @mock_response)
|
355
|
+
end
|
356
|
+
|
357
|
+
it "should return a list of serialized objects when a model search call succeeds" do
|
358
|
+
setup_search_request
|
359
|
+
mock_matches = [1..5].collect {|i| mock("model instance #{i}", :to_yaml => "model instance #{i}") }
|
360
|
+
@mock_model_class.stubs(:search).returns(mock_matches)
|
361
|
+
@handler.process(@mock_request, @mock_response)
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should serialize a controller exception when an exception is thrown by search" do
|
365
|
+
setup_search_request
|
366
|
+
@mock_model_class.expects(:search).raises(ArgumentError)
|
367
|
+
@mock_response.expects(:start).with(404)
|
368
|
+
@handler.process(@mock_request, @mock_response)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
it "should serialize a controller exception if the request fails" do
|
373
|
+
setup_bad_request
|
374
|
+
@mock_response.expects(:start).with(404)
|
375
|
+
@handler.process(@mock_request, @mock_response)
|
376
|
+
end
|
377
|
+
end
|