mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-06 18:01:05 +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
|
end
|
||||||
|
|
||||||
def validate!(response)
|
def validate!(response)
|
||||||
|
raise Mastodon::UnexpectedResponseError, response if response.code >= 400
|
||||||
|
|
||||||
content_digest_header = response.headers['content-digest']
|
content_digest_header = response.headers['content-digest']
|
||||||
raise Mastodon::SignatureVerificationError, 'content-digest missing' if content_digest_header.blank?
|
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)
|
raise Mastodon::SignatureVerificationError, 'content-digest does not match' if content_digest_header != content_digest(response.body)
|
||||||
|
|
|
@ -32,15 +32,29 @@ RSpec.describe Fasp::Request do
|
||||||
context 'when the response is not signed' do
|
context 'when the response is not signed' do
|
||||||
before do
|
before do
|
||||||
stub_request(method, 'https://reqprov.example.com/fasp/test_path')
|
stub_request(method, 'https://reqprov.example.com/fasp/test_path')
|
||||||
.to_return(status: 200)
|
.to_return(status:)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an error' do
|
context 'when the request was successful' do
|
||||||
|
let(:status) { 200 }
|
||||||
|
|
||||||
|
it 'raises a signature verification error' do
|
||||||
expect do
|
expect do
|
||||||
subject.send(method, '/test_path')
|
subject.send(method, '/test_path')
|
||||||
end.to raise_error(Mastodon::SignatureVerificationError)
|
end.to raise_error(Mastodon::SignatureVerificationError)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
describe '#get' do
|
describe '#get' do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user