Skip to content

Commit 200e5c1

Browse files
author
Pavle
committed
Version 3.6.1
1 parent 5547a89 commit 200e5c1

4 files changed

Lines changed: 167 additions & 58 deletions

File tree

lib/queueit_knownuserv3/user_in_queue_service.rb

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module QueueIt
55
class UserInQueueService
6-
SDK_VERSION_NO = "3.6.0"
6+
SDK_VERSION_NO = "3.6.1"
77
SDK_VERSION = "v3-ruby-" + SDK_VERSION_NO
88

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

2828
queueParams = QueueUrlParams::extractQueueParams(queueitToken)
2929

30-
if(!queueParams.nil?)
31-
return getQueueITTokenValidationResult(targetUrl, config, queueParams, customerId, secretKey)
30+
requestValidationResult = nil
31+
isTokenValid = false
32+
33+
if (!queueParams.nil?)
34+
tokenValidationResult = validateToken(config, queueParams, secretKey)
35+
isTokenValid = tokenValidationResult.isValid
36+
37+
if (isTokenValid)
38+
requestValidationResult = getValidTokenResult(config, queueParams, secretKey)
39+
else
40+
requestValidationResult = getErrorResult(customerId, targetUrl, config, queueParams, tokenValidationResult.errorCode)
41+
end
3242
else
33-
return cancelQueueCookieReturnQueueResult(targetUrl, config, customerId)
43+
requestValidationResult = getQueueResult(targetUrl, config, customerId)
44+
end
45+
46+
if (state.isFound && !isTokenValid)
47+
@userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain);
3448
end
49+
50+
return requestValidationResult;
3551
end
3652

3753
def validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
@@ -49,31 +65,19 @@ def validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
4965
end
5066
end
5167

52-
def getQueueITTokenValidationResult(targetUrl, config, queueParams,customerId, secretKey)
53-
calculatedHash = OpenSSL::HMAC.hexdigest('sha256', secretKey, queueParams.queueITTokenWithoutHash)
54-
if (calculatedHash.upcase() != queueParams.hashCode.upcase())
55-
return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "hash")
56-
end
57-
if (queueParams.eventId.upcase() != config.eventId.upcase())
58-
return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "eventid")
59-
end
60-
if (queueParams.timeStamp < Time.now.getutc.tv_sec)
61-
return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "timestamp")
62-
end
63-
68+
def getValidTokenResult(config, queueParams, secretKey)
6469
@userInQueueStateRepository.store(
6570
config.eventId,
6671
queueParams.queueId,
6772
queueParams.cookieValidityMinutes,
6873
!Utils::isNilOrEmpty(config.cookieDomain) ? config.cookieDomain : '',
6974
queueParams.redirectType,
7075
secretKey)
76+
7177
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, queueParams.queueId, nil, queueParams.redirectType, config.actionName)
7278
end
7379

74-
def cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, qParams, errorCode)
75-
@userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)
76-
80+
def getErrorResult(customerId, targetUrl, config, qParams, errorCode)
7781
query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) +
7882
"&queueittoken=" + qParams.queueITToken +
7983
"&ts=" + Time.now.getutc.tv_sec.to_s +
@@ -84,9 +88,7 @@ def cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, qParams, e
8488
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, nil, redirectUrl, nil, config.actionName)
8589
end
8690

87-
def cancelQueueCookieReturnQueueResult(targetUrl, config, customerId)
88-
@userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)
89-
91+
def getQueueResult(targetUrl, config, customerId)
9092
query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) +
9193
(!Utils::isNilOrEmpty(targetUrl) ? "&t=" + Utils.urlEncode( targetUrl) : "")
9294

@@ -126,5 +128,30 @@ def extendQueueCookie(eventId, cookieValidityMinutes, cookieDomain, secretKey)
126128
def getIgnoreActionResult(actionName)
127129
return RequestValidationResult.new(ActionTypes::IGNORE, nil, nil, nil, nil, actionName)
128130
end
131+
132+
def validateToken(config, queueParams, secretKey)
133+
calculatedHash = OpenSSL::HMAC.hexdigest('sha256', secretKey, queueParams.queueITTokenWithoutHash)
134+
if (calculatedHash.upcase() != queueParams.hashCode.upcase())
135+
return TokenValidationResult.new(false, "hash")
136+
end
137+
if (queueParams.eventId.upcase() != config.eventId.upcase())
138+
return TokenValidationResult.new(false, "eventid")
139+
end
140+
if (queueParams.timeStamp < Time.now.getutc.tv_sec)
141+
return TokenValidationResult.new(false, "timestamp")
142+
end
143+
144+
return TokenValidationResult.new(true, nil)
145+
end
146+
147+
class TokenValidationResult
148+
attr_reader :isValid
149+
attr_reader :errorCode
150+
151+
def initialize(isValid, errorCode)
152+
@isValid = isValid
153+
@errorCode = errorCode
154+
end
155+
end
129156
end
130157
end

lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,35 +143,42 @@ def reissueQueueCookie(eventId, cookieValidityMinutes, cookieDomain, secretKey)
143143
end
144144

145145
def getState(eventId, cookieValidityMinutes, secretKey, validateTime)
146-
cookieKey = self.class.getCookieKey(eventId)
147-
if (@cookieManager.getCookie(cookieKey).nil?)
148-
return StateInfo.new(false, nil, nil, nil)
149-
end
150-
cookieNameValueMap = getCookieNameValueMap(@cookieManager.getCookie(cookieKey))
151-
if (!isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValidityMinutes, validateTime))
152-
return StateInfo.new(false, nil, nil, nil)
153-
end
146+
begin
147+
cookieKey = self.class.getCookieKey(eventId)
148+
if (@cookieManager.getCookie(cookieKey).nil?)
149+
return StateInfo.new(false, false, nil, nil, nil)
150+
end
151+
cookieNameValueMap = getCookieNameValueMap(@cookieManager.getCookie(cookieKey))
152+
if (!isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValidityMinutes, validateTime))
153+
return StateInfo.new(true, false, nil, nil, nil)
154+
end
154155

155-
fixedCookieValidityMinutes = nil
156-
if (cookieNameValueMap.key?("FixedValidityMins"))
157-
fixedCookieValidityMinutes = cookieNameValueMap["FixedValidityMins"].to_i
158-
end
156+
fixedCookieValidityMinutes = nil
157+
if (cookieNameValueMap.key?("FixedValidityMins"))
158+
fixedCookieValidityMinutes = cookieNameValueMap["FixedValidityMins"].to_i
159+
end
159160

160-
return StateInfo.new(
161-
true,
162-
cookieNameValueMap["QueueId"],
163-
fixedCookieValidityMinutes,
164-
cookieNameValueMap["RedirectType"])
161+
return StateInfo.new(
162+
true,
163+
true,
164+
cookieNameValueMap["QueueId"],
165+
fixedCookieValidityMinutes,
166+
cookieNameValueMap["RedirectType"])
167+
rescue
168+
return StateInfo.new(true, false, nil, nil, nil)
169+
end
165170
end
166171
end
167172

168173
class StateInfo
174+
attr_reader :isFound
169175
attr_reader :isValid
170176
attr_reader :queueId
171177
attr_reader :fixedCookieValidityMinutes
172178
attr_reader :redirectType
173179

174-
def initialize(isValid, queueId, fixedCookieValidityMinutes, redirectType)
180+
def initialize(isFound, isValid, queueId, fixedCookieValidityMinutes, redirectType)
181+
@isFound = isFound
175182
@isValid = isValid
176183
@queueId = queueId
177184
@fixedCookieValidityMinutes = fixedCookieValidityMinutes

0 commit comments

Comments
 (0)