闭社主体 forked from https://github.com/tootsuite/mastodon
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.

46 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Api::V1::StreamingController do
  4. around(:each) do |example|
  5. before = Rails.configuration.x.streaming_api_base_url
  6. Rails.configuration.x.streaming_api_base_url = Rails.configuration.x.web_domain
  7. example.run
  8. Rails.configuration.x.streaming_api_base_url = before
  9. end
  10. before(:each) do
  11. request.headers.merge! Host: Rails.configuration.x.web_domain
  12. end
  13. context 'with streaming api on same host' do
  14. describe 'GET #index' do
  15. it 'raises ActiveRecord::RecordNotFound' do
  16. get :index
  17. expect(response).to have_http_status(404)
  18. end
  19. end
  20. end
  21. context 'with streaming api on different host' do
  22. before(:each) do
  23. Rails.configuration.x.streaming_api_base_url = 'wss://streaming-' + Rails.configuration.x.web_domain
  24. @streaming_host = URI.parse(Rails.configuration.x.streaming_api_base_url).host
  25. end
  26. describe 'GET #index' do
  27. it 'redirects to streaming host' do
  28. get :index, params: {access_token: 'deadbeef', stream: 'public'}
  29. expect(response).to have_http_status(301)
  30. request_uri = URI.parse(request.url)
  31. redirect_to_uri = URI.parse(response.location)
  32. [:scheme, :path, :query, :fragment].each do |part|
  33. expect(redirect_to_uri.send(part)).to eq(request_uri.send(part)), "redirect target #{part}"
  34. end
  35. expect(redirect_to_uri.host).to eq(@streaming_host), "redirect target host"
  36. end
  37. end
  38. end
  39. end