From 1714ea597866556ef9dd21d5d382f1d9181e0924 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 30 Mar 2019 02:12:06 +0100 Subject: Add ActivityPub representation for identity proofs (#10414) * Add ActivityPub representation for identity proofs * Add tests --- .../activitypub/process_account_service_spec.rb | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'spec') diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb index d3318b2ed..ab8fb5cc3 100644 --- a/spec/services/activitypub/process_account_service_spec.rb +++ b/spec/services/activitypub/process_account_service_spec.rb @@ -28,4 +28,45 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do expect(account.fields[1].value).to eq 'Unit test' end end + + context 'identity proofs' do + let(:payload) do + { + id: 'https://foo.test', + type: 'Actor', + inbox: 'https://foo.test/inbox', + attachment: [ + { type: 'IdentityProof', name: 'Alice', signatureAlgorithm: 'keybase', signatureValue: 'a' * 66 }, + ], + }.with_indifferent_access + end + + it 'parses out of attachment' do + account = subject.call('alice', 'example.com', payload) + + expect(account.identity_proofs.count).to eq 1 + + proof = account.identity_proofs.first + + expect(proof.provider).to eq 'keybase' + expect(proof.provider_username).to eq 'Alice' + expect(proof.token).to eq 'a' * 66 + end + + it 'removes no longer present proofs' do + account = Fabricate(:account, username: 'alice', domain: 'example.com') + old_proof = Fabricate(:account_identity_proof, account: account, provider: 'keybase', provider_username: 'Bob', token: 'b' * 66) + + subject.call('alice', 'example.com', payload) + + expect(account.identity_proofs.count).to eq 1 + expect(account.identity_proofs.find_by(id: old_proof.id)).to be_nil + end + + it 'queues a validity check on the proof' do + allow(ProofProvider::Keybase::Worker).to receive(:perform_async) + account = subject.call('alice', 'example.com', payload) + expect(ProofProvider::Keybase::Worker).to have_received(:perform_async) + end + end end -- cgit