test/pgp_test.rb in iostreams-0.12.1 vs test/pgp_test.rb in iostreams-0.13.0
- old
+ new
@@ -2,35 +2,42 @@
#IOStreams::Pgp.logger = Logger.new(STDOUT)
module Streams
class PgpTest < Minitest::Test
- describe IOStreams::Pgp::Reader do
+ describe IOStreams::Pgp do
let :user_name do
'Joe Bloggs'
end
let :email do
'pgp_test@iostreams.net'
end
+ let :passphrase do
+ 'hello'
+ end
+
let :generated_key_id do
- IOStreams::Pgp.generate_key(name: user_name, email: email, key_length: 1024)
+ IOStreams::Pgp.generate_key(name: user_name, email: email, key_length: 1024, passphrase: passphrase)
end
let :public_key do
generated_key_id
IOStreams::Pgp.export(email: email)
end
let :private_key do
generated_key_id
- IOStreams::Pgp.export(email: email, private: true)
+ IOStreams::Pgp.export(email: email, private: true, passphrase: passphrase)
end
before do
+ #ap IOStreams::Pgp.list_keys(email: email, private: true)
IOStreams::Pgp.delete_keys(email: email, public: true, private: true)
+ #ap "KEYS DELETED"
+ #ap IOStreams::Pgp.list_keys(email: email, private: true)
end
describe '.pgp_version' do
it 'returns pgp version' do
assert IOStreams::Pgp.pgp_version
@@ -84,21 +91,21 @@
assert ascii_keys = IOStreams::Pgp.export(email: email)
assert ascii_keys =~ /BEGIN PGP PUBLIC KEY BLOCK/, ascii_keys
end
it 'exports private keys by email' do
- assert ascii_keys = IOStreams::Pgp.export(email: email, private: true)
+ assert ascii_keys = IOStreams::Pgp.export(email: email, private: true, passphrase: passphrase)
assert ascii_keys =~ /BEGIN PGP PRIVATE KEY BLOCK/, ascii_keys
end
it 'exports public keys as binary' do
assert keys = IOStreams::Pgp.export(email: email, ascii: false)
refute keys =~ /BEGIN PGP (PUBLIC|PRIVATE) KEY BLOCK/, keys
end
it 'exports private keys as binary' do
- assert keys = IOStreams::Pgp.export(email: email, ascii: false, private: true)
+ assert keys = IOStreams::Pgp.export(email: email, ascii: false, private: true, passphrase: passphrase)
refute keys =~ /BEGIN PGP (PUBLIC|PRIVATE) KEY BLOCK/, keys
end
end
describe '.list_keys' do
@@ -111,17 +118,16 @@
assert_equal 1, keys.size
assert key = keys.first
assert_equal key[:date], Date.today
assert_equal email, key[:email]
- assert_equal generated_key_id, key[:key_id]
+ assert_includes key[:key_id], generated_key_id
assert_equal 1024, key[:key_length]
- assert_equal 'R', key[:key_type]
+ assert_includes ['R', 'rsa'], key[:key_type]
assert_equal user_name, key[:name]
refute key[:private], key
ver = IOStreams::Pgp.pgp_version
- ap "Running PGP tests with #{IOStreams::Pgp.executable} v#{ver}"
maint = ver.split('.').last.to_i
if (ver.to_f >= 2) && (maint >= 30)
assert_equal 'ultimate', key[:trust]
end
end
@@ -131,16 +137,15 @@
assert_equal 1, keys.size
assert key = keys.first
assert_equal key[:date], Date.today
assert_equal email, key[:email]
- assert_equal generated_key_id, key[:key_id]
+ assert_includes key[:key_id], generated_key_id
assert_equal 1024, key[:key_length]
- assert_equal 'R', key[:key_type]
+ assert_includes ['R', 'rsa'], key[:key_type]
assert_equal user_name, key[:name]
assert key[:private], key
- refute key.key?(:trust)
end
end
describe '.key_info' do
it 'extracts public key info' do
@@ -148,26 +153,27 @@
assert_equal 1, keys.size
assert key = keys.first
assert_equal key[:date], Date.today
assert_equal email, key[:email]
- assert_equal generated_key_id, key[:key_id]
+ assert_includes key[:key_id], generated_key_id
assert_equal 1024, key[:key_length]
- assert_equal 'R', key[:key_type]
+ assert_includes ['R', 'rsa'], key[:key_type]
assert_equal user_name, key[:name]
refute key[:private], key
refute key.key?(:trust)
end
it 'extracts private key info' do
+ skip 'GnuPG v2.1 and above does not allow batch inspection of private keys' if IOStreams::Pgp.pgp_version.to_f >= 2.1
assert keys = IOStreams::Pgp.key_info(key: private_key)
assert_equal 1, keys.size
assert key = keys.first
assert_equal key[:date], Date.today
assert_equal email, key[:email]
- assert_equal generated_key_id, key[:key_id]
+ assert_includes key[:key_id], generated_key_id
assert_equal 1024, key[:key_length]
assert_equal 'R', key[:key_type]
assert_equal user_name, key[:name]
assert key[:private], key
refute key.key?(:trust)
@@ -202,10 +208,11 @@
assert_equal user_name, key[:name]
refute key[:private], key
end
it 'imports ascii private key' do
+ skip 'GnuPG v2.1 and above does not allow batch import of private keys' if IOStreams::Pgp.pgp_version.to_f >= 2.1
assert keys = IOStreams::Pgp.import(key: @private_key)
assert_equal 1, keys.size
assert key = keys.first
assert_equal email, key[:email]
@@ -224,9 +231,10 @@
assert_equal user_name, key[:name]
refute key[:private], key
end
it 'imports binary private key' do
+ skip 'GnuPG v2.1 and above does not allow batch import of private keys' if IOStreams::Pgp.pgp_version.to_f >= 2.1
assert keys = IOStreams::Pgp.import(key: @private_key)
assert_equal 1, keys.size
assert key = keys.first
assert_equal email, key[:email]