このコミットが含まれているのは:
@@ -48,4 +48,56 @@ RSpec.describe Preview::ThumbnailFetcher do
|
||||
expect(described_class.fetch('https://example.com/page')).to eq('jpeg-bytes')
|
||||
end
|
||||
end
|
||||
|
||||
describe '.fetch_image_response' do
|
||||
it 'rejects an unsafe input URL before HTTP fetch' do
|
||||
allow(Preview::UrlSafety).to receive(:validate)
|
||||
.and_raise(Preview::UrlSafety::UnsafeUrl, '安全でない接続先は使用できません.')
|
||||
expect(Preview::HttpFetcher).not_to receive(:fetch)
|
||||
|
||||
expect {
|
||||
described_class.fetch_image_response('https://unsafe.example.com/thumb.jpg')
|
||||
}.to raise_error(Preview::UrlSafety::UnsafeUrl, '安全でない接続先は使用できません.')
|
||||
end
|
||||
|
||||
it 'rejects an unsafe redirect target' do
|
||||
allow(Preview::UrlSafety).to receive(:validate)
|
||||
.and_return([URI.parse('https://example.com/thumb.jpg'), ['8.8.8.8']])
|
||||
allow(Preview::HttpFetcher).to receive(:fetch)
|
||||
.with('https://example.com/thumb.jpg')
|
||||
.and_raise(Preview::UrlSafety::UnsafeUrl, '安全でない接続先は使用できません.')
|
||||
|
||||
expect {
|
||||
described_class.fetch_image_response('https://example.com/thumb.jpg')
|
||||
}.to raise_error(Preview::UrlSafety::UnsafeUrl, '安全でない接続先は使用できません.')
|
||||
end
|
||||
|
||||
it 'rejects an oversized image response' do
|
||||
allow(Preview::UrlSafety).to receive(:validate)
|
||||
.and_return([URI.parse('https://example.com/thumb.jpg'), ['8.8.8.8']])
|
||||
allow(Preview::HttpFetcher).to receive(:fetch)
|
||||
.with('https://example.com/thumb.jpg')
|
||||
.and_raise(Preview::HttpFetcher::ResponseTooLarge, 'too large')
|
||||
|
||||
expect {
|
||||
described_class.fetch_image_response('https://example.com/thumb.jpg')
|
||||
}.to raise_error(Preview::HttpFetcher::ResponseTooLarge)
|
||||
end
|
||||
|
||||
it 'rejects a non-image content type' do
|
||||
allow(Preview::UrlSafety).to receive(:validate)
|
||||
.and_return([URI.parse('https://example.com/thumb.jpg'), ['8.8.8.8']])
|
||||
allow(Preview::HttpFetcher).to receive(:fetch)
|
||||
.with('https://example.com/thumb.jpg')
|
||||
.and_return(
|
||||
Preview::HttpFetcher::Response.new(
|
||||
'<html></html>',
|
||||
'text/html',
|
||||
'https://example.com/thumb.jpg'))
|
||||
|
||||
expect {
|
||||
described_class.fetch_image_response('https://example.com/thumb.jpg')
|
||||
}.to raise_error(Preview::ThumbnailFetcher::GenerationFailed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
新しい課題から参照
ユーザをブロックする