Skip to content

Commit

Permalink
policy_pusher: send access token correctly
Browse files Browse the repository at this point in the history
Notice that there was a 'token:url' in the code and the tests instead of
'token@url'. While at it, I've changed this to send it via params
because that makes the tests a bit easier (do not need to convert things
to base64) and it's closer to what the system UI shows because
'access_token' appears as a param there.
  • Loading branch information
davidor committed Mar 11, 2019
1 parent 3fa1f9e commit a860367
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions gateway/src/apicast/policy_pusher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ end

local system_endpoint = '/admin/api/registry/policies'

local function system_url(access_token, admin_portal_domain)
return format('https://%s:%s%s', access_token, admin_portal_domain, system_endpoint)
local function system_url(admin_portal_domain)
return format('https://%s%s', admin_portal_domain, system_endpoint)
end

local function push_to_system(name, version, manifest, admin_portal_domain, access_token, http_client)
local url = system_url(access_token, admin_portal_domain)
local url = system_url(admin_portal_domain)

return http_client.json.post(
url, { name = name, version = version, schema = manifest }
url,
{ access_token = access_token, name = name, version = version, schema = manifest }
)
end

Expand Down
6 changes: 4 additions & 2 deletions spec/policy_pusher_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ describe('Policy pusher', function()
describe('if the policy exists', function()
it('pushes the policy to the 3scale admin portal', function()
local request_body = {
access_token = access_token,
name = policy_name,
version = policy_version,
schema = policy_manifest
}

test_backend.expect{
url = 'https://' .. access_token .. ':' .. admin_portal_domain ..
url = 'https://' .. admin_portal_domain ..
'/admin/api/registry/policies',
body = cjson.encode(request_body)
}.respond_with{ status = 200 }
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('Policy pusher', function()
stub(ngx, 'log')

local request_body = {
access_token = access_token,
name = policy_name,
version = policy_version,
schema = policy_manifest
Expand All @@ -74,7 +76,7 @@ describe('Policy pusher', function()
local error_msg_returned = 'Some error'

test_backend.expect{
url = 'https://' .. access_token .. ':' .. admin_portal_domain ..
url = 'https://' .. admin_portal_domain ..
'/admin/api/registry/policies',
body = cjson.encode(request_body)
}.respond_with{ status = 400, body = error_msg_returned }
Expand Down

0 comments on commit a860367

Please sign in to comment.