Skip to content

Commit

Permalink
Merge branch 'master' into module-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz authored May 3, 2017
2 parents e4ce8be + 8976a40 commit 120b96f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ env:
- secure: LLEaIHNfFqblICN7o2KrThFAXAuIwmc1ZMvSVgd6CXDi5FAZNhtwl35hKNOUiyTdvAuDWrJT503UoCnEwrJeKKGbpcjBC6hIgaXy8+K1UU5zh47D7bzOkuXmSv/FrRl6bqfulD7kjERQEozj6DJleNbBHmUckc2j89pdXca9d7lBzYeFMJFDDKhnIVRdTVUSjd1ccQNyEdP1a74gUI5rxKK79ynHPKgF3OneYNZLySkASoud/8i/30uop8gKwqyavQVkMXlhEkAHY1CSHiKo5mUQ5NR5fBl7ZBCFeKJ2h8DQI+R3BHbaA/mzmnacTE8B+w03d8OylZQCDhYdfNqQWBWOO1V0fpYc860Nf6TfMWuCzIG4zbOrweubOM67Tmrfw7wg8FhdXZPxNjlHUIkAVutC7KqM/h9I8cVdwNyp026mCG0pxZ/OrpoJl++S7+bIWBmtR6lP3s78t3K/FG3a3JsIfUgdZuscVpjqKkJ9RkT1v8dWWJULLJONJMZa39lblS1amcw6ZQeL0z6ILJ5Zr0JSEbtPyC/CXErrtV610xnhmcKb9XNpWZmqRaTT6EXtl06kaDoz6PYmeNUvgGfHrOSEU49iK+poDCFOIYNRFQuuQEk63O94OKWI1gT8BbJEqoUkSLochXpuKmkK80ctNXfWefwPDhVv1LQqFwp9hsQ=
- secure: UtFN6c5cd7KEfqBanUEeNSBZ7WtTM4JEQYlQJIefcN41Duse3qSEjNs6uMtJWn6PVB1NPLAbbZ2lwbznI56M1gNQXdHrVjInK90fo28zftG+8iSYpbPEuYIvyDIvLXtCJx0TT09DOzU9g5a8psfqYhnC3N3uBwStXoLLlxjf3fu5JISVpIA1CzGOB0xVmrbybWNyvjZlf5PXBqaYlIEuxB/t0O68J3duaJZFDLNjJVDtwzuzGyGS+w+R6YcasRoEpB2iGpaAAGAdOPoKznZqLm9aY+rQkMmXvQWWDtN+vpe6HqlOmkSgZjY//vLN/Hc0CMKsKxZ78FEe6C3zhWE+z2nQuvsdHOQ9DEHms6uRN9oOswvE6iKhJlKCbEPn/6gFTja/DCh/hUrsszTQC6x4BurfZAg/qHH2LViDfc7zX+Mh22e2gRsUH+nl+UweuFgHmpXDDeJEdL/luEFB8oo/HScGUgmUBRRfwq6I7C35QIl7ah5mql0l8IIOO+R7aPP290zm4lW/g7RXbPxqedJQBNiEHGrosKygonoYvBjnx4LBu2Qdwq6GNAhlIvdOxf1am7ixiVQnGqQhkHUnS7SriJmafo7TO9mKhrdDuhNqXgirwC13wxCAGrSlDGNUzITCeyyLSrS6pH8L+4VsS5p0d2dx+9gSDlL0iNiIB3CxqLg=
matrix:
- OPENRESTY_VERSION=1.11.2.2-5 LUAROCKS_VERSION=2.3.0 S2I_VERSION=1.1.4-870b273
- OPENRESTY_VERSION=1.11.2.3-1 LUAROCKS_VERSION=2.3.0 S2I_VERSION=1.1.5-4dd7721
before_install:
- travis/install-openresty.sh
- travis/install-luarocks.sh
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Print better errors when module loading fails [PR #360](https://github.com/3scale/apicast/pull/360)
- Bump OpenResty version to [1.11.2.3](https://github.com/3scale/s2i-openresty/releases/tag/1.11.2.3-1) [PR #359](https://github.com/3scale/apicast/pull/359)

## [3.0.0-rc1] - 2017-04-04

Expand Down
9 changes: 6 additions & 3 deletions apicast/src/resty/http_ng.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local unpack = unpack
local assert = assert
local tostring = tostring
local setmetatable = setmetatable
local getmetatable = getmetatable
local rawset = rawset
local upper = string.upper
local rawget = rawget
Expand All @@ -24,6 +25,7 @@ local resty_backend = require 'resty.http_ng.backend.resty'
local json = require 'cjson'
local request = require 'resty.http_ng.request'
local resty_url = require 'resty.url'
local http_headers = require 'resty.http_ng.headers'

local DEFAULT_PATH = ''

Expand All @@ -40,7 +42,7 @@ local function merge(...)
local t = all[i]

if type(t) == 'table' then
res = res or {}
res = res or setmetatable({}, getmetatable(t))
for k,v in pairs(t) do
res[k] = merge(res[k], v)
end
Expand All @@ -57,10 +59,11 @@ local function get_request_params(method, client, url, options)
local scheme, user, pass, host, port, path = unpack(assert(resty_url.split(url)))
if port then host = concat({host, port}, ':') end

opts.headers = { ['Host'] = host }
opts.headers = http_headers.new()
opts.headers.host = host

if user or pass then
opts.headers.Authorization = "Basic " .. ngx.encode_base64(concat({ user or '', pass or '' }, ':'))
opts.headers.authorization = "Basic " .. ngx.encode_base64(concat({ user or '', pass or '' }, ':'))
end

return {
Expand Down
1 change: 0 additions & 1 deletion rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = '0.0-0'
dependencies = {
'luacheck == 0.18.0',
'busted >= 0',
'lua-cjson >= 0',
'ldoc >= 0',
'lua-resty-repl >= 0',
}
Expand Down
14 changes: 10 additions & 4 deletions spec/backend_client_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe('backend client', function()
backend_authentication_type = 'auth', backend_authentication_value = 'val'
})
test_backend.expect{
url = 'http://example.com/transactions/authrep.xml?service_id=42&auth=val',
url = 'http://example.com/transactions/authrep.xml?' ..
ngx.encode_args({ auth = service.backend_authentication.value, service_id = service.id }),
headers = { host = 'example.com' }
}.respond_with{ status = 200 }
local backend_client = assert(_M:new(service, test_backend))
Expand All @@ -37,7 +38,9 @@ describe('backend client', function()
backend_authentication_type = 'auth', backend_authentication_value = 'val'
})
test_backend.expect{
url = 'http://example.com/transactions/authrep.xml?service_id=42&auth=val&usage%5Bhits%5D=1&user_key=foobar'
url = 'http://example.com/transactions/authrep.xml?' ..
ngx.encode_args({ auth = service.backend_authentication.value, service_id = service.id }) ..
'&usage%5Bhits%5D=1&user_key=foobar'
}.respond_with{ status = 200 }
local backend_client = assert(_M:new(service, test_backend))

Expand Down Expand Up @@ -92,7 +95,8 @@ describe('backend client', function()
backend_authentication_type = 'auth', backend_authentication_value = 'val'
})
test_backend.expect{
url = 'http://example.com/transactions/authorize.xml?service_id=42&auth=val',
url = 'http://example.com/transactions/authorize.xml?' ..
ngx.encode_args({ auth = service.backend_authentication.value, service_id = service.id }),
headers = { host = 'example.com' }
}.respond_with{ status = 200 }
local backend_client = assert(_M:new(service, test_backend))
Expand All @@ -111,7 +115,9 @@ describe('backend client', function()
backend_authentication_type = 'auth', backend_authentication_value = 'val'
})
test_backend.expect{
url = 'http://example.com/transactions/authorize.xml?service_id=42&auth=val&usage%5Bhits%5D=1&user_key=foobar'
url = 'http://example.com/transactions/authorize.xml?' ..
ngx.encode_args({ auth = service.backend_authentication.value, service_id = service.id }) ..
'&usage%5Bhits%5D=1&user_key=foobar'
}.respond_with{ status = 200 }
local backend_client = assert(_M:new(service, test_backend))

Expand Down
20 changes: 10 additions & 10 deletions t/001-management.t
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ include $TEST_NGINX_MANAGEMENT_CONFIG;
--- request
GET /status/ready
--- response_body
{"status":"error","error":"not configured","success":false}
{"success":false,"status":"error","error":"not configured"}
--- error_code: 412
--- no_error_log
[error]
Expand All @@ -66,7 +66,7 @@ env APICAST_MANAGEMENT_API=status;
--- request
GET /status/ready
--- response_body
{"status":"warning","warning":"no services","success":true}
{"success":true,"status":"warning","warning":"no services"}
--- error_code: 200
--- no_error_log
[error]
Expand Down Expand Up @@ -130,7 +130,7 @@ GET /test
--- response_body
{"status":"ok","config":null}
null
{"status":"ok","services":1,"config":{"services":[{"id":42}]}}
{"services":1,"status":"ok","config":{"services":[{"id":42}]}}
{"services":[{"id":42}]}
--- error_code: 200
--- no_error_log
Expand Down Expand Up @@ -221,7 +221,7 @@ env APICAST_MANAGEMENT_API=debug;
--- request
GET /test
--- response_body
{"status":"ok","services":1,"config":{"services":[{"id":42}]}}
{"services":1,"status":"ok","config":{"services":[{"id":42}]}}
{"status":"ok","config":null}
null
--- error_code: 200
Expand All @@ -247,8 +247,8 @@ env APICAST_MANAGEMENT_API=debug;
'Content-Type: application/json; charset=utf-8' ]
--- response_body eval
[ '{"status":"ok","config":null}'."\n",
'{"status":"ok","services":1,"config":{"services":[{"id":42}]}}'."\n",
'{"status":"ok","services":1,"config":{"services":[{"id":42}]}}'."\n",
'{"services":1,"status":"ok","config":{"services":[{"id":42}]}}'."\n",
'{"services":1,"status":"ok","config":{"services":[{"id":42}]}}'."\n",
'{"services":[{"id":42}]}'."\n" ]
--- no_error_log
[error]
Expand Down Expand Up @@ -278,7 +278,7 @@ GET /dns/cache
--- response_headers
Content-Type: application/json; charset=utf-8
--- response_body
{"127.0.0.1.xip.io":{"expires_in":199,"value":{"1":{"address":"127.0.0.1","section":1,"type":1,"class":1,"name":"127.0.0.1.xip.io","ttl":199},"name":"127.0.0.1.xip.io","ttl":199}}}
{"127.0.0.1.xip.io":{"value":{"1":{"address":"127.0.0.1","class":1,"ttl":199,"name":"127.0.0.1.xip.io","section":1,"type":1},"ttl":199,"name":"127.0.0.1.xip.io"},"expires_in":199}}
--- no_error_log
[error]
Expand Down Expand Up @@ -327,13 +327,13 @@ include $TEST_NGINX_MANAGEMENT_CONFIG;
POST /config
invalid json
--- response_body
{"status":"error","error":"Expected value but found invalid token at character 1","config":null}
{"config":null,"status":"error","error":"Expected value but found invalid token at character 1"}
--- error_code: 400
--- no_error_log
[error]
=== TEST 15: writing wrong configuration
=== TEST 16: writing wrong configuration
JSON is valid but it not a configuration.
--- main_config
env APICAST_MANAGEMENT_API=debug;
Expand All @@ -345,7 +345,7 @@ include $TEST_NGINX_MANAGEMENT_CONFIG;
POST /config
{"id":42}
--- response_body
{"status":"not_configured","services":0,"config":{"id":42}}
{"services":0,"config":{"id":42},"status":"not_configured"}
--- error_code: 406
--- no_error_log
[error]
12 changes: 7 additions & 5 deletions t/005-apicast-oauth.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ called oauth_authorize.xml

location = /backend/transactions/oauth_authorize.xml {
content_by_lua_block {
expected = "provider_key=fookey&service_id=42&redirect_uri=otheruri&app_id=id"
local expected = "provider_key=fookey&service_id=42&app_id=id&redirect_uri=otheruri"
if ngx.var.args == expected and ngx.var.host == ngx.var.backend_host then
ngx.exit(200)
else
ngx.log(ngx.ERR, expected, ' does not match ', ngx.var.args)
ngx.exit(403)
end
}
Expand All @@ -90,7 +91,7 @@ called oauth_authorize.xml
GET /authorize?client_id=id&redirect_uri=otheruri&response_type=code&scope=whatever&state=123456
--- error_code: 302
--- response_headers_like
Location: http://example.com/redirect\?scope=whatever&response_type=code&state=[a-z0-9]{40}&tok=\w+&redirect_uri=otheruri&client_id=id
Location: http://example.com/redirect\?response_type=code&client_id=id&state=[a-z0-9]{40}&scope=whatever&tok=\w+&redirect_uri=otheruri
--- no_error_log
[error]

Expand Down Expand Up @@ -119,9 +120,10 @@ Location: http://example.com/redirect\?scope=whatever&response_type=code&state=[

location = /backend/transactions/oauth_authorize.xml {
content_by_lua_block {
if ngx.var.args == "provider_key=fookey&service_id=42&redirect_uri=otheruri&app_id=id" and ngx.var.host == ngx.var.backend_host then
if ngx.var.args == "provider_key=fookey&service_id=42&app_id=id&redirect_uri=otheruri" and ngx.var.host == ngx.var.backend_host then
ngx.exit(200)
else
ngx.log(ngx.ERR, expected, ' does not match ', ngx.var.args)
ngx.exit(403)
end
}
Expand All @@ -130,7 +132,7 @@ Location: http://example.com/redirect\?scope=whatever&response_type=code&state=[
GET /authorize?client_id=id&redirect_uri=otheruri&response_type=token&scope=whatever
--- error_code: 302
--- response_headers_like
Location: http://example.com/redirect\?scope=whatever&response_type=token&error=unsupported_response_type&redirect_uri=otheruri&client_id=id
Location: http://example.com/redirect\?response_type=token&client_id=id&scope=whatever&redirect_uri=otheruri&error=unsupported_response_type
--- no_error_log
[error]

Expand Down Expand Up @@ -346,7 +348,7 @@ Location: http://example.com/redirect\?code=\w+&state=clientstate
location = /backend/transactions/oauth_authorize.xml {
content_by_lua_block {
expected = "provider_key=fookey&service_id=42&app_key=client_secret&redirect_uri=redirect_uri&app_id=client_id"
expected = "provider_key=fookey&service_id=42&app_key=client_secret&app_id=client_id&redirect_uri=redirect_uri"
if ngx.var.args == expected and ngx.var.host == ngx.var.backend_host then
ngx.exit(200)
else
Expand Down
2 changes: 1 addition & 1 deletion t/007-apicast-upstream-balancer.t
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $::dns->("localhost", "127.0.0.1")
--- request
GET /t
--- response_body
[{"address":"127.0.0.1","ttl":0}]
[{"ttl":0,"address":"127.0.0.1"}]
--- error_code: 200
Expand Down
2 changes: 1 addition & 1 deletion travis/install-s2i.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sha=$(echo "${S2I_VERSION}" | cut -f2 -d-)
if [ ! -f "${PREFIX}/s2i" ]; then
cd /tmp/
mkdir -p "${PREFIX}"
wget -T 60 -c "https://github.com/openshift/source-to-image/releases/download/v${version}/source-to-image-${version}-${sha}-${os}-${arch}.tar.gz" -O source-to-image.tar.gz
wget -T 60 -c "https://github.com/openshift/source-to-image/releases/download/v${version}/source-to-image-v${version}-${sha}-${os}-${arch}.tar.gz" -O source-to-image.tar.gz
tar -xzf source-to-image.tar.gz -C "${PREFIX}/"
rm -rf source-to-image.tar.gz
else
Expand Down

0 comments on commit 120b96f

Please sign in to comment.