Skip to content

Commit 342b0cb

Browse files
committed
version 3.6.1
1 parent 9523556 commit 342b0cb

File tree

4 files changed

+156
-61
lines changed

4 files changed

+156
-61
lines changed

SDK/queueit_knownuserv3/user_in_queue_service.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,13 @@
55

66

77
class UserInQueueService:
8-
SDK_VERSION = "v3-python-" + "3.6.0"
8+
SDK_VERSION = "v3-python-" + "3.6.1"
99

1010
def __init__(self, httpContextProvider, userInQueueStateRepository):
1111
self.httpContextProvider = httpContextProvider
1212
self.userInQueueStateRepository = userInQueueStateRepository
1313

14-
def __getQueueITTokenValidationResult(self, targetUrl, eventId, config,
15-
queueParams, customerId, secretKey):
16-
calculatedHash = QueueitHelpers.hmacSha256Encode(
17-
queueParams.queueITTokenWithoutHash, secretKey)
18-
19-
if (calculatedHash.upper() != queueParams.hashCode.upper()):
20-
return self.__cancelQueueCookieReturnErrorResult(customerId, targetUrl,
21-
config, queueParams, "hash")
22-
23-
if (queueParams.eventId.upper() != eventId.upper()):
24-
return self.__cancelQueueCookieReturnErrorResult(
25-
customerId, targetUrl, config, queueParams, "eventid")
26-
27-
if (queueParams.timeStamp <
28-
QueueitHelpers.getCurrentTime()):
29-
return self.__cancelQueueCookieReturnErrorResult(
30-
customerId, targetUrl, config, queueParams, "timestamp")
14+
def __getValidTokenResult(self, config, queueParams, secretKey):
3115

3216
cookieDomain = ""
3317
if (not Utils.isNilOrEmpty(config.cookieDomain)):
@@ -41,8 +25,7 @@ def __getQueueITTokenValidationResult(self, targetUrl, eventId, config,
4125
queueParams.queueId, None,
4226
queueParams.redirectType, config.actionName)
4327

44-
def __cancelQueueCookieReturnErrorResult(self, customerId, targetUrl, config, qParams, errorCode):
45-
self.userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)
28+
def __getErrorResult(self, customerId, targetUrl, config, qParams, errorCode):
4629
timeStamp = str(QueueitHelpers.getCurrentTime())
4730
targetUrlParam = ""
4831
if (not Utils.isNilOrEmpty(targetUrl)):
@@ -55,8 +38,7 @@ def __cancelQueueCookieReturnErrorResult(self, customerId, targetUrl, config, qP
5538

5639
return RequestValidationResult(ActionTypes.QUEUE, config.eventId, None, redirectUrl, None, config.actionName)
5740

58-
def __cancelQueueCookieReturnQueueResult(self, targetUrl, config, customerId):
59-
self.userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)
41+
def __getQueueResult(self, targetUrl, config, customerId):
6042
targetUrlParam = ""
6143
if (not Utils.isNilOrEmpty(targetUrl)):
6244
targetUrlParam = "&t={}".format(QueueitHelpers.urlEncode(targetUrl))
@@ -93,6 +75,21 @@ def __getQueryString(self, customerId, eventId, configVersion, actionName, cultu
9375

9476
return "&".join(queryStringList)
9577

78+
def __validateToken(self, config, queueParams, secretKey):
79+
calculatedHash = QueueitHelpers.hmacSha256Encode(
80+
queueParams.queueITTokenWithoutHash, secretKey)
81+
82+
if (calculatedHash.upper() != queueParams.hashCode.upper()):
83+
return TokenValidationResult(False, "hash")
84+
85+
if (queueParams.eventId.upper() != config.eventId.upper()):
86+
return TokenValidationResult(False, "eventid")
87+
88+
if (queueParams.timeStamp < QueueitHelpers.getCurrentTime()):
89+
return TokenValidationResult(False, "timestamp")
90+
91+
return TokenValidationResult(True, None)
92+
9693
def validateQueueRequest(self, targetUrl, queueitToken, config, customerId,
9794
secretKey):
9895
state = self.userInQueueStateRepository.getState(
@@ -110,13 +107,24 @@ def validateQueueRequest(self, targetUrl, queueitToken, config, customerId,
110107
return result
111108

112109
queueParams = QueueUrlParams.extractQueueParams(queueitToken)
110+
requestValidationResult = RequestValidationResult(None, None, None, None, None, None)
111+
isTokenValid = False
112+
113113
if (queueParams is not None):
114-
return self.__getQueueITTokenValidationResult(
115-
targetUrl, config.eventId, config, queueParams, customerId,
116-
secretKey)
114+
tokenValidationResult = self.__validateToken(config, queueParams, secretKey)
115+
isTokenValid = tokenValidationResult.isValid
116+
if(isTokenValid):
117+
requestValidationResult = self.__getValidTokenResult(config, queueParams, secretKey)
118+
else:
119+
requestValidationResult = self.__getErrorResult(customerId, targetUrl, config, queueParams,
120+
tokenValidationResult.errorCode)
117121
else:
118-
return self.__cancelQueueCookieReturnQueueResult(targetUrl, config,
119-
customerId)
122+
requestValidationResult = self.__getQueueResult(targetUrl, config, customerId)
123+
124+
if(state.isFound and not isTokenValid):
125+
self.userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)
126+
127+
return requestValidationResult
120128

121129
def validateCancelRequest(self, targetUrl, cancelConfig, customerId,
122130
secretKey):
@@ -148,4 +156,9 @@ def extendQueueCookie(self, eventId, cookieValidityMinutes, cookieDomain,
148156
eventId, cookieValidityMinutes, cookieDomain, secretKey)
149157

150158
def getIgnoreActionResult(self, actionName):
151-
return RequestValidationResult(ActionTypes.IGNORE, None, None, None, None, actionName)
159+
return RequestValidationResult(ActionTypes.IGNORE, None, None, None, None, actionName)
160+
161+
class TokenValidationResult:
162+
def __init__(self, isValid, errorCode):
163+
self.isValid = isValid
164+
self.errorCode = errorCode

SDK/queueit_knownuserv3/user_in_queue_state_cookie_repository.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,29 @@ def store(self, eventId, queueId, fixedCookieValidityMinutes, cookieDomain,
108108

109109
def getState(self, eventId, cookieValidityMinutes, secretKey,
110110
validateTime):
111-
cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId)
111+
try:
112+
cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId)
112113

113-
if (self.httpContextProvider.getCookie(cookieKey) is None):
114-
return StateInfo(False, None, None, None)
114+
if (self.httpContextProvider.getCookie(cookieKey) is None):
115+
return StateInfo(False, False, None, None, None)
115116

116-
cookieNameValueMap = UserInQueueStateCookieRepository.__getCookieNameValueMap(
117-
self.httpContextProvider.getCookie(cookieKey))
118-
if (not UserInQueueStateCookieRepository.__isCookieValid(
119-
secretKey, cookieNameValueMap, eventId, cookieValidityMinutes,
120-
validateTime)):
121-
return StateInfo(False, None, None, None)
117+
cookieNameValueMap = UserInQueueStateCookieRepository.__getCookieNameValueMap(
118+
self.httpContextProvider.getCookie(cookieKey))
119+
if (not UserInQueueStateCookieRepository.__isCookieValid(
120+
secretKey, cookieNameValueMap, eventId, cookieValidityMinutes,
121+
validateTime)):
122+
return StateInfo(True, False, None, None, None)
122123

123-
fixedCookieValidityMinutes = None
124-
if ("FixedValidityMins" in cookieNameValueMap):
125-
fixedCookieValidityMinutes = int(
126-
cookieNameValueMap["FixedValidityMins"])
124+
fixedCookieValidityMinutes = None
125+
if ("FixedValidityMins" in cookieNameValueMap):
126+
fixedCookieValidityMinutes = int(
127+
cookieNameValueMap["FixedValidityMins"])
127128

128-
return StateInfo(True, cookieNameValueMap["QueueId"],
129-
fixedCookieValidityMinutes,
130-
cookieNameValueMap["RedirectType"])
129+
return StateInfo(True, True, cookieNameValueMap["QueueId"],
130+
fixedCookieValidityMinutes,
131+
cookieNameValueMap["RedirectType"])
132+
except:
133+
return StateInfo(True, False, None, None, None)
131134

132135
def cancelQueueCookie(self, eventId, cookieDomain):
133136
cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId)
@@ -163,8 +166,9 @@ def reissueQueueCookie(self, eventId, cookieValidityMinutes, cookieDomain,
163166

164167

165168
class StateInfo:
166-
def __init__(self, isValid, queueId, fixedCookieValidityMinutes,
169+
def __init__(self, isFound, isValid, queueId, fixedCookieValidityMinutes,
167170
redirectType):
171+
self.isFound = isFound
168172
self.isValid = isValid
169173
self.queueId = queueId
170174
self.fixedCookieValidityMinutes = fixedCookieValidityMinutes

0 commit comments

Comments
 (0)