From 1176d210827bbc0bb993cf4d61a7215d1374c89e Mon Sep 17 00:00:00 2001 From: Frederik Williams Date: Wed, 7 Apr 2021 08:59:41 +0200 Subject: [PATCH] version 3.6.5 --- Handlers/KnownUserApacheHandler.lua | 29 +++- SDK/IntegrationEvaluator.lua | 3 + SDK/KnownUser.lua | 52 +++--- SDK/KnownUserImplementationHelpers.lua | 4 + SDK/Tests/IntegrationEvaluatorTest.lua | 53 ++++++ SDK/Tests/ValidationHelpersTest.lua | 25 ++- SDK/UserInQueueService.lua | 208 +++++++++++------------ SDK/UserInQueueStateCookieRepository.lua | 36 ++-- SDK/Utils.lua | 2 +- SDK/ValidatorHelpers.lua | 20 +++ 10 files changed, 274 insertions(+), 158 deletions(-) diff --git a/Handlers/KnownUserApacheHandler.lua b/Handlers/KnownUserApacheHandler.lua index c205970..0f48a42 100644 --- a/Handlers/KnownUserApacheHandler.lua +++ b/Handlers/KnownUserApacheHandler.lua @@ -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. @@ -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() @@ -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) diff --git a/SDK/IntegrationEvaluator.lua b/SDK/IntegrationEvaluator.lua index 3a59186..6368760 100644 --- a/SDK/IntegrationEvaluator.lua +++ b/SDK/IntegrationEvaluator.lua @@ -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 diff --git a/SDK/KnownUser.lua b/SDK/KnownUser.lua index 56551d0..4fcb55d 100644 --- a/SDK/KnownUser.lua +++ b/SDK/KnownUser.lua @@ -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) @@ -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 @@ -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 @@ -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.") @@ -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 @@ -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"] @@ -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 @@ -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 = {} diff --git a/SDK/KnownUserImplementationHelpers.lua b/SDK/KnownUserImplementationHelpers.lua index 822e571..89362ed 100644 --- a/SDK/KnownUserImplementationHelpers.lua +++ b/SDK/KnownUserImplementationHelpers.lua @@ -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(_) diff --git a/SDK/Tests/IntegrationEvaluatorTest.lua b/SDK/Tests/IntegrationEvaluatorTest.lua index 7527da0..06b16a0 100644 --- a/SDK/Tests/IntegrationEvaluatorTest.lua +++ b/SDK/Tests/IntegrationEvaluatorTest.lua @@ -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 diff --git a/SDK/Tests/ValidationHelpersTest.lua b/SDK/Tests/ValidationHelpersTest.lua index 4bd4911..91f2bed 100644 --- a/SDK/Tests/ValidationHelpersTest.lua +++ b/SDK/Tests/ValidationHelpersTest.lua @@ -327,4 +327,27 @@ local function HttpHeaderValidatorHelperTest_evaluate() end assert( validatorHelpers.HttpHeaderValidatorHelper.evaluate(triggerPart, iHelpers.request) == false) end -HttpHeaderValidatorHelperTest_evaluate() \ No newline at end of file +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() \ No newline at end of file diff --git a/SDK/UserInQueueService.lua b/SDK/UserInQueueService.lua index 7dcd6ff..0ed80e9 100644 --- a/SDK/UserInQueueService.lua +++ b/SDK/UserInQueueService.lua @@ -5,8 +5,8 @@ local utils = require("Utils") local userInQueueStateCookieRepository = require("UserInQueueStateCookieRepository") local svc = { - SDK_VERSION = "v3-lua-" .. "3.6.4", - TokenValidationResult = { + SDK_VERSION = "v3-lua-" .. "3.6.5", + TokenValidationResult = { create = function(isValid, errorCode) local model = { isValid = isValid; @@ -21,97 +21,97 @@ local svc = { -- Private functions local function getQueryString(customerId, eventId, configVersion, actionName, culture, layoutName) local queryStringList = { } - table.insert(queryStringList, "c=" .. utils.urlEncode(customerId)) - table.insert(queryStringList, "e=" .. utils.urlEncode(eventId)) - table.insert(queryStringList, "ver=" .. svc.SDK_VERSION) - table.insert(queryStringList, "kupver=" .. utils.urlEncode(iHelpers.system.getConnectorName())) + table.insert(queryStringList, "c=" .. utils.urlEncode(customerId)) + table.insert(queryStringList, "e=" .. utils.urlEncode(eventId)) + table.insert(queryStringList, "ver=" .. svc.SDK_VERSION) + table.insert(queryStringList, "kupver=" .. utils.urlEncode(iHelpers.system.getConnectorName())) if (configVersion == nil) then configVersion = "-1" end - table.insert(queryStringList, "cver=" .. configVersion) - table.insert(queryStringList, "man=" .. utils.urlEncode(actionName)) + table.insert(queryStringList, "cver=" .. configVersion) + table.insert(queryStringList, "man=" .. utils.urlEncode(actionName)) - if (utils.toString(culture) ~= "") then - table.insert(queryStringList, "cid=" .. utils.urlEncode(culture)) - end + if (utils.toString(culture) ~= "") then + table.insert(queryStringList, "cid=" .. utils.urlEncode(culture)) + end - if (utils.toString(layoutName) ~= "") then - table.insert(queryStringList, "l=" .. utils.urlEncode(layoutName)) - end + if (utils.toString(layoutName) ~= "") then + table.insert(queryStringList, "l=" .. utils.urlEncode(layoutName)) + end return table.concat(queryStringList, "&") end local function generateRedirectUrl(queueDomain, uriPath, query) - uriPath = uriPath or "" - if(not utils.endsWith(queueDomain, "/")) then - queueDomain = queueDomain .. "/" - end - return "https://" .. queueDomain .. uriPath .. "?" .. query + uriPath = uriPath or "" + if(not utils.endsWith(queueDomain, "/")) then + queueDomain = queueDomain .. "/" + end + return "https://" .. queueDomain .. uriPath .. "?" .. query end local function getQueueResult(targetUrl, config, customerId) - local tparam = "" + local tparam = "" if (utils.toString(targetUrl) ~= "") then tparam = "&t=" .. utils.urlEncode(targetUrl) end - local query = getQueryString(customerId, config.eventId, config.version, - config.actionName, config.culture, config.layoutName) .. tparam + local query = getQueryString(customerId, config.eventId, config.version, + config.actionName, config.culture, config.layoutName) .. tparam - local redirectUrl = generateRedirectUrl(config.queueDomain, "", query) + local redirectUrl = generateRedirectUrl(config.queueDomain, "", query) - return models.RequestValidationResult.create( - models.ActionTypes.QueueAction, config.eventId, nil, redirectUrl, nil, config.actionName) + return models.RequestValidationResult.create( + models.ActionTypes.QueueAction, config.eventId, nil, redirectUrl, nil, config.actionName) end local function getErrorResult(customerId, targetUrl, config, qParams, errorCode) - local tParam = "" + local tParam = "" if (utils.toString(targetUrl) ~= "") then tParam = "&t=" .. utils.urlEncode(targetUrl) end local query = getQueryString( - customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) - .. "&queueittoken=" .. qParams.queueITToken - .. "&ts=" .. os.time() - .. tParam + customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) + .. "&queueittoken=" .. qParams.queueITToken + .. "&ts=" .. os.time() + .. tParam - local redirectUrl = generateRedirectUrl(config.queueDomain, "error/" .. errorCode .. "/", query) + local redirectUrl = generateRedirectUrl(config.queueDomain, "error/" .. errorCode .. "/", query) - return models.RequestValidationResult.create( - models.ActionTypes.QueueAction, config.eventId, nil, redirectUrl, nil, config.actionName) + return models.RequestValidationResult.create( + models.ActionTypes.QueueAction, config.eventId, nil, redirectUrl, nil, config.actionName) end local function getValidTokenResult(config, queueParams, secretKey) userInQueueStateCookieRepository.store( - config.eventId, - queueParams.queueId, - queueParams.cookieValidityMinutes, - utils.toString(config.cookieDomain), - queueParams.redirectType, - secretKey) + config.eventId, + queueParams.queueId, + queueParams.cookieValidityMinutes, + utils.toString(config.cookieDomain), + queueParams.redirectType, + secretKey) return models.RequestValidationResult.create( - models.ActionTypes.QueueAction, config.eventId, queueParams.queueId, - nil, queueParams.redirectType, config.actionName) + models.ActionTypes.QueueAction, config.eventId, queueParams.queueId, + nil, queueParams.redirectType, config.actionName) end local function validateToken(config, queueParams, secretKey) - local calculatedHash = iHelpers.hash.hmac_sha256_encode(queueParams.queueITTokenWithoutHash, secretKey) - if (string.upper(calculatedHash) ~= string.upper(queueParams.hashCode)) then - return svc.TokenValidationResult.create(false, "hash") - end + local calculatedHash = iHelpers.hash.hmac_sha256_encode(queueParams.queueITTokenWithoutHash, secretKey) + if (string.upper(calculatedHash) ~= string.upper(queueParams.hashCode)) then + return svc.TokenValidationResult.create(false, "hash") + end - if (string.upper(queueParams.eventId) ~= string.upper(config.eventId)) then - return svc.TokenValidationResult.create(false, "eventid") - end + if (string.upper(queueParams.eventId) ~= string.upper(config.eventId)) then + return svc.TokenValidationResult.create(false, "eventid") + end if (queueParams.timeStamp < os.time()) then - return svc.TokenValidationResult.create(false, "timestamp") - end + return svc.TokenValidationResult.create(false, "timestamp") + end - return svc.TokenValidationResult.create(true, "") + return svc.TokenValidationResult.create(true, "") end -- END Private functions @@ -119,69 +119,69 @@ end svc.validateQueueRequest = function(targetUrl, queueitToken, config, customerId, secretKey) local state = userInQueueStateCookieRepository.getState(config.eventId, config.cookieValidityMinute, secretKey, true) - if (state.isValid) then - if (state:isStateExtendable() and config.extendCookieValidity) then - userInQueueStateCookieRepository.store( - config.eventId, - state.queueId, - nil, + if (state.isValid) then + if (state:isStateExtendable() and config.extendCookieValidity) then + userInQueueStateCookieRepository.store( + config.eventId, + state.queueId, + nil, utils.toString(config.cookieDomain), - state.redirectType, - secretKey) - end + state.redirectType, + secretKey) + end local result = models.RequestValidationResult.create( - models.ActionTypes.QueueAction, config.eventId, state.queueId, nil, state.redirectType, config.actionName) - return result - end - - local queueParams = qitHelpers.QueueUrlParams.extractQueueParams(queueitToken) - - local requestValidationResult - local isTokenValid = false - - if (queueParams ~= nil) then - local tokenValidationResult = validateToken(config, queueParams, secretKey) - isTokenValid = tokenValidationResult.isValid - - if(isTokenValid) then - requestValidationResult = getValidTokenResult(config, queueParams, secretKey) - else - requestValidationResult = getErrorResult( - customerId, targetUrl, config, queueParams, tokenValidationResult.errorCode); - end - else - requestValidationResult = getQueueResult(targetUrl, config, customerId); - end - - if (state.isFound and not isTokenValid) then - userInQueueStateCookieRepository.cancelQueueCookie(config.eventId, config.cookieDomain); - end - - return requestValidationResult; + models.ActionTypes.QueueAction, config.eventId, state.queueId, nil, state.redirectType, config.actionName) + return result + end + + local queueParams = qitHelpers.QueueUrlParams.extractQueueParams(queueitToken) + + local requestValidationResult + local isTokenValid = false + + if (queueParams ~= nil) then + local tokenValidationResult = validateToken(config, queueParams, secretKey) + isTokenValid = tokenValidationResult.isValid + + if(isTokenValid) then + requestValidationResult = getValidTokenResult(config, queueParams, secretKey) + else + requestValidationResult = getErrorResult( + customerId, targetUrl, config, queueParams, tokenValidationResult.errorCode); + end + else + requestValidationResult = getQueueResult(targetUrl, config, customerId); + end + + if (state.isFound and not isTokenValid) then + userInQueueStateCookieRepository.cancelQueueCookie(config.eventId, config.cookieDomain); + end + + return requestValidationResult; end svc.validateCancelRequest = function(targetUrl, cancelConfig, customerId, secretKey) - --we do not care how long cookie is valid while canceling cookie + -- we do not care how long cookie is valid while canceling cookie local state = userInQueueStateCookieRepository.getState(cancelConfig.eventId, -1, secretKey, false) - if (state.isValid) then - local uriPath = "cancel/" .. customerId .. "/" .. cancelConfig.eventId .. "/" - userInQueueStateCookieRepository.cancelQueueCookie(cancelConfig.eventId, cancelConfig.cookieDomain) + if (state.isValid) then + local uriPath = "cancel/" .. customerId .. "/" .. cancelConfig.eventId .. "/" + userInQueueStateCookieRepository.cancelQueueCookie(cancelConfig.eventId, cancelConfig.cookieDomain) - local rParam = "" + local rParam = "" if (utils.toString(targetUrl) ~= "") then rParam = "&r=" .. utils.urlEncode(targetUrl) end - local query = getQueryString( - customerId, cancelConfig.eventId, cancelConfig.version, cancelConfig.actionName, nil, nil) .. rParam - local redirectUrl = generateRedirectUrl(cancelConfig.queueDomain, uriPath, query) - - return models.RequestValidationResult.create( - models.ActionTypes.CancelAction, cancelConfig.eventId, - state.queueId, redirectUrl, state.redirectType, cancelConfig.actionName) - else - return models.RequestValidationResult.create( - models.ActionTypes.CancelAction, cancelConfig.eventId, nil, nil, nil, cancelConfig.actionName) - end + local query = getQueryString( + customerId, cancelConfig.eventId, cancelConfig.version, cancelConfig.actionName, nil, nil) .. rParam + local redirectUrl = generateRedirectUrl(cancelConfig.queueDomain, uriPath, query) + + return models.RequestValidationResult.create( + models.ActionTypes.CancelAction, cancelConfig.eventId, + state.queueId, redirectUrl, state.redirectType, cancelConfig.actionName) + else + return models.RequestValidationResult.create( + models.ActionTypes.CancelAction, cancelConfig.eventId, nil, nil, nil, cancelConfig.actionName) + end end svc.extendQueueCookie = function(eventId, cookieValidityMinutes, cookieDomain, secretKey) diff --git a/SDK/UserInQueueStateCookieRepository.lua b/SDK/UserInQueueStateCookieRepository.lua index f6a9c7a..4dcbe91 100644 --- a/SDK/UserInQueueStateCookieRepository.lua +++ b/SDK/UserInQueueStateCookieRepository.lua @@ -19,13 +19,13 @@ local function createCookieValue(eventId, queueId, fixedCookieValidityMinutes, r local cookieValue = "EventId=" .. eventId .. "&QueueId=" .. queueId .. fixedCookieValidityMinutesPart .. "&RedirectType=" .. redirectType .. "&IssueTime=" .. issueTime .. "&Hash=" .. hashValue - return cookieValue + return cookieValue end local function getCookieNameValueMap(cookieValue) local result = { } - local cookieNameValues = utils.explode("&", cookieValue) + local cookieNameValues = utils.explode("&", cookieValue) for _, cookieNameValue in pairs(cookieNameValues) do local arr = utils.explode("=", cookieNameValue) @@ -57,7 +57,7 @@ local function isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValid local fixedCookieValidityMinutes = "" if (cookieNameValueMap["FixedValidityMins"] ~= nil) then fixedCookieValidityMinutes = cookieNameValueMap["FixedValidityMins"] - end + end local hashValue = generateHash( cookieNameValueMap["EventId"], @@ -67,11 +67,11 @@ local function isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValid cookieNameValueMap["IssueTime"], secretKey) - if (hashValue ~= cookieNameValueMap["Hash"]) then + if (hashValue ~= cookieNameValueMap["Hash"]) then return false - end + end - if (string.lower(eventId) ~= string.lower(cookieNameValueMap["EventId"])) then + if (string.lower(eventId) ~= string.lower(cookieNameValueMap["EventId"])) then return false end @@ -85,9 +85,9 @@ local function isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValid if (expirationTime < os.time()) then return false end - end + end - return true + return true end -- END Private functions @@ -114,7 +114,7 @@ repo.getCookieKey = function(eventId) end repo.cancelQueueCookie = function(eventId, cookieDomain) - local cookieKey = repo.getCookieKey(eventId) + local cookieKey = repo.getCookieKey(eventId) iHelpers.response.setCookie(cookieKey, "deleted", 1, cookieDomain) end @@ -152,21 +152,21 @@ repo.getState = function(eventId, cookieValidityMinutes, secretKey, validateTime end repo.reissueQueueCookie = function(eventId, cookieValidityMinutes, cookieDomain, secretKey) - local cookieKey = repo.getCookieKey(eventId) - if (iHelpers.request.getUnescapedCookieValue(cookieKey) == nil) then + local cookieKey = repo.getCookieKey(eventId) + if (iHelpers.request.getUnescapedCookieValue(cookieKey) == nil) then return - end + end local cookieNameValueMap = getCookieNameValueMap(iHelpers.request.getUnescapedCookieValue(cookieKey)) if (isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValidityMinutes, true) == false) then - return - end + return + end local fixedCookieValidityMinutes = "" if (cookieNameValueMap["FixedValidityMins"] ~= nil) then - fixedCookieValidityMinutes = cookieNameValueMap["FixedValidityMins"] - end + fixedCookieValidityMinutes = cookieNameValueMap["FixedValidityMins"] + end - local cookieValue = createCookieValue( + local cookieValue = createCookieValue( eventId, cookieNameValueMap["QueueId"], fixedCookieValidityMinutes, @@ -178,7 +178,7 @@ end repo.store = function(eventId, queueId, fixedCookieValidityMinutes, cookieDomain, redirectType, secretKey) local cookieKey = repo.getCookieKey(eventId) - local cookieValue = createCookieValue( + local cookieValue = createCookieValue( eventId, queueId, utils.toString(fixedCookieValidityMinutes), redirectType, secretKey) iHelpers.response.setCookie(cookieKey, cookieValue, os.time() + (24 * 60 * 60), cookieDomain) end diff --git a/SDK/Utils.lua b/SDK/Utils.lua index a91a7af..917b208 100644 --- a/SDK/Utils.lua +++ b/SDK/Utils.lua @@ -85,7 +85,7 @@ local utils = local count = 0 for _ in pairs(t) do count = count + 1 end return count - end + end } return utils \ No newline at end of file diff --git a/SDK/ValidatorHelpers.lua b/SDK/ValidatorHelpers.lua index dd1a9d1..5855f00 100644 --- a/SDK/ValidatorHelpers.lua +++ b/SDK/ValidatorHelpers.lua @@ -123,6 +123,26 @@ local model = { triggerPart["ValueToCompare"], triggerPart["ValuesToCompare"]) end + }, + RequestBodyValidatorHelper = { + evaluate = function(triggerPart, request) + if (triggerPart == nil or + triggerPart["Operator"] == nil or + triggerPart["IsNegative"] == nil or + triggerPart["IsIgnoreCase"] == nil) then + return false + end + + local requestBody = request.getBody() + + return comparisonOperatorHelper.evaluate( + triggerPart["Operator"], + triggerPart["IsNegative"], + triggerPart["IsIgnoreCase"], + requestBody, + triggerPart["ValueToCompare"], + triggerPart["ValuesToCompare"]) + end } }