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.

56 lines
2.5 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. before do
  7. get :show, params: { :id => account.id, 'hub.topic' => 'topic_url', 'hub.challenge' => '456', 'hub.lease_seconds' => "#{86400 * 30}" }
  8. end
  9. it 'returns http success' do
  10. expect(response).to have_http_status(:success)
  11. end
  12. it 'echoes back the challenge' do
  13. expect(response.body).to match '456'
  14. end
  15. end
  16. describe 'POST #update' do
  17. let(:feed) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
  18. before do
  19. stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {})
  20. stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
  21. stub_request(:head, "https://quitter.no/notice/1269244").to_return(status: 404)
  22. stub_request(:head, "https://quitter.no/notice/1265331").to_return(status: 404)
  23. stub_request(:head, "https://community.highlandarrow.com/notice/54411").to_return(status: 404)
  24. stub_request(:head, "https://community.highlandarrow.com/notice/53857").to_return(status: 404)
  25. stub_request(:head, "https://community.highlandarrow.com/notice/51852").to_return(status: 404)
  26. stub_request(:head, "https://social.umeahackerspace.se/notice/424348").to_return(status: 404)
  27. stub_request(:head, "https://community.highlandarrow.com/notice/50467").to_return(status: 404)
  28. stub_request(:head, "https://quitter.no/notice/1243309").to_return(status: 404)
  29. stub_request(:head, "https://quitter.no/user/7477").to_return(status: 404)
  30. stub_request(:head, "https://community.highlandarrow.com/user/1").to_return(status: 404)
  31. stub_request(:head, "https://social.umeahackerspace.se/user/2").to_return(status: 404)
  32. stub_request(:head, "https://gs.kawa-kun.com/user/2").to_return(status: 404)
  33. stub_request(:head, "https://mastodon.social/users/Gargron").to_return(status: 404)
  34. request.env['HTTP_X_HUB_SIGNATURE'] = "sha1=#{OpenSSL::HMAC.hexdigest('sha1', 'abc', feed)}"
  35. request.env['RAW_POST_DATA'] = feed
  36. post :update, params: { id: account.id }
  37. end
  38. it 'returns http success' do
  39. expect(response).to have_http_status(:success)
  40. end
  41. it 'creates statuses for feed' do
  42. expect(account.statuses.count).to_not eq 0
  43. end
  44. end
  45. end