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.

69 lines
2.9 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::SubscriptionsController, type: :controller do
  3. render_views
  4. let(:account) { Fabricate(:account, username: 'gargron', domain: 'quitter.no', remote_url: 'topic_url', secret: 'abc') }
  5. describe 'GET #show' do
  6. context 'with valid subscription' do
  7. before do
  8. get :show, params: { :id => account.id, 'hub.topic' => 'topic_url', 'hub.challenge' => '456', 'hub.lease_seconds' => "#{86400 * 30}" }
  9. end
  10. it 'returns http success' do
  11. expect(response).to have_http_status(:success)
  12. end
  13. it 'echoes back the challenge' do
  14. expect(response.body).to match '456'
  15. end
  16. end
  17. context 'with invalid subscription' do
  18. before do
  19. expect_any_instance_of(Account).to receive_message_chain(:subscription, :valid?).and_return(false)
  20. get :show, params: { :id => account.id }
  21. end
  22. it 'returns http success' do
  23. expect(response).to have_http_status(:missing)
  24. end
  25. end
  26. end
  27. describe 'POST #update' do
  28. let(:feed) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
  29. before do
  30. stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {})
  31. stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
  32. stub_request(:head, "https://quitter.no/notice/1269244").to_return(status: 404)
  33. stub_request(:head, "https://quitter.no/notice/1265331").to_return(status: 404)
  34. stub_request(:head, "https://community.highlandarrow.com/notice/54411").to_return(status: 404)
  35. stub_request(:head, "https://community.highlandarrow.com/notice/53857").to_return(status: 404)
  36. stub_request(:head, "https://community.highlandarrow.com/notice/51852").to_return(status: 404)
  37. stub_request(:head, "https://social.umeahackerspace.se/notice/424348").to_return(status: 404)
  38. stub_request(:head, "https://community.highlandarrow.com/notice/50467").to_return(status: 404)
  39. stub_request(:head, "https://quitter.no/notice/1243309").to_return(status: 404)
  40. stub_request(:head, "https://quitter.no/user/7477").to_return(status: 404)
  41. stub_request(:head, "https://community.highlandarrow.com/user/1").to_return(status: 404)
  42. stub_request(:head, "https://social.umeahackerspace.se/user/2").to_return(status: 404)
  43. stub_request(:head, "https://gs.kawa-kun.com/user/2").to_return(status: 404)
  44. stub_request(:head, "https://mastodon.social/users/Gargron").to_return(status: 404)
  45. request.env['HTTP_X_HUB_SIGNATURE'] = "sha1=#{OpenSSL::HMAC.hexdigest('sha1', 'abc', feed)}"
  46. request.env['RAW_POST_DATA'] = feed
  47. post :update, params: { id: account.id }
  48. end
  49. it 'returns http success' do
  50. expect(response).to have_http_status(:success)
  51. end
  52. it 'creates statuses for feed' do
  53. expect(account.statuses.count).to_not eq 0
  54. end
  55. end
  56. end