Skip to content

Commit

Permalink
test remove password
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl committed Feb 10, 2024
1 parent cb82904 commit afba349
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/minisign/private_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def to_s

def change_password!(new_password)
@password = new_password
@bytes[2..3] = [0, 0] if new_password.nil? # kdf_algorithm
end

private
Expand Down
18 changes: 18 additions & 0 deletions spec/minisign/private_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
end

describe '#change_password!' do
before do
@private_key = Minisign::PrivateKey.new(File.read('test/minisign.key'), 'password')
end
it 'changes the password' do
random_trusted_comment = SecureRandom.uuid
new_password = SecureRandom.uuid
Expand All @@ -123,11 +126,26 @@
expect do
Minisign::PrivateKey.new(@private_key.to_s, new_password)
end.not_to raise_error
expect do
Minisign::PrivateKey.new(@private_key.to_s)
end.to raise_error('Missing password for encrypted key')

File.write('test/generated/new-password.key', @private_key)
path = 'test/generated'
command = "echo #{new_password} | #{path}/minisign -Sm #{path}/.keep -s #{path}/new-password.key"
expect(system(command)).to be(true)
end

it 'removes the password if nil' do
@private_key.change_password! nil
expect do
Minisign::PrivateKey.new(@private_key.to_s)
end.not_to raise_error
File.write('test/generated/removed-password.key', @private_key)
path = 'test/generated'
# does not prompt for password
command = "#{path}/minisign -Sm #{path}/.keep -s #{path}/removed-password.key"
expect(system(command)).to be(true)
end
end
end

0 comments on commit afba349

Please sign in to comment.