The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
1.7 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Request do
  4. subject { Request.new(:get, 'http://example.com') }
  5. describe '#headers' do
  6. it 'returns user agent' do
  7. expect(subject.headers['User-Agent']).to be_present
  8. end
  9. it 'returns the date header' do
  10. expect(subject.headers['Date']).to be_present
  11. end
  12. it 'returns the host header' do
  13. expect(subject.headers['Host']).to be_present
  14. end
  15. it 'does not return virtual request-target header' do
  16. expect(subject.headers['(request-target)']).to be_nil
  17. end
  18. end
  19. describe '#on_behalf_of' do
  20. it 'when used, adds signature header' do
  21. subject.on_behalf_of(Fabricate(:account))
  22. expect(subject.headers['Signature']).to be_present
  23. end
  24. end
  25. describe '#add_headers' do
  26. it 'adds headers to the request' do
  27. subject.add_headers('Test' => 'Foo')
  28. expect(subject.headers['Test']).to eq 'Foo'
  29. end
  30. end
  31. describe '#perform' do
  32. context 'with valid host' do
  33. before do
  34. stub_request(:get, 'http://example.com')
  35. subject.perform
  36. end
  37. it 'executes a HTTP request' do
  38. expect(a_request(:get, 'http://example.com')).to have_been_made.once
  39. end
  40. it 'sets headers' do
  41. expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made
  42. end
  43. end
  44. context 'with private host' do
  45. around do |example|
  46. WebMock.disable!
  47. example.run
  48. WebMock.enable!
  49. end
  50. it 'raises Mastodon::ValidationError' do
  51. allow(IPSocket).to receive(:getaddress).with('example.com').and_return('0.0.0.0')
  52. expect{ subject.perform }.to raise_error Mastodon::ValidationError
  53. end
  54. end
  55. end
  56. end