Gem Version Build Status Test Coverage Code Climate

RSpec matchers for testing PGP-encrypted messages, and signatures.

Important
This gem calls GnuPG executables internally. However, it does not rely on machine-readable interface yet, and may easily break when they change something in GnuPG’s human-readable output. As long as it is not resolved in a better way, we are going to maintain compatibility with the most recent versions of GnuPG. At the moment of writing this statement, it is GnuPG 2.2.9.
Tip
In order to check which GnuPG version this gem was tested against, check out builds in Travis. One of the build steps in a "before script" phase executes gpg --version to make things clear.

Usage

Getting started

  1. Make sure that you have GnuPG 2.2 installed.

  2. Add this line to your application’s Gemfile:

    gem "rspec-pgp_matchers", github: "riboseinc/rspec-pgp_matchers", require: false, group: :test
  3. And following to your spec helper:

    require "rspec/pgp_matchers"
    RSpec::PGPMatchers.homedir = "path/to/pgp_home_directory/with/development/keys"

Matching signatures

text = "Some text"
signer_uid = "[email protected]"
someones_uid = "[email protected]"

# Not defined in this gem, but required for this example
signature = sign_text(text: text, signer: signer_uid, ascii_armor: true)

# Both following do pass
expect(signature).to be_a_valid_pgp_signature_of(text)
expect(signature).to be_a_valid_pgp_signature_of(text).signed_by(signer_uid)

# This one fails
expect(signature).to be_a_valid_pgp_signature_of(text).signed_by(someones_uid)

Matching encrypted messages

text = "Some text"
recipient1_uid = "[email protected]"
recipient2_uid = "[email protected]"
someones_uid = "[email protected]"

# Not defined in this gem, but required for this example
encrypted = encrypt_text(
  text: text,
  recipients: [recipient1_uid, recipient2_uid],
  ascii_armor: true
)

# Following do pass
expect(encrypted).to be_a_pgp_encrypted_message
expect(encrypted).to be_a_pgp_encrypted_message.containing(text)
expect(encrypted).to be_a_pgp_encrypted_message.encrypted_for(recipient1_uid, recipient2_uid)

# This one fails
expect(encrypted).to be_a_pgp_encrypted_message.encrypted_for(someones_uid)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/riboseinc/rspec-pgp_matchers.

Credits

This gem is developed, maintained and funded by Ribose Inc.

License

The gem is available as open source under the terms of the MIT License.