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
f8249880
Commit
f8249880
authored
Mar 17, 2021
by
Shubham Kumar
Committed by
Markus Koller
Mar 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch network errors when testing integration
parent
542bb6da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
3 deletions
+38
-3
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+1
-1
changelogs/unreleased/skr-networks.yml
changelogs/unreleased/skr-networks.yml
+5
-0
spec/controllers/projects/services_controller_spec.rb
spec/controllers/projects/services_controller_spec.rb
+32
-2
No files found.
app/controllers/projects/services_controller.rb
View file @
f8249880
...
...
@@ -71,7 +71,7 @@ class Projects::ServicesController < Projects::ApplicationController
end
result
[
:data
].
presence
||
{}
rescue
Gitlab
::
HTTP
::
BlockedUrlError
=>
e
rescue
*
Gitlab
::
HTTP
::
HTTP_ERRORS
=>
e
{
error:
true
,
message:
s_
(
'Integrations|Connection failed. Please check your settings.'
),
service_response:
e
.
message
,
test_failed:
true
}
end
...
...
changelogs/unreleased/skr-networks.yml
0 → 100644
View file @
f8249880
---
title
:
Catch network errors
merge_request
:
56457
author
:
Shubham Kumar (@imskr)
type
:
fixed
spec/controllers/projects/services_controller_spec.rb
View file @
f8249880
...
...
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec
.
describe
Projects
::
ServicesController
do
include
JiraServiceHelper
include
AfterNextHelpers
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
@@ -13,7 +14,6 @@ RSpec.describe Projects::ServicesController do
before
do
sign_in
(
user
)
project
.
add_maintainer
(
user
)
allow
(
Gitlab
::
UrlBlocker
).
to
receive
(
:validate!
).
and_return
([
URI
.
parse
(
'http://example.com'
),
nil
])
end
describe
'#test'
do
...
...
@@ -114,7 +114,7 @@ RSpec.describe Projects::ServicesController do
end
context
'failure'
do
it
'returns
success status code and the error message
'
do
it
'returns
an error response when the integration test fails
'
do
stub_request
(
:get
,
'http://example.com/rest/api/2/serverInfo'
)
.
to_return
(
status:
404
)
...
...
@@ -128,6 +128,36 @@ RSpec.describe Projects::ServicesController do
'test_failed'
=>
true
)
end
context
'with the Slack integration'
do
let_it_be
(
:service
)
{
build
(
:slack_service
)
}
it
'returns an error response when the URL is blocked'
do
put
:test
,
params:
project_params
(
service:
{
webhook:
'http://127.0.0.1'
})
expect
(
response
).
to
be_successful
expect
(
json_response
).
to
eq
(
'error'
=>
true
,
'message'
=>
'Connection failed. Please check your settings.'
,
'service_response'
=>
"URL 'http://127.0.0.1' is blocked: Requests to localhost are not allowed"
,
'test_failed'
=>
true
)
end
it
'returns an error response when a network exception is raised'
do
expect_next
(
SlackService
).
to
receive
(
:test
).
and_raise
(
Errno
::
ECONNREFUSED
)
put
:test
,
params:
project_params
expect
(
response
).
to
be_successful
expect
(
json_response
).
to
eq
(
'error'
=>
true
,
'message'
=>
'Connection failed. Please check your settings.'
,
'service_response'
=>
'Connection refused'
,
'test_failed'
=>
true
)
end
end
end
end
...
...
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