File tree Expand file tree Collapse file tree
lib/octocatalog-diff/catalog Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- 0.5.6
1+ 0.5.7
Original file line number Diff line number Diff line change @@ -68,13 +68,17 @@ def build(logger = Logger.new(StringIO.new))
6868
6969 # Returns a hash of parameters for each supported version of the Puppet Server Catalog API.
7070 # @return [Hash] Hash of parameters
71+ #
72+ # Note: The double escaping of the facts here is implemented to correspond to a long standing
73+ # bug in the Puppet code. See https://github.com/puppetlabs/puppet/pull/1818 and
74+ # https://docs.puppet.com/puppet/latest/http_api/http_catalog.html#parameters for explanation.
7175 def puppet_catalog_api
7276 {
7377 2 => {
7478 url : "https://#{ @options [ :puppet_master ] } /#{ @options [ :branch ] } /catalog/#{ @node } " ,
7579 parameters : {
7680 'facts_format' => 'pson' ,
77- 'facts' => @facts . fudge_timestamp . without ( 'trusted' ) . to_pson ,
81+ 'facts' => CGI . escape ( @facts . fudge_timestamp . without ( 'trusted' ) . to_pson ) ,
7882 'transaction_uuid' => SecureRandom . uuid
7983 }
8084 } ,
@@ -83,7 +87,7 @@ def puppet_catalog_api
8387 parameters : {
8488 'environment' => @options [ :branch ] ,
8589 'facts_format' => 'pson' ,
86- 'facts' => @facts . fudge_timestamp . without ( 'trusted' ) . to_pson ,
90+ 'facts' => CGI . escape ( @facts . fudge_timestamp . without ( 'trusted' ) . to_pson ) ,
8791 'transaction_uuid' => SecureRandom . uuid
8892 }
8993 }
Original file line number Diff line number Diff line change 1+ {
2+ "apt_update_last_success" :1458162123 ,
3+ "architecture" :" amd64" ,
4+ "datacenter" :" xyz" ,
5+ "fqdn" :" rspec-node.xyz.github.net" ,
6+ "math" :" 1+2=3" ,
7+ "percent" :" 25%20=5" ,
8+ "_timestamp" :" 2014-12-02 14:56:20 -0600"
9+ }
Original file line number Diff line number Diff line change 1+ # --- !ruby/object:Puppet::Node::Facts
2+ name : rspec-node.xyz.github.net
3+ values :
4+ apt_update_last_success : 1458162123
5+ architecture : amd64
6+ datacenter : xyz
7+ fqdn : rspec-node.xyz.github.net
8+ math : " 1+2=3"
9+ percent : " 25%20=5"
10+ " _timestamp " : 2014-12-02 12:56:20.865795 -08:00
11+ expiration : 2014-12-02 13:11:20.521667 -08:00
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ def self.parse_body(body)
4545 end
4646
4747 def self . facts_match ( body )
48- facts = JSON . parse ( parse_body ( body ) [ 'facts' ] )
48+ facts = JSON . parse ( CGI . unescape ( parse_body ( body ) [ 'facts' ] ) )
4949 facts . delete ( '_timestamp' )
5050 desired_facts = {
5151 'name' => 'rspec-node.xyz.github.net' ,
Original file line number Diff line number Diff line change 1111 node : 'foo' ,
1212 branch : 'foobranch' ,
1313 puppet_master : 'fake-puppetmaster.non-existent-domain.com' ,
14- fact_file : OctocatalogDiff ::Spec . fixture_path ( 'facts/facts .yaml' )
14+ fact_file : OctocatalogDiff ::Spec . fixture_path ( 'facts/facts_esc .yaml' )
1515 }
1616 end
1717
9999 end
100100
101101 it 'should post the correct facts to HTTParty' do
102- answer = JSON . parse ( File . read ( OctocatalogDiff ::Spec . fixture_path ( 'facts/facts .json' ) ) )
102+ answer = JSON . parse ( File . read ( OctocatalogDiff ::Spec . fixture_path ( 'facts/facts_esc .json' ) ) )
103103 answer . delete ( '_timestamp' )
104- result = JSON . parse ( @post_data [ 'facts' ] ) [ 'values' ]
104+ # An extra 'unescape' is here because the facts are double escaped.
105+ # See https://docs.puppet.com/puppet/latest/http_api/http_catalog.html#parameters
106+ # and https://github.com/puppetlabs/puppet/pull/1818
107+ result = JSON . parse ( CGI . unescape ( @post_data [ 'facts' ] ) ) [ 'values' ]
105108 expect ( result ) . to eq ( answer )
106109 end
107110
118121 it 'should log correctly' do
119122 logs = @logger_str . string
120123 expect ( logs ) . to match ( /Start retrieving facts for foo from OctocatalogDiff::Catalog::PuppetMaster/ )
121- expect ( logs ) . to match ( %r{Retrieving facts from.*fixtures/facts/facts .yaml} )
122- expect ( logs ) . to match ( %r{Retrieving facts from.*fixtures/facts/facts .yaml} )
124+ expect ( logs ) . to match ( %r{Retrieving facts from.*fixtures/facts/facts_esc .yaml} )
125+ expect ( logs ) . to match ( %r{Retrieving facts from.*fixtures/facts/facts_esc .yaml} )
123126
124127 answer = Regexp . new ( "Retrieve catalog from #{ api_url [ api_version ] } environment foobranch" )
125128 expect ( logs ) . to match ( answer )
You can’t perform that action at this time.
0 commit comments