Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/private_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
end

it "generates a MD5 fingerprint matching ssh-keygen" do
skip "Fingerprint not available" if md5_fpr.nil?
expect(subject.public_key.fingerprint(md5: true)).to eq(md5_fpr)
end

it "generates a SHA256 fingerprint matching ssh-keygen" do
skip "Fingerprint not available" if sha256_fpr.nil?
expect(subject.public_key.fingerprint).to eq(sha256_fpr)
end

Expand Down
8 changes: 6 additions & 2 deletions spec/public_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
describe name do
let(:openssh) { fixture(name).strip }
let(:comment) { SSHData.key_parts(openssh).last }
let(:sha256_fpr) { ssh_keygen_fingerprint(name, :sha256) }
let(:md5_fpr) { ssh_keygen_fingerprint(name, :md5) }

subject { described_class.parse_openssh(openssh) }

it "generates a MD5 fingerprint matching ssh-keygen" do
expect(subject.fingerprint(md5: true)).to eq(ssh_keygen_fingerprint(name, :md5))
skip "Fingerprint not available" if md5_fpr.nil?
expect(subject.fingerprint(md5: true)).to eq(md5_fpr)
end

it "generates a SHA256 fingerprint matching ssh-keygen" do
expect(subject.fingerprint).to eq(ssh_keygen_fingerprint(name, :sha256))
skip "Fingerprint not available" if sha256_fpr.nil?
expect(subject.fingerprint).to eq(sha256_fpr)
end

it "can re-encode back into authorized_keys format" do
Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "ssh_data"
require "ed25519"
require "rspec-parameterized"
require "open3"

RSpec.configure do |config|
config.color_mode = :off
Expand All @@ -21,7 +22,9 @@ def fixture(name, binary: false, pem: false)
end

def ssh_keygen_fingerprint(name, algo, priv: false)
out = `ssh-keygen #{"-e" if priv} -E #{algo} -l -f #{File.join(FIXTURE_PATH, name)}`
out, * = Open3.capture3("ssh-keygen #{'-e' if priv} -E #{algo} -l -f #{File.join(FIXTURE_PATH, name)}")

return nil if out.strip.empty?
out.split(":", 2).last.split(" ").first
end

Expand Down
Loading