File: digest_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (34 lines) | stat: -rw-r--r-- 1,026 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'spec_helper'

require 'puppet/ssl/digest'

describe Puppet::SSL::Digest do
  it "defaults to sha256" do
    digest = described_class.new(nil, 'blah')
    expect(digest.name).to eq('SHA256')
    expect(digest.digest.hexdigest).to eq("8b7df143d91c716ecfa5fc1730022f6b421b05cedee8fd52b1fc65a96030ad52")
  end

  describe '#name' do
    it "prints the hashing algorithm used by the openssl digest" do
      expect(described_class.new('SHA224', 'blah').name).to eq('SHA224')
    end

    it "upcases the hashing algorithm" do
      expect(described_class.new('sha224', 'blah').name).to eq('SHA224')
    end
  end

  describe '#to_hex' do
    it "returns ':' separated upper case hex pairs" do
      described_class.new(nil, 'blah').to_hex =~ /\A([A-Z0-9]:)+[A-Z0-9]\Z/
    end
  end

  describe '#to_s' do
    it "formats the digest algorithm and the digest as a string" do
      digest = described_class.new('sha512', 'some content')
      expect(digest.to_s).to eq("(#{digest.name}) #{digest.to_hex}")
    end
  end
end