You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

826 lines
23 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe StatusesController do
  4. render_views
  5. describe 'GET #show' do
  6. let(:account) { Fabricate(:account) }
  7. let(:status) { Fabricate(:status, account: account) }
  8. context 'when account is suspended' do
  9. let(:account) { Fabricate(:account, suspended: true) }
  10. before do
  11. get :show, params: { account_username: account.username, id: status.id }
  12. end
  13. it 'returns http gone' do
  14. expect(response).to have_http_status(410)
  15. end
  16. end
  17. context 'when status is a reblog' do
  18. let(:original_account) { Fabricate(:account, domain: 'example.com') }
  19. let(:original_status) { Fabricate(:status, account: original_account, url: 'https://example.com/123') }
  20. let(:status) { Fabricate(:status, account: account, reblog: original_status) }
  21. before do
  22. get :show, params: { account_username: status.account.username, id: status.id }
  23. end
  24. it 'redirects to the original status' do
  25. expect(response).to redirect_to(original_status.url)
  26. end
  27. end
  28. context 'when status is public' do
  29. before do
  30. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  31. end
  32. context 'as HTML' do
  33. let(:format) { 'html' }
  34. it 'returns http success' do
  35. expect(response).to have_http_status(200)
  36. end
  37. it 'returns Link header' do
  38. expect(response.headers['Link'].to_s).to include 'activity+json'
  39. end
  40. it 'returns Vary header' do
  41. expect(response.headers['Vary']).to eq 'Accept'
  42. end
  43. it 'returns public Cache-Control header' do
  44. expect(response.headers['Cache-Control']).to include 'public'
  45. end
  46. it 'renders status' do
  47. expect(response).to render_template(:show)
  48. expect(response.body).to include status.text
  49. end
  50. end
  51. context 'as JSON' do
  52. let(:format) { 'json' }
  53. it 'returns http success' do
  54. expect(response).to have_http_status(200)
  55. end
  56. it 'returns Link header' do
  57. expect(response.headers['Link'].to_s).to include 'activity+json'
  58. end
  59. it 'returns Vary header' do
  60. expect(response.headers['Vary']).to eq 'Accept'
  61. end
  62. it 'returns public Cache-Control header' do
  63. expect(response.headers['Cache-Control']).to include 'public'
  64. end
  65. it 'returns Content-Type header' do
  66. expect(response.headers['Content-Type']).to include 'application/activity+json'
  67. end
  68. it 'renders ActivityPub Note object' do
  69. json = body_as_json
  70. expect(json[:content]).to include status.text
  71. end
  72. end
  73. end
  74. context 'when status is private' do
  75. let(:status) { Fabricate(:status, account: account, visibility: :private) }
  76. before do
  77. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  78. end
  79. context 'as JSON' do
  80. let(:format) { 'json' }
  81. it 'returns http not found' do
  82. expect(response).to have_http_status(404)
  83. end
  84. end
  85. context 'as HTML' do
  86. let(:format) { 'html' }
  87. it 'returns http not found' do
  88. expect(response).to have_http_status(404)
  89. end
  90. end
  91. end
  92. context 'when status is direct' do
  93. let(:status) { Fabricate(:status, account: account, visibility: :direct) }
  94. before do
  95. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  96. end
  97. context 'as JSON' do
  98. let(:format) { 'json' }
  99. it 'returns http not found' do
  100. expect(response).to have_http_status(404)
  101. end
  102. end
  103. context 'as HTML' do
  104. let(:format) { 'html' }
  105. it 'returns http not found' do
  106. expect(response).to have_http_status(404)
  107. end
  108. end
  109. end
  110. context 'when signed-in' do
  111. let(:user) { Fabricate(:user) }
  112. before do
  113. sign_in(user)
  114. end
  115. context 'when account blocks user' do
  116. before do
  117. account.block!(user.account)
  118. get :show, params: { account_username: status.account.username, id: status.id }
  119. end
  120. it 'returns http not found' do
  121. expect(response).to have_http_status(404)
  122. end
  123. end
  124. context 'when status is public' do
  125. before do
  126. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  127. end
  128. context 'as HTML' do
  129. let(:format) { 'html' }
  130. it 'returns http success' do
  131. expect(response).to have_http_status(200)
  132. end
  133. it 'returns Link header' do
  134. expect(response.headers['Link'].to_s).to include 'activity+json'
  135. end
  136. it 'returns Vary header' do
  137. expect(response.headers['Vary']).to eq 'Accept'
  138. end
  139. it 'returns no Cache-Control header' do
  140. expect(response.headers).to_not include 'Cache-Control'
  141. end
  142. it 'renders status' do
  143. expect(response).to render_template(:show)
  144. expect(response.body).to include status.text
  145. end
  146. end
  147. context 'as JSON' do
  148. let(:format) { 'json' }
  149. it 'returns http success' do
  150. expect(response).to have_http_status(200)
  151. end
  152. it 'returns Link header' do
  153. expect(response.headers['Link'].to_s).to include 'activity+json'
  154. end
  155. it 'returns Vary header' do
  156. expect(response.headers['Vary']).to eq 'Accept'
  157. end
  158. it 'returns public Cache-Control header' do
  159. expect(response.headers['Cache-Control']).to include 'public'
  160. end
  161. it 'returns Content-Type header' do
  162. expect(response.headers['Content-Type']).to include 'application/activity+json'
  163. end
  164. it 'renders ActivityPub Note object' do
  165. json = body_as_json
  166. expect(json[:content]).to include status.text
  167. end
  168. end
  169. end
  170. context 'when status is private' do
  171. let(:status) { Fabricate(:status, account: account, visibility: :private) }
  172. context 'when user is authorized to see it' do
  173. before do
  174. user.account.follow!(account)
  175. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  176. end
  177. context 'as HTML' do
  178. let(:format) { 'html' }
  179. it 'returns http success' do
  180. expect(response).to have_http_status(200)
  181. end
  182. it 'returns Link header' do
  183. expect(response.headers['Link'].to_s).to include 'activity+json'
  184. end
  185. it 'returns Vary header' do
  186. expect(response.headers['Vary']).to eq 'Accept'
  187. end
  188. it 'returns no Cache-Control header' do
  189. expect(response.headers).to_not include 'Cache-Control'
  190. end
  191. it 'renders status' do
  192. expect(response).to render_template(:show)
  193. expect(response.body).to include status.text
  194. end
  195. end
  196. context 'as JSON' do
  197. let(:format) { 'json' }
  198. it 'returns http success' do
  199. expect(response).to have_http_status(200)
  200. end
  201. it 'returns Link header' do
  202. expect(response.headers['Link'].to_s).to include 'activity+json'
  203. end
  204. it 'returns Vary header' do
  205. expect(response.headers['Vary']).to eq 'Accept'
  206. end
  207. it 'returns private Cache-Control header' do
  208. expect(response.headers['Cache-Control']).to include 'private'
  209. end
  210. it 'returns Content-Type header' do
  211. expect(response.headers['Content-Type']).to include 'application/activity+json'
  212. end
  213. it 'renders ActivityPub Note object' do
  214. json = body_as_json
  215. expect(json[:content]).to include status.text
  216. end
  217. end
  218. end
  219. context 'when user is not authorized to see it' do
  220. before do
  221. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  222. end
  223. context 'as JSON' do
  224. let(:format) { 'json' }
  225. it 'returns http not found' do
  226. expect(response).to have_http_status(404)
  227. end
  228. end
  229. context 'as HTML' do
  230. let(:format) { 'html' }
  231. it 'returns http not found' do
  232. expect(response).to have_http_status(404)
  233. end
  234. end
  235. end
  236. end
  237. context 'when status is direct' do
  238. let(:status) { Fabricate(:status, account: account, visibility: :direct) }
  239. context 'when user is authorized to see it' do
  240. before do
  241. Fabricate(:mention, account: user.account, status: status)
  242. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  243. end
  244. context 'as HTML' do
  245. let(:format) { 'html' }
  246. it 'returns http success' do
  247. expect(response).to have_http_status(200)
  248. end
  249. it 'returns Link header' do
  250. expect(response.headers['Link'].to_s).to include 'activity+json'
  251. end
  252. it 'returns Vary header' do
  253. expect(response.headers['Vary']).to eq 'Accept'
  254. end
  255. it 'returns no Cache-Control header' do
  256. expect(response.headers).to_not include 'Cache-Control'
  257. end
  258. it 'renders status' do
  259. expect(response).to render_template(:show)
  260. expect(response.body).to include status.text
  261. end
  262. end
  263. context 'as JSON' do
  264. let(:format) { 'json' }
  265. it 'returns http success' do
  266. expect(response).to have_http_status(200)
  267. end
  268. it 'returns Link header' do
  269. expect(response.headers['Link'].to_s).to include 'activity+json'
  270. end
  271. it 'returns Vary header' do
  272. expect(response.headers['Vary']).to eq 'Accept'
  273. end
  274. it 'returns private Cache-Control header' do
  275. expect(response.headers['Cache-Control']).to include 'private'
  276. end
  277. it 'returns Content-Type header' do
  278. expect(response.headers['Content-Type']).to include 'application/activity+json'
  279. end
  280. it 'renders ActivityPub Note object' do
  281. json = body_as_json
  282. expect(json[:content]).to include status.text
  283. end
  284. end
  285. end
  286. context 'when user is not authorized to see it' do
  287. before do
  288. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  289. end
  290. context 'as JSON' do
  291. let(:format) { 'json' }
  292. it 'returns http not found' do
  293. expect(response).to have_http_status(404)
  294. end
  295. end
  296. context 'as HTML' do
  297. let(:format) { 'html' }
  298. it 'returns http not found' do
  299. expect(response).to have_http_status(404)
  300. end
  301. end
  302. end
  303. end
  304. end
  305. context 'with signature' do
  306. let(:remote_account) { Fabricate(:account, domain: 'example.com') }
  307. before do
  308. allow(controller).to receive(:signed_request_account).and_return(remote_account)
  309. end
  310. context 'when account blocks account' do
  311. before do
  312. account.block!(remote_account)
  313. get :show, params: { account_username: status.account.username, id: status.id }
  314. end
  315. it 'returns http not found' do
  316. expect(response).to have_http_status(404)
  317. end
  318. end
  319. context 'when account domain blocks account' do
  320. before do
  321. account.block_domain!(remote_account.domain)
  322. get :show, params: { account_username: status.account.username, id: status.id }
  323. end
  324. it 'returns http not found' do
  325. expect(response).to have_http_status(404)
  326. end
  327. end
  328. context 'when status is public' do
  329. before do
  330. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  331. end
  332. context 'as HTML' do
  333. let(:format) { 'html' }
  334. it 'returns http success' do
  335. expect(response).to have_http_status(200)
  336. end
  337. it 'returns Link header' do
  338. expect(response.headers['Link'].to_s).to include 'activity+json'
  339. end
  340. it 'returns Vary header' do
  341. expect(response.headers['Vary']).to eq 'Accept'
  342. end
  343. it 'returns no Cache-Control header' do
  344. expect(response.headers).to_not include 'Cache-Control'
  345. end
  346. it 'renders status' do
  347. expect(response).to render_template(:show)
  348. expect(response.body).to include status.text
  349. end
  350. end
  351. context 'as JSON' do
  352. let(:format) { 'json' }
  353. it 'returns http success' do
  354. expect(response).to have_http_status(200)
  355. end
  356. it 'returns Link header' do
  357. expect(response.headers['Link'].to_s).to include 'activity+json'
  358. end
  359. it 'returns Vary header' do
  360. expect(response.headers['Vary']).to eq 'Accept'
  361. end
  362. it 'returns public Cache-Control header' do
  363. expect(response.headers['Cache-Control']).to include 'public'
  364. end
  365. it 'returns Content-Type header' do
  366. expect(response.headers['Content-Type']).to include 'application/activity+json'
  367. end
  368. it 'renders ActivityPub Note object' do
  369. json = body_as_json
  370. expect(json[:content]).to include status.text
  371. end
  372. end
  373. end
  374. context 'when status is private' do
  375. let(:status) { Fabricate(:status, account: account, visibility: :private) }
  376. context 'when user is authorized to see it' do
  377. before do
  378. remote_account.follow!(account)
  379. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  380. end
  381. context 'as HTML' do
  382. let(:format) { 'html' }
  383. it 'returns http success' do
  384. expect(response).to have_http_status(200)
  385. end
  386. it 'returns Link header' do
  387. expect(response.headers['Link'].to_s).to include 'activity+json'
  388. end
  389. it 'returns Vary header' do
  390. expect(response.headers['Vary']).to eq 'Accept'
  391. end
  392. it 'returns no Cache-Control header' do
  393. expect(response.headers).to_not include 'Cache-Control'
  394. end
  395. it 'renders status' do
  396. expect(response).to render_template(:show)
  397. expect(response.body).to include status.text
  398. end
  399. end
  400. context 'as JSON' do
  401. let(:format) { 'json' }
  402. it 'returns http success' do
  403. expect(response).to have_http_status(200)
  404. end
  405. it 'returns Link header' do
  406. expect(response.headers['Link'].to_s).to include 'activity+json'
  407. end
  408. it 'returns Vary header' do
  409. expect(response.headers['Vary']).to eq 'Accept'
  410. end
  411. it 'returns private Cache-Control header' do
  412. expect(response.headers['Cache-Control']).to include 'private'
  413. end
  414. it 'returns Content-Type header' do
  415. expect(response.headers['Content-Type']).to include 'application/activity+json'
  416. end
  417. it 'renders ActivityPub Note object' do
  418. json = body_as_json
  419. expect(json[:content]).to include status.text
  420. end
  421. end
  422. end
  423. context 'when user is not authorized to see it' do
  424. before do
  425. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  426. end
  427. context 'as JSON' do
  428. let(:format) { 'json' }
  429. it 'returns http not found' do
  430. expect(response).to have_http_status(404)
  431. end
  432. end
  433. context 'as HTML' do
  434. let(:format) { 'html' }
  435. it 'returns http not found' do
  436. expect(response).to have_http_status(404)
  437. end
  438. end
  439. end
  440. end
  441. context 'when status is direct' do
  442. let(:status) { Fabricate(:status, account: account, visibility: :direct) }
  443. context 'when user is authorized to see it' do
  444. before do
  445. Fabricate(:mention, account: remote_account, status: status)
  446. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  447. end
  448. context 'as HTML' do
  449. let(:format) { 'html' }
  450. it 'returns http success' do
  451. expect(response).to have_http_status(200)
  452. end
  453. it 'returns Link header' do
  454. expect(response.headers['Link'].to_s).to include 'activity+json'
  455. end
  456. it 'returns Vary header' do
  457. expect(response.headers['Vary']).to eq 'Accept'
  458. end
  459. it 'returns no Cache-Control header' do
  460. expect(response.headers).to_not include 'Cache-Control'
  461. end
  462. it 'renders status' do
  463. expect(response).to render_template(:show)
  464. expect(response.body).to include status.text
  465. end
  466. end
  467. context 'as JSON' do
  468. let(:format) { 'json' }
  469. it 'returns http success' do
  470. expect(response).to have_http_status(200)
  471. end
  472. it 'returns Link header' do
  473. expect(response.headers['Link'].to_s).to include 'activity+json'
  474. end
  475. it 'returns Vary header' do
  476. expect(response.headers['Vary']).to eq 'Accept'
  477. end
  478. it 'returns private Cache-Control header' do
  479. expect(response.headers['Cache-Control']).to include 'private'
  480. end
  481. it 'returns Content-Type header' do
  482. expect(response.headers['Content-Type']).to include 'application/activity+json'
  483. end
  484. it 'renders ActivityPub Note object' do
  485. json = body_as_json
  486. expect(json[:content]).to include status.text
  487. end
  488. end
  489. end
  490. context 'when user is not authorized to see it' do
  491. before do
  492. get :show, params: { account_username: status.account.username, id: status.id, format: format }
  493. end
  494. context 'as JSON' do
  495. let(:format) { 'json' }
  496. it 'returns http not found' do
  497. expect(response).to have_http_status(404)
  498. end
  499. end
  500. context 'as HTML' do
  501. let(:format) { 'html' }
  502. it 'returns http not found' do
  503. expect(response).to have_http_status(404)
  504. end
  505. end
  506. end
  507. end
  508. end
  509. end
  510. describe 'GET #activity' do
  511. let(:account) { Fabricate(:account) }
  512. let(:status) { Fabricate(:status, account: account) }
  513. context 'when account is suspended' do
  514. let(:account) { Fabricate(:account, suspended: true) }
  515. before do
  516. get :activity, params: { account_username: account.username, id: status.id }
  517. end
  518. it 'returns http gone' do
  519. expect(response).to have_http_status(410)
  520. end
  521. end
  522. context 'when status is public' do
  523. pending
  524. end
  525. context 'when status is private' do
  526. pending
  527. end
  528. context 'when status is direct' do
  529. pending
  530. end
  531. context 'when signed-in' do
  532. context 'when status is public' do
  533. pending
  534. end
  535. context 'when status is private' do
  536. context 'when user is authorized to see it' do
  537. pending
  538. end
  539. context 'when user is not authorized to see it' do
  540. pending
  541. end
  542. end
  543. context 'when status is direct' do
  544. context 'when user is authorized to see it' do
  545. pending
  546. end
  547. context 'when user is not authorized to see it' do
  548. pending
  549. end
  550. end
  551. end
  552. context 'with signature' do
  553. context 'when status is public' do
  554. pending
  555. end
  556. context 'when status is private' do
  557. context 'when user is authorized to see it' do
  558. pending
  559. end
  560. context 'when user is not authorized to see it' do
  561. pending
  562. end
  563. end
  564. context 'when status is direct' do
  565. context 'when user is authorized to see it' do
  566. pending
  567. end
  568. context 'when user is not authorized to see it' do
  569. pending
  570. end
  571. end
  572. end
  573. end
  574. describe 'GET #embed' do
  575. let(:account) { Fabricate(:account) }
  576. let(:status) { Fabricate(:status, account: account) }
  577. context 'when account is suspended' do
  578. let(:account) { Fabricate(:account, suspended: true) }
  579. before do
  580. get :embed, params: { account_username: account.username, id: status.id }
  581. end
  582. it 'returns http gone' do
  583. expect(response).to have_http_status(410)
  584. end
  585. end
  586. context 'when status is a reblog' do
  587. let(:original_account) { Fabricate(:account, domain: 'example.com') }
  588. let(:original_status) { Fabricate(:status, account: original_account, url: 'https://example.com/123') }
  589. let(:status) { Fabricate(:status, account: account, reblog: original_status) }
  590. before do
  591. get :embed, params: { account_username: status.account.username, id: status.id }
  592. end
  593. it 'returns http not found' do
  594. expect(response).to have_http_status(404)
  595. end
  596. end
  597. context 'when status is public' do
  598. before do
  599. get :embed, params: { account_username: status.account.username, id: status.id }
  600. end
  601. it 'returns http success' do
  602. expect(response).to have_http_status(200)
  603. end
  604. it 'returns Link header' do
  605. expect(response.headers['Link'].to_s).to include 'activity+json'
  606. end
  607. it 'returns Vary header' do
  608. expect(response.headers['Vary']).to eq 'Accept'
  609. end
  610. it 'returns public Cache-Control header' do
  611. expect(response.headers['Cache-Control']).to include 'public'
  612. end
  613. it 'renders status' do
  614. expect(response).to render_template(:embed)
  615. expect(response.body).to include status.text
  616. end
  617. end
  618. context 'when status is private' do
  619. let(:status) { Fabricate(:status, account: account, visibility: :private) }
  620. before do
  621. get :embed, params: { account_username: status.account.username, id: status.id }
  622. end
  623. it 'returns http not found' do
  624. expect(response).to have_http_status(404)
  625. end
  626. end
  627. context 'when status is direct' do
  628. let(:status) { Fabricate(:status, account: account, visibility: :direct) }
  629. before do
  630. get :embed, params: { account_username: status.account.username, id: status.id }
  631. end
  632. it 'returns http not found' do
  633. expect(response).to have_http_status(404)
  634. end
  635. end
  636. end
  637. end