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.

837 lines
24 KiB

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