Commit a104a6da authored by charlieablett's avatar charlieablett

Change SpamVerdictService GET to POST

- Add error logging if any HTTP errors occur
parent e63e567b
...@@ -41,10 +41,10 @@ module Spam ...@@ -41,10 +41,10 @@ module Spam
return unless Gitlab::CurrentSettings.spam_check_endpoint_enabled return unless Gitlab::CurrentSettings.spam_check_endpoint_enabled
return if endpoint_url.blank? return if endpoint_url.blank?
result = Gitlab::HTTP.try_get(endpoint_url, verdict_params) begin
result = Gitlab::HTTP.post(endpoint_url, body: verdict_params.to_json, headers: { 'Content-Type' => 'application/json' })
return unless result return unless result
begin
json_result = Gitlab::Json.parse(result).with_indifferent_access json_result = Gitlab::Json.parse(result).with_indifferent_access
# @TODO metrics/logging # @TODO metrics/logging
# Expecting: # Expecting:
...@@ -56,6 +56,10 @@ module Spam ...@@ -56,6 +56,10 @@ module Spam
# @TODO log if json_result[:error] # @TODO log if json_result[:error]
json_result[:verdict] json_result[:verdict]
rescue *Gitlab::HTTP::HTTP_ERRORS => e
# @TODO: log error via try_post https://gitlab.com/gitlab-org/gitlab/-/issues/219223
Gitlab::ErrorTracking.log_exception(e)
return
rescue rescue
# @TODO log # @TODO log
ALLOW ALLOW
......
...@@ -169,7 +169,7 @@ describe Spam::SpamVerdictService do ...@@ -169,7 +169,7 @@ describe Spam::SpamVerdictService do
before do before do
stub_application_setting(spam_check_endpoint_enabled: true) stub_application_setting(spam_check_endpoint_enabled: true)
stub_application_setting(spam_check_endpoint_url: "http://www.spamcheckurl.com/spam_check") stub_application_setting(spam_check_endpoint_url: "http://www.spamcheckurl.com/spam_check")
stub_request(:any, /.*spamcheckurl.com.*/).to_return( body: spam_check_body.to_json, status: spam_check_http_status ) stub_request(:post, /.*spamcheckurl.com.*/).to_return( body: spam_check_body.to_json, status: spam_check_http_status )
end end
context 'if the endpoint is accessible' do context 'if the endpoint is accessible' do
...@@ -248,7 +248,7 @@ describe Spam::SpamVerdictService do ...@@ -248,7 +248,7 @@ describe Spam::SpamVerdictService do
context 'if the endpoint times out' do context 'if the endpoint times out' do
before do before do
stub_request(:any, /.*spamcheckurl.com.*/).to_timeout stub_request(:post, /.*spamcheckurl.com.*/).to_timeout
end end
it 'returns nil' do it 'returns nil' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment