diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-05-01 15:44:32 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2018-05-01 15:44:41 -0700 |
commit | b22c6add10d641cce298ae80cc0526f977aec6ac (patch) | |
tree | f5a4c4a657c510c23644a4ee56e457b8e3f99f49 | |
parent | 3564dc7e94955d1827d711d1e3249863709c3f96 (diff) | |
download | ohai-b22c6add10d641cce298ae80cc0526f977aec6ac.tar.gz |
Update and upgrade tests.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
-rw-r--r-- | spec/unit/plugins/shard_spec.rb | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/spec/unit/plugins/shard_spec.rb b/spec/unit/plugins/shard_spec.rb index b8945660..6a7d6f5c 100644 --- a/spec/unit/plugins/shard_spec.rb +++ b/spec/unit/plugins/shard_spec.rb @@ -26,6 +26,12 @@ describe Ohai::System, "shard plugin" do let(:serial) { "234du3m4i498xdjr2" } let(:machine_id) { "0a1f869f457a4c8080ab19faf80af9cc" } let(:machinename) { "somehost004" } + let(:fips) { false } + + subject do + plugin.run + plugin[:shard_seed] + end before(:each) do allow(plugin).to receive(:collect_os).and_return(:linux) @@ -35,26 +41,36 @@ describe Ohai::System, "shard plugin" do plugin["dmi"] = { "system" => {} } plugin["dmi"]["system"]["uuid"] = uuid plugin["dmi"]["system"]["serial_number"] = serial + plugin["fips"] = {"kernel" => {"enabled" => fips}} allow(plugin).to receive(:collect_os).and_return(:linux) end it "should provide a shard with a default-safe set of sources" do - plugin.run - result = Digest::MD5.hexdigest( - "#{machinename}#{serial}#{uuid}" - )[0...7].to_i(16) - expect(plugin[:shard_seed]).to eq(result) + expect(subject).to eq(27767217) end it "should provide a shard with a configured source" do Ohai.config[:plugin][:shard_seed][:sources] = [:fqdn] - plugin.run - result = Digest::MD5.hexdigest(fqdn)[0...7].to_i(16) - expect(plugin[:shard_seed]).to eq(result) + expect(subject).to eq(203669792) end it "fails on an unrecognized source" do Ohai.config[:plugin][:shard_seed][:sources] = [:GreatGooglyMoogly] - expect { plugin.run }.to raise_error(RuntimeError) + expect { subject }.to raise_error(RuntimeError) + end + + it "should provide a shard with a configured algorithm" do + Ohai.config[:plugin][:shard_seed][:digest_algorithm] = "sha256" + expect(Digest::MD5).to_not receive(:new) + expect(subject).to eq(117055036) + end + + context "with FIPS mode enabled" do + let(:fips) { true } + + it "should use SHA2" do + expect(Digest::MD5).to_not receive(:new) + expect(subject).to eq(117055036) + end end end |