Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
2744f616
Unverified
Commit
2744f616
authored
4 years ago
by
Eugen Rochko
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix not being able to resolve public resources in development environment (#13505)
parent
be637146
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/services/fetch_resource_service.rb
+12
-1
12 additions, 1 deletion
app/services/fetch_resource_service.rb
spec/services/fetch_resource_service_spec.rb
+10
-2
10 additions, 2 deletions
spec/services/fetch_resource_service_spec.rb
with
22 additions
and
3 deletions
app/services/fetch_resource_service.rb
+
12
−
1
View file @
2744f616
...
...
@@ -25,7 +25,18 @@ class FetchResourceService < BaseService
end
def
perform_request
(
&
block
)
Request
.
new
(
:get
,
@url
).
add_headers
(
'Accept'
=>
ACCEPT_HEADER
).
on_behalf_of
(
Account
.
representative
).
perform
(
&
block
)
Request
.
new
(
:get
,
@url
).
tap
do
|
request
|
request
.
add_headers
(
'Accept'
=>
ACCEPT_HEADER
)
# In a real setting we want to sign all outgoing requests,
# in case the remote server has secure mode enabled and requires
# authentication on all resources. However, during development,
# sending request signatures with an inaccessible host is useless
# and prevents even public resources from being fetched, so
# don't do it
request
.
on_behalf_of
(
Account
.
representative
)
unless
Rails
.
env
.
development?
end
.
perform
(
&
block
)
end
def
process_response
(
response
,
terminal
=
false
)
...
...
This diff is collapsed.
Click to expand it.
spec/services/fetch_resource_service_spec.rb
+
10
−
2
View file @
2744f616
...
...
@@ -21,7 +21,11 @@ RSpec.describe FetchResourceService, type: :service do
context
'when OpenSSL::SSL::SSLError is raised'
do
before
do
allow
(
Request
).
to
receive_message_chain
(
:new
,
:add_headers
,
:on_behalf_of
,
:perform
).
and_raise
(
OpenSSL
::
SSL
::
SSLError
)
request
=
double
()
allow
(
Request
).
to
receive
(
:new
).
and_return
(
request
)
allow
(
request
).
to
receive
(
:add_headers
)
allow
(
request
).
to
receive
(
:on_behalf_of
)
allow
(
request
).
to
receive
(
:perform
).
and_raise
(
OpenSSL
::
SSL
::
SSLError
)
end
it
{
is_expected
.
to
be_nil
}
...
...
@@ -29,7 +33,11 @@ RSpec.describe FetchResourceService, type: :service do
context
'when HTTP::ConnectionError is raised'
do
before
do
allow
(
Request
).
to
receive_message_chain
(
:new
,
:add_headers
,
:on_behalf_of
,
:perform
).
and_raise
(
HTTP
::
ConnectionError
)
request
=
double
()
allow
(
Request
).
to
receive
(
:new
).
and_return
(
request
)
allow
(
request
).
to
receive
(
:add_headers
)
allow
(
request
).
to
receive
(
:on_behalf_of
)
allow
(
request
).
to
receive
(
:perform
).
and_raise
(
HTTP
::
ConnectionError
)
end
it
{
is_expected
.
to
be_nil
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment