Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream: return error if the value given is cjson.null #1136

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

- Fix issues when TLS is enabled in Lazy mode [#1135](https://github.com/3scale/APIcast/pull/1135), [THREESCALE-3713](https://issues.jboss.org/browse/THREESCALE-3713)
- Fix exception if api_backend is null [THREESCALE-3869](https://issues.jboss.org/browse/THREESCALE-3869) [PR #1136](https://github.com/3scale/APIcast/pull/1136)

### Added

- Return 404 back if the upstream is not defined [THREESCALE-3775](https://issues.jboss.org/browse/THREESCALE-3775) [PR #1129](https://github.com/3scale/APIcast/pull/1129)


## [Unreleased]

### Added
Expand Down
1 change: 0 additions & 1 deletion gateway/src/apicast/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ function _M.get_upstream(service)
if not service then
return errors.service_not_found()
end

local upstream, err = Upstream.new(service.api_backend)

if not upstream then
Expand Down
5 changes: 5 additions & 0 deletions gateway/src/apicast/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local url_helper = require('resty.url_helper')

local http_proxy = require('apicast.http_proxy')
local format = string.format
local cjson = require('cjson')

local _M = {

Expand All @@ -34,6 +35,10 @@ local mt = {
--- @treturn nil|string error when upstream can't be initialized
--- @static
function _M.new(url)
if not url or url == cjson.null then
return nil, 'Upstream cannot be null'
end

local uri, err = url_helper.parse_url(url)
if err then
return nil, 'invalid upstream'
Expand Down
33 changes: 33 additions & 0 deletions t/apicast-blackbox.t
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,36 @@ GET /?user_key=value
could not find upstream for service: 42
--- no_error_log
[error]

=== TEST 6: api backend is null andreturns 404
The request url is correct in the mapping rules but api_backend is null
--- configuration
{
"services": [
{
"id": 42,
"backend_version": 1,
"proxy": {
"api_backend": null,
"proxy_rules": [
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 }
]
}
}
]
}
--- backend
location /transactions/authrep.xml {
echo 'ok';
}
--- upstream
location / {
echo 'path: $uri';
}
--- request
GET /?user_key=value
--- error_code: 404
--- error_log
could not find upstream for service: 42
--- no_error_log
[error]