Skip to content

Commit 036d074

Browse files
committed
(MODULES-1723) Test Ruby Registry methods uncalled
- Ensure that under Ruby 2.1.x that problematic method calls to Win32::Registry are not made. This was made in a separate commit because unfortunately Mocha's any_instance will actually hide other errors (which are visible in the prior commit). Once code has been changed to alter code paths under other Ruby versions, the guarding will be changed accordingly.
1 parent 75b4af8 commit 036d074

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

spec/unit/puppet/provider/registry_key_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@
1010
puppet_key = "SOFTWARE\\Puppet Labs"
1111
subkey_name ="PuppetRegProviderTest"
1212

13+
before(:each) do
14+
if RUBY_VERSION >= '2.1'
15+
# problematic Ruby codepath triggers a conversion of UTF-16LE to
16+
# a local codepage which can totally break when that codepage has no
17+
# conversion from the given UTF-16LE characters to local codepage
18+
# a prime example is that IBM437 has no conversion from a Unicode en-dash
19+
Win32::Registry.any_instance.expects(:export_string).never
20+
21+
Win32::Registry.any_instance.expects(:delete_value).never
22+
Win32::Registry.any_instance.expects(:delete_key).never
23+
24+
# also, expect that we're not using Rubys each_key / each_value which exhibit bad behavior
25+
Win32::Registry.any_instance.expects(:each_key).never
26+
Win32::Registry.any_instance.expects(:each_value).never
27+
end
28+
end
29+
1330
describe "#destroy" do
1431
it "can destroy a randomly created key" do
1532

spec/unit/puppet/provider/registry_value_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@
1616
PuppetX::Puppetlabs::Registry::KEY_WOW64_64KEY)
1717
end
1818

19+
before(:each) do
20+
if RUBY_VERSION >= '2.1'
21+
# problematic Ruby codepath triggers a conversion of UTF-16LE to
22+
# a local codepage which can totally break when that codepage has no
23+
# conversion from the given UTF-16LE characters to local codepage
24+
# a prime example is that IBM437 has no conversion from a Unicode en-dash
25+
Win32::Registry.any_instance.expects(:export_string).never
26+
27+
Win32::Registry.any_instance.expects(:delete_value).never
28+
Win32::Registry.any_instance.expects(:delete_key).never
29+
30+
# also, expect that we're not using Rubys each_key / each_value which exhibit bad behavior
31+
Win32::Registry.any_instance.expects(:each_key).never
32+
Win32::Registry.any_instance.expects(:each_value).never
33+
end
34+
end
35+
1936
after(:all) do
2037
# Ruby 2.1.5 has bugs with deleting registry keys due to using ANSI
2138
# character APIs, but passing wide strings to them (facepalm)

0 commit comments

Comments
 (0)