Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl committed Feb 18, 2024
1 parent 5e5445c commit fcf0dd4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/minisign/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def self.verify(options)
signature = Minisign::Signature.new(File.read(options[:x]))
begin
verification = public_key.verify(signature, message)
rescue StandardError
puts 'Signature verification failed'
rescue Minisign::SignatureVerificationError => e
puts e.message
exit 1
end
return if options[:q]
Expand Down
4 changes: 2 additions & 2 deletions lib/minisign/public_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def verify_comment_signature(signature, comment)

def verify_message_signature(signature, message)
ed25519_verify_key.verify(signature, blake2b512(message))
rescue Ed25519::VerifyError => e
raise Minisign::SignatureVerificationError, e
rescue Ed25519::VerifyError
raise Minisign::SignatureVerificationError, 'Signature verification failed'
end

def untrusted_comment
Expand Down
24 changes: 23 additions & 1 deletion spec/minisign/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
end
it 'does not prompt for a password if -W' do
keyname = SecureRandom.uuid
SecureRandom.uuid
options = {
p: "test/generated/cli/#{keyname}.pub",
s: "test/generated/cli/#{keyname}.key",
Expand All @@ -33,6 +32,19 @@
expect(Minisign::CLI).not_to receive(:prompt)
Minisign::CLI.generate(options)
end
it 'prints an error message if the passwords dont match' do
password = SecureRandom.uuid
password_confirmation = SecureRandom.uuid
keyname = SecureRandom.uuid
options = {
p: "test/generated/cli/#{keyname}.pub",
s: "test/generated/cli/#{keyname}.key"
}
allow(Minisign::CLI).to receive(:prompt).and_return(password, password_confirmation)
expect do
Minisign::CLI.generate(options)
end.to raise_error(SystemExit)
end
it 'writes the key files' do
keyname = SecureRandom.uuid
password = SecureRandom.uuid
Expand Down Expand Up @@ -151,6 +163,16 @@
Minisign::CLI.verify(options)
end.not_to raise_error
end
it 'prints an error message' do
options = {
p: 'test/minisign.pub',
m: 'test/example.txt',
x: 'test/example.txt.minisig.tampered'
}
expect do
Minisign::CLI.verify(options)
end.to raise_error(SystemExit)
end
it 'outputs the message' do
options = {
p: 'test/minisign.pub',
Expand Down
2 changes: 1 addition & 1 deletion spec/minisign/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
command = 'minisign -Vm test/example.txt -x test/example.txt.minisig.unverifiable -p test/minisign.pub'
expect(`#{command}`).to match(/Signature verification failed/)
command = 'minisign -Vm test/example.txt -x test/example.txt.minisig.tampered -p test/minisign.pub'
expect(`#{command}`).to match(/Signature verification failed/)
expect(`#{command}`).to match(/Comment signature verification failed/)
end
end
2 changes: 1 addition & 1 deletion spec/minisign/public_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@signature = Minisign::Signature.new(File.read('test/example.txt.minisig.unverifiable'))
expect do
@pk.verify(@signature, @message)
end.to raise_error(Minisign::SignatureVerificationError, 'signature verification failed!')
end.to raise_error(Minisign::SignatureVerificationError, 'Signature verification failed')
end
it 'verifies trusted comments' do
@signature = Minisign::Signature.new(File.read('test/example.txt.minisig.tampered'))
Expand Down

0 comments on commit fcf0dd4

Please sign in to comment.