Skip to content
Snippets Groups Projects
Commit d91226dd authored by Vasilli Iakliushin's avatar Vasilli Iakliushin
Browse files

Fix NoMethodError for ActivityPub

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/424371

Handle the case when Accept header is missing.

Changelog: fixed
parent fed6773b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,7 +3,7 @@
module Constraints
class ActivityPubConstrainer
def matches?(request)
mime_types.any? { |m| request.headers['Accept'].include?(m) }
mime_types.any? { |m| request.headers.fetch('Accept', '').include?(m) }
end
 
private
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Constraints::ActivityPubConstrainer, feature_category: :groups_and_projects do
subject(:constraint) { described_class.new }
describe '#matches?' do
subject { constraint.matches?(request) }
let(:request) { ActionDispatch::Request.new(headers) }
['application/ld+json; profile="https://www.w3.org/ns/activitystreams"', 'application/activity+json'].each do |mime|
context "when mime is #{mime}" do
let(:headers) { { 'HTTP_ACCEPT' => mime } }
it 'matches the header' do
is_expected.to be_truthy
end
end
end
context 'when Accept header is missing' do
let(:headers) { {} }
it 'does not match' do
is_expected.to be_falsey
end
end
end
end
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