diff --git a/app/controllers/diaspora_federation/fetch_controller.rb b/app/controllers/diaspora_federation/fetch_controller.rb index 95f8d3c..fddbb0b 100644 --- a/app/controllers/diaspora_federation/fetch_controller.rb +++ b/app/controllers/diaspora_federation/fetch_controller.rb @@ -29,7 +29,7 @@ module DiasporaFederation end def create_magic_envelope(entity) - privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, entity.author) + privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, entity.author) Salmon::MagicEnvelope.new(entity, entity.author).envelop(privkey) if privkey end end diff --git a/lib/diaspora_federation.rb b/lib/diaspora_federation.rb index 5120099..2e05497 100644 --- a/lib/diaspora_federation.rb +++ b/lib/diaspora_federation.rb @@ -23,8 +23,8 @@ module DiasporaFederation fetch_person_for_webfinger fetch_person_for_hcard save_person_after_webfinger - fetch_private_key_by_diaspora_id - fetch_public_key_by_diaspora_id + fetch_private_key + fetch_public_key fetch_related_entity queue_public_receive queue_private_receive @@ -143,12 +143,12 @@ module DiasporaFederation # so the application saves the person data # @param [DiasporaFederation::Entities::Person] person data # - # fetch_private_key_by_diaspora_id + # fetch_private_key # Fetches a private key of a person by her Diaspora ID from the application # @param [String] Diaspora ID of the person # @return [OpenSSL::PKey::RSA] key # - # fetch_public_key_by_diaspora_id + # fetch_public_key # Fetches a public key of a person by her Diaspora ID from the application # @param [String] Diaspora ID of the person # @return [OpenSSL::PKey::RSA] key diff --git a/lib/diaspora_federation/entities/relayable.rb b/lib/diaspora_federation/entities/relayable.rb index ac22047..c3ac091 100644 --- a/lib/diaspora_federation/entities/relayable.rb +++ b/lib/diaspora_federation/entities/relayable.rb @@ -82,7 +82,7 @@ module DiasporaFederation # verifies the signatures (+author_signature+ and +parent_author_signature+ if needed) # @raise [SignatureVerificationFailed] if the signature is not valid or no public key is found def verify_signatures - pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key_by_diaspora_id, author) + pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, author) raise PublicKeyNotFound, "author_signature author=#{author} guid=#{guid}" if pubkey.nil? raise SignatureVerificationFailed, "wrong author_signature" unless verify_signature(pubkey, author_signature) @@ -93,7 +93,7 @@ module DiasporaFederation # this happens only on downstream federation def verify_parent_author_signature - pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key_by_diaspora_id, parent.author) + pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, parent.author) raise PublicKeyNotFound, "parent_author_signature parent_author=#{parent.author} guid=#{guid}" if pubkey.nil? unless verify_signature(pubkey, parent_author_signature) raise SignatureVerificationFailed, "wrong parent_author_signature parent_guid=#{parent_guid}" @@ -120,7 +120,7 @@ module DiasporaFederation # @raise [AuthorPrivateKeyNotFound] if the author private key is not found # @return [String] A Base64 encoded signature of #signature_data with key def sign_with_author - privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, author) + privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author) raise AuthorPrivateKeyNotFound, "author=#{author} guid=#{guid}" if privkey.nil? sign_with_key(privkey).tap do logger.info "event=sign status=complete signature=author_signature author=#{author} guid=#{guid}" @@ -130,7 +130,7 @@ module DiasporaFederation # sign with parent author key, if the parent author is local (if the private key is found) # @return [String] A Base64 encoded signature of #signature_data with key def sign_with_parent_author_if_available - privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, parent.author) + privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, parent.author) if privkey sign_with_key(privkey).tap do logger.info "event=sign status=complete signature=parent_author_signature guid=#{guid}" diff --git a/lib/diaspora_federation/entities/relayable_retraction.rb b/lib/diaspora_federation/entities/relayable_retraction.rb index bec49df..628257e 100644 --- a/lib/diaspora_federation/entities/relayable_retraction.rb +++ b/lib/diaspora_federation/entities/relayable_retraction.rb @@ -88,7 +88,7 @@ module DiasporaFederation # # @return [Hash] xml elements with updated signatures def xml_elements - privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, author) + privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author) super.tap do |xml_elements| fill_required_signature(privkey, xml_elements) unless privkey.nil? diff --git a/lib/diaspora_federation/entities/signed_retraction.rb b/lib/diaspora_federation/entities/signed_retraction.rb index 43cbf85..611f6aa 100644 --- a/lib/diaspora_federation/entities/signed_retraction.rb +++ b/lib/diaspora_federation/entities/signed_retraction.rb @@ -79,7 +79,7 @@ module DiasporaFederation end def sign_with_author - privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, author) + privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author) SignedRetraction.sign_with_key(privkey, self) unless privkey.nil? end end diff --git a/lib/diaspora_federation/salmon/magic_envelope.rb b/lib/diaspora_federation/salmon/magic_envelope.rb index ad8ef69..5e510f3 100644 --- a/lib/diaspora_federation/salmon/magic_envelope.rb +++ b/lib/diaspora_federation/salmon/magic_envelope.rb @@ -176,7 +176,7 @@ module DiasporaFederation env.at_xpath("me:encoding").content, env.at_xpath("me:alg").content]) - sender_key = DiasporaFederation.callbacks.trigger(:fetch_public_key_by_diaspora_id, sender) + sender_key = DiasporaFederation.callbacks.trigger(:fetch_public_key, sender) raise SenderKeyNotFound unless sender_key sig = Base64.urlsafe_decode64(env.at_xpath("me:sig").content) diff --git a/spec/controllers/diaspora_federation/fetch_controller_spec.rb b/spec/controllers/diaspora_federation/fetch_controller_spec.rb index de3ade6..7031f2d 100644 --- a/spec/controllers/diaspora_federation/fetch_controller_spec.rb +++ b/spec/controllers/diaspora_federation/fetch_controller_spec.rb @@ -11,13 +11,13 @@ module DiasporaFederation :fetch_public_entity, "StatusMessage", guid ).and_return(post) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, alice.diaspora_id + :fetch_private_key, alice.diaspora_id ).and_return(alice.private_key) get :fetch, type: "status_message", guid: guid expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, alice.diaspora_id + :fetch_public_key, alice.diaspora_id ).and_return(alice.public_key) magic_env_xml = Nokogiri::XML::Document.parse(response.body).root @@ -36,13 +36,13 @@ module DiasporaFederation :fetch_public_entity, "Post", guid ).and_return(post) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, alice.diaspora_id + :fetch_private_key, alice.diaspora_id ).and_return(alice.private_key) get :fetch, type: "post", guid: guid expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, alice.diaspora_id + :fetch_public_key, alice.diaspora_id ).and_return(alice.public_key) magic_env_xml = Nokogiri::XML::Document.parse(response.body).root @@ -61,7 +61,7 @@ module DiasporaFederation :fetch_public_entity, "Post", guid ).and_return(post) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, alice.diaspora_id + :fetch_private_key, alice.diaspora_id ).and_return(nil) expect(DiasporaFederation.callbacks).to receive(:trigger).with( :fetch_person_url_to, alice.diaspora_id, "/fetch/post/#{guid}" diff --git a/spec/integration/comment_integration_spec.rb b/spec/integration/comment_integration_spec.rb index c1a5be6..e77c906 100644 --- a/spec/integration/comment_integration_spec.rb +++ b/spec/integration/comment_integration_spec.rb @@ -188,10 +188,10 @@ XML context "test-data creation" do it "creates comment xml" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, author + :fetch_private_key, author ).and_return(author_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, parent.author + :fetch_private_key, parent.author ).and_return(nil) comment.to_xml @@ -199,10 +199,10 @@ XML it "creates relayed comment xml" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_key.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, parent.author + :fetch_private_key, parent.author ).and_return(parent_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( :fetch_related_entity, "Post", parent_guid @@ -216,10 +216,10 @@ XML context "relaying on bobs pod" do before do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_key.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, parent.author + :fetch_private_key, parent.author ).and_return(parent_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( :fetch_related_entity, "Post", parent_guid @@ -250,10 +250,10 @@ XML before do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_key.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, parent.author + :fetch_public_key, parent.author ).and_return(parent_key.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( :fetch_related_entity, "Post", parent_guid diff --git a/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb b/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb index e915def..4a2580c 100644 --- a/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb +++ b/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb @@ -45,7 +45,7 @@ XML it "updates author signature when it was nil and key was supplied" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, hash[:author] + :fetch_private_key, hash[:author] ).and_return(author_pkey) signed_string = "#{hash[:target_guid]};#{hash[:target_type]}" @@ -61,7 +61,7 @@ XML hash[:target] = FactoryGirl.build(:related_entity, author: bob.diaspora_id, parent: parent) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, hash[:author] + :fetch_private_key, hash[:author] ).and_return(author_pkey) signed_string = "#{hash[:target_guid]};#{hash[:target_type]}" @@ -83,7 +83,7 @@ XML it "doesn't change signatures if keys weren't supplied" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, hash[:author] + :fetch_private_key, hash[:author] ).and_return(nil) xml = Entities::RelayableRetraction.new(hash).to_xml diff --git a/spec/lib/diaspora_federation/entities/relayable_spec.rb b/spec/lib/diaspora_federation/entities/relayable_spec.rb index 71b58d3..80c8972 100644 --- a/spec/lib/diaspora_federation/entities/relayable_spec.rb +++ b/spec/lib/diaspora_federation/entities/relayable_spec.rb @@ -43,10 +43,10 @@ module DiasporaFederation hash[:parent] = remote_parent expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, remote_parent.author + :fetch_public_key, remote_parent.author ).and_return(parent_pkey.public_key) expect { SomeRelayable.new(hash).verify_signatures }.not_to raise_error @@ -54,7 +54,7 @@ module DiasporaFederation it "raises when no public key for author was fetched" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, anything + :fetch_public_key, anything ).and_return(nil) expect { @@ -66,7 +66,7 @@ module DiasporaFederation hash[:author_signature] = nil expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) expect { @@ -79,10 +79,10 @@ module DiasporaFederation hash[:parent] = remote_parent expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, remote_parent.author + :fetch_public_key, remote_parent.author ).and_return(nil) expect { @@ -96,10 +96,10 @@ module DiasporaFederation hash[:parent] = remote_parent expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, remote_parent.author + :fetch_public_key, remote_parent.author ).and_return(parent_pkey.public_key) expect { @@ -113,7 +113,7 @@ module DiasporaFederation hash[:parent] = local_parent expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) expect { SomeRelayable.new(hash).verify_signatures }.not_to raise_error @@ -129,10 +129,10 @@ module DiasporaFederation hash[:parent] = remote_parent expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, remote_parent.author + :fetch_public_key, remote_parent.author ).and_return(parent_pkey.public_key) expect { SomeRelayable.new(hash, xml_order).verify_signatures }.not_to raise_error @@ -147,10 +147,10 @@ module DiasporaFederation hash[:parent] = remote_parent expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, remote_parent.author + :fetch_public_key, remote_parent.author ).and_return(parent_pkey.public_key) expect { @@ -162,7 +162,7 @@ module DiasporaFederation hash[:author_signature] = sign_with_key(author_pkey, legacy_signature_data) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) xml_order = [:author, :guid, :parent_guid, :property, "new_property"] @@ -196,10 +196,10 @@ XML it "computes correct signatures for the entity" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, author + :fetch_private_key, author ).and_return(author_pkey) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, local_parent.author + :fetch_private_key, local_parent.author ).and_return(parent_pkey) xml = SomeRelayable.new(hash).to_xml @@ -213,10 +213,10 @@ XML it "computes correct signatures for the entity with new unknown xml elements" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, author + :fetch_private_key, author ).and_return(author_pkey) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, local_parent.author + :fetch_private_key, local_parent.author ).and_return(parent_pkey) xml_order = [:author, :guid, :parent_guid, "new_property", :property] @@ -242,7 +242,7 @@ XML it "raises when author_signature not set and key isn't supplied" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, author + :fetch_private_key, author ).and_return(nil) expect { @@ -252,10 +252,10 @@ XML it "doesn't set parent_author_signature if key isn't supplied" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, author + :fetch_private_key, author ).and_return(author_pkey) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, local_parent.author + :fetch_private_key, local_parent.author ).and_return(nil) xml = SomeRelayable.new(hash).to_xml @@ -274,10 +274,10 @@ XML context "parsing" do before do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, remote_parent.author + :fetch_public_key, remote_parent.author ).and_return(parent_pkey.public_key) end @@ -335,7 +335,7 @@ XML xml = SomeRelayable.new(hash).to_xml expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, author + :fetch_public_key, author ).and_return(author_pkey.public_key) expect { diff --git a/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb b/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb index 08b9934..0463ec7 100644 --- a/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb +++ b/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb @@ -35,7 +35,7 @@ XML it "updates author signature when it was nil and key was supplied" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, hash[:author] + :fetch_private_key, hash[:author] ).and_return(author_pkey) signed_string = "#{hash[:target_guid]};#{hash[:target_type]}" @@ -56,7 +56,7 @@ XML it "doesn't change signature if a key wasn't supplied" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_private_key_by_diaspora_id, hash[:author] + :fetch_private_key, hash[:author] ).and_return(nil) xml = Entities::SignedRetraction.new(hash).to_xml diff --git a/spec/lib/diaspora_federation/federation/fetcher_spec.rb b/spec/lib/diaspora_federation/federation/fetcher_spec.rb index b334912..e31a812 100644 --- a/spec/lib/diaspora_federation/federation/fetcher_spec.rb +++ b/spec/lib/diaspora_federation/federation/fetcher_spec.rb @@ -12,7 +12,7 @@ module DiasporaFederation :fetch_person_url_to, post.author, "/fetch/post/#{post.guid}" ).and_return("https://example.org/fetch/post/#{post.guid}") expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, post.author + :fetch_public_key, post.author ).and_return(alice.public_key) receiver = double @@ -40,7 +40,7 @@ module DiasporaFederation :fetch_person_url_to, post.author, "/fetch/post/#{post.guid}" ).and_return("https://example.org/fetch/post/#{post.guid}") expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, post.author + :fetch_public_key, post.author ).and_return(alice.public_key) receiver = double diff --git a/spec/lib/diaspora_federation/federation/receiver_spec.rb b/spec/lib/diaspora_federation/federation/receiver_spec.rb index a0ac95c..da07828 100644 --- a/spec/lib/diaspora_federation/federation/receiver_spec.rb +++ b/spec/lib/diaspora_federation/federation/receiver_spec.rb @@ -8,7 +8,7 @@ module DiasporaFederation it "parses the entity with magic envelope receiver" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, post.author + :fetch_public_key, post.author ).and_return(sender_key) data = Salmon::MagicEnvelope.new(post, post.author).envelop(sender_key).to_xml @@ -27,7 +27,7 @@ module DiasporaFederation it "parses the entity with legacy slap receiver" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, post.author + :fetch_public_key, post.author ).and_return(sender_key) data = DiasporaFederation::Salmon::Slap.generate_xml(post.author, sender_key, post) @@ -50,7 +50,7 @@ module DiasporaFederation it "parses the entity with magic envelope receiver" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, post.author + :fetch_public_key, post.author ).and_return(sender_key) magic_env = Salmon::MagicEnvelope.new(post, post.author).envelop(sender_key) @@ -70,7 +70,7 @@ module DiasporaFederation it "parses the entity with legacy slap receiver" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, post.author + :fetch_public_key, post.author ).and_return(sender_key) data = DiasporaFederation::Salmon::EncryptedSlap.prepare(post.author, sender_key, post) diff --git a/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb b/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb index 157342b..8023d9d 100644 --- a/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb +++ b/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb @@ -140,7 +140,7 @@ module DiasporaFederation context "sanity" do it "accepts correct params" do allow(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, sender + :fetch_public_key, sender ).and_return(privkey.public_key) expect { diff --git a/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb b/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb index e8eb12f..c879b57 100644 --- a/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb +++ b/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb @@ -106,7 +106,7 @@ module DiasporaFederation context "sanity" do before do allow(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, sender + :fetch_public_key, sender ).and_return(privkey.public_key) end @@ -140,7 +140,7 @@ module DiasporaFederation other_key = OpenSSL::PKey::RSA.generate(512) expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, other_sender + :fetch_public_key, other_sender ).and_return(other_key) expect { @@ -175,7 +175,7 @@ module DiasporaFederation it "decrypts on the fly, when cipher params are present" do allow(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, sender + :fetch_public_key, sender ).and_return(privkey.public_key) env = Salmon::MagicEnvelope.new(payload) @@ -206,7 +206,7 @@ module DiasporaFederation it "raises if the sender key is not found" do expect(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, sender + :fetch_public_key, sender ).and_return(nil) expect { diff --git a/spec/lib/diaspora_federation/salmon/slap_spec.rb b/spec/lib/diaspora_federation/salmon/slap_spec.rb index 46d7861..2d597d0 100644 --- a/spec/lib/diaspora_federation/salmon/slap_spec.rb +++ b/spec/lib/diaspora_federation/salmon/slap_spec.rb @@ -51,7 +51,7 @@ module DiasporaFederation context "sanity" do it "accepts salmon xml as param" do allow(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, sender + :fetch_public_key, sender ).and_return(privkey.public_key) expect { diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a3755fb..0e5ca61 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,10 +37,6 @@ def bob @bob ||= Person.find_by(diaspora_id: "bob@localhost:3000") end -def test_pkey - DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id) -end - # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. fixture_builder_file = "#{File.dirname(__FILE__)}/support/fixture_builder.rb" diff --git a/spec/support/shared_magic_envelope_specs.rb b/spec/support/shared_magic_envelope_specs.rb index a2c0400..cbfcde3 100644 --- a/spec/support/shared_magic_envelope_specs.rb +++ b/spec/support/shared_magic_envelope_specs.rb @@ -1,7 +1,7 @@ shared_examples "a MagicEnvelope instance" do before do allow(DiasporaFederation.callbacks).to receive(:trigger).with( - :fetch_public_key_by_diaspora_id, sender + :fetch_public_key, sender ).and_return(privkey.public_key) end diff --git a/test/dummy/config/initializers/diaspora_federation.rb b/test/dummy/config/initializers/diaspora_federation.rb index fdd8339..c42cfc6 100644 --- a/test/dummy/config/initializers/diaspora_federation.rb +++ b/test/dummy/config/initializers/diaspora_federation.rb @@ -60,12 +60,12 @@ DiasporaFederation.configure do |config| end end - on :fetch_private_key_by_diaspora_id do |diaspora_id| + on :fetch_private_key do |diaspora_id| key = Person.where(diaspora_id: diaspora_id).pluck(:serialized_private_key).first OpenSSL::PKey::RSA.new(key) unless key.nil? end - on :fetch_public_key_by_diaspora_id do |diaspora_id| + on :fetch_public_key do |diaspora_id| key = Person.where(diaspora_id: diaspora_id).pluck(:serialized_public_key).first key = DiasporaFederation::Discovery::Discovery.new(diaspora_id).fetch_and_save.exported_key if key.nil? OpenSSL::PKey::RSA.new(key) unless key.nil?