0
0
Fork 0

Add request specs for caching behavior (#24592)

This commit is contained in:
Claire 2023-05-02 13:58:29 +02:00 committed by GitHub
parent 88d33f361f
commit 1eb51bd749
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 707 additions and 0 deletions

View file

@ -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'