Skip to content

Commit 4d93afa

Browse files
authored
Merge pull request #8832 from mhashizume/manual_mergeup
(maint) Manual mergeup
2 parents 0fc096f + 51cdc67 commit 4d93afa

File tree

7 files changed

+90
-95
lines changed

7 files changed

+90
-95
lines changed

.github/workflows/rspec_tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818
- {os: ubuntu-18.04, ruby: 2.7}
1919
- {os: ubuntu-18.04, ruby: 3.0}
2020
- {os: ubuntu-18.04, ruby: jruby-9.2.17.0}
21-
- {os: windows-2016, ruby: 2.5}
22-
- {os: windows-2016, ruby: 2.6}
23-
- {os: windows-2016, ruby: 2.7}
24-
- {os: windows-2016, ruby: 3.0}
21+
- {os: windows-2019, ruby: 2.5}
22+
- {os: windows-2019, ruby: 2.6}
23+
- {os: windows-2019, ruby: 2.7}
24+
- {os: windows-2019, ruby: 3.0}
2525

2626
runs-on: ${{ matrix.cfg.os }}
2727
steps:

lib/puppet/pops/serialization/to_data_converter.rb

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class ToDataConverter
1414
# @option options [Boolean] :local_reference use local references instead of duplicating complex entries
1515
# @option options [Boolean] :type_by_reference `true` if Object types are converted to references rather than embedded.
1616
# @option options [Boolean] :symbol_as_string `true` if Symbols should be converted to strings (with type loss)
17-
# @option options [Boolean] :force_symbol `false` if Symbols should not be converted (rich_data and symbol_as_string must be false)
18-
# @option options [Boolean] :silence_warnings `false` if warnings should be silenced
1917
# @option options [String] :message_prefix String to prepend to in warnings and errors
2018
# @return [Data] the processed result. An object assignable to `Data`.
2119
#
@@ -43,12 +41,6 @@ def initialize(options = EMPTY_HASH)
4341
@symbol_as_string = options[:symbol_as_string]
4442
@symbol_as_string = false if @symbol_as_string.nil?
4543

46-
@force_symbol = options[:force_symbol]
47-
@force_symbol = false if @force_symbol.nil?
48-
49-
@silence_warnings = options[:silence_warnings]
50-
@silence_warnings = false if @silence_warnings.nil?
51-
5244
@rich_data = options[:rich_data]
5345
@rich_data = false if @rich_data.nil?
5446

@@ -100,11 +92,7 @@ def to_data(value)
10092
elsif @rich_data
10193
{ PCORE_TYPE_KEY => PCORE_TYPE_SYMBOL, PCORE_VALUE_KEY => value.to_s }
10294
else
103-
if @force_symbol
104-
value
105-
else
106-
@silence_warnings ? unknown_to_string(value) : unknown_to_string_with_warning(value)
107-
end
95+
unknown_to_string_with_warning(value)
10896
end
10997
elsif value.instance_of?(Array)
11098
process(value) do
@@ -129,11 +117,7 @@ def to_data(value)
129117
{ PCORE_TYPE_KEY => PCORE_TYPE_SENSITIVE, PCORE_VALUE_KEY => to_data(value.unwrap) }
130118
end
131119
else
132-
if @rich_data
133-
value_to_data_hash(value)
134-
else
135-
@silence_warnings ? unknown_to_string(value) : unknown_to_string_with_warning(value)
136-
end
120+
unknown_to_data(value)
137121
end
138122
end
139123

@@ -207,6 +191,10 @@ def with_recursive_guard(value)
207191
v
208192
end
209193

194+
def unknown_to_data(value)
195+
@rich_data ? value_to_data_hash(value) : unknown_to_string_with_warning(value)
196+
end
197+
210198
def unknown_key_to_string_with_warning(value)
211199
str = unknown_to_string(value)
212200
serialization_issue(Issues::SERIALIZATION_UNKNOWN_KEY_CONVERTED_TO_STRING, :path => path_to_s, :klass => value.class, :value => str)

lib/puppet/ssl/verifier.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ def call(preverify_ok, store_context)
117117
return false
118118
end
119119

120-
when OpenSSL::X509::V_ERR_HOSTNAME_MISMATCH # new in ruby-openssl 2.2.0/ruby 3.0
120+
# ruby-openssl#74ef8c0cc56b840b772240f2ee2b0fc0aafa2743 now sets the
121+
# store_context error when the cert is mismatched
122+
when OpenSSL::X509::V_ERR_HOSTNAME_MISMATCH
121123
@last_error = Puppet::SSL::CertMismatchError.new(peer_cert, @hostname)
122124
return false
123125

lib/puppet/transaction/persistence.rb

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66
# as calculating corrective_change).
77
# @api private
88
class Puppet::Transaction::Persistence
9+
10+
def self.allowed_classes
11+
@allowed_classes ||= [
12+
Symbol,
13+
Time,
14+
Regexp,
15+
# URI is excluded, because it serializes all instance variables including the
16+
# URI parser. Better to serialize the URL encoded representation.
17+
SemanticPuppet::Version,
18+
# SemanticPuppet::VersionRange has many nested classes and is unlikely to be
19+
# used directly, so ignore it
20+
Puppet::Pops::Time::Timestamp,
21+
Puppet::Pops::Time::TimeData,
22+
Puppet::Pops::Time::Timespan,
23+
Puppet::Pops::Types::PBinaryType::Binary,
24+
# Puppet::Pops::Types::PSensitiveType::Sensitive values are excluded from
25+
# the persistence store, ignore it.
26+
].freeze
27+
end
28+
929
def initialize
1030
@old_data = {}
1131
@new_data = {"resources" => {}}
@@ -62,7 +82,7 @@ def load
6282
result = nil
6383
Puppet::Util.benchmark(:debug, _("Loaded transaction store file in %{seconds} seconds")) do
6484
begin
65-
result = Puppet::Util::Yaml.safe_load_file(filename, [Symbol, Time])
85+
result = Puppet::Util::Yaml.safe_load_file(filename, self.class.allowed_classes)
6686
rescue Puppet::Util::Yaml::YamlLoadError => detail
6787
Puppet.log_exception(detail, _("Transaction store file %{filename} is corrupt (%{detail}); replacing") % { filename: filename, detail: detail })
6888

@@ -87,17 +107,7 @@ def load
87107

88108
# Save data from internal class to persistence store on disk.
89109
def save
90-
converted_data = Puppet::Pops::Serialization::ToDataConverter.convert(
91-
@new_data, {
92-
symbol_as_string: false,
93-
local_reference: false,
94-
type_by_reference: true,
95-
force_symbol: true,
96-
silence_warnings: true,
97-
message_prefix: to_s
98-
}
99-
)
100-
Puppet::Util::Yaml.dump(converted_data, Puppet[:transactionstorefile])
110+
Puppet::Util::Yaml.dump(@new_data, Puppet[:transactionstorefile])
101111
end
102112

103113
# Use the catalog and run_mode to determine if persistence should be enabled or not

lib/puppet/util/monkey_patches.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ def set_default_paths
105105
end
106106

107107
unless Puppet::Util::Platform.jruby_fips?
108-
unless OpenSSL::X509.const_defined?(:V_ERR_HOSTNAME_MISMATCH)
109-
OpenSSL::X509.const_set(:V_ERR_HOSTNAME_MISMATCH, 62)
108+
unless defined?(OpenSSL::X509::V_ERR_HOSTNAME_MISMATCH)
109+
module OpenSSL::X509
110+
OpenSSL::X509::V_ERR_HOSTNAME_MISMATCH = 0x3E
111+
end
110112
end
111113

112114
# jruby-openssl doesn't support this

spec/unit/pops/serialization/to_from_hr_spec.rb

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -559,29 +559,6 @@ def _pcore_init_hash
559559
expect(warnings).to eql(["['key'] contains the special value default. It will be converted to the String 'default'"])
560560
end
561561
end
562-
context 'and force_symbol set to true' do
563-
let(:to_converter) { ToDataConverter.new(:rich_data => false, :force_symbol => true) }
564-
565-
it 'A Hash with Symbol values is converted to hash with Symbol values' do
566-
val = { 'one' => :one, 'two' => :two }
567-
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
568-
569-
# write and read methods does not work here as we cannot force Symbols in Json.
570-
# and a hash with symbol values cannot be an instance of Types::TypeFactory.data.
571-
# Using YAML for this instead
572-
io.reopen
573-
value = to_converter.convert(val)
574-
io << [value].to_yaml
575-
io.rewind
576-
577-
val2 = from_converter.convert(YAML::load(io.read)[0])
578-
579-
expect(val2).to be_a(Hash)
580-
expect(val2).to eql({ 'one' => :one, 'two' => :two })
581-
end
582-
expect(warnings).to be_empty
583-
end
584-
end
585562
end
586563

587564
context 'with rich_data is set to true' do
@@ -655,41 +632,6 @@ def _pcore_init_hash
655632
end.to raise_error(/Cannot create a Pcore::TimestampType from a Integer/)
656633
end
657634
end
658-
659-
context 'when data is unknown' do
660-
let(:to_converter) { ToDataConverter.new(:message_prefix => 'Test Hash') }
661-
let(:logs) { [] }
662-
let(:warnings) { logs.select { |log| log.level == :warning }.map { |log| log.message } }
663-
let(:val) { Class.new }
664-
665-
context 'and :silence_warnings undefined or set to false' do
666-
it 'convert the unknown data to string with warnings' do
667-
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
668-
write(val)
669-
val2 = read
670-
expect(val2).to be_a(String)
671-
expect(val2).to match(/Class/)
672-
end
673-
expect(warnings).to eql([
674-
"Test Hash contains a #{val.class} value. It will be converted to the String '#{val.to_s}'"])
675-
end
676-
end
677-
678-
context 'and :silence_warnings undefined or set to true' do
679-
let(:to_converter) { ToDataConverter.new(:message_prefix => 'Test Hash', :silence_warnings => true) }
680-
681-
it 'convert the unknown data to string without warnings if silence_warnings set to true' do
682-
val = Class.new
683-
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
684-
write(val)
685-
val2 = read
686-
expect(val2).to be_a(String)
687-
expect(val2).to match(/Class/)
688-
end
689-
expect(warnings).to be_empty
690-
end
691-
end
692-
end
693635
end
694636
end
695637
end

spec/unit/transaction/persistence_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,57 @@ def write_state_file(contents)
138138
persistence = Puppet::Transaction::Persistence.new
139139
expect(persistence.load.dig("File[/tmp/audit]", "parameters", "mtime", "system_value")).to contain_exactly(be_a(Time))
140140
end
141+
142+
it 'should load Regexp' do
143+
write_state_file(<<~END)
144+
system_value:
145+
- !ruby/regexp /regexp/
146+
END
147+
148+
persistence = Puppet::Transaction::Persistence.new
149+
expect(persistence.load.dig("system_value")).to contain_exactly(be_a(Regexp))
150+
end
151+
152+
it 'should load semantic puppet version' do
153+
write_state_file(<<~END)
154+
system_value:
155+
- !ruby/object:SemanticPuppet::Version
156+
major: 1
157+
minor: 0
158+
patch: 0
159+
prerelease:
160+
build:
161+
END
162+
163+
persistence = Puppet::Transaction::Persistence.new
164+
expect(persistence.load.dig("system_value")).to contain_exactly(be_a(SemanticPuppet::Version))
165+
end
166+
167+
it 'should load puppet time related objects' do
168+
write_state_file(<<~END)
169+
system_value:
170+
- !ruby/object:Puppet::Pops::Time::Timestamp
171+
nsecs: 1638316135955087259
172+
- !ruby/object:Puppet::Pops::Time::TimeData
173+
nsecs: 1495789430910161286
174+
- !ruby/object:Puppet::Pops::Time::Timespan
175+
nsecs: 1495789430910161286
176+
END
177+
178+
persistence = Puppet::Transaction::Persistence.new
179+
expect(persistence.load.dig("system_value")).to contain_exactly(be_a(Puppet::Pops::Time::Timestamp), be_a(Puppet::Pops::Time::TimeData), be_a(Puppet::Pops::Time::Timespan))
180+
end
181+
182+
it 'should load binary objects' do
183+
write_state_file(<<~END)
184+
system_value:
185+
- !ruby/object:Puppet::Pops::Types::PBinaryType::Binary
186+
binary_buffer: ''
187+
END
188+
189+
persistence = Puppet::Transaction::Persistence.new
190+
expect(persistence.load.dig("system_value")).to contain_exactly(be_a(Puppet::Pops::Types::PBinaryType::Binary))
191+
end
141192
end
142193
end
143194

0 commit comments

Comments
 (0)