diff --git a/config/mail_room.yml b/config/mail_room.yml index 49cb765ebe623f867bd6120fb75f80a8448e849a..1e76f5e9875bb6af718bc591053a7c5baa2dc71e 100644 --- a/config/mail_room.yml +++ b/config/mail_room.yml @@ -46,6 +46,7 @@ :delivery_method: postback :delivery_options: :delivery_url: <%= config[:gitlab_url] %>/api/v4/internal/mail_room/<%= key %> + :content_type: text/plain :jwt_auth_header: <%= Gitlab::MailRoom::INTERNAL_API_REQUEST_HEADER %> :jwt_issuer: <%= Gitlab::MailRoom::INTERNAL_API_REQUEST_JWT_ISSUER %> :jwt_algorithm: "HS256" diff --git a/lib/api/internal/mail_room.rb b/lib/api/internal/mail_room.rb index 238a83670d684e7a00844039f4abf5e0caa1016b..1e5e8c4c4e2e6d27f0423bb130acad1b30d6b444 100644 --- a/lib/api/internal/mail_room.rb +++ b/lib/api/internal/mail_room.rb @@ -12,6 +12,10 @@ module Internal class MailRoom < ::API::Base feature_category :service_desk + format :json + content_type :txt, 'text/plain' + default_format :txt + before do authenticate_gitlab_mailroom_request! end diff --git a/spec/lib/gitlab/mail_room/mail_room_spec.rb b/spec/lib/gitlab/mail_room/mail_room_spec.rb index 12fb12ebd87c72344743a1d1c1c3dd62c75b85c2..06a25be757ed7632eb1f315c23d14e90ba901688 100644 --- a/spec/lib/gitlab/mail_room/mail_room_spec.rb +++ b/spec/lib/gitlab/mail_room/mail_room_spec.rb @@ -303,6 +303,7 @@ delivery_method: 'postback', delivery_options: { delivery_url: "http://gitlab.example/api/v4/internal/mail_room/incoming_email", + content_type: "text/plain", jwt_auth_header: Gitlab::MailRoom::INTERNAL_API_REQUEST_HEADER, jwt_issuer: Gitlab::MailRoom::INTERNAL_API_REQUEST_JWT_ISSUER, jwt_algorithm: 'HS256', @@ -316,6 +317,7 @@ delivery_method: 'postback', delivery_options: { delivery_url: "http://gitlab.example/api/v4/internal/mail_room/service_desk_email", + content_type: "text/plain", jwt_auth_header: Gitlab::MailRoom::INTERNAL_API_REQUEST_HEADER, jwt_issuer: Gitlab::MailRoom::INTERNAL_API_REQUEST_JWT_ISSUER, jwt_algorithm: 'HS256', diff --git a/spec/requests/api/internal/mail_room_spec.rb b/spec/requests/api/internal/mail_room_spec.rb index 2a056f21bc825b62eaf991216d86702e04007e68..a0a9c1f9cb3e7edb03ad4d1e9022a0299d55a483 100644 --- a/spec/requests/api/internal/mail_room_spec.rb +++ b/spec/requests/api/internal/mail_room_spec.rb @@ -215,5 +215,29 @@ expect(job).to match a_hash_including('args' => [encoded_email_content]) end end + + context 'handle text/plain request content type' do + let(:auth_headers) do + jwt_token = JWT.encode(auth_payload, incoming_email_secret, 'HS256') + { + Gitlab::MailRoom::INTERNAL_API_REQUEST_HEADER => jwt_token, + 'Content-Type' => 'text/plain' + } + end + + it 'schedules a EmailReceiverWorker job with email content encoded to utf-8 forcefully' do + Sidekiq::Testing.fake! do + expect do + post api("/internal/mail_room/incoming_email"), headers: auth_headers, params: email_content + end.to change { EmailReceiverWorker.jobs.size }.by(1) + end + + expect(response).to have_gitlab_http_status(:ok) + expect(response.content_type).to eql('application/json') + + job = EmailReceiverWorker.jobs.last + expect(job).to match a_hash_including('args' => [email_content]) + end + end end end