2024-08-27 18:44:16 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 14:12:25 +09:00
|
|
|
RSpec.describe 'Media Proxy' do
|
2024-08-27 18:44:16 +09:00
|
|
|
describe 'GET /media_proxy/:id' do
|
2024-09-04 00:28:57 +09:00
|
|
|
before { stub_attachment_request }
|
2024-08-27 18:44:16 +09:00
|
|
|
|
|
|
|
context 'when attached to a status' do
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png') }
|
|
|
|
|
|
|
|
it 'redirects to correct original url' do
|
|
|
|
get "/media_proxy/#{media_attachment.id}"
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(302)
|
|
|
|
.and redirect_to media_attachment.file.url(:original)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to small style url' do
|
|
|
|
get "/media_proxy/#{media_attachment.id}/small"
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(302)
|
|
|
|
.and redirect_to media_attachment.file.url(:small)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is not an attached status' do
|
|
|
|
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png') }
|
|
|
|
|
|
|
|
it 'responds with missing' do
|
|
|
|
get "/media_proxy/#{media_attachment.id}"
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when id cannot be found' do
|
|
|
|
it 'responds with missing' do
|
|
|
|
get '/media_proxy/missing'
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not permitted to view' do
|
|
|
|
let(:status) { Fabricate(:status, visibility: :direct) }
|
|
|
|
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png') }
|
|
|
|
|
|
|
|
it 'responds with missing' do
|
|
|
|
get "/media_proxy/#{media_attachment.id}"
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
2024-09-04 00:28:57 +09:00
|
|
|
|
|
|
|
def stub_attachment_request
|
|
|
|
stub_request(
|
|
|
|
:get,
|
|
|
|
'http://example.com/attachment.png'
|
|
|
|
)
|
|
|
|
.to_return(
|
|
|
|
request_fixture('avatar.txt')
|
|
|
|
)
|
|
|
|
end
|
2024-08-27 18:44:16 +09:00
|
|
|
end
|
|
|
|
end
|