create_spec.rb 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::Activity::Create do
  4. let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers', domain: 'example.com', uri: 'https://example.com/actor') }
  5. let(:json) do
  6. {
  7. '@context': 'https://www.w3.org/ns/activitystreams',
  8. id: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join,
  9. type: 'Create',
  10. actor: ActivityPub::TagManager.instance.uri_for(sender),
  11. object: object_json,
  12. }.with_indifferent_access
  13. end
  14. before do
  15. sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
  16. stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
  17. stub_request(:get, 'http://example.com/emoji.png').to_return(body: attachment_fixture('emojo.png'))
  18. stub_request(:get, 'http://example.com/emojib.png').to_return(body: attachment_fixture('emojo.png'), headers: { 'Content-Type' => 'application/octet-stream' })
  19. end
  20. describe '#perform' do
  21. context 'when fetching' do
  22. subject { described_class.new(json, sender) }
  23. before do
  24. subject.perform
  25. end
  26. context 'when object has been edited' do
  27. let(:object_json) do
  28. {
  29. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  30. type: 'Note',
  31. content: 'Lorem ipsum',
  32. published: '2022-01-22T15:00:00Z',
  33. updated: '2022-01-22T16:00:00Z',
  34. }
  35. end
  36. it 'creates status' do
  37. status = sender.statuses.first
  38. expect(status).to_not be_nil
  39. expect(status.text).to eq 'Lorem ipsum'
  40. end
  41. it 'marks status as edited' do
  42. status = sender.statuses.first
  43. expect(status).to_not be_nil
  44. expect(status.edited?).to be true
  45. end
  46. end
  47. context 'when object has update date equal to creation date' do
  48. let(:object_json) do
  49. {
  50. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  51. type: 'Note',
  52. content: 'Lorem ipsum',
  53. published: '2022-01-22T15:00:00Z',
  54. updated: '2022-01-22T15:00:00Z',
  55. }
  56. end
  57. it 'creates status' do
  58. status = sender.statuses.first
  59. expect(status).to_not be_nil
  60. expect(status.text).to eq 'Lorem ipsum'
  61. end
  62. it 'does not mark status as edited' do
  63. status = sender.statuses.first
  64. expect(status).to_not be_nil
  65. expect(status.edited?).to be false
  66. end
  67. end
  68. context 'with an unknown object type' do
  69. let(:object_json) do
  70. {
  71. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  72. type: 'Banana',
  73. content: 'Lorem ipsum',
  74. }
  75. end
  76. it 'does not create a status' do
  77. expect(sender.statuses.count).to be_zero
  78. end
  79. end
  80. context 'with a standalone' do
  81. let(:object_json) do
  82. {
  83. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  84. type: 'Note',
  85. content: 'Lorem ipsum',
  86. }
  87. end
  88. it 'creates status' do
  89. status = sender.statuses.first
  90. expect(status).to_not be_nil
  91. expect(status.text).to eq 'Lorem ipsum'
  92. end
  93. it 'missing to/cc defaults to direct privacy' do
  94. status = sender.statuses.first
  95. expect(status).to_not be_nil
  96. expect(status.visibility).to eq 'direct'
  97. end
  98. end
  99. context 'when public with explicit public address' do
  100. let(:object_json) do
  101. {
  102. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  103. type: 'Note',
  104. content: 'Lorem ipsum',
  105. to: 'https://www.w3.org/ns/activitystreams#Public',
  106. }
  107. end
  108. it 'creates status' do
  109. status = sender.statuses.first
  110. expect(status).to_not be_nil
  111. expect(status.visibility).to eq 'public'
  112. end
  113. end
  114. context 'when public with as:Public' do
  115. let(:object_json) do
  116. {
  117. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  118. type: 'Note',
  119. content: 'Lorem ipsum',
  120. to: 'as:Public',
  121. }
  122. end
  123. it 'creates status' do
  124. status = sender.statuses.first
  125. expect(status).to_not be_nil
  126. expect(status.visibility).to eq 'public'
  127. end
  128. end
  129. context 'when public with Public' do
  130. let(:object_json) do
  131. {
  132. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  133. type: 'Note',
  134. content: 'Lorem ipsum',
  135. to: 'Public',
  136. }
  137. end
  138. it 'creates status' do
  139. status = sender.statuses.first
  140. expect(status).to_not be_nil
  141. expect(status.visibility).to eq 'public'
  142. end
  143. end
  144. context 'when unlisted with explicit public address' do
  145. let(:object_json) do
  146. {
  147. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  148. type: 'Note',
  149. content: 'Lorem ipsum',
  150. cc: 'https://www.w3.org/ns/activitystreams#Public',
  151. }
  152. end
  153. it 'creates status' do
  154. status = sender.statuses.first
  155. expect(status).to_not be_nil
  156. expect(status.visibility).to eq 'unlisted'
  157. end
  158. end
  159. context 'when unlisted with as:Public' do
  160. let(:object_json) do
  161. {
  162. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  163. type: 'Note',
  164. content: 'Lorem ipsum',
  165. cc: 'as:Public',
  166. }
  167. end
  168. it 'creates status' do
  169. status = sender.statuses.first
  170. expect(status).to_not be_nil
  171. expect(status.visibility).to eq 'unlisted'
  172. end
  173. end
  174. context 'when unlisted with Public' do
  175. let(:object_json) do
  176. {
  177. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  178. type: 'Note',
  179. content: 'Lorem ipsum',
  180. cc: 'Public',
  181. }
  182. end
  183. it 'creates status' do
  184. status = sender.statuses.first
  185. expect(status).to_not be_nil
  186. expect(status.visibility).to eq 'unlisted'
  187. end
  188. end
  189. context 'when private' do
  190. let(:object_json) do
  191. {
  192. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  193. type: 'Note',
  194. content: 'Lorem ipsum',
  195. to: 'http://example.com/followers',
  196. }
  197. end
  198. it 'creates status' do
  199. status = sender.statuses.first
  200. expect(status).to_not be_nil
  201. expect(status.visibility).to eq 'private'
  202. end
  203. end
  204. context 'when private with inlined Collection in audience' do
  205. let(:object_json) do
  206. {
  207. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  208. type: 'Note',
  209. content: 'Lorem ipsum',
  210. to: {
  211. type: 'OrderedCollection',
  212. id: 'http://example.com/followers',
  213. first: 'http://example.com/followers?page=true',
  214. },
  215. }
  216. end
  217. it 'creates status' do
  218. status = sender.statuses.first
  219. expect(status).to_not be_nil
  220. expect(status.visibility).to eq 'private'
  221. end
  222. end
  223. context 'when limited' do
  224. let(:recipient) { Fabricate(:account) }
  225. let(:object_json) do
  226. {
  227. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  228. type: 'Note',
  229. content: 'Lorem ipsum',
  230. to: ActivityPub::TagManager.instance.uri_for(recipient),
  231. }
  232. end
  233. it 'creates status' do
  234. status = sender.statuses.first
  235. expect(status).to_not be_nil
  236. expect(status.visibility).to eq 'limited'
  237. end
  238. it 'creates silent mention' do
  239. status = sender.statuses.first
  240. expect(status.mentions.first).to be_silent
  241. end
  242. end
  243. context 'when direct' do
  244. let(:recipient) { Fabricate(:account) }
  245. let(:object_json) do
  246. {
  247. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  248. type: 'Note',
  249. content: 'Lorem ipsum',
  250. to: ActivityPub::TagManager.instance.uri_for(recipient),
  251. tag: {
  252. type: 'Mention',
  253. href: ActivityPub::TagManager.instance.uri_for(recipient),
  254. },
  255. }
  256. end
  257. it 'creates status' do
  258. status = sender.statuses.first
  259. expect(status).to_not be_nil
  260. expect(status.visibility).to eq 'direct'
  261. end
  262. end
  263. context 'with a reply' do
  264. let(:original_status) { Fabricate(:status) }
  265. let(:object_json) do
  266. {
  267. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  268. type: 'Note',
  269. content: 'Lorem ipsum',
  270. inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
  271. }
  272. end
  273. it 'creates status' do
  274. status = sender.statuses.first
  275. expect(status).to_not be_nil
  276. expect(status.thread).to eq original_status
  277. expect(status.reply?).to be true
  278. expect(status.in_reply_to_account).to eq original_status.account
  279. expect(status.conversation).to eq original_status.conversation
  280. end
  281. end
  282. context 'with mentions' do
  283. let(:recipient) { Fabricate(:account) }
  284. let(:object_json) do
  285. {
  286. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  287. type: 'Note',
  288. content: 'Lorem ipsum',
  289. tag: [
  290. {
  291. type: 'Mention',
  292. href: ActivityPub::TagManager.instance.uri_for(recipient),
  293. },
  294. ],
  295. }
  296. end
  297. it 'creates status' do
  298. status = sender.statuses.first
  299. expect(status).to_not be_nil
  300. expect(status.mentions.map(&:account)).to include(recipient)
  301. end
  302. end
  303. context 'with mentions missing href' do
  304. let(:object_json) do
  305. {
  306. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  307. type: 'Note',
  308. content: 'Lorem ipsum',
  309. tag: [
  310. {
  311. type: 'Mention',
  312. },
  313. ],
  314. }
  315. end
  316. it 'creates status' do
  317. status = sender.statuses.first
  318. expect(status).to_not be_nil
  319. end
  320. end
  321. context 'with media attachments' do
  322. let(:object_json) do
  323. {
  324. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  325. type: 'Note',
  326. content: 'Lorem ipsum',
  327. attachment: [
  328. {
  329. type: 'Document',
  330. mediaType: 'image/png',
  331. url: 'http://example.com/attachment.png',
  332. },
  333. ],
  334. }
  335. end
  336. it 'creates status' do
  337. status = sender.statuses.first
  338. expect(status).to_not be_nil
  339. expect(status.media_attachments.map(&:remote_url)).to include('http://example.com/attachment.png')
  340. end
  341. end
  342. context 'with media attachments with long description' do
  343. let(:object_json) do
  344. {
  345. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  346. type: 'Note',
  347. content: 'Lorem ipsum',
  348. attachment: [
  349. {
  350. type: 'Document',
  351. mediaType: 'image/png',
  352. url: 'http://example.com/attachment.png',
  353. name: '*' * 1500,
  354. },
  355. ],
  356. }
  357. end
  358. it 'creates status' do
  359. status = sender.statuses.first
  360. expect(status).to_not be_nil
  361. expect(status.media_attachments.map(&:description)).to include('*' * 1500)
  362. end
  363. end
  364. context 'with media attachments with long description as summary' do
  365. let(:object_json) do
  366. {
  367. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  368. type: 'Note',
  369. content: 'Lorem ipsum',
  370. attachment: [
  371. {
  372. type: 'Document',
  373. mediaType: 'image/png',
  374. url: 'http://example.com/attachment.png',
  375. summary: '*' * 1500,
  376. },
  377. ],
  378. }
  379. end
  380. it 'creates status' do
  381. status = sender.statuses.first
  382. expect(status).to_not be_nil
  383. expect(status.media_attachments.map(&:description)).to include('*' * 1500)
  384. end
  385. end
  386. context 'with media attachments with focal points' do
  387. let(:object_json) do
  388. {
  389. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  390. type: 'Note',
  391. content: 'Lorem ipsum',
  392. attachment: [
  393. {
  394. type: 'Document',
  395. mediaType: 'image/png',
  396. url: 'http://example.com/attachment.png',
  397. focalPoint: [0.5, -0.7],
  398. },
  399. ],
  400. }
  401. end
  402. it 'creates status' do
  403. status = sender.statuses.first
  404. expect(status).to_not be_nil
  405. expect(status.media_attachments.map(&:focus)).to include('0.5,-0.7')
  406. end
  407. end
  408. context 'with media attachments missing url' do
  409. let(:object_json) do
  410. {
  411. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  412. type: 'Note',
  413. content: 'Lorem ipsum',
  414. attachment: [
  415. {
  416. type: 'Document',
  417. mediaType: 'image/png',
  418. },
  419. ],
  420. }
  421. end
  422. it 'creates status' do
  423. status = sender.statuses.first
  424. expect(status).to_not be_nil
  425. end
  426. end
  427. context 'with hashtags' do
  428. let(:object_json) do
  429. {
  430. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  431. type: 'Note',
  432. content: 'Lorem ipsum',
  433. tag: [
  434. {
  435. type: 'Hashtag',
  436. href: 'http://example.com/blah',
  437. name: '#test',
  438. },
  439. ],
  440. }
  441. end
  442. it 'creates status' do
  443. status = sender.statuses.first
  444. expect(status).to_not be_nil
  445. expect(status.tags.map(&:name)).to include('test')
  446. end
  447. end
  448. context 'with hashtags missing name' do
  449. let(:object_json) do
  450. {
  451. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  452. type: 'Note',
  453. content: 'Lorem ipsum',
  454. tag: [
  455. {
  456. type: 'Hashtag',
  457. href: 'http://example.com/blah',
  458. },
  459. ],
  460. }
  461. end
  462. it 'creates status' do
  463. status = sender.statuses.first
  464. expect(status).to_not be_nil
  465. end
  466. end
  467. context 'with hashtags invalid name' do
  468. let(:object_json) do
  469. {
  470. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  471. type: 'Note',
  472. content: 'Lorem ipsum',
  473. tag: [
  474. {
  475. type: 'Hashtag',
  476. href: 'http://example.com/blah',
  477. name: 'foo, #eh !',
  478. },
  479. ],
  480. }
  481. end
  482. it 'creates status' do
  483. status = sender.statuses.first
  484. expect(status).to_not be_nil
  485. end
  486. end
  487. context 'with emojis' do
  488. let(:object_json) do
  489. {
  490. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  491. type: 'Note',
  492. content: 'Lorem ipsum :tinking:',
  493. tag: [
  494. {
  495. type: 'Emoji',
  496. icon: {
  497. url: 'http://example.com/emoji.png',
  498. },
  499. name: 'tinking',
  500. },
  501. ],
  502. }
  503. end
  504. it 'creates status' do
  505. status = sender.statuses.first
  506. expect(status).to_not be_nil
  507. expect(status.emojis.map(&:shortcode)).to include('tinking')
  508. end
  509. end
  510. context 'with emojis served with invalid content-type' do
  511. let(:object_json) do
  512. {
  513. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  514. type: 'Note',
  515. content: 'Lorem ipsum :tinkong:',
  516. tag: [
  517. {
  518. type: 'Emoji',
  519. icon: {
  520. url: 'http://example.com/emojib.png',
  521. },
  522. name: 'tinkong',
  523. },
  524. ],
  525. }
  526. end
  527. it 'creates status' do
  528. status = sender.statuses.first
  529. expect(status).to_not be_nil
  530. expect(status.emojis.map(&:shortcode)).to include('tinkong')
  531. end
  532. end
  533. context 'with emojis missing name' do
  534. let(:object_json) do
  535. {
  536. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  537. type: 'Note',
  538. content: 'Lorem ipsum :tinking:',
  539. tag: [
  540. {
  541. type: 'Emoji',
  542. icon: {
  543. url: 'http://example.com/emoji.png',
  544. },
  545. },
  546. ],
  547. }
  548. end
  549. it 'creates status' do
  550. status = sender.statuses.first
  551. expect(status).to_not be_nil
  552. end
  553. end
  554. context 'with emojis missing icon' do
  555. let(:object_json) do
  556. {
  557. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  558. type: 'Note',
  559. content: 'Lorem ipsum :tinking:',
  560. tag: [
  561. {
  562. type: 'Emoji',
  563. name: 'tinking',
  564. },
  565. ],
  566. }
  567. end
  568. it 'creates status' do
  569. status = sender.statuses.first
  570. expect(status).to_not be_nil
  571. end
  572. end
  573. context 'with poll' do
  574. let(:object_json) do
  575. {
  576. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  577. type: 'Question',
  578. content: 'Which color was the submarine?',
  579. oneOf: [
  580. {
  581. name: 'Yellow',
  582. replies: {
  583. type: 'Collection',
  584. totalItems: 10,
  585. },
  586. },
  587. {
  588. name: 'Blue',
  589. replies: {
  590. type: 'Collection',
  591. totalItems: 3,
  592. },
  593. },
  594. ],
  595. }
  596. end
  597. it 'creates status' do
  598. status = sender.statuses.first
  599. expect(status).to_not be_nil
  600. expect(status.poll).to_not be_nil
  601. end
  602. it 'creates a poll' do
  603. poll = sender.polls.first
  604. expect(poll).to_not be_nil
  605. expect(poll.status).to_not be_nil
  606. expect(poll.options).to eq %w(Yellow Blue)
  607. expect(poll.cached_tallies).to eq [10, 3]
  608. end
  609. end
  610. context 'when a vote to a local poll' do
  611. let(:poll) { Fabricate(:poll, options: %w(Yellow Blue)) }
  612. let!(:local_status) { Fabricate(:status, poll: poll) }
  613. let(:object_json) do
  614. {
  615. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  616. type: 'Note',
  617. name: 'Yellow',
  618. inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
  619. }
  620. end
  621. it 'adds a vote to the poll with correct uri' do
  622. vote = poll.votes.first
  623. expect(vote).to_not be_nil
  624. expect(vote.uri).to eq object_json[:id]
  625. expect(poll.reload.cached_tallies).to eq [1, 0]
  626. end
  627. end
  628. context 'when a vote to an expired local poll' do
  629. let(:poll) do
  630. poll = Fabricate.build(:poll, options: %w(Yellow Blue), expires_at: 1.day.ago)
  631. poll.save(validate: false)
  632. poll
  633. end
  634. let!(:local_status) { Fabricate(:status, poll: poll) }
  635. let(:object_json) do
  636. {
  637. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  638. type: 'Note',
  639. name: 'Yellow',
  640. inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
  641. }
  642. end
  643. it 'does not add a vote to the poll' do
  644. expect(poll.votes.first).to be_nil
  645. end
  646. end
  647. end
  648. context 'with an encrypted message' do
  649. subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) }
  650. let(:recipient) { Fabricate(:account) }
  651. let(:object_json) do
  652. {
  653. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  654. type: 'EncryptedMessage',
  655. attributedTo: {
  656. type: 'Device',
  657. deviceId: '1234',
  658. },
  659. to: {
  660. type: 'Device',
  661. deviceId: target_device.device_id,
  662. },
  663. messageType: 1,
  664. cipherText: 'Foo',
  665. messageFranking: 'Baz678',
  666. digest: {
  667. digestAlgorithm: 'Bar456',
  668. digestValue: 'Foo123',
  669. },
  670. }
  671. end
  672. let(:target_device) { Fabricate(:device, account: recipient) }
  673. before do
  674. subject.perform
  675. end
  676. it 'creates an encrypted message' do
  677. encrypted_message = target_device.encrypted_messages.reload.first
  678. expect(encrypted_message).to_not be_nil
  679. expect(encrypted_message.from_device_id).to eq '1234'
  680. expect(encrypted_message.from_account).to eq sender
  681. expect(encrypted_message.type).to eq 1
  682. expect(encrypted_message.body).to eq 'Foo'
  683. expect(encrypted_message.digest).to eq 'Foo123'
  684. end
  685. it 'creates a message franking' do
  686. encrypted_message = target_device.encrypted_messages.reload.first
  687. message_franking = encrypted_message.message_franking
  688. crypt = ActiveSupport::MessageEncryptor.new(SystemKey.current_key, serializer: Oj)
  689. json = crypt.decrypt_and_verify(message_franking)
  690. expect(json['source_account_id']).to eq sender.id
  691. expect(json['target_account_id']).to eq recipient.id
  692. expect(json['original_franking']).to eq 'Baz678'
  693. end
  694. end
  695. context 'when sender is followed by local users' do
  696. subject { described_class.new(json, sender, delivery: true) }
  697. before do
  698. Fabricate(:account).follow!(sender)
  699. subject.perform
  700. end
  701. let(:object_json) do
  702. {
  703. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  704. type: 'Note',
  705. content: 'Lorem ipsum',
  706. }
  707. end
  708. it 'creates status' do
  709. status = sender.statuses.first
  710. expect(status).to_not be_nil
  711. expect(status.text).to eq 'Lorem ipsum'
  712. end
  713. end
  714. context 'when sender replies to local status' do
  715. subject { described_class.new(json, sender, delivery: true) }
  716. let!(:local_status) { Fabricate(:status) }
  717. let(:object_json) do
  718. {
  719. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  720. type: 'Note',
  721. content: 'Lorem ipsum',
  722. inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
  723. }
  724. end
  725. before do
  726. subject.perform
  727. end
  728. it 'creates status' do
  729. status = sender.statuses.first
  730. expect(status).to_not be_nil
  731. expect(status.text).to eq 'Lorem ipsum'
  732. end
  733. end
  734. context 'when sender targets a local user' do
  735. subject { described_class.new(json, sender, delivery: true) }
  736. let!(:local_account) { Fabricate(:account) }
  737. let(:object_json) do
  738. {
  739. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  740. type: 'Note',
  741. content: 'Lorem ipsum',
  742. to: ActivityPub::TagManager.instance.uri_for(local_account),
  743. }
  744. end
  745. before do
  746. subject.perform
  747. end
  748. it 'creates status' do
  749. status = sender.statuses.first
  750. expect(status).to_not be_nil
  751. expect(status.text).to eq 'Lorem ipsum'
  752. end
  753. end
  754. context 'when sender cc\'s a local user' do
  755. subject { described_class.new(json, sender, delivery: true) }
  756. let!(:local_account) { Fabricate(:account) }
  757. let(:object_json) do
  758. {
  759. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  760. type: 'Note',
  761. content: 'Lorem ipsum',
  762. cc: ActivityPub::TagManager.instance.uri_for(local_account),
  763. }
  764. end
  765. before do
  766. subject.perform
  767. end
  768. it 'creates status' do
  769. status = sender.statuses.first
  770. expect(status).to_not be_nil
  771. expect(status.text).to eq 'Lorem ipsum'
  772. end
  773. end
  774. context 'when the sender has no relevance to local activity' do
  775. subject { described_class.new(json, sender, delivery: true) }
  776. before do
  777. subject.perform
  778. end
  779. let(:object_json) do
  780. {
  781. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  782. type: 'Note',
  783. content: 'Lorem ipsum',
  784. }
  785. end
  786. it 'does not create anything' do
  787. expect(sender.statuses.count).to eq 0
  788. end
  789. end
  790. end
  791. end