Skip to content

Commit

Permalink
version 3.6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
frwiqueueit committed Apr 7, 2021
1 parent b90a840 commit 1176d21
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 158 deletions.
29 changes: 21 additions & 8 deletions Handlers/KnownUserApacheHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,26 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques

iHelpers.hash.hmac_sha256_encode = function(message, key)
local sha2 = require("sha2")
return sha2.hmac(sha2.sha256, key, message)
return sha2.hmac(sha2.sha256, key, message)
end

iHelpers.request.getHeader = function(name)
return request_rec.headers_in[name]
end

iHelpers.request.getBody = function()
local reqBody = ""
-- Out of memory error will be raised,
-- when trying to read an empty request body.
-- Therefore wrap this in a pcall to ignore that scenario.
pcall(
function()
reqBody = request_rec:requestbody()
end
)
return reqBody
end

iHelpers.request.getUnescapedCookieValue = function(name)
-- Alternative to request_rec:getcookie method,
-- which fails if client sends a Cookie header with multiple entries with same name/key.
Expand Down Expand Up @@ -129,15 +142,15 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
if (isIntegrationConfig) then
validationResult = knownUser.validateRequestByIntegrationConfig(currentUrlWithoutQueueitToken, queueitToken, config, customerId, secretKey)
else
validationResult = knownUser.resolveQueueRequestByLocalConfig(currentUrlWithoutQueueitToken, queueitToken, config, customerId, secretKey)
validationResult = knownUser.resolveQueueRequestByLocalConfig(currentUrlWithoutQueueitToken, queueitToken, config, customerId, secretKey)
end

if (validationResult:doRedirect()) then
--Adding no cache headers to prevent browsers to cache requests
request_rec.err_headers_out["Cache-Control"] = "no-cache, no-store, must-revalidate, max-age=0"
request_rec.err_headers_out["Pragma"] = "no-cache"
request_rec.err_headers_out["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
--end
-- Adding no cache headers to prevent browsers to cache requests
request_rec.err_headers_out["Cache-Control"] = "no-cache, no-store, must-revalidate, max-age=0"
request_rec.err_headers_out["Pragma"] = "no-cache"
request_rec.err_headers_out["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
-- end

if (validationResult.isAjaxResult) then
request_rec.err_headers_out[validationResult.getAjaxQueueRedirectHeaderKey()] = validationResult:getAjaxRedirectUrl()
Expand All @@ -157,7 +170,7 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
end

aHandler.handleByIntegrationConfig = function(customerId, secretKey, integrationConfigJson, request_rec)
return handle(customerId, secretKey, integrationConfigJson, true, request_rec)
return handle(customerId, secretKey, integrationConfigJson, true, request_rec)
end

aHandler.handleByLocalConfig = function(customerId, secretKey, queueEventConfig, request_rec)
Expand Down
3 changes: 3 additions & 0 deletions SDK/IntegrationEvaluator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ local model = {
if (_triggerPart["ValidatorType"] == "HttpHeaderValidator") then
return validatorHelpers.HttpHeaderValidatorHelper.evaluate(_triggerPart, _request)
end
if (_triggerPart["ValidatorType"] == "RequestBodyValidator") then
return validatorHelpers.RequestBodyValidatorHelper.evaluate(_triggerPart, _request)
end

return false
end
Expand Down
52 changes: 26 additions & 26 deletions SDK/KnownUser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ end

local function logMoreRequestDetails(debugEntries)
debugEntries["ServerUtcTime"] = os.date("!%Y-%m-%dT%H:%M:%SZ")
debugEntries["RequestIP"] = iHelpers.request.getUserHostAddress()
debugEntries["RequestHttpHeader_Via"] = utils.toString(iHelpers.request.getHeader('via'))
debugEntries["RequestHttpHeader_Forwarded"] = utils.toString(iHelpers.request.getHeader('forwarded'))
debugEntries["RequestHttpHeader_XForwardedFor"] = utils.toString(iHelpers.request.getHeader('x-forwarded-for'))
debugEntries["RequestHttpHeader_XForwardedHost"] = utils.toString(iHelpers.request.getHeader('x-forwarded-host'))
debugEntries["RequestHttpHeader_XForwardedProto"] = utils.toString(iHelpers.request.getHeader('x-forwarded-proto'))
debugEntries["RequestIP"] = iHelpers.request.getUserHostAddress()
debugEntries["RequestHttpHeader_Via"] = utils.toString(iHelpers.request.getHeader('via'))
debugEntries["RequestHttpHeader_Forwarded"] = utils.toString(iHelpers.request.getHeader('forwarded'))
debugEntries["RequestHttpHeader_XForwardedFor"] = utils.toString(iHelpers.request.getHeader('x-forwarded-for'))
debugEntries["RequestHttpHeader_XForwardedHost"] = utils.toString(iHelpers.request.getHeader('x-forwarded-host'))
debugEntries["RequestHttpHeader_XForwardedProto"] = utils.toString(iHelpers.request.getHeader('x-forwarded-proto'))
end

local function setDebugCookie(debugEntries)
Expand All @@ -45,7 +45,7 @@ local function generateTargetUrl(originalTargetUrl)
local headerValue = iHelpers.request.getHeader(QUEUEIT_AJAX_HEADER_KEY)
return utils.urlDecode(headerValue)
else
return originalTargetUrl
return originalTargetUrl
end
end

Expand Down Expand Up @@ -95,7 +95,7 @@ local function cancelRequestByLocalConfig(
targetUrl = generateTargetUrl(targetUrl)

if (isDebug) then
local cancelConfigValue = "NULL"
local cancelConfigValue = "NULL"
if (cancelConfig ~= nil) then
cancelConfigValue = cancelConfig:getString()
end
Expand All @@ -109,7 +109,7 @@ local function cancelRequestByLocalConfig(
debugEntries["CancelConfig"] = cancelConfigValue

logMoreRequestDetails(debugEntries)
end
end

assert(utils.toString(targetUrl) ~= "", "targetUrl can not be nil or empty.")
assert(utils.toString(customerId) ~= "", "customerId can not be nil or empty.")
Expand All @@ -118,9 +118,9 @@ local function cancelRequestByLocalConfig(
assert(utils.toString(cancelConfig.eventId) ~= "", "eventId from cancelConfig can not be nil or empty.")
assert(utils.toString(cancelConfig.queueDomain) ~= "", "queueDomain from cancelConfig can not be nil or empty.")

local result = userInQueueService.validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
result.isAjaxResult = isQueueAjaxCall()
return result
local result = userInQueueService.validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
result.isAjaxResult = isQueueAjaxCall()
return result
end
-- END Private functions

Expand Down Expand Up @@ -163,20 +163,20 @@ end

ku.validateRequestByIntegrationConfig = function(
currentUrlWithoutQueueITToken, queueitToken, integrationConfigJson, customerId, secretKey)
-- Private functions
-- Private functions
local function handleQueueAction(
_currentUrlWithoutQueueITToken, _queueitToken, _customerIntegration,
_customerId, _secretKey, _matchedConfig, _debugEntries, _isDebug)

local eventConfig = models.QueueEventConfig.create()
local targetUrl
eventConfig.eventId = _matchedConfig["EventId"]
eventConfig.queueDomain = _matchedConfig["QueueDomain"]
eventConfig.layoutName = _matchedConfig["LayoutName"]
local targetUrl
eventConfig.eventId = _matchedConfig["EventId"]
eventConfig.queueDomain = _matchedConfig["QueueDomain"]
eventConfig.layoutName = _matchedConfig["LayoutName"]
eventConfig.culture = _matchedConfig["Culture"]
eventConfig.cookieDomain = _matchedConfig["CookieDomain"]
eventConfig.extendCookieValidity = _matchedConfig["ExtendCookieValidity"]
eventConfig.cookieValidityMinute = _matchedConfig["CookieValidityMinute"]
eventConfig.cookieDomain = _matchedConfig["CookieDomain"]
eventConfig.extendCookieValidity = _matchedConfig["ExtendCookieValidity"]
eventConfig.cookieValidityMinute = _matchedConfig["CookieValidityMinute"]
eventConfig.version = _customerIntegration["Version"]
eventConfig.actionName = _matchedConfig["Name"]

Expand All @@ -187,11 +187,11 @@ ku.validateRequestByIntegrationConfig = function(
if (_matchedConfig["RedirectLogic"] == "EventTargetUrl") then
targetUrl = ""
else
targetUrl = generateTargetUrl(_currentUrlWithoutQueueITToken)
targetUrl = generateTargetUrl(_currentUrlWithoutQueueITToken)
end
end

return resolveQueueRequestByLocalConfig(
return resolveQueueRequestByLocalConfig(
targetUrl, _queueitToken, eventConfig, _customerId, _secretKey, _debugEntries, _isDebug)
end

Expand All @@ -200,15 +200,15 @@ ku.validateRequestByIntegrationConfig = function(
_customerId, _secretKey, _matchedConfig, _debugEntries, _isDebug)

local cancelEventConfig = models.CancelEventConfig.create()
cancelEventConfig.eventId = _matchedConfig["EventId"]
cancelEventConfig.queueDomain = _matchedConfig["QueueDomain"]
cancelEventConfig.cookieDomain = _matchedConfig["CookieDomain"]
cancelEventConfig.eventId = _matchedConfig["EventId"]
cancelEventConfig.queueDomain = _matchedConfig["QueueDomain"]
cancelEventConfig.cookieDomain = _matchedConfig["CookieDomain"]
cancelEventConfig.version = _customerIntegration["Version"]
cancelEventConfig.actionName = _matchedConfig["Name"]

return cancelRequestByLocalConfig(
_currentUrlWithoutQueueITToken, _queueitToken, cancelEventConfig, _customerId, _secretKey, _debugEntries, _isDebug)
end
end
-- END Private functions

local debugEntries = {}
Expand Down
4 changes: 4 additions & 0 deletions SDK/KnownUserImplementationHelpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ local iHelpers =
getHeader = function(_)
error("Not implemented : request.getHeader(name)")
end,
-- returns: string | nil
getBody = function(_)
error("Not implemented : request.getBody()")
end,
-- arguments: name -> name of cookie
-- returns: the unescaped (url decoded) value ( string | nil ) in the cookie found by name
getUnescapedCookieValue = function(_)
Expand Down
53 changes: 53 additions & 0 deletions SDK/Tests/IntegrationEvaluatorTest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,59 @@ local function IntegrationEvaluatorTest()
end
test_getMatchedIntegrationConfig_OneTrigger_And_NotMatched_HttpHeader()

local function test_getMatchedIntegrationConfig_OneTrigger_And_Matched_RequestBody()
iHelpers.request.getBody = function()
return "test body test request"
end

local integrationConfig =
{
Integrations =
{
{
Name = "integration1",
Triggers =
{
{
LogicalOperator = "And",
TriggerParts =
{
{
CookieName = "c1",
Operator = "Equals",
ValueToCompare = "value1",
ValidatorType = "CookieValidator",
IsIgnoreCase = true,
IsNegative = false
},
{
UrlPart = "PageUrl",
ValidatorType = "UrlValidator",
ValueToCompare = "test",
Operator = "Contains",
IsIgnoreCase = false,
IsNegative = false
},
{
ValidatorType = "RequestBodyValidator",
ValueToCompare = "test body",
Operator = "Contains",
IsIgnoreCase = true,
IsNegative = false
}
}
}
}
}
}
}

local url = "http://test.tesdomain.com:8080/test?q=2"
assert(integrationEvaluator.getMatchedIntegrationConfig(
integrationConfig, url, iHelpers.request).Name == "integration1")
end
test_getMatchedIntegrationConfig_OneTrigger_And_Matched_RequestBody()

local function test_getMatchedIntegrationConfig_OneTrigger_Or_NotMatched()
iHelpers.request.getUnescapedCookieValue = function(_) return nil end

Expand Down
25 changes: 24 additions & 1 deletion SDK/Tests/ValidationHelpersTest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,27 @@ local function HttpHeaderValidatorHelperTest_evaluate()
end
assert( validatorHelpers.HttpHeaderValidatorHelper.evaluate(triggerPart, iHelpers.request) == false)
end
HttpHeaderValidatorHelperTest_evaluate()
HttpHeaderValidatorHelperTest_evaluate()

local function RequestBodyValidatorHelperTest_evaluate()
local triggerPart = {}
triggerPart["Operator"] = "Contains"
triggerPart["IsIgnoreCase"] = true
triggerPart["IsNegative"] = false
triggerPart["ValueToCompare"] = "t1"
iHelpers.request.getBody = function()
return "post with t1"
end
assert( validatorHelpers.RequestBodyValidatorHelper.evaluate(triggerPart, iHelpers.request) )

triggerPart = {}
triggerPart["Operator"] = "Contains"
triggerPart["IsIgnoreCase"] = true
triggerPart["IsNegative"] = false
triggerPart["ValueToCompare"] = "t2"
iHelpers.request.getBody = function()
return "post with t1"
end
assert( validatorHelpers.RequestBodyValidatorHelper.evaluate(triggerPart, iHelpers.request) == false)
end
RequestBodyValidatorHelperTest_evaluate()
Loading

0 comments on commit 1176d21

Please sign in to comment.