Signed-off-by: Michael Stahnke <sta...@puppetlabs.com>
Signed-off-by: Mo Morsi <mmo...@redhat.com>
---
Local-branch: feature/master/7474
CHANGELOG | 120 +++++++++++++++++++++++++++++++++++++++++++++++
conf/redhat/puppet.spec | 7 ++-
conf/solaris/pkginfo | 2 +-
conf/suse/puppet.spec | 7 ++-
lib/puppet.rb | 2 +-
5 files changed, 132 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index be49f3e..423bc6b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,123 @@
+2.7.2rc1
+===
+902c414 Update configurer_spec.rb to work with Ruby 1.8.5
+7ad1b04 Clean up indentation, whitespace, and commented out code
+014d952 Remove order dependency from functions integration spec
+243aaa9 (#7956) Porting cron tests
+3e3fc69 (#7956) Port resource acceptance tests
+534ccfe (#8048) Gem install puppet no longer fails if rdoc enabled.
+bbde5b5 Readying for release of 2.6.9
+5160822 Clean up indentation, whitespace, and commented out code
+92a8f4a Remove order dependency from functions integration spec
+31554c0 (#6854) Update Red Hat spec file
+cba645c Bumping release in lib/puppet.rb and updating CHANGELOG.
+43027de Bumping RPM spec file to 2.6.9rc1.
+99330fa (#7224) Reword 'hostname was not match' error message
+1d867b0 (#7224) Add a helper to Puppet::SSL::Certificate to retrieve alternate names
+db1a392 (#7506) Organize READMEs; specify supported Ruby versions in README.md
+de06469 (#5641) Help text: document that puppet doc takes modulepath, manifestdir, and environment options
+381fa40 (#6418) Make test 64118 more portable
+98ba407 (#7127) Stop puppet if a prerun command fails
+6996e0b Do not needlessly create multiple reports when creating a transaction
+caca469 (#4416) Ensure types are providified after reloading
+413b136 (#4416) Always remove old provider before recreating it
+d866ce1 Cleanup indentation, comment, and unused code
+d1c965a Make temporary auth.conf in acceptance test readable by Puppet
+4af9784 (#7117) Use a different auth.conf instead of overwriting the default
+ecde134 (#3360) Delete SSL directory in acceptance test before running
+b502423 Update acceptance tests to use with_master_running_on
+053e613 Remove pending copy of an active acceptance test
+98f58ce (#2128) Add WARNING for node_name_{fact,value} descriptions
+1cd848c (#2128) Whitespace only reflow commit
+d9b5c1a (#2128) In-line docs for node_name_{fact,value}
+3f0dbb5 (#650) Allow symlinks for configuration directories
+c260cf1 Fix acceptance tests not managing their masters
+1c70f0c (#2128) Add support for setting node name based on a fact
+c629958 (#2128) Get facts before retrieving catalog
+cd4fe14 (#2128) Add the ability to specify a node name
+8ebec1e (#7193) Fix path issues with acceptance tests that call old shell tests
+16b2311 (#6885) puppet agent fingerprint requires --verbose to return a value.
+77a5987 maint: Confine augeas specs to require the augeas feature
+8eb0e16 (#2728) Add diff output for changes made by Augeas provider
+a00fd25 maint: Refactor specs in preparation for making node name more flexible
+2f8bc26 maint: Fix order dependent test failure
+c02126d (#5966) Add support for hostname regular expressions in auth.conf
+75e2764 (#5318) Always notice changes to manifests when compiling.
+bc71266 maint: Fix order dependent spec failure for face indirection
+6547835 (#7690) Don't blow up when listing terminuses available for faces
+0bcbca5 maint: Dedup the loadpath so we don't have to walk it multiple times
+4a5e99d (#7681) Add an acceptance test for resource refs with array variables
+996dc07 Maint: Fix ellipses for short descriptions
+53af6f3 (#7563) DRY: Remove indirector boilerplate from individual faces
+74aff59 (#7564) Finish templates
+3026333 (#7561) Complete help text for all faces and actions
+13e473e Maint: Add ellipsis to generated short_descriptions.
+89d447b (#6962) Add "arguments" method to help API
+646919e (4123) Fix test for 4123/4 on old egrep in cent4
+b101804 add puppet master polling step for ticket 7117
+9145569 maint: Remove reliance on system clock from schedule spec tests
+107b38a maint: Fix pacman provider to work with Ruby 1.9
+8eea3f5 Added the vcsrepo type and providers to the core
+8f0cecf Added the vcsrepo type and providers to the core
+4645c99 add puppet master polling step for ticket 7117
+17e7223 (#7507) Add exclude filter for ruby 1.9 spec failures
+181098b (#7502) Fixed parser spec for ruby 1.8.5
+9c3bedd (#7507) Add more 1.9 filters
+f037662 (#6395) Add extpuppet help, eval, and interfaces
+4d4d587 Adding a sleep state post starting master
+c81f5c6 Adding a sleep state post starting master
+d1cc24f maint: fix spec_helper inclusions again.
+3ac7aed (#7523) Refactor the grammar to reduce duplication
+d22b130 (#7114) Fix specs for ssh authorized key parsed provider
+551cb3e (#7114) Target returns correct value
+15c6fc7 (#7114) Add integration tests for authorized_key
+a5ac82a (#7114) Improve unit tests for ssh_authorized_key
+1c7f0c3 (#7114) Improve value validation for authorized_key
+0b8ebac (#7300) Fix instances method of mount provider
+1dc662a (#1853) Pacman package provider
+6bb2a85 (#1853) Pacman package provider
+c8775f9 (#7259) Remove ActiveRecord requirement from indirector face spec
+1ad8158 (#7259) Do not try to load all Terminus classes when configuring the Indirector
+8b76be3 (#3836) External nodes should only capture stdout
+d63fc34 Revert "(#7220) Add the ability to "inherit" options."
+c21539f maint: sync 'authconfig' to 'rest_authconfig' setting
+81d566f Fixed #7481 - Added MIT license to Thomas Bellman's function code
+1695dac (#7264) Docs: Clarify that subscribe/notify imply require/before
+8f907f2 adding test for ticket 7139
+90eb937 (#7139) Accept '/' as a valid path in filesets
+1f3b8e7 (#7300) Add specs for the mount provider
+1b2a7d9 case seems needless here as there is only two opts, also the rest of the file seems to use if so this should make things more consistant
+729336e (#6845) Mount writes incorrect vfstab entries
+16cf1ac (#6442) Be able to start agents --listen without namespaceauth.conf
+e059539 Update CHANGELOG for 2.6.8
+ac0581f (#7101) Fix template error messages in Ruby 1.8.5
+9d2500e (#7101) Fix template error messages in Ruby 1.8.5
+0352402 (#3420) Nagios "name" attribute does not output correctly
+f656818 (#4487) When setting environment on a host, ensure it is a string.
+89e9a21 add test for ticket 7101
+74498af add test for ticket 7101
+2cce326 add test for ticket 7101
+c1edcb2 add test for ticket 7101
+9329a1f (#7220) Add the ability to "inherit" options.
+c306db2 (#6487) Add some testing for OS X version support in DirectoryService provider
+0008b63 (#6487) Directoryservice provider will fail in future OS releases
+f21162b (#6368) Make the File type autorequire its nearest ancestor directory
+c3a76a9 (#7021) Fix order dependent spec failures
+7bd6a2f maint: Remove unused code
+34f9f41 Maint: Fix a #4655 introduced log inconsistency
+6981ee5 Maint: Fix a #4655 introduced log inconsistency
+cb43cfc Moving tests from Puppet-acceptance repo
+ac428b9 Move tests from Puppet-acceptance repo
+db26326 Move tests from puppet-acceptance repo
+6b18f8f Move acceptance tests from puppet-acceptance repo
+9a5bf6e Fixed #7166 - Replaced deprecated stomp "send" method with "publish"
+a18ac78 maint: Fix PSON order dependency in test
+656eff8 (#4655) Allow stage to be set using a default class parameter
+b3ab0d9 (#4655) Allow stage to be set using a default class parameter
+7d3c303 Fixed #7166 - Replaced deprecated stomp "send" method with "publish"
+7f658e6 vim: Initial ftplugin and indent support
+ccbe9f3 Fixed #6681 - Remove --force-yes option from aptitude is used
+
2.7.1
===
a49d5b8 (#8048) Gem install puppet no longer fails if rdoc enabled.
diff --git a/conf/redhat/puppet.spec b/conf/redhat/puppet.spec
index 4581c48..7a58665 100644
--- a/conf/redhat/puppet.spec
+++ b/conf/redhat/puppet.spec
@@ -5,8 +5,8 @@
%global confdir conf/redhat
Name: puppet
-Version: 2.6.9
-Release: 1%{?dist}
+Version: 2.7.2
+Release: 0.1.rc1%{?dist}
Summary: A network tool for managing many disparate systems
License: Apache 2.0
URL: http://puppetlabs.com
@@ -253,6 +253,9 @@ fi
rm -rf %{buildroot}
%changelog
+* Wed Jul 06 2011 Michael Stahnke <sta...@puppetlabs.com> - 2.7.2-0.1rc1
+- Update to 2.7.2rc1
+
* Tue Jun 21 2011 Michael Stahnke <sta...@puppetlabs.com> - 2.6.9-1
- Release of 2.6.9
diff --git a/conf/solaris/pkginfo b/conf/solaris/pkginfo
index 14a2f0a..547f489 100644
--- a/conf/solaris/pkginfo
+++ b/conf/solaris/pkginfo
@@ -1,6 +1,6 @@
PKG=CSWpuppet
NAME=puppet - System Automation Framework
-VERSION=2.7.0
+VERSION=2.7.2
CATEGORY=application
VENDOR=http://projects.puppetlabs.com/projects/puppet
EMAIL=lu...@puppetlabs.com
diff --git a/conf/suse/puppet.spec b/conf/suse/puppet.spec
index 2a5b9f4..0613045 100644
--- a/conf/suse/puppet.spec
+++ b/conf/suse/puppet.spec
@@ -4,8 +4,8 @@
Summary: A network tool for managing many disparate systems
Name: puppet
-Version: 2.6.1
-Release: 1%{?dist}
+Version: 2.7.2
+Release: 0.1rc1%{?dist}
License: Apache 2.0
Group: Productivity/Networking/System
@@ -136,6 +136,9 @@ find %{buildroot}%{ruby_sitelibdir} -type f -perm +ugo+x -exec chmod a-x '{}' \;
%{__rm} -rf %{buildroot}
%changelog
+* Wed Jul 06 2011 Michael Stahnke <sta...@puppetlabs.com> - 2.7.2-0.1rc1
+- Updating to 2.7.2rc1
+
* Tue Sep 14 2010 Ben Kevan <ben....@gmail.com> - 2.6.1
- New version to 2.6.1
- Add client.init and server.init from source since it's now included in the packages
diff --git a/lib/puppet.rb b/lib/puppet.rb
index c895da9..765c95c 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -24,7 +24,7 @@ require 'puppet/util/run_mode'
# it's also a place to find top-level commands like 'debug'
module Puppet
- PUPPETVERSION = '2.7.1'
+ PUPPETVERSION = '2.7.2'
def Puppet.version
PUPPETVERSION
--
1.7.5.4
This is the second revision of the patch I had previous sent out,
including put and delete methods, better session security and
handling, and many more tests
Signed-off-by: Mo Morsi <mmo...@redhat.com>
---
Local-branch: feature/master/7474
lib/puppet/external/curl.rb | 77 ++++++++++++++++++++++
lib/puppet/provider/web/curl.rb | 100 ++++++++++++++++++++++++++++
lib/puppet/type/web.rb | 110 +++++++++++++++++++++++++++++++
spec/unit/provider/web/curl_spec.rb | 122 +++++++++++++++++++++++++++++++++++
spec/unit/type/web_spec.rb | 90 ++++++++++++++++++++++++++
5 files changed, 499 insertions(+), 0 deletions(-)
create mode 100644 lib/puppet/external/curl.rb
create mode 100644 lib/puppet/provider/web/curl.rb
create mode 100644 lib/puppet/type/web.rb
create mode 100644 spec/unit/provider/web/curl_spec.rb
create mode 100644 spec/unit/type/web_spec.rb
diff --git a/lib/puppet/external/curl.rb b/lib/puppet/external/curl.rb
new file mode 100644
index 0000000..ecffb5e
--- /dev/null
+++ b/lib/puppet/external/curl.rb
@@ -0,0 +1,77 @@
+# Provides an interface to curl using the curb gem for puppet
+require 'curb'
+
+# uses nokogiri to verify responses w/ xpath
+require 'nokogiri'
+
+class Curl::Easy
+
+ # Format request parameters for the specified request method
+ def self.format_params(method, params)
+ if([:get, :delete].include?(method))
+ return params.collect { |k,v| "#{k}=#{v}" }.join("&") unless params.nil?
+ return ""
+ end
+ # post, put:
+ cparams = []
+ params.each_pair { |k,v| cparams << Curl::PostField.content(k,v) } unless params.nil?
+ return cparams
+ end
+
+ # Format a url for the specified request method, base uri, and parameters
+ def self.format_url(method, uri, params)
+ if([:get, :delete].include?(method))
+ url = uri
+ url += ";" + format_params(method, params)
+ return url
+ end
+ # post, put:
+ return uri
+ end
+
+ # Invoke a new curl request and return result
+ def self.web_request(method, uri, request_params, params = {})
+ raise Puppet::Error, "Must specify http method (#{method}) and uri (#{uri})" if method.nil? || uri.nil?
+
+ curl = self.new
+
+ if params.has_key?(:cookie) && !params[:cookie].nil?
+ curl.enable_cookies = true
+ curl.cookiefile = params[:cookie]
+ curl.cookiejar = params[:cookie]
+ end
+
+ curl.follow_location = (params.has_key?(:follow) && params[:follow])
+
+ case(method)
+ when 'get'
+ curl.url = format_url(method, uri, request_params)
+ curl.http_get
+ return curl
+
+ when 'post'
+ curl.url = format_url(method, uri, request_params)
+ curl.http_post(format_params(method, request_params))
+ return curl
+
+ when 'put'
+ curl.url = format_url(method, uri, request_params)
+ curl.http_put(format_params(method, request_params))
+ return curl
+
+ when 'delete'
+ curl.url = format_url(method, uri, request_params)
+ curl.http_delete
+ return curl
+ end
+ end
+
+ def valid_status_code?(valid_values=[])
+ valid_values.include?(response_code.to_s)
+ end
+
+ def valid_xpath?(xpath="/")
+ !Nokogiri::HTML(body_str.to_s).xpath(xpath.to_s).empty?
+ end
+
+end
diff --git a/lib/puppet/provider/web/curl.rb b/lib/puppet/provider/web/curl.rb
new file mode 100644
index 0000000..5f37742
--- /dev/null
+++ b/lib/puppet/provider/web/curl.rb
@@ -0,0 +1,100 @@
+require 'fileutils'
+require 'puppet/external/curl'
+
+# Puppet provider definition
+Puppet::Type.type(:web).provide :curl do
+ desc "Use curl to access web resources"
+
+ def get
+ @uri
+ end
+
+ def post
+ @uri
+ end
+
+ def delete
+ @uri
+ end
+
+ def put
+ @uri
+ end
+
+ def get=(uri)
+ @uri = uri
+ process_params('get', @resource, uri)
+ end
+
+ def post=(uri)
+ @uri = uri
+ process_params('post', @resource, uri)
+ end
+
+ def delete=(uri)
+ @uri = uri
+ process_params('delete', @resource, uri)
+ end
+
+ def put=(uri)
+ @uri = uri
+ process_params('put', @resource, uri)
+ end
+
+ private
+
+ # Helper to process/parse web parameters
+ def process_params(request_method, params, uri)
+ begin
+ cookies = nil
+ if params[:store_cookies_at]
+ FileUtils.touch(params[:store_cookies_at]) if !File.exist?(params[:store_cookies_at])
+ cookies = params[:store_cookies_at]
+ elsif params[:use_cookies_at]
+ cookies = params[:use_cookies_at]
+ end
+
+ # Actually run the request and verify the result
+ result = Curl::Easy::web_request(request_method, uri, params[:parameters],
+ :cookie => cookies,
+ :follow => params[:follow])
+ verify_result(result,
+ :returns => params[:returns],
+ :does_not_return => params[:does_not_return],
+ :contains => params[:contains],
+ :does_not_contain => params[:does_not_contain] )
+ result.close
+
+ rescue Exception => e
+ raise Puppet::Error, "An exception was raised when invoking web request: #{e}"
+
+ ensure
+ FileUtils.rm_f(cookies) if params[:remove_cookies]
+ end
+ end
+
+ # Helper to verify the response
+ def verify_result(result, verify = {})
+ if !verify[:returns].nil? &&
+ !result.valid_status_code?(verify[:returns])
+ raise Puppet::Error, "Invalid HTTP Return Code: #{result.response_code},
+ was expecting one of #{verify[:returns].join(", ")}"
+ end
+
+ if !verify[:does_not_return].nil? &&
+ result.valid_status_code?(verify[:does_not_return])
+ raise Puppet::Error, "Invalid HTTP Return Code: #{result.response_code},
+ was not expecting one of #{verify[:does_not_return].join(", ")}"
+ end
+
+ if !verify[:contains].nil? &&
+ !result.valid_xpath?(verify[:contains])
+ raise Puppet::Error, "Expecting #{verify[:contains]} in the result"
+ end
+
+ if !verify[:does_not_contain].nil? &&
+ result.valid_xpath?(verify[:does_not_contain])
+ raise Puppet::Error, "Not expecting #{verify[:does_not_contain]} in the result"
+ end
+ end
+end
diff --git a/lib/puppet/type/web.rb b/lib/puppet/type/web.rb
new file mode 100644
index 0000000..c59fece
--- /dev/null
+++ b/lib/puppet/type/web.rb
@@ -0,0 +1,110 @@
+require 'uri'
+
+# A puppet resource type used to access resources on the World Wide Web
+Puppet::Type.newtype(:web) do
+ @doc = "Issue a request to a resource on the world wide web"
+
+ private
+
+ # Validates uris passed in
+ def self.validate_uri(url)
+ begin
+ uri = URI.parse(url)
+ raise ArgumentError, "Specified uri #{url} is not valid" if ![URI::HTTP, URI::HTTPS].include?(uri.class)
+ rescue URI::InvalidURIError
+ raise ArgumentError, "Specified uri #{url} is not valid"
+ end
+ end
+
+ # Validates http statuses passed in
+ def self.validate_http_status(status)
+ status = [status] unless status.is_a?(Array)
+ status.each { |stat|
+ stat = stat.to_s
+ unless ['100', '101', '102', '122',
+ '200', '201', '202', '203', '204', '205', '206', '207', '226',
+ '300', '301', '302', '303', '304', '305', '306', '307',
+ '400', '401', '402', '403', '404', '405', '406', '407', '408', '409',
+ '410', '411', '412', '413', '414', '415', '416', '417', '418',
+ '422', '423', '424', '425', '426', '444', '449', '450', '499',
+ '500', '501', '502', '503', '504', '505', '506', '507', '508', ' 509', '510'
+ ].include?(stat)
+ raise ArgumentError, "Invalid http status code #{stat} specified"
+ end
+ }
+ end
+
+ # Convert singular params into arrays of strings
+ def self.munge_array_params(value)
+ value = [value] unless value.is_a?(Array)
+ value = value.collect { |val| val.to_s }
+ value
+ end
+
+ newparam :name
+
+ newproperty(:get) do
+ desc "Issue get request to the specified uri"
+ validate do |value| Puppet::Type::Web.validate_uri(value) end
+ end
+
+ newproperty(:post) do
+ desc "Issue post request to the specified uri"
+ validate do |value| Puppet::Type::Web.validate_uri(value) end
+ end
+
+ newproperty(:delete) do
+ desc "Issue delete request to the specified uri"
+ validate do |value| Puppet::Type::Web.validate_uri(value) end
+ end
+
+ newproperty(:put) do
+ desc "Issue put request to the specified uri"
+ validate do |value| Puppet::Type::Web.validate_uri(value) end
+ end
+
+ newparam(:parameters) do
+ desc "Hash of parameters to include in the web request"
+ end
+
+ newparam(:follow) do
+ desc "Boolean indicating if redirects should be followed"
+ newvalues(:true, :false)
+ end
+
+ newparam(:store_cookies_at) do
+ desc "String indicating where session cookies should be stored"
+ end
+
+ newparam(:use_cookies_at) do
+ desc "String indicating where session cookies should be read from"
+ end
+
+ newparam(:remove_cookies) do
+ desc "Boolean indicating if cookies should be removed after using them"
+ newvalues(:true, :false)
+ end
+
+ newparam(:returns) do
+ desc "Expected http return codes of the request"
+ defaultto ["200"]
+ validate do |value| Puppet::Type::Web.validate_http_status(value) end
+ munge do |value| Puppet::Type::Web.munge_array_params(value) end
+ end
+
+ newparam(:does_not_return) do
+ desc "Unexecpected http return codes of the request"
+ validate do |value| Puppet::Type::Web.validate_http_status(value) end
+ munge do |value| Puppet::Type::Web.munge_array_params(value) end
+ end
+
+ newparam(:contains) do
+ desc "XPath to verify as part of the result"
+ munge do |value| Puppet::Type::Web.munge_array_params(value) end
+ end
+
+ newparam(:does_not_contain) do
+ desc "XPath to verify as not being part of the result"
+ munge do |value| Puppet::Type::Web.munge_array_params(value) end
+ end
+end
diff --git a/spec/unit/provider/web/curl_spec.rb b/spec/unit/provider/web/curl_spec.rb
new file mode 100644
index 0000000..36f1ddf
--- /dev/null
+++ b/spec/unit/provider/web/curl_spec.rb
@@ -0,0 +1,122 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+provider_class = Puppet::Type.type(:web).provider(:curl)
+
+describe provider_class do
+ before :each do
+ @resource = Puppet::Resource.new(:web, 'foo')
+ @resource.stubs(:[]).returns(nil)
+ @provider = provider_class.new(@resource)
+ end
+
+ def http_request(http_method, url)
+ @provider.method("#{http_method}=".to_sym).call url
+ end
+
+ ['get', 'post', 'put', 'delete'].each do |http_method|
+ describe "##{http_method}" do
+ it "should issue #{http_method} request to uri" do
+ proc {
+ http_request http_method, "http://www.puppetlabs.com"
+ }.should_not raise_error(Puppet::Error)
+ end
+
+ it "should accept parameters for #{http_method} request to uri" do
+ proc {
+ @resource.stubs(:[]).with(:parameters).returns({:q => 'puppet' })
+ @resource.stubs(:[]).with(:follow).returns(true)
+ http_request http_method, "http://www.google.com"
+ }.should_not raise_error(Puppet::Error)
+ end
+
+ it "should verify default success return http status code for #{http_method} request to uri" do
+ proc {
+ http_request http_method, "http://foobar"
+ }.should raise_error(Puppet::Error)
+
+ proc {
+ @resource.stubs(:[]).with(:follow).returns(true)
+ http_request http_method, "http://google.com"
+ }.should_not raise_error(Puppet::Error)
+ end
+
+ it "should verify return http status code for #{http_method} request to uri" do
+ proc {
+ expected_return_code = '500'
+ @resource.stubs(:[]).with(:follow).returns(false)
+ @resource.stubs(:[]).with(:returns).returns([expected_return_code])
+ http_request http_method, "http://google.com"
+ }.should raise_error(Puppet::Error)
+
+ proc {
+ expected_return_code = http_method == "get" ? '301' : '405'
+ @resource.stubs(:[]).with(:follow).returns(false)
+ @resource.stubs(:[]).with(:returns).returns([expected_return_code])
+ http_request http_method, "http://google.com"
+ }.should_not raise_error(Puppet::Error)
+ end
+
+ it "should verify does_not_return http status code for #{http_method} request to uri" do
+ proc {
+ return_code_not_expected = http_method == "get" ? '301' : '405'
+ @resource.stubs(:[]).with(:does_not_return).returns(return_code_not_expected)
+ http_request http_method, "http://google.com"
+ }.should raise_error(Puppet::Error)
+
+ proc {
+ return_code_not_expected = "500"
+ @resource.stubs(:[]).with(:follow).returns(true)
+ @resource.stubs(:[]).with(:does_not_return).returns(return_code_not_expected)
+ http_request http_method, "http://google.com"
+ }.should_not raise_error(Puppet::Error)
+ end
+
+ it "should verify result contains specified xpath for #{http_method} request to uri" do
+ proc {
+ @resource.stubs(:[]).with(:contains).returns('/html/body')
+ @resource.stubs(:[]).with(:follow).returns(true)
+ http_request http_method, "http://www.puppetlabs.com"
+ }.should_not raise_error(Puppet::Error)
+
+ proc {
+ @resource.stubs(:[]).with(:contains).returns('/html/head/body')
+ @resource.stubs(:[]).with(:follow).returns(true)
+ http_request http_method, "http://www.puppetlabs.com"
+ }.should raise_error(Puppet::Error)
+ end
+
+ it "should verify result does_not_contain specified xpath for #{http_method} request to uri" do
+ proc {
+ @resource.stubs(:[]).with(:does_not_contain).returns('/html/head/body')
+ @resource.stubs(:[]).with(:follow).returns(true)
+ http_request http_method, "http://www.puppetlabs.com"
+ }.should_not raise_error(Puppet::Error)
+
+ proc {
+ @resource.stubs(:[]).with(:does_not_contain).returns('/html/body')
+ @resource.stubs(:[]).with(:follow).returns(true)
+ http_request http_method, "http://www.puppetlabs.com"
+ }.should raise_error(Puppet::Error)
+ end
+
+ it "should verify cookies are stored for a #{http_method} request to uri" do
+ @resource.stubs(:[]).with(:store_cookies_at).returns("/tmp/#{http_method}.cookie")
+ http_request http_method, "http://amazon.com"
+ File.exist?("/tmp/#{http_method}.cookie").should be_true
+ FileUtils.rm_f "/tmp/#{http_method}.cookie"
+ end
+
+ #it "should verify cookies are used when for a #{http_method} request to uri" do
+ # how ?
+ #end
+
+ it "should verify cookies are removed for a #{http_method} request to uri" do
+ @resource.stubs(:[]).with(:store_cookies_at).returns("/tmp/#{http_method}.cookie")
+ @resource.stubs(:[]).with(:remove_cookies).returns(true)
+ http_request http_method, "http://amazon.com"
+ File.exist?("/tmp/#{http_method}.cookie").should be_false
+ end
+ end
+ end
+end
diff --git a/spec/unit/type/web_spec.rb b/spec/unit/type/web_spec.rb
new file mode 100644
index 0000000..e170681
--- /dev/null
+++ b/spec/unit/type/web_spec.rb
@@ -0,0 +1,90 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+host = Puppet::Type.type(:web)
+
+describe Puppet::Type.type(:web) do
+ before do
+ @class = host
+ end
+
+ it "should have :name be its namevar" do
+ @class.key_attributes.should == [:name]
+ end
+
+ describe "when validating attributes" do
+ [:parameters, :follow, :store_cookies_at, :use_cookies_at, :remove_cookies,
+ :returns, :does_not_return, :contains, :does_not_contain].each do |param|
+ it "should have a #{param} parameter" do
+ @class.attrtype(param).should == :param
+ end
+ end
+
+ [:get, :post, :put, :delete ].each do |property|
+ it "should have a #{property} property" do
+ @class.attrtype(property).should == :property
+ end
+ end
+ end
+
+ describe "when validating values" do
+ it "should validate uris" do
+ proc { Puppet::Type::Web.validate_uri("http://google.com") }.should_not raise_error
+ proc { Puppet::Type::Web.validate_uri("foobar123") }.should raise_error(ArgumentError) end
+
+ it "should validate http_status" do
+ proc { Puppet::Type::Web.validate_http_status("200") }.should_not raise_error
+ proc { Puppet::Type::Web.validate_http_status(["200", "400"]) }.should_not raise_error
+ proc { Puppet::Type::Web.validate_http_status("909") }.should raise_error(ArgumentError)
+ proc { Puppet::Type::Web.validate_http_status(["200", "909"]) }.should raise_error(ArgumentError)
+ end
+
+ it "should munge array parameters" do
+ Puppet::Type::Web.munge_array_params(200).should == ["200"]
+ Puppet::Type::Web.munge_array_params([200]).should == ["200"]
+ Puppet::Type::Web.munge_array_params(["200"]).should == ["200"]
+ end
+
+ [:get, :post, :put, :delete ].each do |property|
+ it "should require a valid uri for #{property} requests" do
+ proc { @class.new(:name => "#{property}_uri", property.to_sym => "") }.should raise_error(Puppet::Error,"Parameter #{property} failed: Specified uri is not valid")
+ end
+
+ it "should require a valid returns value for #{property} requests if specified" do
+ proc { @class.new(:name => "#{property}_uri", property.to_sym => "http://www.puppetlabs.com", :returns => "invalid" ) }.should raise_error(Puppet::Error,"Parameter returns failed: Invalid http status code invalid specified")
+ end
+
+ it "should munge the returns value for #{property} requests if specified" do
+ type = @class.new(:name => "#{property}_uri", property.to_sym => "http://www.puppetlabs.com", :returns => 200 )
+ type.parameters[:returns].value.should == ['200']
+ end
+
+ it "should require a valid does_not_return value for #{property} requests if specified" do
+ proc { @class.new(:name => "#{property}_uri", property.to_sym => "http://www.puppetlabs.com", :does_not_return => "invalid" ) }.should raise_error(Puppet::Error,"Parameter does_not_return failed: Invalid http status code invalid specified")
+ end
+
+ it "should munge the does_not_return value for #{property} requests if specified" do
+ type = @class.new(:name => "#{property}_uri", property.to_sym => "http://www.puppetlabs.com", :does_not_return => 200 )
+ type.parameters[:does_not_return].value.should == ['200']
+ end
+
+ it "should require a valid follow value for #{property} requests" do
+ proc { @class.new(:name => "#{property}_uri", property.to_sym => "http://www.puppetlabs.com", :follow => "invalid" ) }.should raise_error(Puppet::Error,'Parameter follow failed: Invalid value "invalid". Valid values are true, false. ')
+ end
+
+ it "should munge the contains value for #{property} requests if specified" do
+ type = @class.new(:name => "#{property}_uri", property.to_sym => "http://www.puppetlabs.com", :contains => '/foobar' )
+ type.parameters[:contains].value.should == ['/foobar']
+ end
+
+ it "should munge the does_not_contains value for #{property} requests if specified" do
+ type = @class.new(:name => "#{property}_uri", property.to_sym => "http://www.puppetlabs.com", :does_not_contain => '/foobar' )
+ type.parameters[:does_not_contain].value.should == ['/foobar']
+ end
+
+ it "should require a valid remove_cookies value for #{property} requests" do
+ proc { @class.new(:name => "#{property}_uri", property.to_sym => "http://www.puppetlabs.com", :remove_cookies => 5 ) }.should raise_error(Puppet::Error,'Parameter remove_cookies failed: Invalid value 5. Valid values are true, false. ')
+ end
+ end
+ end
+end
--
1.7.5.4