ohai 14.0.29 → 14.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -4
- data/lib/ohai/common/dmi.rb +16 -4
- data/lib/ohai/plugins/dmi.rb +1 -2
- data/lib/ohai/plugins/linux/fips.rb +12 -5
- data/lib/ohai/plugins/scsi.rb +52 -0
- data/lib/ohai/plugins/shard.rb +55 -5
- data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
- data/lib/ohai/plugins/windows/fips.rb +21 -14
- data/lib/ohai/version.rb +1 -1
- data/spec/unit/plugins/dmi_spec.rb +25 -17
- data/spec/unit/plugins/linux/fips_spec.rb +37 -6
- data/spec/unit/plugins/scsi_spec.rb +67 -0
- data/spec/unit/plugins/shard_spec.rb +69 -11
- data/spec/unit/plugins/windows/fips_spec.rb +37 -6
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aaa80eca02eed6b1bf25be0dab653f121320347693d75453dd3591306050aca
|
4
|
+
data.tar.gz: 62b76f41b745726f29d6a13c8dd5159ee2cd45a3b4742fe5fa64745dc8825a31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 678928cc6387c5613a03c63b1df7c2639a96991c850485096c0162a138cf56285a69eb9c4f4e2fce9d8bab48c8feadef741e2e7cf53b84e4cc980f6a7286a4ee
|
7
|
+
data.tar.gz: 633ba5a734a9e497593276781c53fb802096d2f1164c64896b78837615fb4f8ca9d7363b59029c06b28bf36bf92a472a84a2742d3890bbf6a23d6ad80f0c7e37
|
data/Gemfile
CHANGED
@@ -17,10 +17,6 @@ group :ci do
|
|
17
17
|
gem "rspec_junit_formatter"
|
18
18
|
end
|
19
19
|
|
20
|
-
group :changelog do
|
21
|
-
gem "github_changelog_generator", git: "https://github.com/chef/github-changelog-generator"
|
22
|
-
end
|
23
|
-
|
24
20
|
instance_eval(ENV["GEMFILE_MOD"]) if ENV["GEMFILE_MOD"]
|
25
21
|
|
26
22
|
# If you want to load debugging tools into the bundle exec sandbox,
|
data/lib/ohai/common/dmi.rb
CHANGED
@@ -72,10 +72,22 @@ module Ohai
|
|
72
72
|
127 => "end_of_table_marker",
|
73
73
|
}
|
74
74
|
|
75
|
-
# list of IDs to collect
|
76
|
-
#
|
75
|
+
# list of IDs to collect from config or default to a sane list that prunes
|
76
|
+
# away some of the less useful IDs
|
77
77
|
ID_TO_CAPTURE = [ 0, 1, 2, 3, 4, 6, 11 ]
|
78
78
|
|
79
|
+
# return the list of DMI IDs to capture
|
80
|
+
def whitelisted_ids
|
81
|
+
if Ohai.config[:additional_dmi_ids]
|
82
|
+
if [ Integer, Array ].include?(Ohai.config[:additional_dmi_ids].class)
|
83
|
+
return ID_TO_CAPTURE + Array(Ohai.config[:additional_dmi_ids])
|
84
|
+
else
|
85
|
+
Ohai::Log.warn("The DMI plugin additional_dmi_ids config must be an array of IDs!")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
ID_TO_CAPTURE
|
89
|
+
end
|
90
|
+
|
79
91
|
# look up DMI ID
|
80
92
|
def id_lookup(id)
|
81
93
|
id = id.to_i
|
@@ -85,7 +97,7 @@ module Ohai
|
|
85
97
|
id = DMI::ID_TO_DESCRIPTION[id]
|
86
98
|
else
|
87
99
|
Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
|
88
|
-
id = "
|
100
|
+
id = "unknown_dmi_id_#{id}"
|
89
101
|
end
|
90
102
|
rescue
|
91
103
|
Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
|
@@ -122,7 +134,7 @@ module Ohai
|
|
122
134
|
end
|
123
135
|
end
|
124
136
|
|
125
|
-
module_function :id_lookup, :convenience_keys
|
137
|
+
module_function :id_lookup, :convenience_keys, :whitelisted_ids
|
126
138
|
end
|
127
139
|
end
|
128
140
|
end
|
data/lib/ohai/plugins/dmi.rb
CHANGED
@@ -75,8 +75,7 @@ Ohai.plugin(:DMI) do
|
|
75
75
|
dmi[:table_location] = table_location[1]
|
76
76
|
|
77
77
|
elsif ( handle = handle_line.match(line) )
|
78
|
-
|
79
|
-
unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(handle[2].to_i)
|
78
|
+
unless Ohai::Common::DMI.whitelisted_ids.include?(handle[2].to_i)
|
80
79
|
dmi_record = nil
|
81
80
|
next
|
82
81
|
end
|
@@ -28,11 +28,18 @@ Ohai.plugin(:Fips) do
|
|
28
28
|
collect_data(:linux) do
|
29
29
|
fips Mash.new
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
fips["kernel"] = { "enabled" =>
|
31
|
+
# Check for new fips_mode method added in Ruby 2.5. After we drop support
|
32
|
+
# for Ruby 2.4, clean up everything after this and collapse the FIPS plugins.
|
33
|
+
require "openssl"
|
34
|
+
if defined?(OpenSSL.fips_mode) && !$FIPS_TEST_MODE
|
35
|
+
fips["kernel"] = { "enabled" => OpenSSL.fips_mode }
|
36
|
+
else
|
37
|
+
begin
|
38
|
+
enabled = File.read("/proc/sys/crypto/fips_enabled").chomp
|
39
|
+
fips["kernel"] = { "enabled" => enabled == "0" ? false : true }
|
40
|
+
rescue Errno::ENOENT
|
41
|
+
fips["kernel"] = { "enabled" => false }
|
42
|
+
end
|
36
43
|
end
|
37
44
|
end
|
38
45
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Phil Dibowitz <phil@ipom.com>
|
3
|
+
# Copyright:: Copyright (c) 2018 Facebook, 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
|
+
Ohai.plugin(:Lsscsi) do
|
20
|
+
depends "platform"
|
21
|
+
provides "scsi"
|
22
|
+
optional true
|
23
|
+
|
24
|
+
require "mixlib/shellout"
|
25
|
+
|
26
|
+
collect_data(:linux) do
|
27
|
+
devices = Mash.new
|
28
|
+
lsscsi = shell_out("lsscsi")
|
29
|
+
|
30
|
+
lsscsi.stdout.each_line do |line|
|
31
|
+
line_bits = line.split
|
32
|
+
info = {}
|
33
|
+
|
34
|
+
# The first three fields are consistent...
|
35
|
+
info["scsi_addr"] = line_bits.shift[1..-2]
|
36
|
+
info["type"] = line_bits.shift
|
37
|
+
info["transport"] = line_bits.shift
|
38
|
+
|
39
|
+
# After that the last two are consistent...
|
40
|
+
info["device"] = line_bits.pop
|
41
|
+
info["revision"] = line_bits.pop
|
42
|
+
|
43
|
+
# What"s in the middle is the make and model...
|
44
|
+
# which could have arbitrary spaces
|
45
|
+
info["name"] = line_bits.join(" ")
|
46
|
+
|
47
|
+
devices[info["scsi_addr"]] = info
|
48
|
+
end
|
49
|
+
|
50
|
+
scsi devices
|
51
|
+
end
|
52
|
+
end
|
data/lib/ohai/plugins/shard.rb
CHANGED
@@ -17,10 +17,8 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
Ohai.plugin(:ShardSeed) do
|
20
|
-
|
21
|
-
depends "hostname", "dmi", "machine_id", "machinename"
|
20
|
+
depends "hostname", "dmi", "machine_id", "machinename", "fips", "hardware", "kernel"
|
22
21
|
provides "shard_seed"
|
23
|
-
optional true
|
24
22
|
|
25
23
|
def get_dmi_property(dmi, thing)
|
26
24
|
%w{system base_board chassis}.each do |section|
|
@@ -31,7 +29,33 @@ Ohai.plugin(:ShardSeed) do
|
|
31
29
|
end
|
32
30
|
|
33
31
|
def default_sources
|
34
|
-
|
32
|
+
case collect_os
|
33
|
+
when :linux, :darwin, :windows
|
34
|
+
[:machinename, :serial, :uuid]
|
35
|
+
else
|
36
|
+
[:machinename]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_digest_algorithm
|
41
|
+
if fips["kernel"]["enabled"]
|
42
|
+
# Even though it is being used safely, FIPS-mode will still blow up on
|
43
|
+
# any use of MD5 so default to SHA2 instead.
|
44
|
+
"sha256"
|
45
|
+
else
|
46
|
+
"md5"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def digest_algorithm
|
51
|
+
case Ohai.config[:plugin][:shard_seed][:digest_algorithm] || default_digest_algorithm
|
52
|
+
when "md5"
|
53
|
+
require "digest/md5"
|
54
|
+
Digest::MD5
|
55
|
+
when "sha256"
|
56
|
+
require "digest/sha2"
|
57
|
+
Digest::SHA256
|
58
|
+
end
|
35
59
|
end
|
36
60
|
|
37
61
|
# Common sources go here. Put sources that need to be different per-platform
|
@@ -53,7 +77,31 @@ Ohai.plugin(:ShardSeed) do
|
|
53
77
|
yield(src)
|
54
78
|
end
|
55
79
|
end
|
56
|
-
shard_seed
|
80
|
+
shard_seed digest_algorithm.hexdigest(data)[0...7].to_i(16)
|
81
|
+
end
|
82
|
+
|
83
|
+
collect_data do
|
84
|
+
create_seed do |src|
|
85
|
+
raise "No such shard_seed source: #{src}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
collect_data(:windows) do
|
90
|
+
require "wmi-lite/wmi"
|
91
|
+
wmi = WmiLite::Wmi.new
|
92
|
+
|
93
|
+
create_seed do |src|
|
94
|
+
case src
|
95
|
+
when :serial
|
96
|
+
wmi.first_of("Win32_BIOS")["SerialNumber"]
|
97
|
+
when :os_serial
|
98
|
+
kernel["os_info"]["serial_number"]
|
99
|
+
when :uuid
|
100
|
+
wmi.first_of("Win32_ComputerSystemProduct")["UUID"]
|
101
|
+
else
|
102
|
+
raise "No such shard_seed source: #{src}"
|
103
|
+
end
|
104
|
+
end
|
57
105
|
end
|
58
106
|
|
59
107
|
collect_data(:darwin) do
|
@@ -63,6 +111,8 @@ Ohai.plugin(:ShardSeed) do
|
|
63
111
|
hardware["serial_number"]
|
64
112
|
when :uuid
|
65
113
|
hardware["platform_UUID"]
|
114
|
+
else
|
115
|
+
raise "No such shard_seed source: #{src}"
|
66
116
|
end
|
67
117
|
end
|
68
118
|
end
|
@@ -129,7 +129,7 @@ Ohai.plugin(:DMI) do
|
|
129
129
|
id = smb_to_id[header_information[3]]
|
130
130
|
|
131
131
|
# Don't overcapture for now (OHAI-260)
|
132
|
-
unless Ohai::Common::DMI
|
132
|
+
unless Ohai::Common::DMI.whitelisted_ids.include?(id)
|
133
133
|
dmi_record = nil
|
134
134
|
next
|
135
135
|
end
|
@@ -26,25 +26,32 @@ Ohai.plugin(:Fips) do
|
|
26
26
|
provides "fips"
|
27
27
|
|
28
28
|
collect_data(:windows) do
|
29
|
-
require "win32/registry"
|
30
29
|
fips Mash.new
|
31
30
|
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
# Check for new fips_mode method added in Ruby 2.5. After we drop support
|
32
|
+
# for Ruby 2.4, clean up everything after this and collapse the FIPS plugins.
|
33
|
+
require "openssl"
|
34
|
+
if defined?(OpenSSL.fips_mode) && !$FIPS_TEST_MODE
|
35
|
+
fips["kernel"] = { "enabled" => OpenSSL.fips_mode }
|
37
36
|
else
|
38
|
-
|
39
|
-
|
37
|
+
require "win32/registry"
|
38
|
+
# from http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
|
39
|
+
if ::RbConfig::CONFIG["target_cpu"] == "i386"
|
40
|
+
reg_type = Win32::Registry::KEY_READ | 0x100
|
41
|
+
elsif ::RbConfig::CONFIG["target_cpu"] == "x86_64"
|
42
|
+
reg_type = Win32::Registry::KEY_READ | 0x200
|
43
|
+
else
|
44
|
+
reg_type = Win32::Registry::KEY_READ
|
45
|
+
end
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
47
|
+
begin
|
48
|
+
Win32::Registry::HKEY_LOCAL_MACHINE.open('System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy', reg_type) do |policy|
|
49
|
+
enabled = policy["Enabled"]
|
50
|
+
fips["kernel"] = { "enabled" => enabled == 0 ? false : true }
|
51
|
+
end
|
52
|
+
rescue Win32::Registry::Error
|
53
|
+
fips["kernel"] = { "enabled" => false }
|
45
54
|
end
|
46
|
-
rescue Win32::Registry::Error
|
47
|
-
fips["kernel"] = { "enabled" => false }
|
48
55
|
end
|
49
56
|
end
|
50
57
|
end
|
data/lib/ohai/version.rb
CHANGED
@@ -101,15 +101,16 @@ Chassis Information
|
|
101
101
|
EOS
|
102
102
|
|
103
103
|
describe Ohai::System, "plugin dmi" do
|
104
|
+
let(:plugin) { get_plugin("dmi") }
|
105
|
+
let(:stdout) { DMI_OUT }
|
106
|
+
|
104
107
|
before(:each) do
|
105
|
-
|
106
|
-
@stdout = DMI_OUT
|
107
|
-
allow(@plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, @stdout, ""))
|
108
|
+
allow(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, stdout, ""))
|
108
109
|
end
|
109
110
|
|
110
|
-
it "
|
111
|
-
expect(
|
112
|
-
|
111
|
+
it "runs dmidecode" do
|
112
|
+
expect(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, stdout, ""))
|
113
|
+
plugin.run
|
113
114
|
end
|
114
115
|
|
115
116
|
# Test some simple sample data
|
@@ -128,21 +129,28 @@ describe Ohai::System, "plugin dmi" do
|
|
128
129
|
},
|
129
130
|
}.each do |id, data|
|
130
131
|
data.each do |attribute, value|
|
131
|
-
it "
|
132
|
-
|
133
|
-
expect(
|
132
|
+
it "attribute [:dmi][:#{id}][:#{attribute}] is set" do
|
133
|
+
plugin.run
|
134
|
+
expect(plugin[:dmi][id][attribute]).to eql(value)
|
134
135
|
end
|
135
|
-
it "
|
136
|
-
|
137
|
-
expect(
|
138
|
-
|
139
|
-
expect(
|
136
|
+
it "attribute [:dmi][:#{id}][:#{attribute}] set for windows output" do
|
137
|
+
stdout = convert_windows_output(DMI_OUT)
|
138
|
+
expect(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, stdout, ""))
|
139
|
+
plugin.run
|
140
|
+
expect(plugin[:dmi][id][attribute]).to eql(value)
|
140
141
|
end
|
141
142
|
end
|
142
143
|
end
|
143
144
|
|
144
|
-
it "
|
145
|
-
|
146
|
-
|
145
|
+
it "allows capturing additional DMI data" do
|
146
|
+
Ohai.config[:additional_dmi_ids] = [ 16 ]
|
147
|
+
plugin.run
|
148
|
+
expect(plugin[:dmi]).to have_key(:physical_memory_array)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "correctly ignores data in excluded DMI IDs" do
|
152
|
+
expect(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, stdout, ""))
|
153
|
+
plugin.run
|
154
|
+
expect(plugin[:dmi]).not_to have_key(:physical_memory_array)
|
147
155
|
end
|
148
156
|
end
|
@@ -17,23 +17,38 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require_relative "../../../spec_helper.rb"
|
20
|
+
require "openssl"
|
20
21
|
|
21
22
|
describe Ohai::System, "plugin fips" do
|
22
23
|
let(:enabled) { "0" }
|
23
24
|
let(:plugin) { get_plugin("linux/fips") }
|
24
25
|
let(:fips_path) { "/proc/sys/crypto/fips_enabled" }
|
26
|
+
let(:openssl_test_mode) { true }
|
27
|
+
|
28
|
+
subject do
|
29
|
+
plugin.run
|
30
|
+
plugin["fips"]["kernel"]["enabled"]
|
31
|
+
end
|
25
32
|
|
26
33
|
before(:each) do
|
27
34
|
allow(plugin).to receive(:collect_os).and_return(:linux)
|
28
35
|
allow(::File).to receive(:read).with(fips_path).and_return(enabled)
|
29
36
|
end
|
30
37
|
|
38
|
+
around do |ex|
|
39
|
+
begin
|
40
|
+
$FIPS_TEST_MODE = openssl_test_mode
|
41
|
+
ex.run
|
42
|
+
ensure
|
43
|
+
$FIPS_TEST_MODE = false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
31
47
|
context "fips file is present and contains 1" do
|
32
48
|
let(:enabled) { "1" }
|
33
49
|
|
34
50
|
it "sets fips plugin" do
|
35
|
-
|
36
|
-
expect(plugin["fips"]["kernel"]["enabled"]).to be(true)
|
51
|
+
expect(subject).to be(true)
|
37
52
|
end
|
38
53
|
end
|
39
54
|
|
@@ -41,8 +56,7 @@ describe Ohai::System, "plugin fips" do
|
|
41
56
|
let(:enabled) { "0" }
|
42
57
|
|
43
58
|
it "does not set fips plugin" do
|
44
|
-
|
45
|
-
expect(plugin["fips"]["kernel"]["enabled"]).to be(false)
|
59
|
+
expect(subject).to be(false)
|
46
60
|
end
|
47
61
|
end
|
48
62
|
|
@@ -52,8 +66,25 @@ describe Ohai::System, "plugin fips" do
|
|
52
66
|
end
|
53
67
|
|
54
68
|
it "does not set fips plugin" do
|
55
|
-
|
56
|
-
|
69
|
+
expect(subject).to be(false)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with Ruby 2.5 or newer", if: defined?(OpenSSL.fips_mode) do
|
74
|
+
let(:openssl_test_mode) { false }
|
75
|
+
|
76
|
+
context "with OpenSSL.fips_mode == false" do
|
77
|
+
before { allow(OpenSSL).to receive(:fips_mode).and_return(false) }
|
78
|
+
it "does not set fips plugin" do
|
79
|
+
expect(subject).to be(false)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with OpenSSL.fips_mode == true" do
|
84
|
+
before { allow(OpenSSL).to receive(:fips_mode).and_return(true) }
|
85
|
+
it "sets fips plugin" do
|
86
|
+
expect(subject).to be(true)
|
87
|
+
end
|
57
88
|
end
|
58
89
|
end
|
59
90
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Phil Dibowitz <phil@ipom.com>
|
3
|
+
# Copyright:: Copyright (c) 2018 Facebook, 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_relative "../../spec_helper.rb"
|
20
|
+
|
21
|
+
describe Ohai::System, "lsscsi plugin" do
|
22
|
+
let(:plugin) { get_plugin("scsi") }
|
23
|
+
before(:each) do
|
24
|
+
allow(plugin).to receive(:collect_os).and_return(:linux)
|
25
|
+
@stdout = <<LSSCSI
|
26
|
+
[5:0:0:0] disk ATA Hitachi HUA72205 A3EA /dev/sda
|
27
|
+
[6:2:0:0] disk LSI MR9286CV-8e 3.41 /dev/sdb
|
28
|
+
[6:2:1:0] disk LSI MR9286CV-8e 3.41 /dev/sdc
|
29
|
+
[6:2:2:0] disk LSI MR9286CV-8e 3.41 /dev/sdd
|
30
|
+
[6:2:3:0] disk LSI MR9286CV-8e 3.41 /dev/sde
|
31
|
+
[6:2:4:0] disk LSI MR9286CV-8e 3.41 /dev/sdf
|
32
|
+
LSSCSI
|
33
|
+
allow(plugin).to receive(:shell_out).with("lsscsi").and_return(
|
34
|
+
mock_shell_out(0, @stdout, ""))
|
35
|
+
plugin.run
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "when gathering data from lsscsi" do
|
39
|
+
it "lists all devices" do
|
40
|
+
expect(plugin[:scsi].keys).to eq(
|
41
|
+
["5:0:0:0", "6:2:0:0", "6:2:1:0", "6:2:2:0", "6:2:3:0", "6:2:4:0"]
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "parses out type" do
|
46
|
+
expect(plugin[:scsi]["6:2:0:0"]["type"]).to eq("disk")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "parses out transport" do
|
50
|
+
expect(plugin[:scsi]["5:0:0:0"]["transport"]).to eq("ATA")
|
51
|
+
expect(plugin[:scsi]["6:2:0:0"]["transport"]).to eq("LSI")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "parses out device" do
|
55
|
+
expect(plugin[:scsi]["6:2:0:0"]["device"]).to eq("/dev/sdb")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "parses out revision" do
|
59
|
+
expect(plugin[:scsi]["6:2:3:0"]["revision"]).to eq("3.41")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "parses out name" do
|
63
|
+
expect(plugin[:scsi]["5:0:0:0"]["name"]).to eq("Hitachi HUA72205")
|
64
|
+
expect(plugin[:scsi]["6:2:4:0"]["name"]).to eq("MR9286CV-8e")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -26,35 +26,93 @@ describe Ohai::System, "shard plugin" do
|
|
26
26
|
let(:serial) { "234du3m4i498xdjr2" }
|
27
27
|
let(:machine_id) { "0a1f869f457a4c8080ab19faf80af9cc" }
|
28
28
|
let(:machinename) { "somehost004" }
|
29
|
+
let(:fips) { false }
|
30
|
+
let(:os) { :linux }
|
31
|
+
|
32
|
+
subject do
|
33
|
+
plugin.run
|
34
|
+
plugin[:shard_seed]
|
35
|
+
end
|
29
36
|
|
30
37
|
before(:each) do
|
31
|
-
allow(plugin).to receive(:collect_os).and_return(:linux)
|
32
38
|
plugin["machinename"] = machinename
|
33
39
|
plugin["machine_id"] = machine_id
|
34
40
|
plugin["fqdn"] = fqdn
|
35
41
|
plugin["dmi"] = { "system" => {} }
|
36
42
|
plugin["dmi"]["system"]["uuid"] = uuid
|
37
43
|
plugin["dmi"]["system"]["serial_number"] = serial
|
38
|
-
|
44
|
+
plugin["fips"] = { "kernel" => { "enabled" => fips } }
|
45
|
+
allow(plugin).to receive(:collect_os).and_return(os)
|
39
46
|
end
|
40
47
|
|
41
48
|
it "should provide a shard with a default-safe set of sources" do
|
42
|
-
|
43
|
-
result = Digest::MD5.hexdigest(
|
44
|
-
"#{machinename}#{serial}#{uuid}"
|
45
|
-
)[0...7].to_i(16)
|
46
|
-
expect(plugin[:shard_seed]).to eq(result)
|
49
|
+
expect(subject).to eq(27767217)
|
47
50
|
end
|
48
51
|
|
49
52
|
it "should provide a shard with a configured source" do
|
50
53
|
Ohai.config[:plugin][:shard_seed][:sources] = [:fqdn]
|
51
|
-
|
52
|
-
result = Digest::MD5.hexdigest(fqdn)[0...7].to_i(16)
|
53
|
-
expect(plugin[:shard_seed]).to eq(result)
|
54
|
+
expect(subject).to eq(203669792)
|
54
55
|
end
|
55
56
|
|
56
57
|
it "fails on an unrecognized source" do
|
57
58
|
Ohai.config[:plugin][:shard_seed][:sources] = [:GreatGooglyMoogly]
|
58
|
-
expect {
|
59
|
+
expect { subject }.to raise_error(RuntimeError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should provide a shard with a configured algorithm" do
|
63
|
+
Ohai.config[:plugin][:shard_seed][:digest_algorithm] = "sha256"
|
64
|
+
expect(Digest::MD5).to_not receive(:new)
|
65
|
+
expect(subject).to eq(117055036)
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with Darwin OS" do
|
69
|
+
let(:os) { :darwin }
|
70
|
+
before do
|
71
|
+
plugin["hardware"] = { "serial_number" => serial, "platform_UUID" => uuid }
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should provide a shard with a default-safe set of sources" do
|
75
|
+
expect(subject).to eq(27767217)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with Windows OS" do
|
80
|
+
let(:os) { :windows }
|
81
|
+
before do
|
82
|
+
wmi = double("WmiLite::Wmi")
|
83
|
+
allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
|
84
|
+
allow(wmi).to receive(:first_of).with("Win32_BIOS").and_return("SerialNumber" => serial)
|
85
|
+
allow(wmi).to receive(:first_of).with("Win32_ComputerSystemProduct").and_return("UUID" => uuid)
|
86
|
+
plugin["kernel"] = { "os_info" => { "serial_number" => serial + "0" } }
|
87
|
+
plugin.data.delete("dmi") # To make sure we aren't using the wrong data.
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should provide a shard with a default-safe set of sources" do
|
91
|
+
expect(subject).to eq(27767217)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should allow os_serial source" do
|
95
|
+
Ohai.config[:plugin][:shard_seed][:sources] = [:machinename, :os_serial, :uuid]
|
96
|
+
# Different from above.
|
97
|
+
expect(subject).to eq(178738102)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "with a weird OS" do
|
102
|
+
let(:os) { :aix }
|
103
|
+
|
104
|
+
it "should provide a shard with a default-safe set of sources" do
|
105
|
+
# Note: this is different than the other defaults.
|
106
|
+
expect(subject).to eq(253499154)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "with FIPS mode enabled" do
|
111
|
+
let(:fips) { true }
|
112
|
+
|
113
|
+
it "should use SHA2" do
|
114
|
+
expect(Digest::MD5).to_not receive(:hexdigest)
|
115
|
+
expect(subject).to eq(117055036)
|
116
|
+
end
|
59
117
|
end
|
60
118
|
end
|
@@ -17,25 +17,40 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require_relative "../../../spec_helper.rb"
|
20
|
+
require "openssl"
|
20
21
|
|
21
22
|
describe Ohai::System, "plugin fips", :windows_only do
|
22
23
|
let(:enabled) { 0 }
|
23
24
|
let(:plugin) { get_plugin("windows/fips") }
|
24
25
|
let(:fips_key) { 'System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy' }
|
25
26
|
let(:win_reg_entry) { { "Enabled" => enabled } }
|
27
|
+
let(:openssl_test_mode) { true }
|
28
|
+
|
29
|
+
subject do
|
30
|
+
plugin.run
|
31
|
+
plugin["fips"]["kernel"]["enabled"]
|
32
|
+
end
|
26
33
|
|
27
34
|
before(:each) do
|
28
35
|
allow(plugin).to receive(:collect_os).and_return(:windows)
|
29
36
|
allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with(fips_key, arch).and_yield(win_reg_entry)
|
30
37
|
end
|
31
38
|
|
39
|
+
around do |ex|
|
40
|
+
begin
|
41
|
+
$FIPS_TEST_MODE = openssl_test_mode
|
42
|
+
ex.run
|
43
|
+
ensure
|
44
|
+
$FIPS_TEST_MODE = false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
32
48
|
shared_examples "fips_plugin" do
|
33
49
|
context "fips enabled key is set to 1" do
|
34
50
|
let(:enabled) { 1 }
|
35
51
|
|
36
52
|
it "sets fips plugin" do
|
37
|
-
|
38
|
-
expect(plugin["fips"]["kernel"]["enabled"]).to be(true)
|
53
|
+
expect(subject).to be(true)
|
39
54
|
end
|
40
55
|
end
|
41
56
|
|
@@ -43,8 +58,7 @@ describe Ohai::System, "plugin fips", :windows_only do
|
|
43
58
|
let(:enabled) { 0 }
|
44
59
|
|
45
60
|
it "does not set fips plugin" do
|
46
|
-
|
47
|
-
expect(plugin["fips"]["kernel"]["enabled"]).to be(false)
|
61
|
+
expect(subject).to be(false)
|
48
62
|
end
|
49
63
|
end
|
50
64
|
|
@@ -54,8 +68,7 @@ describe Ohai::System, "plugin fips", :windows_only do
|
|
54
68
|
end
|
55
69
|
|
56
70
|
it "does not set fips plugin" do
|
57
|
-
|
58
|
-
expect(plugin["fips"]["kernel"]["enabled"]).to be(false)
|
71
|
+
expect(subject).to be(false)
|
59
72
|
end
|
60
73
|
end
|
61
74
|
end
|
@@ -83,4 +96,22 @@ describe Ohai::System, "plugin fips", :windows_only do
|
|
83
96
|
|
84
97
|
it_behaves_like "fips_plugin"
|
85
98
|
end
|
99
|
+
|
100
|
+
context "with Ruby 2.5 or newer", if: defined?(OpenSSL.fips_mode) do
|
101
|
+
let(:openssl_test_mode) { false }
|
102
|
+
|
103
|
+
context "with OpenSSL.fips_mode == false" do
|
104
|
+
before { allow(OpenSSL).to receive(:fips_mode).and_return(false) }
|
105
|
+
it "does not set fips plugin" do
|
106
|
+
expect(subject).to be(false)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "with OpenSSL.fips_mode == true" do
|
111
|
+
before { allow(OpenSSL).to receive(:fips_mode).and_return(true) }
|
112
|
+
it "sets fips plugin" do
|
113
|
+
expect(subject).to be(true)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
86
117
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 14.0
|
4
|
+
version: 14.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: systemu
|
@@ -315,6 +315,7 @@ files:
|
|
315
315
|
- lib/ohai/plugins/rust.rb
|
316
316
|
- lib/ohai/plugins/scala.rb
|
317
317
|
- lib/ohai/plugins/scaleway.rb
|
318
|
+
- lib/ohai/plugins/scsi.rb
|
318
319
|
- lib/ohai/plugins/shard.rb
|
319
320
|
- lib/ohai/plugins/shells.rb
|
320
321
|
- lib/ohai/plugins/softlayer.rb
|
@@ -493,6 +494,7 @@ files:
|
|
493
494
|
- spec/unit/plugins/rust_spec.rb
|
494
495
|
- spec/unit/plugins/scala_spec.rb
|
495
496
|
- spec/unit/plugins/scaleway_spec.rb
|
497
|
+
- spec/unit/plugins/scsi_spec.rb
|
496
498
|
- spec/unit/plugins/shard_spec.rb
|
497
499
|
- spec/unit/plugins/shells_spec.rb
|
498
500
|
- spec/unit/plugins/softlayer_spec.rb
|
@@ -542,7 +544,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
542
544
|
version: '0'
|
543
545
|
requirements: []
|
544
546
|
rubyforge_project:
|
545
|
-
rubygems_version: 2.7.
|
547
|
+
rubygems_version: 2.7.6
|
546
548
|
signing_key:
|
547
549
|
specification_version: 4
|
548
550
|
summary: Ohai profiles your system and emits JSON
|