Skip to content

Commit

Permalink
Handle cases when PGP key metadata is 'nil'
Browse files Browse the repository at this point in the history
  • Loading branch information
ribose-jeffreylau committed Jul 12, 2019
1 parent 3cdd192 commit 1d705bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/rails/keyserver/key/pgp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.extension
Engine.config.key_host = nil

def derive_metadata_if_empty
derive_metadata if metadata.empty?
derive_metadata if metadata.blank?
end

# Pick the one without primar key grip.
Expand Down
17 changes: 17 additions & 0 deletions spec/models/rails/key/pgp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,23 @@
end
end

describe "#derive_metadata_if_empty" do
context "with nil metadata" do
let(:key) do
FactoryBot.build(:rails_keyserver_key_pgp).tap do |k|
allow(k).to receive(:metadata).and_return(nil)
allow(k).to receive(:derive_metadata)
expect(k.metadata).to be_nil
end
end

it "runs #derive_metadata_if_empty" do
expect(key).to receive :derive_metadata
key.derive_metadata_if_empty
end
end
end

# - wrong key
#
# …
Expand Down

0 comments on commit 1d705bf

Please sign in to comment.