Skip to content

Commit

Permalink
Release 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
frwiqueueit committed Mar 2, 2020
1 parent 2d73345 commit 8dd3a19
Show file tree
Hide file tree
Showing 13 changed files with 1,126 additions and 524 deletions.
1 change: 1 addition & 0 deletions lib/queueit_knownuserv3.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative "queueit_knownuserv3/known_user"
require_relative "queueit_knownuserv3/models"
require_relative "queueit_knownuserv3/connector_diagnostics"
require_relative "queueit_knownuserv3/queue_url_params"
require_relative "queueit_knownuserv3/user_in_queue_state_cookie_repository"
require_relative "queueit_knownuserv3/user_in_queue_service"
Expand Down
69 changes: 69 additions & 0 deletions lib/queueit_knownuserv3/connector_diagnostics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module QueueIt
class ConnectorDiagnostics
attr_accessor :isEnabled
attr_accessor :hasError
attr_accessor :validationResult

def initialize
@isEnabled = false
@hasError = false
@validationResult = nil
end

def setStateWithTokenError(customerId, errorCode)
@hasError = true
@validationResult = RequestValidationResult.new(
"ConnectorDiagnosticsRedirect",
nil, nil,
"https://" + customerId + ".api2.queue-it.net/" + customerId + "/diagnostics/connector/error/?code=" + errorCode,
nil, nil)
end

def setStateWithSetupError()
@hasError = true
@validationResult = RequestValidationResult.new(
"ConnectorDiagnosticsRedirect",
nil, nil,
"https://api2.queue-it.net/diagnostics/connector/error/?code=setup",
nil, nil)
end

def self.verify(customerId, secretKey, queueitToken)
diagnostics = ConnectorDiagnostics.new

qParams = QueueUrlParams.extractQueueParams(queueitToken)

if(qParams == nil)
return diagnostics
end

if(qParams.redirectType == nil)
return diagnostics
end

if(not qParams.redirectType.upcase.eql?("DEBUG"))
return diagnostics
end

if(Utils.isNilOrEmpty(customerId) or Utils.isNilOrEmpty(secretKey))
diagnostics.setStateWithSetupError()
return diagnostics
end

calculatedHash = OpenSSL::HMAC.hexdigest('sha256', secretKey, qParams.queueITTokenWithoutHash)
if(not qParams.hashCode.eql?(calculatedHash))
diagnostics.setStateWithTokenError(customerId, "hash")
return diagnostics
end

if(qParams.timeStamp < Time.now.getutc.tv_sec)
diagnostics.setStateWithTokenError(customerId, "timestamp")
return diagnostics
end

diagnostics.isEnabled = true

return diagnostics
end
end
end
51 changes: 1 addition & 50 deletions lib/queueit_knownuserv3/integration_config_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ def self.evaluate(opt, isNegative, ignoreCase, value, valueToCompare, valuesToCo
return ComparisonOperatorHelper.equals(value, valueToCompare, isNegative, ignoreCase)
when "Contains"
return ComparisonOperatorHelper.contains(value, valueToCompare, isNegative, ignoreCase)
when "StartsWith"
return ComparisonOperatorHelper.startsWith(value, valueToCompare, isNegative, ignoreCase)
when "EndsWith"
return ComparisonOperatorHelper.endsWith(value, valueToCompare, isNegative, ignoreCase)
when "MatchesWith"
return ComparisonOperatorHelper.matchesWith(value, valueToCompare, isNegative, ignoreCase)
when "EqualsAny"
return ComparisonOperatorHelper.equalsAny(value, valuesToCompare, isNegative, ignoreCase)
when "ContainsAny"
Expand All @@ -241,7 +235,7 @@ def self.equals(value, valueToCompare, isNegative, ignoreCase)
end

def self.contains(value, valueToCompare, isNegative, ignoreCase)
if(valueToCompare.eql? "*")
if((valueToCompare.eql? "*") && !(value.empty? || value.nil?))
return true
end

Expand All @@ -258,49 +252,6 @@ def self.contains(value, valueToCompare, isNegative, ignoreCase)
end
end

def self.startsWith(value, valueToCompare, isNegative, ignoreCase)
if(ignoreCase)
evaluation = value.upcase.start_with? valueToCompare.upcase
else
evaluation = value.start_with? valueToCompare
end

if(isNegative)
return !evaluation
else
return evaluation
end
end

def self.endsWith(value, valueToCompare, isNegative, ignoreCase)
if(ignoreCase)
evaluation = value.upcase.end_with? valueToCompare.upcase
else
evaluation = value.end_with? valueToCompare
end

if(isNegative)
return !evaluation
else
return evaluation
end
end

def self.matchesWith(value, valueToCompare, isNegative, ignoreCase)
if(ignoreCase)
pattern = Regexp.new(valueToCompare, Regexp::IGNORECASE)
else
pattern = Regexp.new(valueToCompare)
end

evaluation = pattern.match(value) != nil
if(isNegative)
return !evaluation
else
return evaluation
end
end

def self.equalsAny(value, valuesToCompare, isNegative, ignoreCase)
valuesToCompare.each do |valueToCompare|
if (ComparisonOperatorHelper.equals(value, valueToCompare, false, ignoreCase))
Expand Down
140 changes: 84 additions & 56 deletions lib/queueit_knownuserv3/known_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,6 @@ def self.logMoreRequestDetails(debugEntries, request)
end
private_class_method :logMoreRequestDetails

def self.getIsDebug(queueitToken, secretKey)
qParams = QueueUrlParams.extractQueueParams(queueitToken)
if(qParams == nil)
return false
end

redirectType = qParams.redirectType
if(redirectType == nil)
return false
end

if (redirectType.upcase.eql?("DEBUG"))
calculatedHash = OpenSSL::HMAC.hexdigest('sha256', secretKey, qParams.queueITTokenWithoutHash)
valid = qParams.hashCode.eql?(calculatedHash)
return valid
end
return false
end
private_class_method :getIsDebug

def self.setDebugCookie(debugEntries, cookieJar)
if(debugEntries == nil || debugEntries.length == 0)
return
Expand All @@ -86,9 +66,11 @@ def self.setDebugCookie(debugEntries, cookieJar)
end
private_class_method :setDebugCookie

def self._resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries)
isDebug = getIsDebug(queueitToken, secretKey)
def self._resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries, isDebug)

if(isDebug)
debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
debugEntries["Runtime"] = getRuntime()
debugEntries["TargetUrl"] = targetUrl
debugEntries["QueueitToken"] = queueitToken
debugEntries["OriginalUrl"] = getRealOriginalUrl(request)
Expand Down Expand Up @@ -137,10 +119,12 @@ def self._resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig,
end
private_class_method :_resolveQueueRequestByLocalConfig

def self._cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries)
targetUrl = generateTargetUrl(targetUrl, request)
isDebug = getIsDebug(queueitToken, secretKey)
def self._cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries, isDebug)
targetUrl = generateTargetUrl(targetUrl, request)

if(isDebug)
debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
debugEntries["Runtime"] = getRuntime()
debugEntries["TargetUrl"] = targetUrl
debugEntries["QueueitToken"] = queueitToken
debugEntries["OriginalUrl"] = getRealOriginalUrl(request)
Expand Down Expand Up @@ -204,40 +188,64 @@ def self.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKe

def self.resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request)
debugEntries = Hash.new
connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)

if(connectorDiagnostics.hasError)
return connectorDiagnostics.validationResult
end
begin
targetUrl = generateTargetUrl(targetUrl, request)
return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries)
return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries, connectorDiagnostics.isEnabled)
rescue Exception => e
if(connectorDiagnostics.isEnabled)
debugEntries["Exception"] = e.message
end
raise e
ensure
setDebugCookie(debugEntries, request.cookie_jar)
end
end

def self.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queueitToken, integrationsConfigString, customerId, secretKey, request)
if(Utils.isNilOrEmpty(currentUrlWithoutQueueITToken))
raise KnownUserError, "currentUrlWithoutQueueITToken can not be nil or empty."
end

if(Utils.isNilOrEmpty(integrationsConfigString))
raise KnownUserError, "integrationsConfigString can not be nil or empty."
def self.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queueitToken, integrationConfigJson, customerId, secretKey, request)
debugEntries = Hash.new
customerIntegration = Hash.new
connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)
if(connectorDiagnostics.hasError)
return connectorDiagnostics.validationResult
end

debugEntries = Hash.new
begin
customerIntegration = JSON.parse(integrationsConfigString)

isDebug = getIsDebug(queueitToken, secretKey)
if(isDebug)
debugEntries["ConfigVersion"] = customerIntegration["Version"]
if(connectorDiagnostics.isEnabled)
debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
debugEntries["Runtime"] = getRuntime()
debugEntries["PureUrl"] = currentUrlWithoutQueueITToken
debugEntries["QueueitToken"] = queueitToken
debugEntries["OriginalUrl"] = getRealOriginalUrl(request)
logMoreRequestDetails(debugEntries, request)
end


customerIntegration = JSON.parse(integrationConfigJson)

if(connectorDiagnostics.isEnabled)
if(customerIntegration.length != 0 and customerIntegration["Version"] != nil)
debugEntries["ConfigVersion"] = customerIntegration["Version"]
else
debugEntries["ConfigVersion"] = "NULL"
end
end

if(Utils.isNilOrEmpty(currentUrlWithoutQueueITToken))
raise KnownUserError, "currentUrlWithoutQueueITToken can not be nil or empty."
end

if(customerIntegration.length == 0 || customerIntegration["Version"] == nil)
raise KnownUserError, "integrationConfigJson is not valid json."
end

integrationEvaluator = IntegrationEvaluator.new
matchedConfig = integrationEvaluator.getMatchedIntegrationConfig(customerIntegration, currentUrlWithoutQueueITToken, request)

if(isDebug)
if(connectorDiagnostics.isEnabled)
if(matchedConfig == nil)
debugEntries["MatchedConfig"] = "NULL"
else
Expand All @@ -246,33 +254,37 @@ def self.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queue
end

if(matchedConfig == nil)
return RequestValidationResult.new(nil, nil, nil, nil, nil)
return RequestValidationResult.new(nil, nil, nil, nil, nil, nil)
end

# unspecified or 'Queue' specified
if(!matchedConfig.key?("ActionType") || Utils.isNilOrEmpty(matchedConfig["ActionType"]) || matchedConfig["ActionType"].eql?(ActionTypes::QUEUE))
return handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
return handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration,
customerId, secretKey, matchedConfig, request, debugEntries, connectorDiagnostics.isEnabled)

elsif(matchedConfig["ActionType"].eql?(ActionTypes::CANCEL))
return handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
return handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration,
customerId, secretKey, matchedConfig, request, debugEntries, connectorDiagnostics.isEnabled)

# for all unknown types default to 'Ignore'
else
userInQueueService = getUserInQueueService(request.cookie_jar)
result = userInQueueService.getIgnoreActionResult()
result = userInQueueService.getIgnoreActionResult(matchedConfig["Name"])
result.isAjaxResult = isQueueAjaxCall(request)

return result
end

rescue StandardError => stdErr
raise KnownUserError, "integrationConfiguration text was not valid: " + stdErr.message
rescue Exception => e
if(connectorDiagnostics.isEnabled)
debugEntries["Exception"] = e.message
end
raise e
ensure
setDebugCookie(debugEntries, request.cookie_jar)
end
end

def self.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
def self.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries, isDebug)
queueConfig = QueueEventConfig.new
queueConfig.eventId = matchedConfig["EventId"]
queueConfig.queueDomain = matchedConfig["QueueDomain"]
Expand All @@ -282,7 +294,8 @@ def self.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customer
queueConfig.extendCookieValidity = matchedConfig["ExtendCookieValidity"]
queueConfig.cookieValidityMinute = matchedConfig["CookieValidityMinute"]
queueConfig.version = customerIntegration["Version"]

queueConfig.actionName = matchedConfig["Name"]

case matchedConfig["RedirectLogic"]
when "ForcedTargetUrl"
targetUrl = matchedConfig["ForcedTargetUrl"]
Expand All @@ -292,23 +305,34 @@ def self.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customer
targetUrl = generateTargetUrl(currentUrlWithoutQueueITToken, request)
end

return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries)
return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries, isDebug)
end

def self.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
def self.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries, isDebug)
cancelConfig = CancelEventConfig.new
cancelConfig.eventId = matchedConfig["EventId"]
cancelConfig.queueDomain = matchedConfig["QueueDomain"]
cancelConfig.cookieDomain = matchedConfig["CookieDomain"]
cancelConfig.version = customerIntegration["Version"]

return _cancelRequestByLocalConfig(currentUrlWithoutQueueITToken, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries)
cancelConfig.actionName = matchedConfig["Name"]

return _cancelRequestByLocalConfig(currentUrlWithoutQueueITToken, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries, isDebug)
end

def self.cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request)
debugEntries = Hash.new
connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)

if(connectorDiagnostics.hasError)
return connectorDiagnostics.validationResult
end
begin
return _cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries)
return _cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries, connectorDiagnostics.isEnabled)
rescue Exception => e
if(connectorDiagnostics.isEnabled)
debugEntries["Exception"] = e.message
end
raise e
ensure
setDebugCookie(debugEntries, request.cookie_jar)
end
Expand All @@ -319,6 +343,10 @@ def self.getRealOriginalUrl(request)
# Therefore we need this method to be able to access the 'real' original url.
return request.env["rack.url_scheme"] + "://" + request.env["HTTP_HOST"] + request.original_fullpath
end

def self.getRuntime()
return RUBY_VERSION.to_s
end
end

class CookieManager
Expand Down
Loading

0 comments on commit 8dd3a19

Please sign in to comment.