chef-config 17.9.52 → 17.10.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,128 +1,128 @@
1
- #
2
- # Author:: Matt Wrock (<matt@mattwrock.com>)
3
- # Copyright:: Copyright (c) Chef Software Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "chef-config/fips"
20
- require "spec_helper"
21
-
22
- begin
23
- require "win32/registry" unless defined?(Win32::Registry)
24
- rescue LoadError
25
- # not on unix
26
- end
27
-
28
- RSpec.describe "ChefConfig.fips?" do
29
- let(:enabled) { "0" }
30
-
31
- context "on *nix" do
32
- let(:fips_path) { "/proc/sys/crypto/fips_enabled" }
33
-
34
- before(:each) do
35
- allow(ChefUtils).to receive(:windows?).and_return(false)
36
- allow(::File).to receive(:exist?).with(fips_path).and_return(true)
37
- allow(::File).to receive(:read).with(fips_path).and_return(enabled)
38
- end
39
-
40
- context "fips file is present and contains 1" do
41
- let(:enabled) { "1" }
42
-
43
- it "returns true" do
44
- expect(ChefConfig.fips?).to be(true)
45
- end
46
- end
47
-
48
- context "fips file does not contain 1" do
49
- let(:enabled) { "0" }
50
-
51
- it "returns false" do
52
- expect(ChefConfig.fips?).to be(false)
53
- end
54
- end
55
-
56
- context "fips file is not present" do
57
- before do
58
- allow(::File).to receive(:exist?).with(fips_path).and_return(false)
59
- end
60
-
61
- it "returns false" do
62
- expect(ChefConfig.fips?).to be(false)
63
- end
64
- end
65
- end
66
-
67
- context "on windows", :windows_only do
68
- let(:fips_key) { "System\\CurrentControlSet\\Control\\Lsa\\FIPSAlgorithmPolicy" }
69
- let(:win_reg_entry) { { "Enabled" => enabled } }
70
-
71
- before(:each) do
72
- allow(ChefUtils).to receive(:windows?).and_return(true)
73
- allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with(fips_key, arch).and_yield(win_reg_entry)
74
- end
75
-
76
- shared_examples "fips_detection" do
77
- context "fips enabled key is set to 1" do
78
- let(:enabled) { 1 }
79
-
80
- it "returns true" do
81
- expect(ChefConfig.fips?).to be(true)
82
- end
83
- end
84
-
85
- context "fips enabled key is set to 0" do
86
- let(:enabled) { 0 }
87
-
88
- it "returns false" do
89
- expect(ChefConfig.fips?).to be(false)
90
- end
91
- end
92
-
93
- context "fips key does not exist" do
94
- before do
95
- allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).and_raise(Win32::Registry::Error, 50)
96
- end
97
-
98
- it "returns false" do
99
- expect(ChefConfig.fips?).to be(false)
100
- end
101
- end
102
- end
103
-
104
- context "on 32 bit ruby" do
105
- let(:arch) { Win32::Registry::KEY_READ | 0x100 }
106
-
107
- before { stub_const("::RbConfig::CONFIG", { "target_cpu" => "i386" } ) }
108
-
109
- it_behaves_like "fips_detection"
110
- end
111
-
112
- context "on 64 bit ruby" do
113
- let(:arch) { Win32::Registry::KEY_READ | 0x200 }
114
-
115
- before { stub_const("::RbConfig::CONFIG", { "target_cpu" => "x86_64" } ) }
116
-
117
- it_behaves_like "fips_detection"
118
- end
119
-
120
- context "on unknown ruby" do
121
- let(:arch) { Win32::Registry::KEY_READ }
122
-
123
- before { stub_const("::RbConfig::CONFIG", { "target_cpu" => nil } ) }
124
-
125
- it_behaves_like "fips_detection"
126
- end
127
- end
128
- end
1
+ #
2
+ # Author:: Matt Wrock (<matt@mattwrock.com>)
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "chef-config/fips"
20
+ require "spec_helper"
21
+
22
+ begin
23
+ require "win32/registry" unless defined?(Win32::Registry)
24
+ rescue LoadError
25
+ # not on unix
26
+ end
27
+
28
+ RSpec.describe "ChefConfig.fips?" do
29
+ let(:enabled) { "0" }
30
+
31
+ context "on *nix" do
32
+ let(:fips_path) { "/proc/sys/crypto/fips_enabled" }
33
+
34
+ before(:each) do
35
+ allow(ChefUtils).to receive(:windows?).and_return(false)
36
+ allow(::File).to receive(:exist?).with(fips_path).and_return(true)
37
+ allow(::File).to receive(:read).with(fips_path).and_return(enabled)
38
+ end
39
+
40
+ context "fips file is present and contains 1" do
41
+ let(:enabled) { "1" }
42
+
43
+ it "returns true" do
44
+ expect(ChefConfig.fips?).to be(true)
45
+ end
46
+ end
47
+
48
+ context "fips file does not contain 1" do
49
+ let(:enabled) { "0" }
50
+
51
+ it "returns false" do
52
+ expect(ChefConfig.fips?).to be(false)
53
+ end
54
+ end
55
+
56
+ context "fips file is not present" do
57
+ before do
58
+ allow(::File).to receive(:exist?).with(fips_path).and_return(false)
59
+ end
60
+
61
+ it "returns false" do
62
+ expect(ChefConfig.fips?).to be(false)
63
+ end
64
+ end
65
+ end
66
+
67
+ context "on windows", :windows_only do
68
+ let(:fips_key) { "System\\CurrentControlSet\\Control\\Lsa\\FIPSAlgorithmPolicy" }
69
+ let(:win_reg_entry) { { "Enabled" => enabled } }
70
+
71
+ before(:each) do
72
+ allow(ChefUtils).to receive(:windows?).and_return(true)
73
+ allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with(fips_key, arch).and_yield(win_reg_entry)
74
+ end
75
+
76
+ shared_examples "fips_detection" do
77
+ context "fips enabled key is set to 1" do
78
+ let(:enabled) { 1 }
79
+
80
+ it "returns true" do
81
+ expect(ChefConfig.fips?).to be(true)
82
+ end
83
+ end
84
+
85
+ context "fips enabled key is set to 0" do
86
+ let(:enabled) { 0 }
87
+
88
+ it "returns false" do
89
+ expect(ChefConfig.fips?).to be(false)
90
+ end
91
+ end
92
+
93
+ context "fips key does not exist" do
94
+ before do
95
+ allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).and_raise(Win32::Registry::Error, 50)
96
+ end
97
+
98
+ it "returns false" do
99
+ expect(ChefConfig.fips?).to be(false)
100
+ end
101
+ end
102
+ end
103
+
104
+ context "on 32 bit ruby" do
105
+ let(:arch) { Win32::Registry::KEY_READ | 0x100 }
106
+
107
+ before { stub_const("::RbConfig::CONFIG", { "target_cpu" => "i386" } ) }
108
+
109
+ it_behaves_like "fips_detection"
110
+ end
111
+
112
+ context "on 64 bit ruby" do
113
+ let(:arch) { Win32::Registry::KEY_READ | 0x200 }
114
+
115
+ before { stub_const("::RbConfig::CONFIG", { "target_cpu" => "x86_64" } ) }
116
+
117
+ it_behaves_like "fips_detection"
118
+ end
119
+
120
+ context "on unknown ruby" do
121
+ let(:arch) { Win32::Registry::KEY_READ }
122
+
123
+ before { stub_const("::RbConfig::CONFIG", { "target_cpu" => nil } ) }
124
+
125
+ it_behaves_like "fips_detection"
126
+ end
127
+ end
128
+ end