queueit_knownuserv3 3.6.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ ################################################################################
2
+ # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3
+ ################################################################################
4
+
5
+ /.vs
@@ -3,7 +3,7 @@ require 'cgi'
3
3
 
4
4
  module QueueIt
5
5
  class UserInQueueService
6
- SDK_VERSION_NO = "3.6.0"
6
+ SDK_VERSION_NO = "3.6.1"
7
7
  SDK_VERSION = "v3-ruby-" + SDK_VERSION_NO
8
8
 
9
9
  def initialize(userInQueueStateRepository)
@@ -27,11 +27,27 @@ module QueueIt
27
27
 
28
28
  queueParams = QueueUrlParams::extractQueueParams(queueitToken)
29
29
 
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
32
42
  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);
34
48
  end
49
+
50
+ return requestValidationResult;
35
51
  end
36
52
 
37
53
  def validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
@@ -49,18 +65,7 @@ module QueueIt
49
65
  end
50
66
  end
51
67
 
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)
64
69
  @userInQueueStateRepository.store(
65
70
  config.eventId,
66
71
  queueParams.queueId,
@@ -68,12 +73,11 @@ module QueueIt
68
73
  !Utils::isNilOrEmpty(config.cookieDomain) ? config.cookieDomain : '',
69
74
  queueParams.redirectType,
70
75
  secretKey)
76
+
71
77
  return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, queueParams.queueId, nil, queueParams.redirectType, config.actionName)
72
78
  end
73
79
 
74
- def cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, qParams, errorCode)
75
- @userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)
76
-
80
+ def getErrorResult(customerId, targetUrl, config, qParams, errorCode)
77
81
  query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) +
78
82
  "&queueittoken=" + qParams.queueITToken +
79
83
  "&ts=" + Time.now.getutc.tv_sec.to_s +
@@ -84,9 +88,7 @@ module QueueIt
84
88
  return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, nil, redirectUrl, nil, config.actionName)
85
89
  end
86
90
 
87
- def cancelQueueCookieReturnQueueResult(targetUrl, config, customerId)
88
- @userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)
89
-
91
+ def getQueueResult(targetUrl, config, customerId)
90
92
  query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) +
91
93
  (!Utils::isNilOrEmpty(targetUrl) ? "&t=" + Utils.urlEncode( targetUrl) : "")
92
94
 
@@ -126,5 +128,30 @@ module QueueIt
126
128
  def getIgnoreActionResult(actionName)
127
129
  return RequestValidationResult.new(ActionTypes::IGNORE, nil, nil, nil, nil, actionName)
128
130
  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
129
156
  end
130
157
  end
@@ -143,35 +143,42 @@ module QueueIt
143
143
  end
144
144
 
145
145
  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
154
155
 
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
159
160
 
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
165
170
  end
166
171
  end
167
172
 
168
173
  class StateInfo
174
+ attr_reader :isFound
169
175
  attr_reader :isValid
170
176
  attr_reader :queueId
171
177
  attr_reader :fixedCookieValidityMinutes
172
178
  attr_reader :redirectType
173
179
 
174
- def initialize(isValid, queueId, fixedCookieValidityMinutes, redirectType)
180
+ def initialize(isFound, isValid, queueId, fixedCookieValidityMinutes, redirectType)
181
+ @isFound = isFound
175
182
  @isValid = isValid
176
183
  @queueId = queueId
177
184
  @fixedCookieValidityMinutes = fixedCookieValidityMinutes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queueit_knownuserv3
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-03-02 00:00:00.000000000 Z
12
+ date: 2020-06-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -20,9 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - .devcontainer/Dockerfile
22
22
  - .devcontainer/devcontainer.json
23
- - .vs/VSWorkspaceState.json
24
- - .vs/knownuser-v3-ruby/v16/.suo
25
- - .vs/slnx.sqlite
23
+ - .gitignore
26
24
  - .vscode/launch.json
27
25
  - Gemfile
28
26
  - Rakefile
@@ -1,9 +0,0 @@
1
- {
2
- "ExpandedNodes": [
3
- "",
4
- "\\test",
5
- "\\test\\queueit_knownuserv3"
6
- ],
7
- "SelectedNode": "\\test\\test_queueit_knownuserv3.rb",
8
- "PreviewInSolutionExplorer": false
9
- }
Binary file