Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a104a6da
Commit
a104a6da
authored
May 27, 2020
by
charlieablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change SpamVerdictService GET to POST
- Add error logging if any HTTP errors occur
parent
e63e567b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
5 deletions
+9
-5
app/services/spam/spam_verdict_service.rb
app/services/spam/spam_verdict_service.rb
+7
-3
spec/services/spam/spam_verdict_service_spec.rb
spec/services/spam/spam_verdict_service_spec.rb
+2
-2
No files found.
app/services/spam/spam_verdict_service.rb
View file @
a104a6da
...
...
@@ -41,10 +41,10 @@ module Spam
return
unless
Gitlab
::
CurrentSettings
.
spam_check_endpoint_enabled
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
begin
json_result
=
Gitlab
::
Json
.
parse
(
result
).
with_indifferent_access
# @TODO metrics/logging
# Expecting:
...
...
@@ -56,6 +56,10 @@ module Spam
# @TODO log if json_result[:error]
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
# @TODO log
ALLOW
...
...
spec/services/spam/spam_verdict_service_spec.rb
View file @
a104a6da
...
...
@@ -169,7 +169,7 @@ describe Spam::SpamVerdictService do
before
do
stub_application_setting
(
spam_check_endpoint_enabled:
true
)
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
context
'if the endpoint is accessible'
do
...
...
@@ -248,7 +248,7 @@ describe Spam::SpamVerdictService do
context
'if the endpoint times out'
do
before
do
stub_request
(
:
any
,
/.*spamcheckurl.com.*/
).
to_timeout
stub_request
(
:
post
,
/.*spamcheckurl.com.*/
).
to_timeout
end
it
'returns nil'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment