Skip to content
Snippets Groups Projects
Unverified Commit 1eb51bd7 authored by Claire's avatar Claire Committed by GitHub
Browse files

Add request specs for caching behavior (#24592)

parent 88d33f36
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,26 @@ Devise::Test::ControllerHelpers.module_eval do
end
end
module SignedRequestHelpers
def get(path, headers: nil, sign_with: nil, **args)
return super path, headers: headers, **args if sign_with.nil?
headers ||= {}
headers['Date'] = Time.now.utc.httpdate
headers['Host'] = ENV.fetch('LOCAL_DOMAIN')
signed_headers = headers.merge('(request-target)' => "get #{path}").slice('(request-target)', 'Host', 'Date')
key_id = ActivityPub::TagManager.instance.key_uri_for(sign_with)
keypair = sign_with.keypair
signed_string = signed_headers.map { |key, value| "#{key.downcase}: #{value}" }.join("\n")
signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest.new('SHA256'), signed_string))
headers['Signature'] = "keyId=\"#{key_id}\",algorithm=\"rsa-sha256\",headers=\"#{signed_headers.keys.join(' ').downcase}\",signature=\"#{signature}\""
super path, headers: headers, **args
end
end
RSpec.configure do |config|
config.fixture_path = "#{Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
......@@ -46,10 +66,12 @@ RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :helper
config.include Devise::Test::ControllerHelpers, type: :view
config.include Devise::Test::IntegrationHelpers, type: :feature
config.include Devise::Test::IntegrationHelpers, type: :request
config.include Paperclip::Shoulda::Matchers
config.include ActiveSupport::Testing::TimeHelpers
config.include Chewy::Rspec::Helpers
config.include Redisable
config.include SignedRequestHelpers, type: :request
config.before :each, type: :feature do
https = ENV['LOCAL_HTTPS'] == 'true'
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment