process_account_service_spec.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::ProcessAccountService, type: :service do
  3. subject { described_class.new }
  4. context 'property values' do
  5. let(:payload) do
  6. {
  7. id: 'https://foo.test',
  8. type: 'Actor',
  9. inbox: 'https://foo.test/inbox',
  10. attachment: [
  11. { type: 'PropertyValue', name: 'Pronouns', value: 'They/them' },
  12. { type: 'PropertyValue', name: 'Occupation', value: 'Unit test' },
  13. ],
  14. }.with_indifferent_access
  15. end
  16. it 'parses out of attachment' do
  17. account = subject.call('alice', 'example.com', payload)
  18. expect(account.fields).to be_a Array
  19. expect(account.fields.size).to eq 2
  20. expect(account.fields[0]).to be_a Account::Field
  21. expect(account.fields[0].name).to eq 'Pronouns'
  22. expect(account.fields[0].value).to eq 'They/them'
  23. expect(account.fields[1]).to be_a Account::Field
  24. expect(account.fields[1].name).to eq 'Occupation'
  25. expect(account.fields[1].value).to eq 'Unit test'
  26. end
  27. end
  28. context 'identity proofs' do
  29. let(:payload) do
  30. {
  31. id: 'https://foo.test',
  32. type: 'Actor',
  33. inbox: 'https://foo.test/inbox',
  34. attachment: [
  35. { type: 'IdentityProof', name: 'Alice', signatureAlgorithm: 'keybase', signatureValue: 'a' * 66 },
  36. ],
  37. }.with_indifferent_access
  38. end
  39. it 'parses out of attachment' do
  40. allow(ProofProvider::Keybase::Worker).to receive(:perform_async)
  41. account = subject.call('alice', 'example.com', payload)
  42. expect(account.identity_proofs.count).to eq 1
  43. proof = account.identity_proofs.first
  44. expect(proof.provider).to eq 'keybase'
  45. expect(proof.provider_username).to eq 'Alice'
  46. expect(proof.token).to eq 'a' * 66
  47. end
  48. it 'removes no longer present proofs' do
  49. allow(ProofProvider::Keybase::Worker).to receive(:perform_async)
  50. account = Fabricate(:account, username: 'alice', domain: 'example.com')
  51. old_proof = Fabricate(:account_identity_proof, account: account, provider: 'keybase', provider_username: 'Bob', token: 'b' * 66)
  52. subject.call('alice', 'example.com', payload)
  53. expect(account.identity_proofs.count).to eq 1
  54. expect(account.identity_proofs.find_by(id: old_proof.id)).to be_nil
  55. end
  56. it 'queues a validity check on the proof' do
  57. allow(ProofProvider::Keybase::Worker).to receive(:perform_async)
  58. account = subject.call('alice', 'example.com', payload)
  59. expect(ProofProvider::Keybase::Worker).to have_received(:perform_async)
  60. end
  61. end
  62. end