Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl committed May 30, 2022
1 parent 5be679e commit 79485ef
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

source 'https://rubygems.org'

gem 'rspec', '~> 3.1'
gem 'rubocop', '~> 1.30'
gem 'rubocop-rspec', '~> 2.10'
gem 'simplecov', '~> 0.21', require: false
gemspec
26 changes: 26 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
diff-lcs (1.5.0)
docile (1.4.0)
ed25519 (1.3.0)
parallel (1.22.1)
parser (3.1.2.0)
ast (~> 2.4.1)
rainbow (3.1.1)
regexp_parser (2.5.0)
rexml (3.2.5)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.30.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
Expand All @@ -26,15 +41,26 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.18.0)
parser (>= 3.1.1.0)
rubocop-rspec (2.11.1)
rubocop (~> 1.19)
ruby-progressbar (1.11.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
unicode-display_width (2.1.0)

PLATFORMS
ruby

DEPENDENCIES
minisign!
rspec (~> 3.1)
rubocop (~> 1.30)
rubocop-rspec (~> 2.10)
simplecov (~> 0.21)

BUNDLED WITH
2.1.4
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Minisign.rb
# Minisign

A rubygem for verifying [Minisign](http://jedisct1.github.io/minisign/) signatures.

Expand Down
20 changes: 20 additions & 0 deletions spec/minisign_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

describe Minisign::PublicKey do
before do
@pk = Minisign::PublicKey.new(File.read('test/local.pub').split("\n").pop)
@message = File.read('test/example.txt')
end
it 'verifies signatures' do
@signature = Minisign::Signature.new(File.read('test/example.txt.minisig'))
expect(@pk.verify(@signature, @message)).to match('Trusted comment')
end
it 'raises ed25519 errors' do
@signature = Minisign::Signature.new(File.read('test/example.txt.minisig.unverifiable'))
expect { @pk.verify(@signature, @message) }.to raise_error(Ed25519::VerifyError)
end
it 'verifies trusted comments' do
@signature = Minisign::Signature.new(File.read('test/example.txt.minisig.tampered'))
expect { @pk.verify(@signature, @message) }.to raise_error('Comment signature verification failed')
end
end
18 changes: 18 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'simplecov'
SimpleCov.start do
add_filter '/spec'
end

require 'minisign'

RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.shared_context_metadata_behavior = :apply_to_host_groups
end
4 changes: 4 additions & 0 deletions test/example.txt.minisig.tampered
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
untrusted comment: signature from minisign secret key
RUTg6JXWzv6GDmPMFIE8V3D+S6mi6FBFrUNwvRVZrLNrySSWT8HPLXhN16nSzb3WLTSd59SceVfGtgEP2FMHVAqTc40mLXBbJQ4=
trusted comment: timestamp:1653934367 file:example.txt hashed
YU7xAGNcc5LGLHHyw14S6xtIvhfF3chGJ/rLSauaiPb1jtnt6JHB/ieMIjqEZ8unxxLllXQ2t6uQqzIKsiwAAg==
4 changes: 4 additions & 0 deletions test/example.txt.minisig.unverifiable
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
untrusted comment: signature from minisign secret key
RUTg6JXWzv6GDmPMFIE8V3D+S5mi6FBFrUNwvRVZrLNrySSWT8HPLXhN16nSzb3WLTSd59SceVfGtgEP2FMHVAqTc40mLXBbJQ4=
trusted comment: timestamp:1653934067 file:example.txt hashed
YU7xAGNcc5LGLHHyw14S6xtIvhfF3chGJ/rLSauaiPb1jtnt6JHB/ieMIjqEZ8unxxLllXQ2t6uQqzIKsiwAAg==

0 comments on commit 79485ef

Please sign in to comment.