diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2016-04-04 01:56:45 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2016-06-26 07:20:59 +0300 |
commit | e9f53265c90614dd034331708124d9ace8d78569 (patch) | |
tree | d1627b35b10278bab45e6cf6a839a112d74e6c65 /spec/workers | |
parent | 9021268e7a9ddc63f6b98995d13c8b336f9bf8a1 (diff) |
create new receive workers
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/receive_private_spec.rb | 40 | ||||
-rw-r--r-- | spec/workers/receive_public_spec.rb | 31 | ||||
-rw-r--r-- | spec/workers/receive_salmon_spec.rb | 23 |
3 files changed, 71 insertions, 23 deletions
diff --git a/spec/workers/receive_private_spec.rb b/spec/workers/receive_private_spec.rb new file mode 100644 index 000000000..86d09ed19 --- /dev/null +++ b/spec/workers/receive_private_spec.rb @@ -0,0 +1,40 @@ +require "spec_helper" + +describe Workers::ReceivePrivate do + let(:data) { "<xml></xml>" } + + it "calls receive_private of federation gem" do + rsa_key = double + + expect(OpenSSL::PKey::RSA).to receive(:new).with(alice.serialized_private_key).and_return(rsa_key) + expect(DiasporaFederation::Federation::Receiver).to receive(:receive_private).with(data, rsa_key, alice.id, true) + + Workers::ReceivePrivate.new.perform(alice.id, data, true) + end + + it "filters errors that would also fail on second try" do + rsa_key = double + + expect(OpenSSL::PKey::RSA).to receive(:new).with(alice.serialized_private_key).and_return(rsa_key) + expect(DiasporaFederation::Federation::Receiver).to receive(:receive_private).with( + data, rsa_key, alice.id, false + ).and_raise(DiasporaFederation::Salmon::InvalidSignature) + + expect { + Workers::ReceivePrivate.new.perform(alice.id, data, false) + }.not_to raise_error + end + + it "does not filter errors that would succeed on second try" do + rsa_key = double + + expect(OpenSSL::PKey::RSA).to receive(:new).with(alice.serialized_private_key).and_return(rsa_key) + expect(DiasporaFederation::Federation::Receiver).to receive(:receive_private).with( + data, rsa_key, alice.id, false + ).and_raise(DiasporaFederation::Federation::Fetcher::NotFetchable) + + expect { + Workers::ReceivePrivate.new.perform(alice.id, data, false) + }.to raise_error DiasporaFederation::Federation::Fetcher::NotFetchable + end +end diff --git a/spec/workers/receive_public_spec.rb b/spec/workers/receive_public_spec.rb new file mode 100644 index 000000000..0f2c3aa7c --- /dev/null +++ b/spec/workers/receive_public_spec.rb @@ -0,0 +1,31 @@ +require "spec_helper" + +describe Workers::ReceivePublic do + let(:data) { "<xml></xml>" } + + it "calls receive_public of federation gem" do + expect(DiasporaFederation::Federation::Receiver).to receive(:receive_public).with(data, true) + + Workers::ReceivePublic.new.perform(data, true) + end + + it "filters errors that would also fail on second try" do + expect(DiasporaFederation::Federation::Receiver).to receive(:receive_public).with( + data, false + ).and_raise(DiasporaFederation::Salmon::InvalidSignature) + + expect { + Workers::ReceivePublic.new.perform(data, false) + }.not_to raise_error + end + + it "does not filter errors that would succeed on second try" do + expect(DiasporaFederation::Federation::Receiver).to receive(:receive_public).with( + data, false + ).and_raise(DiasporaFederation::Federation::Fetcher::NotFetchable) + + expect { + Workers::ReceivePublic.new.perform(data, false) + }.to raise_error DiasporaFederation::Federation::Fetcher::NotFetchable + end +end diff --git a/spec/workers/receive_salmon_spec.rb b/spec/workers/receive_salmon_spec.rb deleted file mode 100644 index a57bc6fbc..000000000 --- a/spec/workers/receive_salmon_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' - -describe Workers::ReceiveEncryptedSalmon do - before do - @user = alice - @xml = '<xml></xml>' - allow(User).to receive(:find){ |id| - if id == @user.id - @user - else - nil - end - } - end - it 'calls receive_salmon' do - zord = double - - expect(zord).to receive(:perform!) - expect(Postzord::Receiver::Private).to receive(:new).with(@user, hash_including(:salmon_xml => @xml)).and_return(zord) - - Workers::ReceiveEncryptedSalmon.new.perform(@user.id, @xml) - end -end |