Raise better exception on FASP error responses (#35262)

This commit is contained in:
David Roetzel 2025-07-04 09:25:42 +02:00 committed by GitHub
parent 5a7c0d42f7
commit 1fa72d6c44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 5 deletions

View File

@ -49,6 +49,8 @@ class Fasp::Request
end
def validate!(response)
raise Mastodon::UnexpectedResponseError, response if response.code >= 400
content_digest_header = response.headers['content-digest']
raise Mastodon::SignatureVerificationError, 'content-digest missing' if content_digest_header.blank?
raise Mastodon::SignatureVerificationError, 'content-digest does not match' if content_digest_header != content_digest(response.body)

View File

@ -32,13 +32,27 @@ RSpec.describe Fasp::Request do
context 'when the response is not signed' do
before do
stub_request(method, 'https://reqprov.example.com/fasp/test_path')
.to_return(status: 200)
.to_return(status:)
end
it 'raises an error' do
expect do
subject.send(method, '/test_path')
end.to raise_error(Mastodon::SignatureVerificationError)
context 'when the request was successful' do
let(:status) { 200 }
it 'raises a signature verification error' do
expect do
subject.send(method, '/test_path')
end.to raise_error(Mastodon::SignatureVerificationError)
end
end
context 'when an error response is received' do
let(:status) { 401 }
it 'raises an unexpected response error' do
expect do
subject.send(method, '/test_path')
end.to raise_error(Mastodon::UnexpectedResponseError)
end
end
end
end