mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Raise better exception on FASP error responses (#35262)
This commit is contained in:
parent
5a7c0d42f7
commit
1fa72d6c44
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user