Skip to content
This repository has been archived by the owner on Sep 27, 2018. It is now read-only.

Commit

Permalink
Merge pull request #11 from 3scale/app_key_in_report_keys
Browse files Browse the repository at this point in the history
Include the app_key in report keys
  • Loading branch information
unleashed committed Mar 6, 2017
2 parents e613e48 + bcc06cc commit 67886f0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
20 changes: 20 additions & 0 deletions spec/storage_key_spec.lua
Expand Up @@ -117,6 +117,26 @@ describe('storage_keys', function()
assert.are.same(expected, actual)
end)
end)

it('includes all the credentials needed to identify a report', function()
-- These are all the credentials that we can find in a report key.
local all_report_creds = { ['access_token'] = 'an_access_token',
['app_id'] = 'an_app_id',
['app_key'] = 'an_app_key',
['user_id'] = 'a_user_id',
['user_key'] = 'a_user_key' }

local encoded_creds = {}
for key, value in pairs(all_report_creds) do
table.insert(encoded_creds, key .. ':' .. value)
end
table.sort(encoded_creds) -- Credentials appear sorted in the key
encoded_creds = table.concat(encoded_creds, ',')

local expected = 'report,' .. 'service_id:' .. service_id .. ',' .. encoded_creds
local actual = storage_keys.get_report_key(service_id, all_report_creds)
assert.are.same(expected, actual)
end)
end)

describe('get_pubsub_req_msg', function()
Expand Down
8 changes: 6 additions & 2 deletions xc/storage_keys.lua
Expand Up @@ -10,7 +10,11 @@ local _M = { AUTH_REQUESTS_CHANNEL = 'xc_channel_auth_requests',

local AUTH_RESPONSES_CHANNEL_PREFIX = 'xc_channel_auth_response:'

local REPORT_CREDS_IN_KEY = { 'app_id', 'user_key', 'access_token', 'user_id' }
local REPORT_CREDS_IN_KEY = { 'app_id',
'user_key',
'access_token',
'user_id',
'app_key' }

-- Escapes ':' and ','.
local function escape(string)
Expand Down Expand Up @@ -84,7 +88,7 @@ end
-- keys. However, for reporting, we do not care about the referrer, because
-- the app is still the same. That's why the referrer is not included in
-- 'report' keys. The credentials that can be used for reporting are: 'app_id',
-- 'user_key', 'access_token', 'user_id'.
-- 'user_key', 'access_token', 'user_id', 'app_key'.
--
-- Params:
-- service_id: String. Service ID.
Expand Down

0 comments on commit 67886f0

Please sign in to comment.