Skip to content

Commit

Permalink
Version 3.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavle committed Jun 12, 2020
1 parent 5547a89 commit 200e5c1
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 58 deletions.
71 changes: 49 additions & 22 deletions lib/queueit_knownuserv3/user_in_queue_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module QueueIt
class UserInQueueService
SDK_VERSION_NO = "3.6.0"
SDK_VERSION_NO = "3.6.1"
SDK_VERSION = "v3-ruby-" + SDK_VERSION_NO

def initialize(userInQueueStateRepository)
Expand All @@ -27,11 +27,27 @@ def validateQueueRequest(targetUrl, queueitToken, config, customerId, secretKey)

queueParams = QueueUrlParams::extractQueueParams(queueitToken)

if(!queueParams.nil?)
return getQueueITTokenValidationResult(targetUrl, config, queueParams, customerId, secretKey)
requestValidationResult = nil
isTokenValid = false

if (!queueParams.nil?)
tokenValidationResult = validateToken(config, queueParams, secretKey)
isTokenValid = tokenValidationResult.isValid

if (isTokenValid)
requestValidationResult = getValidTokenResult(config, queueParams, secretKey)
else
requestValidationResult = getErrorResult(customerId, targetUrl, config, queueParams, tokenValidationResult.errorCode)
end
else
return cancelQueueCookieReturnQueueResult(targetUrl, config, customerId)
requestValidationResult = getQueueResult(targetUrl, config, customerId)
end

if (state.isFound && !isTokenValid)
@userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain);
end

return requestValidationResult;
end

def validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
Expand All @@ -49,31 +65,19 @@ def validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
end
end

def getQueueITTokenValidationResult(targetUrl, config, queueParams,customerId, secretKey)
calculatedHash = OpenSSL::HMAC.hexdigest('sha256', secretKey, queueParams.queueITTokenWithoutHash)
if (calculatedHash.upcase() != queueParams.hashCode.upcase())
return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "hash")
end
if (queueParams.eventId.upcase() != config.eventId.upcase())
return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "eventid")
end
if (queueParams.timeStamp < Time.now.getutc.tv_sec)
return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "timestamp")
end

def getValidTokenResult(config, queueParams, secretKey)
@userInQueueStateRepository.store(
config.eventId,
queueParams.queueId,
queueParams.cookieValidityMinutes,
!Utils::isNilOrEmpty(config.cookieDomain) ? config.cookieDomain : '',
queueParams.redirectType,
secretKey)

return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, queueParams.queueId, nil, queueParams.redirectType, config.actionName)
end

def cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, qParams, errorCode)
@userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)

def getErrorResult(customerId, targetUrl, config, qParams, errorCode)
query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) +
"&queueittoken=" + qParams.queueITToken +
"&ts=" + Time.now.getutc.tv_sec.to_s +
Expand All @@ -84,9 +88,7 @@ def cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, qParams, e
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, nil, redirectUrl, nil, config.actionName)
end

def cancelQueueCookieReturnQueueResult(targetUrl, config, customerId)
@userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)

def getQueueResult(targetUrl, config, customerId)
query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) +
(!Utils::isNilOrEmpty(targetUrl) ? "&t=" + Utils.urlEncode( targetUrl) : "")

Expand Down Expand Up @@ -126,5 +128,30 @@ def extendQueueCookie(eventId, cookieValidityMinutes, cookieDomain, secretKey)
def getIgnoreActionResult(actionName)
return RequestValidationResult.new(ActionTypes::IGNORE, nil, nil, nil, nil, actionName)
end

def validateToken(config, queueParams, secretKey)
calculatedHash = OpenSSL::HMAC.hexdigest('sha256', secretKey, queueParams.queueITTokenWithoutHash)
if (calculatedHash.upcase() != queueParams.hashCode.upcase())
return TokenValidationResult.new(false, "hash")
end
if (queueParams.eventId.upcase() != config.eventId.upcase())
return TokenValidationResult.new(false, "eventid")
end
if (queueParams.timeStamp < Time.now.getutc.tv_sec)
return TokenValidationResult.new(false, "timestamp")
end

return TokenValidationResult.new(true, nil)
end

class TokenValidationResult
attr_reader :isValid
attr_reader :errorCode

def initialize(isValid, errorCode)
@isValid = isValid
@errorCode = errorCode
end
end
end
end
43 changes: 25 additions & 18 deletions lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,42 @@ def reissueQueueCookie(eventId, cookieValidityMinutes, cookieDomain, secretKey)
end

def getState(eventId, cookieValidityMinutes, secretKey, validateTime)
cookieKey = self.class.getCookieKey(eventId)
if (@cookieManager.getCookie(cookieKey).nil?)
return StateInfo.new(false, nil, nil, nil)
end
cookieNameValueMap = getCookieNameValueMap(@cookieManager.getCookie(cookieKey))
if (!isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValidityMinutes, validateTime))
return StateInfo.new(false, nil, nil, nil)
end
begin
cookieKey = self.class.getCookieKey(eventId)
if (@cookieManager.getCookie(cookieKey).nil?)
return StateInfo.new(false, false, nil, nil, nil)
end
cookieNameValueMap = getCookieNameValueMap(@cookieManager.getCookie(cookieKey))
if (!isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValidityMinutes, validateTime))
return StateInfo.new(true, false, nil, nil, nil)
end

fixedCookieValidityMinutes = nil
if (cookieNameValueMap.key?("FixedValidityMins"))
fixedCookieValidityMinutes = cookieNameValueMap["FixedValidityMins"].to_i
end
fixedCookieValidityMinutes = nil
if (cookieNameValueMap.key?("FixedValidityMins"))
fixedCookieValidityMinutes = cookieNameValueMap["FixedValidityMins"].to_i
end

return StateInfo.new(
true,
cookieNameValueMap["QueueId"],
fixedCookieValidityMinutes,
cookieNameValueMap["RedirectType"])
return StateInfo.new(
true,
true,
cookieNameValueMap["QueueId"],
fixedCookieValidityMinutes,
cookieNameValueMap["RedirectType"])
rescue
return StateInfo.new(true, false, nil, nil, nil)
end
end
end

class StateInfo
attr_reader :isFound
attr_reader :isValid
attr_reader :queueId
attr_reader :fixedCookieValidityMinutes
attr_reader :redirectType

def initialize(isValid, queueId, fixedCookieValidityMinutes, redirectType)
def initialize(isFound, isValid, queueId, fixedCookieValidityMinutes, redirectType)
@isFound = isFound
@isValid = isValid
@queueId = queueId
@fixedCookieValidityMinutes = fixedCookieValidityMinutes
Expand Down
Loading

0 comments on commit 200e5c1

Please sign in to comment.