Skip to content

Commit

Permalink
[remote_v2] don't crash when endpoint is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed Sep 1, 2017
1 parent 50ac300 commit 9c2dba5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Crash on empty OIDC Issuer endpoint [PR #408](https://github.com/3scale/apicast/pull/408)
- Handle partial credentials [PR #409](https://github.com/3scale/apicast/pull/409)
- Crash when configuration endpoint was missing []()

### Changed

Expand Down
12 changes: 10 additions & 2 deletions apicast/src/configuration_loader/remote_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,13 @@ function _M:services()
return nil, 'not initialized'
end

local url = resty_url.join(self.endpoint, '/admin/api/services.json')
local endpoint = self.endpoint

if not endpoint then
return nil, 'no endpoint'
end

local url = resty_url.join(self.endpoint, '/admin/api/services.json')
local res, err = http_client.get(url)

if not res and err then
Expand Down Expand Up @@ -281,6 +286,9 @@ function _M:config(service, environment, version)

if not http_client then return nil, 'not initialized' end

local endpoint = self.endpoint
if not endpoint then return nil, 'no endpoint' end

local id = service and service.id

if not id then return nil, 'invalid service, missing id' end
Expand All @@ -290,7 +298,7 @@ function _M:config(service, environment, version)
local version_override = resty_env.get(format('APICAST_SERVICE_%s_CONFIGURATION_VERSION', id))

local url = resty_url.join(
self.endpoint,
endpoint,
'/admin/api/services/', id , '/proxy/configs/', environment, '/',
format('%s.json', version_override or version)
)
Expand Down
12 changes: 12 additions & 0 deletions spec/configuration_loader/remote_v2_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ describe('Configuration Remote Loader V2', function()

after_each(function() test_backend.verify_no_outstanding_expectations() end)

describe('loader without endpoint', function()
before_each(function() loader = _M.new() end)

it('wont crash when getting services', function()
assert.same({ nil, 'no endpoint' }, { loader:services() })
end)

it('wont crash when getting config', function()
assert.same({ nil, 'no endpoint' }, { loader:config() })
end)
end)

describe('http_client #http', function()
it('has correct user agent', function()
test_backend.expect{ url = 'http://example.com/t', headers = { ['User-Agent'] = tostring(user_agent) } }
Expand Down

0 comments on commit 9c2dba5

Please sign in to comment.