From b32b57c35552f98d40f5653cecfaf076255e612c Mon Sep 17 00:00:00 2001 From: Frederik Williams Date: Thu, 31 Aug 2017 14:14:26 +0200 Subject: [PATCH] support for user-agent triggers, cancel queue actions and debug information cookie --- .../knownuserv3/sdk/CancelEventConfig.java | 53 + .../queueit/knownuserv3/sdk/Constants.java | 7 + .../queueit/knownuserv3/sdk/KnownUser.java | 269 +++- ...EventConfig.java => QueueEventConfig.java} | 16 +- .../knownuserv3/sdk/QueueITHelpers.java | 23 +- .../sdk/RequestValidationResult.java | 8 +- .../knownuserv3/sdk/UserInQueueService.java | 91 +- .../sdk/UserInQueueStateCookieRepository.java | 7 +- .../IntegrationConfigModel.java | 5 +- .../knownuserv3/sdk/KnownUserTest.java | 1225 ++++++++++++----- .../sdk/UserInQueueServiceTest.java | 115 +- .../UserInQueueStateCookieRepositoryTest.java | 46 +- 12 files changed, 1333 insertions(+), 532 deletions(-) create mode 100644 SDK/src/queueit/knownuserv3/sdk/CancelEventConfig.java create mode 100644 SDK/src/queueit/knownuserv3/sdk/Constants.java rename SDK/src/queueit/knownuserv3/sdk/{EventConfig.java => QueueEventConfig.java} (77%) diff --git a/SDK/src/queueit/knownuserv3/sdk/CancelEventConfig.java b/SDK/src/queueit/knownuserv3/sdk/CancelEventConfig.java new file mode 100644 index 0000000..3f25f68 --- /dev/null +++ b/SDK/src/queueit/knownuserv3/sdk/CancelEventConfig.java @@ -0,0 +1,53 @@ +package queueit.knownuserv3.sdk; + +public class CancelEventConfig { + + private String eventId; + private String queueDomain; + private String cookieDomain; + private int version; + + public String getEventId() { + return eventId; + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public String getQueueDomain() { + return queueDomain; + } + + public void setQueueDomain(String queueDomain) { + this.queueDomain = queueDomain; + } + + public String getCookieDomain() { + return cookieDomain; + } + + public void setCookieDomain(String cookieDomain) { + this.cookieDomain = cookieDomain; + } + + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } + + public CancelEventConfig() { + this.version = -1; + } + + @Override + public String toString() { + return "EventId:" + eventId + + "&Version:" + version + + "&QueueDomain:" + queueDomain + + "&CookieDomain:" + cookieDomain; + } +} \ No newline at end of file diff --git a/SDK/src/queueit/knownuserv3/sdk/Constants.java b/SDK/src/queueit/knownuserv3/sdk/Constants.java new file mode 100644 index 0000000..4ad7bd9 --- /dev/null +++ b/SDK/src/queueit/knownuserv3/sdk/Constants.java @@ -0,0 +1,7 @@ +package queueit.knownuserv3.sdk; + +final class ActionType { + + public static final String CANCEL_ACTION = "Cancel"; + public static final String QUEUE_ACTION = "Queue"; +} diff --git a/SDK/src/queueit/knownuserv3/sdk/KnownUser.java b/SDK/src/queueit/knownuserv3/sdk/KnownUser.java index c2fe4e1..d080eee 100644 --- a/SDK/src/queueit/knownuserv3/sdk/KnownUser.java +++ b/SDK/src/queueit/knownuserv3/sdk/KnownUser.java @@ -1,13 +1,15 @@ package queueit.knownuserv3.sdk; +import java.util.HashMap; +import java.util.Map; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import queueit.knownuserv3.sdk.integrationconfig.*; - public class KnownUser { - + public static final String QueueITTokenKey = "queueittoken"; + public static final String QueueITDebugKey = "queueitdebug"; private static IUserInQueueService _userInQueueService; private static IUserInQueueService createUserInQueueService(HttpServletRequest request, HttpServletResponse response) { @@ -30,89 +32,193 @@ public static RequestValidationResult validateRequestByIntegrationConfig(String String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey) throws Exception { - if (Utils.isNullOrWhiteSpace(currentUrlWithoutQueueITToken)) { - throw new Exception("currentUrlWithoutQueueITToken can not be null or empty."); - } - if (customerIntegrationInfo == null) { - throw new KnowUserException("customerIntegrationInfo can not be null."); - } - Cookie[] cookies = request != null ? request.getCookies() : new Cookie[0]; - IntegrationEvaluator configEvaluater = new IntegrationEvaluator(); - String userAgent = request.getHeader("User-Agent"); - IntegrationConfigModel matchedConfig = configEvaluater.getMatchedIntegrationConfig( - customerIntegrationInfo, currentUrlWithoutQueueITToken, cookies, userAgent != null ? userAgent : ""); - if (matchedConfig == null) { - return new RequestValidationResult(null, null, null); - } - - String targetUrl; - switch (matchedConfig.RedirectLogic) { - case "ForecedTargetUrl": // suuport for typo (fall through) - case "ForcedTargetUrl": - targetUrl = matchedConfig.ForcedTargetUrl; - break; - case "EventTargetUrl": - targetUrl = ""; - break; - default: - targetUrl = currentUrlWithoutQueueITToken; - break; - } - - EventConfig eventConfig = new EventConfig(); - eventConfig.setQueueDomain(matchedConfig.QueueDomain); - eventConfig.setCulture(matchedConfig.Culture); - eventConfig.setEventId(matchedConfig.EventId); - eventConfig.setExtendCookieValidity(matchedConfig.ExtendCookieValidity); - eventConfig.setLayoutName(matchedConfig.LayoutName); - eventConfig.setCookieValidityMinute(matchedConfig.CookieValidityMinute); - eventConfig.setCookieDomain(matchedConfig.CookieDomain); - eventConfig.setVersion(customerIntegrationInfo.Version); - - return validateRequestByLocalEventConfig(targetUrl, queueitToken, eventConfig, customerId, request, response, secretKey); + Map debugEntries = new HashMap<>(); + + try { + boolean isDebug = getIsDebug(queueitToken, secretKey); + if (isDebug) { + debugEntries.put("configVersion", Integer.toString(customerIntegrationInfo.Version)); + debugEntries.put("pureUrl", currentUrlWithoutQueueITToken); + debugEntries.put("queueitToken", queueitToken); + debugEntries.put("OriginalURL", request.getRequestURL().toString()); + } + + if (Utils.isNullOrWhiteSpace(currentUrlWithoutQueueITToken)) { + throw new Exception("currentUrlWithoutQueueITToken can not be null or empty."); + } + if (customerIntegrationInfo == null) { + throw new KnowUserException("customerIntegrationInfo can not be null."); + } + + Cookie[] cookies = request != null ? request.getCookies() : new Cookie[0]; + + IntegrationEvaluator configEvaluater = new IntegrationEvaluator(); + String userAgent = request.getHeader("User-Agent"); + + IntegrationConfigModel matchedConfig = configEvaluater.getMatchedIntegrationConfig( + customerIntegrationInfo, currentUrlWithoutQueueITToken, cookies, userAgent != null ? userAgent : ""); + + if (isDebug) { + String matchedConfigName = (matchedConfig != null) ? matchedConfig.Name : "NULL"; + debugEntries.put("matchedConfig", matchedConfigName); + } + + if (matchedConfig == null) { + return new RequestValidationResult(null, null, null, null); + } + + if(Utils.isNullOrWhiteSpace(matchedConfig.ActionType) || ActionType.QUEUE_ACTION.equals(matchedConfig.ActionType)) { + String targetUrl; + switch (matchedConfig.RedirectLogic) { + case "ForecedTargetUrl": // suuport for typo (fall through) + case "ForcedTargetUrl": + targetUrl = matchedConfig.ForcedTargetUrl; + break; + case "EventTargetUrl": + targetUrl = ""; + break; + default: + targetUrl = currentUrlWithoutQueueITToken; + break; + } + + QueueEventConfig queueConfig = new QueueEventConfig(); + queueConfig.setQueueDomain(matchedConfig.QueueDomain); + queueConfig.setCulture(matchedConfig.Culture); + queueConfig.setEventId(matchedConfig.EventId); + queueConfig.setExtendCookieValidity(matchedConfig.ExtendCookieValidity); + queueConfig.setLayoutName(matchedConfig.LayoutName); + queueConfig.setCookieValidityMinute(matchedConfig.CookieValidityMinute); + queueConfig.setCookieDomain(matchedConfig.CookieDomain); + queueConfig.setVersion(customerIntegrationInfo.Version); + + return resolveQueueRequestByLocalConfig( + targetUrl, queueitToken, queueConfig, customerId, request, response, secretKey, debugEntries); + } + // CancelQueueAction + else { + CancelEventConfig cancelConfig = new CancelEventConfig(); + cancelConfig.setQueueDomain(matchedConfig.QueueDomain); + cancelConfig.setEventId(matchedConfig.EventId); + cancelConfig.setCookieDomain(matchedConfig.CookieDomain); + cancelConfig.setVersion(customerIntegrationInfo.Version); + + return cancelRequestByLocalConfig( + currentUrlWithoutQueueITToken, queueitToken, cancelConfig, customerId, request, response, secretKey, debugEntries); + } + } + finally { + setDebugCookie(debugEntries, request, response); + } } - public static RequestValidationResult validateRequestByLocalEventConfig(String targetUrl, String queueitToken, EventConfig eventConfig, + public static RequestValidationResult cancelRequestByLocalConfig( + String targetUrl, String queueitToken, CancelEventConfig cancelConfig, + String customerId, HttpServletRequest request, + HttpServletResponse response, String secretKey) throws Exception { + + Map debugEntries = new HashMap<>(); + + try { + return cancelRequestByLocalConfig( + targetUrl, queueitToken, cancelConfig, customerId, request, response, secretKey, debugEntries); + } + finally { + setDebugCookie(debugEntries, request, response); + } + } + + private static RequestValidationResult cancelRequestByLocalConfig( + String targetUrl, String queueitToken, CancelEventConfig cancelConfig, + String customerId, HttpServletRequest request, + HttpServletResponse response, String secretKey, + Map debugEntries) throws Exception { + + boolean isDebug = getIsDebug(queueitToken, secretKey); + if (isDebug) { + debugEntries.put("targetUrl", targetUrl); + debugEntries.put("queueitToken", queueitToken); + debugEntries.put("cancelConfig", cancelConfig != null ? cancelConfig.toString() : "NULL"); + debugEntries.put("OriginalURL", request.getRequestURL().toString()); + } + + if (Utils.isNullOrWhiteSpace(targetUrl)) { + throw new Exception("targetUrl can not be null or empty."); + } + if (Utils.isNullOrWhiteSpace(customerId)) { + throw new Exception("customerId can not be null or empty."); + } + if (Utils.isNullOrWhiteSpace(secretKey)) { + throw new Exception("secretKey can not be null or empty."); + } + if (cancelConfig == null) { + throw new Exception("cancelConfig can not be null."); + } + if (Utils.isNullOrWhiteSpace(cancelConfig.getEventId())) { + throw new Exception("EventId from cancelConfig can not be null or empty."); + } + if (Utils.isNullOrWhiteSpace(cancelConfig.getQueueDomain())) { + throw new Exception("QueueDomain from cancelConfig can not be null or empty."); + } + + IUserInQueueService userInQueueService = createUserInQueueService(request, response); + return userInQueueService.validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey); + } + + public static RequestValidationResult resolveQueueRequestByLocalConfig( + String targetUrl, String queueitToken, QueueEventConfig queueConfig, String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey) throws Exception { + Map debugEntries = new HashMap<>(); + + try { + return resolveQueueRequestByLocalConfig( + targetUrl, queueitToken, queueConfig, customerId, request, response, secretKey, debugEntries); + } + finally { + setDebugCookie(debugEntries, request, response); + } + } + + private static RequestValidationResult resolveQueueRequestByLocalConfig( + String targetUrl, String queueitToken, QueueEventConfig queueConfig, + String customerId, HttpServletRequest request, + HttpServletResponse response, String secretKey, + Map debugEntries) throws Exception { + + boolean isDebug = getIsDebug(queueitToken, secretKey); + if (isDebug) { + debugEntries.put("targetUrl", targetUrl); + debugEntries.put("queueitToken", queueitToken); + debugEntries.put("queueConfig", queueConfig != null ? queueConfig.toString() : "NULL"); + debugEntries.put("OriginalURL", request.getRequestURL().toString()); + } + if (Utils.isNullOrWhiteSpace(customerId)) { throw new Exception("customerId can not be null or empty."); } if (Utils.isNullOrWhiteSpace(secretKey)) { throw new Exception("secretKey can not be null or empty."); } - if (eventConfig == null) { + if (queueConfig == null) { throw new Exception("eventConfig can not be null."); } - if (Utils.isNullOrWhiteSpace(eventConfig.getEventId())) { - throw new Exception("EventId from eventConfig can not be null or empty."); + if (Utils.isNullOrWhiteSpace(queueConfig.getEventId())) { + throw new Exception("EventId from queueConfig can not be null or empty."); } - if (Utils.isNullOrWhiteSpace(eventConfig.getQueueDomain())) { - throw new Exception("QueueDomain from eventConfig can not be null or empty."); + if (Utils.isNullOrWhiteSpace(queueConfig.getQueueDomain())) { + throw new Exception("QueueDomain from queueConfig can not be null or empty."); } - if (eventConfig.getCookieValidityMinute() <= 0) { - throw new Exception("cookieValidityMinute from eventConfig should be greater than 0."); + if (queueConfig.getCookieValidityMinute() <= 0) { + throw new Exception("cookieValidityMinute from queueConfig should be greater than 0."); } if (queueitToken == null) { queueitToken = ""; } IUserInQueueService userInQueueService = createUserInQueueService(request, response); - return userInQueueService.validateRequest(targetUrl, queueitToken, eventConfig, customerId, secretKey); - } - - public static void cancelQueueCookie(String eventId, - String cookieDomain, - HttpServletRequest request, - HttpServletResponse response) throws Exception { - - if (Utils.isNullOrWhiteSpace(eventId)) { - throw new Exception("eventId can not be null or empty."); - } - - IUserInQueueService userInQueueService = createUserInQueueService(request, response); - userInQueueService.cancelQueueCookie(eventId, cookieDomain); + return userInQueueService.validateQueueRequest(targetUrl, queueitToken, queueConfig, customerId, secretKey); } public static void extendQueueCookie(String eventId, @@ -135,6 +241,30 @@ public static void extendQueueCookie(String eventId, IUserInQueueService userInQueueService = createUserInQueueService(request, response); userInQueueService.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey); } + + private static void setDebugCookie(Map debugEntries, HttpServletRequest request, HttpServletResponse response) { + if(debugEntries.isEmpty()) + return; + + ICookieManager cookieManager = new CookieManager(request, response); + String cookieValue = ""; + for (Map.Entry entry : debugEntries.entrySet()) { + cookieValue += (entry.getKey() + "=" + entry.getValue() + "&"); + } + if(!"".equals(cookieValue)) + cookieValue = cookieValue.substring(0, cookieValue.length() - 1); // remove trailing & + cookieManager.setCookie(QueueITDebugKey, cookieValue, null, null); + } + + private static boolean getIsDebug(String queueitToken, String secretKey) throws Exception + { + QueueUrlParams qParams = QueueParameterHelper.extractQueueParams(queueitToken); + if (qParams != null && qParams.getRedirectType() != null && "debug".equals(qParams.getRedirectType().toLowerCase())) { + String hash = HashHelper.generateSHA256Hash(secretKey, qParams.getQueueITTokenWithoutHash()); + return qParams.getHashCode().equals(hash); + } + return false; + } } class CookieManager implements ICookieManager { @@ -149,13 +279,17 @@ public CookieManager(HttpServletRequest request, } @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { + if(response == null) + return; + Cookie cookie = new Cookie(cookieName, cookieValue); if (cookieValue == null) { cookieValue = ""; } cookie.setValue(cookieValue); - cookie.setMaxAge(expiration); + if(expiration != null) + cookie.setMaxAge(expiration); cookie.setPath("/"); if (!Utils.isNullOrWhiteSpace(cookieDomain)) { cookie.setDomain(cookieDomain); @@ -167,6 +301,9 @@ public void setCookie(String cookieName, String cookieValue, int expiration, Str @Override public String getCookie(String cookieName) { + if(request == null) + return null; + Cookie[] cookies = request.getCookies(); if (cookies == null) { return null; diff --git a/SDK/src/queueit/knownuserv3/sdk/EventConfig.java b/SDK/src/queueit/knownuserv3/sdk/QueueEventConfig.java similarity index 77% rename from SDK/src/queueit/knownuserv3/sdk/EventConfig.java rename to SDK/src/queueit/knownuserv3/sdk/QueueEventConfig.java index 7803014..0be6523 100644 --- a/SDK/src/queueit/knownuserv3/sdk/EventConfig.java +++ b/SDK/src/queueit/knownuserv3/sdk/QueueEventConfig.java @@ -1,6 +1,6 @@ package queueit.knownuserv3.sdk; -public class EventConfig { +public class QueueEventConfig { private String eventId; private String layoutName; @@ -75,7 +75,19 @@ public void setVersion(int version) { this.version = version; } - public EventConfig() { + public QueueEventConfig() { this.version = -1; } + + @Override + public String toString() { + return "EventId:" + eventId + + "&Version:" + version + + "&QueueDomain:" + queueDomain + + "&CookieDomain:" + cookieDomain + + "&ExtendCookieValidity:" + extendCookieValidity + + "&CookieValidityMinute:" + cookieValidityMinute + + "&LayoutName:" + layoutName + + "&Culture:" + culture; + } } diff --git a/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java b/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java index bc621f9..1ac463a 100644 --- a/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java +++ b/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java @@ -35,8 +35,8 @@ class QueueParameterHelper { public static final String CookieValidityMinuteKey = "cv"; public static final String HashKey = "h"; public static final String QueueIdKey = "q"; - - public static final String EventIdKey = "e"; + public static final String RedirectTypeKey = "rt"; + public static final String EventIdKey = "e"; public static final String KeyValueSeparatorChar = "_"; public static final String KeyValueSeparatorGroupChar = "~"; @@ -76,15 +76,15 @@ public static QueueUrlParams extractQueueParams(String queueitToken) { case QueueIdKey: result.setQueueId(keyValueArr[1]); break; - case ExtendableCookieKey: { - + case ExtendableCookieKey: result.setExtendableCookie(Boolean.parseBoolean(keyValueArr[1])); - break; - } + break; case HashKey: result.setHashCode(keyValueArr[1]); break; - + case RedirectTypeKey: + result.setRedirectType(keyValueArr[1]); + break; } } String queueITTokenWithoutHash = result.getQueueITToken().replace(KeyValueSeparatorGroupChar + HashKey + KeyValueSeparatorChar + result.getHashCode(), ""); @@ -124,6 +124,7 @@ class QueueUrlParams { private Integer cookieValidityMinute; private long timeStamp; private String queueId; + private String redirectType; public QueueUrlParams(){ this.eventId = ""; @@ -199,4 +200,12 @@ public void setQueueId(String queueId) { public String getQueueId() { return this.queueId; } + + public void setRedirectType(String redirectType) { + this.redirectType = redirectType; + } + + public String getRedirectType() { + return this.redirectType; + } } diff --git a/SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java b/SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java index 1cd8968..34305fb 100644 --- a/SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java +++ b/SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java @@ -2,16 +2,22 @@ public class RequestValidationResult { + private String actionType; private String eventId; private String redirectUrl; private String queueId; - public RequestValidationResult(String eventId, String queueId, String redirectUrl) { + public RequestValidationResult(String actionType, String eventId, String queueId, String redirectUrl) { + this.actionType = actionType; this.eventId = eventId; this.queueId = queueId; this.redirectUrl = redirectUrl; } + public String getActionType() { + return actionType; + } + public String getEventId() { return eventId; } diff --git a/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java b/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java index 6f8d9ba..1132ddf 100644 --- a/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java +++ b/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java @@ -6,15 +6,19 @@ interface IUserInQueueService { - RequestValidationResult validateRequest( + RequestValidationResult validateQueueRequest( String targetUrl, String queueitToken, - EventConfig config, + QueueEventConfig config, String customerId, String secretKey) throws Exception; - void cancelQueueCookie(String eventId, String cookieDomain); - + RequestValidationResult validateCancelRequest( + String targetUrl, + CancelEventConfig config, + String customerId, + String secretKey) throws Exception; + void extendQueueCookie( String eventId, int cookieValidityMinute, @@ -25,7 +29,7 @@ void extendQueueCookie( class UserInQueueService implements IUserInQueueService { - public static final String SDK_VERSION = "1.0.0.0"; + public static final String SDK_VERSION = "3.2.0"; private final IUserInQueueStateRepository _userInQueueStateRepository; public UserInQueueService( @@ -34,10 +38,10 @@ public UserInQueueService( } @Override - public RequestValidationResult validateRequest( + public RequestValidationResult validateQueueRequest( String targetUrl, String queueitToken, - EventConfig config, + QueueEventConfig config, String customerId, String secretKey ) throws Exception { @@ -51,7 +55,7 @@ public RequestValidationResult validateRequest( config.getCookieValidityMinute(), secretKey); } - return new RequestValidationResult(config.getEventId(), stateInfo.getQueueId(), null); + return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), stateInfo.getQueueId(), null); } QueueUrlParams queueParmas = QueueParameterHelper.extractQueueParams(queueitToken); @@ -66,7 +70,7 @@ public RequestValidationResult validateRequest( private RequestValidationResult getQueueITTokenValidationResult( String targetUrl, String eventId, - EventConfig config, + QueueEventConfig config, QueueUrlParams queueParams, String customerId, String secretKey) throws Exception { @@ -91,17 +95,17 @@ private RequestValidationResult getQueueITTokenValidationResult( queueParams.getCookieValidityMinute() != null ? queueParams.getCookieValidityMinute() : config.getCookieValidityMinute(), secretKey); - return new RequestValidationResult(config.getEventId(), queueParams.getQueueId(), null); + return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), queueParams.getQueueId(), null); } private RequestValidationResult getVaidationErrorResult( String customerId, String targetUrl, - EventConfig config, + QueueEventConfig config, QueueUrlParams qParams, String errorCode) throws Exception { - String query = getQueryString(customerId, config) + String query = getQueryString(customerId, config.getEventId(), config.getVersion(), config.getCulture(), config.getLayoutName()) + "&queueittoken=" + qParams.getQueueITToken() + "&ts=" + System.currentTimeMillis() / 1000L; if(!Utils.isNullOrWhiteSpace(targetUrl)) @@ -113,49 +117,46 @@ private RequestValidationResult getVaidationErrorResult( domainAlias = domainAlias + "/"; } String redirectUrl = "https://" + domainAlias + "error/" + errorCode + "?" + query; - return new RequestValidationResult(config.getEventId(), null, redirectUrl); + return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), null, redirectUrl); } private RequestValidationResult getInQueueRedirectResult( String targetUrl, - EventConfig config, + QueueEventConfig config, String customerId) throws Exception { String redirectUrl = "https://" + config.getQueueDomain() + "?" - + getQueryString(customerId, config); - if(!Utils.isNullOrWhiteSpace(targetUrl)) - { + + getQueryString(customerId, config.getEventId(), config.getVersion(), config.getCulture(), config.getLayoutName()); + if(!Utils.isNullOrWhiteSpace(targetUrl)) { redirectUrl += "&t=" + URLEncoder.encode(targetUrl, "UTF-8"); } - return new RequestValidationResult(config.getEventId(), null, redirectUrl); + return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), null, redirectUrl); } private String getQueryString( String customerId, - EventConfig config) throws Exception { + String eventId, + int configVersion, + String culture, + String layoutName) throws Exception { ArrayList queryStringList = new ArrayList<>(); queryStringList.add("c=" + URLEncoder.encode(customerId, "UTF-8")); - queryStringList.add("e=" + URLEncoder.encode(config.getEventId(), "UTF-8")); + queryStringList.add("e=" + URLEncoder.encode(eventId, "UTF-8")); queryStringList.add("ver=v3-java-" + URLEncoder.encode(SDK_VERSION, "UTF-8")); - queryStringList.add("cver=" + URLEncoder.encode(String.valueOf(config.getVersion()), "UTF-8")); + queryStringList.add("cver=" + URLEncoder.encode(String.valueOf(configVersion), "UTF-8")); - if (!Utils.isNullOrWhiteSpace(config.getCulture())) { - queryStringList.add("cid=" + URLEncoder.encode(config.getCulture(), "UTF-8")); + if (!Utils.isNullOrWhiteSpace(culture)) { + queryStringList.add("cid=" + URLEncoder.encode(culture, "UTF-8")); } - if (!Utils.isNullOrWhiteSpace(config.getLayoutName())) { - queryStringList.add("l=" + URLEncoder.encode(config.getLayoutName(), "UTF-8")); + if (!Utils.isNullOrWhiteSpace(layoutName)) { + queryStringList.add("l=" + URLEncoder.encode(layoutName, "UTF-8")); } return String.join("&", queryStringList); } - - @Override - public void cancelQueueCookie(String eventId, String cookieDomain) { - this._userInQueueStateRepository.cancelQueueCookie(eventId, cookieDomain); - } - + @Override public void extendQueueCookie( String eventId, @@ -164,4 +165,32 @@ public void extendQueueCookie( String secretKey) { this._userInQueueStateRepository.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey); } + + @Override + public RequestValidationResult validateCancelRequest( + String targetUrl, CancelEventConfig config, String customerId, String secretKey) throws Exception { + + StateInfo state = _userInQueueStateRepository.getState(config.getEventId(), secretKey); + + if (state.isValid()) { + this._userInQueueStateRepository.cancelQueueCookie(config.getEventId(), config.getCookieDomain()); + + String query = getQueryString(customerId, config.getEventId(), config.getVersion(), null, null); + + if(targetUrl != null) + query += "&r=" + URLEncoder.encode(targetUrl, "UTF-8"); + + String domainAlias = config.getQueueDomain(); + if (!domainAlias.endsWith("/")) + domainAlias = domainAlias + "/"; + + String redirectUrl = "https://" + domainAlias + "cancel/" + customerId + "/" + config.getEventId() + "/?" + query; + + return new RequestValidationResult(ActionType.CANCEL_ACTION, config.getEventId(), state.getQueueId(), redirectUrl); + } + else + { + return new RequestValidationResult(ActionType.CANCEL_ACTION, config.getEventId(), null, null); + } + } } diff --git a/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java b/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java index f8669e1..c8e9a98 100644 --- a/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java +++ b/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java @@ -155,9 +155,7 @@ public void cancelQueueCookie( String eventId, String cookieDomain) { String cookieKey = getCookieKey(eventId); - if (cookieManager.getCookie(cookieKey) != null) { - cookieManager.setCookie(cookieKey, null, 0, cookieDomain); - } + cookieManager.setCookie(cookieKey, null, 0, cookieDomain); } @Override @@ -187,8 +185,7 @@ public void extendQueueCookie( interface ICookieManager { - void setCookie(String cookieName, String cookieValue, int maxAg, String cookieDomain); - + void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain); String getCookie(String cookieName); } diff --git a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java b/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java index aedeb7c..4cf7390 100644 --- a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java +++ b/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java @@ -7,10 +7,11 @@ public class IntegrationConfigModel { public String CookieDomain; public String LayoutName; public String Culture; - public boolean ExtendCookieValidity; - public int CookieValidityMinute; + public Boolean ExtendCookieValidity; + public Integer CookieValidityMinute; public String QueueDomain; public String RedirectLogic; public String ForcedTargetUrl; + public String ActionType; public TriggerModel[] Triggers; } diff --git a/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java b/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java index a3da65f..46db154 100644 --- a/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java @@ -2,6 +2,7 @@ import java.io.BufferedReader; import java.io.IOException; +import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.security.Principal; import java.util.ArrayList; @@ -15,6 +16,7 @@ import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.Cookie; @@ -34,12 +36,12 @@ public class KnownUserTest { class UserInQueueServiceMock implements IUserInQueueService { - public ArrayList> validateRequestCalls = new ArrayList<>(); - public ArrayList> cancelQueueCookieCalls = new ArrayList<>(); + public ArrayList> validateQueueRequestCalls = new ArrayList<>(); + public ArrayList> validateCancelRequestCalls = new ArrayList<>(); public ArrayList> extendQueueCookieCalls = new ArrayList<>(); @Override - public RequestValidationResult validateRequest(String targetUrl, String queueitToken, EventConfig config, String customerId, String secretKey) throws Exception { + public RequestValidationResult validateQueueRequest(String targetUrl, String queueitToken, QueueEventConfig config, String customerId, String secretKey) throws Exception { ArrayList args = new ArrayList<>(); args.add(targetUrl); args.add(queueitToken); @@ -53,19 +55,31 @@ public RequestValidationResult validateRequest(String targetUrl, String queueitT + config.getVersion()); args.add(customerId); args.add(secretKey); - validateRequestCalls.add(args); + validateQueueRequestCalls.add(args); return null; } @Override - public void cancelQueueCookie(String eventId, String cookieDomain) { + public RequestValidationResult validateCancelRequest( + String targetUrl, + CancelEventConfig config, + String customerId, + String secretKey) throws Exception { + ArrayList args = new ArrayList<>(); - args.add(eventId); - args.add(cookieDomain); - cancelQueueCookieCalls.add(args); - } + args.add(targetUrl); + args.add(config.getCookieDomain() + ":" + + config.getEventId() + ":" + + config.getQueueDomain() + ":" + + config.getVersion()); + args.add(customerId); + args.add(secretKey); + validateCancelRequestCalls.add(args); + return null; + } + @Override public void extendQueueCookie(String eventId, int cookieValidityMinute, String cookieDomain, String secretKey) { ArrayList args = new ArrayList<>(); @@ -78,38 +92,177 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void cancelQueueCookieTest() throws Exception { + public void cancelRequestByLocalConfigTest() throws Exception { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser.setUserInQueueService(mock); + CancelEventConfig cancelEventConfig = new CancelEventConfig(); + cancelEventConfig.setCookieDomain("cookiedomain"); + cancelEventConfig.setEventId("eventid"); + cancelEventConfig.setQueueDomain("queuedomain"); + cancelEventConfig.setVersion(1); + + // Act + KnownUser.cancelRequestByLocalConfig("url", "queueitToken", cancelEventConfig,"customerid",null, null, "secretkey"); + // Assert + assertTrue("url".equals(mock.validateCancelRequestCalls.get(0).get(0))); + assertTrue("cookiedomain:eventid:queuedomain:1".equals(mock.validateCancelRequestCalls.get(0).get(1))); + assertTrue("customerid".equals(mock.validateCancelRequestCalls.get(0).get(2))); + assertTrue("secretkey".equals(mock.validateCancelRequestCalls.get(0).get(3))); + } + + @Test + public void cancelRequestByLocalConfigDebugCookieLoggingTest() throws Exception { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); + CancelEventConfig cancelEventConfig = new CancelEventConfig(); + cancelEventConfig.setCookieDomain("cookiedomain"); + cancelEventConfig.setEventId("eventid"); + cancelEventConfig.setQueueDomain("queuedomain"); + cancelEventConfig.setVersion(1); + + HttpServletRequestMock requestMock = new HttpServletRequestMock(); + requestMock.RequestURL = "requestUrl"; + + HttpServletResponseMock responseMock = new HttpServletResponseMock(); + // Act - KnownUser.cancelQueueCookie("eventId", "cookieDomain", null, null); + String secretKey = "secretkey"; + String queueittoken = QueueITTokenGenerator.generateToken("eventId", secretKey); + + KnownUser.cancelRequestByLocalConfig("url", queueittoken, cancelEventConfig, "customerId", requestMock, responseMock, secretKey); // Assert - assertTrue("eventId".equals(mock.cancelQueueCookieCalls.get(0).get(0))); - assertTrue("cookieDomain".equals(mock.cancelQueueCookieCalls.get(0).get(1))); + String expectedCookieValue = "cancelConfig=EventId:eventid&Version:1&QueueDomain:queuedomain&CookieDomain:cookiedomain&OriginalURL=requestUrl&queueitToken=" + queueittoken + "&targetUrl=url"; + + assertTrue(responseMock.addedCookies.size() == 1); + assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey)); + assertTrue(responseMock.addedCookies.get(0).getValue().equals(expectedCookieValue)); } @Test - public void cancelQueueCookieNullEventIdTest() { + public void cancelRequestByLocalConfigNullQueueDomainTest() { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); + boolean exceptionWasThrown = false; + CancelEventConfig cancelEventConfig = new CancelEventConfig(); + cancelEventConfig.setEventId("eventid"); + cancelEventConfig.setCookieDomain("cookieDomain"); + cancelEventConfig.setVersion(12); + + // Act + try { + KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", cancelEventConfig, "customerId", null, null, "secretKey"); + } catch (Exception ex) { + exceptionWasThrown = "QueueDomain from cancelConfig can not be null or empty.".equals(ex.getMessage()); + } + + // Assert + assertTrue(mock.validateCancelRequestCalls.isEmpty()); + assertTrue(exceptionWasThrown); + } + + @Test + public void cancelRequestByLocalConfigEventIdNullTest() { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser.setUserInQueueService(mock); boolean exceptionWasThrown = false; + CancelEventConfig cancelEventConfig = new CancelEventConfig(); + cancelEventConfig.setCookieDomain("domain"); + cancelEventConfig.setVersion(12); + + // Act + try { + KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", cancelEventConfig, "customerId", null, null, "secretKey"); + } catch (Exception ex) { + exceptionWasThrown = "EventId from cancelConfig can not be null or empty.".equals(ex.getMessage()); + } + // Assert + assertTrue(mock.validateCancelRequestCalls.isEmpty()); + assertTrue(exceptionWasThrown); + } + + @Test + public void cancelRequestByLocalConfigCancelEventConfigNullTest() { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); + boolean exceptionWasThrown = false; + // Act try { - KnownUser.cancelQueueCookie(null, null, null, null); + KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId", null, null, "secretKey"); } catch (Exception ex) { - exceptionWasThrown = "eventId can not be null or empty.".equals(ex.getMessage()); + exceptionWasThrown = "cancelConfig can not be null.".equals(ex.getMessage()); + } + + // Assert + assertTrue(mock.validateCancelRequestCalls.isEmpty()); + assertTrue(exceptionWasThrown); + } + + @Test + public void cancelRequestByLocalConfigCustomerIdNullTest() { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); + boolean exceptionWasThrown = false; + + // Act + try { + KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", new CancelEventConfig(), null, null, null, "secretKey"); + } catch (Exception ex) { + exceptionWasThrown = "customerId can not be null or empty.".equals(ex.getMessage()); + } + + // Assert + assertTrue(mock.validateCancelRequestCalls.isEmpty()); + assertTrue(exceptionWasThrown); + } + + @Test + public void cancelRequestByLocalConfigSecretKeyNullTest() { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); + boolean exceptionWasThrown = false; + + // Act + try { + KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", new CancelEventConfig(), "customerId", null, null, null); + } catch (Exception ex) { + exceptionWasThrown = "secretKey can not be null or empty.".equals(ex.getMessage()); } // Assert - assertTrue(mock.cancelQueueCookieCalls.isEmpty()); + assertTrue(mock.validateCancelRequestCalls.isEmpty()); assertTrue(exceptionWasThrown); } + + @Test + public void CancelRequestByLocalConfigTargetUrlNullTest() { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); + boolean exceptionWasThrown = false; + + // Act + try { + KnownUser.cancelRequestByLocalConfig(null, "queueitToken", new CancelEventConfig(), "customerId", null, null, "secretKey"); + } catch (Exception ex) { + exceptionWasThrown = "targetUrl can not be null or empty.".equals(ex.getMessage()); + } + // Assert + assertTrue(mock.validateCancelRequestCalls.isEmpty()); + assertTrue(exceptionWasThrown); + } + @Test public void extendQueueCookieNullEventIdTest() { // Arrange @@ -184,7 +337,7 @@ public void extendQueueCookieTest() throws Exception { } @Test - public void validateRequestByLocalEventConfigNullCustomerIdTest() { + public void resolveQueueRequestByLocalConfigNullCustomerIdTest() { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser.setUserInQueueService(mock); @@ -192,18 +345,18 @@ public void validateRequestByLocalEventConfigNullCustomerIdTest() { // Act try { - KnownUser.validateRequestByLocalEventConfig("targetUrl", "queueitToken", null, null, null, null, "secretKey"); + KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, null, null, null, "secretKey"); } catch (Exception ex) { exceptionWasThrown = "customerId can not be null or empty.".equals(ex.getMessage()); } // Assert - assertTrue(mock.validateRequestCalls.isEmpty()); + assertTrue(mock.validateQueueRequestCalls.isEmpty()); assertTrue(exceptionWasThrown); } @Test - public void validateRequestByLocalEventConfigNullSecretKeyTest() { + public void resolveQueueRequestByLocalConfigNullSecretKeyTest() { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser.setUserInQueueService(mock); @@ -211,18 +364,18 @@ public void validateRequestByLocalEventConfigNullSecretKeyTest() { // Act try { - KnownUser.validateRequestByLocalEventConfig("targetUrl", "queueitToken", null, "customerId", null, null, null); + KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId", null, null, null); } catch (Exception ex) { exceptionWasThrown = "secretKey can not be null or empty.".equals(ex.getMessage()); } // Assert - assertTrue(mock.validateRequestCalls.isEmpty()); + assertTrue(mock.validateQueueRequestCalls.isEmpty()); assertTrue(exceptionWasThrown); } @Test - public void validateRequestByLocalEventConfigNullEventConfigTest() { + public void resolveQueueRequestByLocalConfigNullEventConfigTest() { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser.setUserInQueueService(mock); @@ -230,24 +383,24 @@ public void validateRequestByLocalEventConfigNullEventConfigTest() { // Act try { - KnownUser.validateRequestByLocalEventConfig("targetUrl", "queueitToken", null, "customerId", null, null, "secretKey"); + KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId", null, null, "secretKey"); } catch (Exception ex) { exceptionWasThrown = "eventConfig can not be null.".equals(ex.getMessage()); } // Assert - assertTrue(mock.validateRequestCalls.isEmpty()); + assertTrue(mock.validateQueueRequestCalls.isEmpty()); assertTrue(exceptionWasThrown); } @Test - public void validateRequestByLocalEventConfigNullEventIdTest() { + public void resolveQueueRequestByLocalConfigNullEventIdTest() { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser.setUserInQueueService(mock); boolean exceptionWasThrown = false; - EventConfig eventConfig = new EventConfig(); + QueueEventConfig eventConfig = new QueueEventConfig(); eventConfig.setCookieDomain("cookieDomain"); eventConfig.setLayoutName("layoutName"); eventConfig.setCulture("culture"); @@ -259,24 +412,24 @@ public void validateRequestByLocalEventConfigNullEventIdTest() { // Act try { - KnownUser.validateRequestByLocalEventConfig("targetUrl", "queueitToken", eventConfig, "customerId", null, null, "secretKey"); + KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId", null, null, "secretKey"); } catch (Exception ex) { - exceptionWasThrown = "EventId from eventConfig can not be null or empty.".equals(ex.getMessage()); + exceptionWasThrown = "EventId from queueConfig can not be null or empty.".equals(ex.getMessage()); } // Assert - assertTrue(mock.validateRequestCalls.isEmpty()); + assertTrue(mock.validateQueueRequestCalls.isEmpty()); assertTrue(exceptionWasThrown); } @Test - public void validateRequestByLocalEventConfigNullQueueDomainTest() { + public void resolveQueueRequestByLocalConfigNullQueueDomainTest() { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser.setUserInQueueService(mock); boolean exceptionWasThrown = false; - EventConfig eventConfig = new EventConfig(); + QueueEventConfig eventConfig = new QueueEventConfig(); eventConfig.setCookieDomain("cookieDomain"); eventConfig.setLayoutName("layoutName"); eventConfig.setCulture("culture"); @@ -288,24 +441,24 @@ public void validateRequestByLocalEventConfigNullQueueDomainTest() { // Act try { - KnownUser.validateRequestByLocalEventConfig("targetUrl", "queueitToken", eventConfig, "customerId", null, null, "secretKey"); + KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId", null, null, "secretKey"); } catch (Exception ex) { - exceptionWasThrown = "QueueDomain from eventConfig can not be null or empty.".equals(ex.getMessage()); + exceptionWasThrown = "QueueDomain from queueConfig can not be null or empty.".equals(ex.getMessage()); } // Assert - assertTrue(mock.validateRequestCalls.isEmpty()); + assertTrue(mock.validateQueueRequestCalls.isEmpty()); assertTrue(exceptionWasThrown); } @Test - public void validateRequestByLocalEventConfigInvalidCookieValidityMinuteTest() { + public void resolveQueueRequestByLocalConfigInvalidCookieValidityMinuteTest() { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser.setUserInQueueService(mock); boolean exceptionWasThrown = false; - EventConfig eventConfig = new EventConfig(); + QueueEventConfig eventConfig = new QueueEventConfig(); eventConfig.setCookieDomain("cookieDomain"); eventConfig.setLayoutName("layoutName"); eventConfig.setCulture("culture"); @@ -317,23 +470,23 @@ public void validateRequestByLocalEventConfigInvalidCookieValidityMinuteTest() { // Act try { - KnownUser.validateRequestByLocalEventConfig("targetUrl", "queueitToken", eventConfig, "customerId", null, null, "secretKey"); + KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId", null, null, "secretKey"); } catch (Exception ex) { - exceptionWasThrown = "cookieValidityMinute from eventConfig should be greater than 0.".equals(ex.getMessage()); + exceptionWasThrown = "cookieValidityMinute from queueConfig should be greater than 0.".equals(ex.getMessage()); } // Assert - assertTrue(mock.validateRequestCalls.isEmpty()); + assertTrue(mock.validateQueueRequestCalls.isEmpty()); assertTrue(exceptionWasThrown); } @Test - public void validateRequestByLocalEventConfigTest() throws Exception { + public void resolveQueueRequestByLocalConfigTest() throws Exception { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser.setUserInQueueService(mock); - EventConfig eventConfig = new EventConfig(); + QueueEventConfig eventConfig = new QueueEventConfig(); eventConfig.setCookieDomain("cookieDomain"); eventConfig.setLayoutName("layoutName"); eventConfig.setCulture("culture"); @@ -344,16 +497,51 @@ public void validateRequestByLocalEventConfigTest() throws Exception { eventConfig.setVersion(12); // Act - KnownUser.validateRequestByLocalEventConfig("targetUrl", "queueitToken", eventConfig, "customerId", null, null, "secretKey"); + KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId", null, null, "secretKey"); // Assert - assertTrue("targetUrl".equals(mock.validateRequestCalls.get(0).get(0))); - assertTrue("queueitToken".equals(mock.validateRequestCalls.get(0).get(1))); - assertTrue("cookieDomain:layoutName:culture:eventId:queueDomain:true:10:12".equals(mock.validateRequestCalls.get(0).get(2))); - assertTrue("customerId".equals(mock.validateRequestCalls.get(0).get(3))); - assertTrue("secretKey".equals(mock.validateRequestCalls.get(0).get(4))); + assertTrue("targetUrl".equals(mock.validateQueueRequestCalls.get(0).get(0))); + assertTrue("queueitToken".equals(mock.validateQueueRequestCalls.get(0).get(1))); + assertTrue("cookieDomain:layoutName:culture:eventId:queueDomain:true:10:12".equals(mock.validateQueueRequestCalls.get(0).get(2))); + assertTrue("customerId".equals(mock.validateQueueRequestCalls.get(0).get(3))); + assertTrue("secretKey".equals(mock.validateQueueRequestCalls.get(0).get(4))); } + @Test + public void resolveQueueRequestByLocalConfigDebugCookieLoggingTest() throws Exception { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); + + QueueEventConfig queueConfig = new QueueEventConfig(); + queueConfig.setCookieDomain("cookieDomain"); + queueConfig.setLayoutName("layoutName"); + queueConfig.setCulture("culture"); + queueConfig.setEventId("eventId"); + queueConfig.setQueueDomain("queueDomain"); + queueConfig.setExtendCookieValidity(true); + queueConfig.setCookieValidityMinute(10); + queueConfig.setVersion(12); + + HttpServletRequestMock requestMock = new HttpServletRequestMock(); + requestMock.RequestURL = "requestUrl"; + + HttpServletResponseMock responseMock = new HttpServletResponseMock(); + + // Act + String secretKey = "secretkey"; + String queueittoken = QueueITTokenGenerator.generateToken("eventId", secretKey); + + KnownUser.resolveQueueRequestByLocalConfig("targetUrl", queueittoken, queueConfig, "customerId", requestMock, responseMock, secretKey); + + // Assert + String expectedCookieValue = "OriginalURL=requestUrl&queueConfig=EventId:eventId&Version:12&QueueDomain:queueDomain&CookieDomain:cookieDomain&ExtendCookieValidity:true&CookieValidityMinute:10&LayoutName:layoutName&Culture:culture&queueitToken=" +queueittoken + "&targetUrl=targetUrl"; + + assertTrue(responseMock.addedCookies.size() == 1); + assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey)); + assertTrue(responseMock.addedCookies.get(0).getValue().equals(expectedCookieValue)); + } + @Test public void validateRequestByIntegrationConfigEmptyCurrentUrlTest() { // Arrange @@ -369,7 +557,7 @@ public void validateRequestByIntegrationConfigEmptyCurrentUrlTest() { } // Assert - assertTrue(mock.validateRequestCalls.isEmpty()); + assertTrue(mock.validateQueueRequestCalls.isEmpty()); assertTrue(exceptionWasThrown); } @@ -388,7 +576,7 @@ public void validateRequestByIntegrationConfigEmptyIntegrationsConfigTest() { } // Assert - assertTrue(mock.validateRequestCalls.isEmpty()); + assertTrue(mock.validateQueueRequestCalls.isEmpty()); assertTrue(exceptionWasThrown); } @@ -419,7 +607,6 @@ public void validateRequestByIntegrationConfigTest() throws Exception { IntegrationConfigModel config = new IntegrationConfigModel(); config.Name = "event1action"; - //config.ActionType = "Queue"; config.EventId = "event1"; config.CookieDomain = ".test.com"; config.LayoutName = "Christmas Layout by Queue-it"; @@ -430,6 +617,7 @@ public void validateRequestByIntegrationConfigTest() throws Exception { config.QueueDomain = "knownusertest.queue-it.net"; config.RedirectLogic = "AllowTParameter"; config.ForcedTargetUrl = ""; + config.ActionType = ActionType.QUEUE_ACTION; CustomerIntegration customerIntegration = new CustomerIntegration(); customerIntegration.Integrations = new IntegrationConfigModel[]{config}; @@ -440,14 +628,77 @@ public void validateRequestByIntegrationConfigTest() throws Exception { KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", httpContextMock, null, "secretKey"); // Assert - assertTrue(mock.validateRequestCalls.size() == 1); - assertTrue("http://test.com?event1=true".equals(mock.validateRequestCalls.get(0).get(0))); - assertTrue("queueitToken".equals(mock.validateRequestCalls.get(0).get(1))); - assertTrue(".test.com:Christmas Layout by Queue-it:da-DK:event1:knownusertest.queue-it.net:true:20:3".equals(mock.validateRequestCalls.get(0).get(2))); - assertTrue("customerId".equals(mock.validateRequestCalls.get(0).get(3))); - assertTrue("secretKey".equals(mock.validateRequestCalls.get(0).get(4))); + assertTrue(mock.validateQueueRequestCalls.size() == 1); + assertTrue("http://test.com?event1=true".equals(mock.validateQueueRequestCalls.get(0).get(0))); + assertTrue("queueitToken".equals(mock.validateQueueRequestCalls.get(0).get(1))); + assertTrue(".test.com:Christmas Layout by Queue-it:da-DK:event1:knownusertest.queue-it.net:true:20:3".equals(mock.validateQueueRequestCalls.get(0).get(2))); + assertTrue("customerId".equals(mock.validateQueueRequestCalls.get(0).get(3))); + assertTrue("secretKey".equals(mock.validateQueueRequestCalls.get(0).get(4))); } + @Test + public void validateRequestByIntegrationConfigDebugCookieLoggingTest() throws Exception { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); + + TriggerPart triggerPart1 = new TriggerPart(); + triggerPart1.Operator = "Contains"; + triggerPart1.ValueToCompare = "event1"; + triggerPart1.UrlPart = "PageUrl"; + triggerPart1.ValidatorType = "UrlValidator"; + triggerPart1.IsNegative = false; + triggerPart1.IsIgnoreCase = true; + + TriggerPart triggerPart2 = new TriggerPart(); + triggerPart2.Operator = "Contains"; + triggerPart2.ValueToCompare = "googlebot"; + triggerPart2.ValidatorType = "UserAgentValidator"; + triggerPart2.IsNegative = false; + triggerPart2.IsIgnoreCase = false; + + TriggerModel trigger = new TriggerModel(); + trigger.LogicalOperator = "And"; + trigger.TriggerParts = new TriggerPart[]{triggerPart1,triggerPart2}; + + IntegrationConfigModel config = new IntegrationConfigModel(); + config.Name = "event1action"; + config.EventId = "event1"; + config.CookieDomain = ".test.com"; + config.LayoutName = "Christmas Layout by Queue-it"; + config.Culture = "da-DK"; + config.ExtendCookieValidity = true; + config.CookieValidityMinute = 20; + config.Triggers = new TriggerModel[]{trigger}; + config.QueueDomain = "knownusertest.queue-it.net"; + config.RedirectLogic = "AllowTParameter"; + config.ForcedTargetUrl = ""; + config.ActionType = ActionType.QUEUE_ACTION; + + CustomerIntegration customerIntegration = new CustomerIntegration(); + customerIntegration.Integrations = new IntegrationConfigModel[]{config}; + customerIntegration.Version = 3; + + HttpServletRequestMock requestMock = new HttpServletRequestMock(); + requestMock.UserAgent = "googlebot"; + requestMock.RequestURL = "requestUrl"; + + HttpServletResponseMock responseMock = new HttpServletResponseMock(); + + // Act + String secretKey = "secretkey"; + String queueittoken = QueueITTokenGenerator.generateToken("eventId", secretKey); + + KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", queueittoken, customerIntegration, "customerId", requestMock, responseMock, secretKey); + + // Assert + String expectedCookieValue = "OriginalURL=requestUrl&pureUrl=http://test.com?event1=true&configVersion=3&queueConfig=EventId:event1&Version:3&QueueDomain:knownusertest.queue-it.net&CookieDomain:.test.com&ExtendCookieValidity:true&CookieValidityMinute:20&LayoutName:Christmas Layout by Queue-it&Culture:da-DK&queueitToken=" + queueittoken + "&targetUrl=http://test.com?event1=true&matchedConfig=event1action"; + + assertTrue(responseMock.addedCookies.size() == 1); + assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey)); + assertTrue(responseMock.addedCookies.get(0).getValue().equals(expectedCookieValue)); + } + @Test public void validateRequestByIntegrationConfigNotMatchTest() throws Exception { // Arrange @@ -462,10 +713,39 @@ public void validateRequestByIntegrationConfigNotMatchTest() throws Exception { RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey"); // Assert - assertTrue(mock.validateRequestCalls.isEmpty()); + assertTrue(mock.validateQueueRequestCalls.isEmpty()); assertTrue(!result.doRedirect()); } + @Test + public void validateRequestByIntegrationConfigNotMatchDebugCookieLoggingTest() throws Exception { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); + + CustomerIntegration customerIntegration = new CustomerIntegration(); + customerIntegration.Integrations = new IntegrationConfigModel[0]; + customerIntegration.Version = 3; + + HttpServletRequestMock requestMock = new HttpServletRequestMock(); + requestMock.RequestURL = "requestUrl"; + + HttpServletResponseMock responseMock = new HttpServletResponseMock(); + + // Act + String secretKey = "secretkey"; + String queueittoken = QueueITTokenGenerator.generateToken("eventId", secretKey); + + KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", queueittoken, customerIntegration, "customerId", requestMock, responseMock, secretKey); + + // Assert + String expectedCookieValue = "OriginalURL=requestUrl&pureUrl=http://test.com?event1=true&configVersion=3&queueitToken=" + queueittoken + "&matchedConfig=NULL"; + + assertTrue(responseMock.addedCookies.size() == 1); + assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey)); + assertTrue(responseMock.addedCookies.get(0).getValue().equals(expectedCookieValue)); + } + @Test public void validateRequestByIntegrationConfigForcedTargeturlTest() throws Exception { // Arrange @@ -486,7 +766,6 @@ public void validateRequestByIntegrationConfigForcedTargeturlTest() throws Excep IntegrationConfigModel config = new IntegrationConfigModel(); config.Name = "event1action"; - //config.ActionType = "Queue"; config.EventId = "event1"; config.CookieDomain = ".test.com"; config.LayoutName = "Christmas Layout by Queue-it"; @@ -497,6 +776,7 @@ public void validateRequestByIntegrationConfigForcedTargeturlTest() throws Excep config.QueueDomain = "knownusertest.queue-it.net"; config.RedirectLogic = "ForcedTargetUrl"; config.ForcedTargetUrl = "http://forcedtargeturl.com"; + config.ActionType = ActionType.QUEUE_ACTION; CustomerIntegration customerIntegration = new CustomerIntegration(); customerIntegration.Integrations = new IntegrationConfigModel[]{config}; @@ -506,8 +786,8 @@ public void validateRequestByIntegrationConfigForcedTargeturlTest() throws Excep KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey"); // Assert - assertTrue(mock.validateRequestCalls.size() == 1); - assertTrue("http://forcedtargeturl.com".equals(mock.validateRequestCalls.get(0).get(0))); + assertTrue(mock.validateQueueRequestCalls.size() == 1); + assertTrue("http://forcedtargeturl.com".equals(mock.validateQueueRequestCalls.get(0).get(0))); } @Test @@ -530,7 +810,6 @@ public void validateRequestByIntegrationConfigForecedTargeturlTest() throws Exce IntegrationConfigModel config = new IntegrationConfigModel(); config.Name = "event1action"; - //config.ActionType = "Queue"; config.EventId = "event1"; config.CookieDomain = ".test.com"; config.LayoutName = "Christmas Layout by Queue-it"; @@ -541,6 +820,7 @@ public void validateRequestByIntegrationConfigForecedTargeturlTest() throws Exce config.QueueDomain = "knownusertest.queue-it.net"; config.RedirectLogic = "ForecedTargetUrl"; config.ForcedTargetUrl = "http://forcedtargeturl.com"; + config.ActionType = ActionType.QUEUE_ACTION; CustomerIntegration customerIntegration = new CustomerIntegration(); customerIntegration.Integrations = new IntegrationConfigModel[]{config}; @@ -550,8 +830,8 @@ public void validateRequestByIntegrationConfigForecedTargeturlTest() throws Exce KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey"); // Assert - assertTrue(mock.validateRequestCalls.size() == 1); - assertTrue("http://forcedtargeturl.com".equals(mock.validateRequestCalls.get(0).get(0))); + assertTrue(mock.validateQueueRequestCalls.size() == 1); + assertTrue("http://forcedtargeturl.com".equals(mock.validateQueueRequestCalls.get(0).get(0))); } @Test @@ -574,7 +854,6 @@ public void validateRequestByIntegrationConfigEventTargetUrl() throws Exception IntegrationConfigModel config = new IntegrationConfigModel(); config.Name = "event1action"; - //config.ActionType = "Queue"; config.EventId = "event1"; config.CookieDomain = ".test.com"; config.LayoutName = "Christmas Layout by Queue-it"; @@ -584,6 +863,7 @@ public void validateRequestByIntegrationConfigEventTargetUrl() throws Exception config.Triggers = new TriggerModel[]{trigger}; config.QueueDomain = "knownusertest.queue-it.net"; config.RedirectLogic = "EventTargetUrl"; + config.ActionType = ActionType.QUEUE_ACTION; CustomerIntegration customerIntegration = new CustomerIntegration(); customerIntegration.Integrations = new IntegrationConfigModel[]{config}; @@ -593,361 +873,606 @@ public void validateRequestByIntegrationConfigEventTargetUrl() throws Exception KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey"); // Assert - assertTrue(mock.validateRequestCalls.size() == 1); - assertTrue("".equals(mock.validateRequestCalls.get(0).get(0))); + assertTrue(mock.validateQueueRequestCalls.size() == 1); + assertTrue("".equals(mock.validateQueueRequestCalls.get(0).get(0))); } - -class HttpServletRequestMock implements HttpServletRequest -{ -public Cookie[] CookiesValue; -public String UserAgent; - @Override - public String getAuthType() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Test + public void validateRequestByIntegrationConfigCancelAction() throws Exception { + // Arrange + UserInQueueServiceMock mock = new UserInQueueServiceMock(); + KnownUser.setUserInQueueService(mock); - @Override - public Cookie[] getCookies() { - return this.CookiesValue; - } + TriggerPart triggerPart = new TriggerPart(); + triggerPart.Operator = "Contains"; + triggerPart.ValueToCompare = "event1"; + triggerPart.UrlPart = "PageUrl"; + triggerPart.ValidatorType = "UrlValidator"; + triggerPart.IsNegative = false; + triggerPart.IsIgnoreCase = true; - @Override - public long getDateHeader(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + TriggerModel trigger = new TriggerModel(); + trigger.LogicalOperator = "And"; + trigger.TriggerParts = new TriggerPart[]{triggerPart}; - @Override - public String getHeader(String key) { - if("User-Agent".equals(key)) - return this.UserAgent; - return ""; - } + IntegrationConfigModel config = new IntegrationConfigModel(); + config.Name = "event1action"; + config.EventId = "event1"; + config.CookieDomain = "cookiedomain"; + config.Triggers = new TriggerModel[]{trigger}; + config.QueueDomain = "queuedomain"; + config.ActionType = ActionType.CANCEL_ACTION; - @Override - public Enumeration getHeaders(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + CustomerIntegration customerIntegration = new CustomerIntegration(); + customerIntegration.Integrations = new IntegrationConfigModel[]{config}; + customerIntegration.Version = 3; - @Override - public Enumeration getHeaderNames() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + // Act + KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey"); - @Override - public int getIntHeader(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + // Assert + assertTrue("http://test.com?event1=true".equals(mock.validateCancelRequestCalls.get(0).get(0))); + assertTrue("cookiedomain:event1:queuedomain:3".equals(mock.validateCancelRequestCalls.get(0).get(1))); + assertTrue("customerId".equals(mock.validateCancelRequestCalls.get(0).get(2))); + assertTrue("secretKey".equals(mock.validateCancelRequestCalls.get(0).get(3))); } + + class HttpServletRequestMock implements HttpServletRequest { + public Cookie[] CookiesValue; + public String UserAgent; + public String RequestURL; - @Override - public String getMethod() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getAuthType() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getPathInfo() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Cookie[] getCookies() { + return this.CookiesValue; + } - @Override - public String getPathTranslated() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public long getDateHeader(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getContextPath() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getHeader(String key) { + if("User-Agent".equals(key)) + return this.UserAgent; + return ""; + } - @Override - public String getQueryString() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getHeaders(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRemoteUser() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getHeaderNames() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isUserInRole(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public int getIntHeader(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Principal getUserPrincipal() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getMethod() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRequestedSessionId() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getPathInfo() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRequestURI() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getPathTranslated() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public StringBuffer getRequestURL() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getContextPath() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getServletPath() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getQueryString() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public HttpSession getSession(boolean bln) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRemoteUser() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public HttpSession getSession() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isUserInRole(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String changeSessionId() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Principal getUserPrincipal() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isRequestedSessionIdValid() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRequestedSessionId() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isRequestedSessionIdFromCookie() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRequestURI() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isRequestedSessionIdFromURL() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public StringBuffer getRequestURL() { + return new StringBuffer(this.RequestURL); + } - @Override - public boolean isRequestedSessionIdFromUrl() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getServletPath() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean authenticate(HttpServletResponse hsr) throws IOException, ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public HttpSession getSession(boolean bln) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void login(String string, String string1) throws ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public HttpSession getSession() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void logout() throws ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String changeSessionId() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Collection getParts() throws IOException, ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isRequestedSessionIdValid() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Part getPart(String string) throws IOException, ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isRequestedSessionIdFromCookie() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public T upgrade(Class type) throws IOException, ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isRequestedSessionIdFromURL() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Object getAttribute(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isRequestedSessionIdFromUrl() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Enumeration getAttributeNames() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean authenticate(HttpServletResponse hsr) throws IOException, ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getCharacterEncoding() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void login(String string, String string1) throws ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void setCharacterEncoding(String string) throws UnsupportedEncodingException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void logout() throws ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public int getContentLength() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Collection getParts() throws IOException, ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public long getContentLengthLong() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Part getPart(String string) throws IOException, ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getContentType() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public T upgrade(Class type) throws IOException, ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public ServletInputStream getInputStream() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Object getAttribute(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getParameter(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getAttributeNames() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Enumeration getParameterNames() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getCharacterEncoding() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String[] getParameterValues(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void setCharacterEncoding(String string) throws UnsupportedEncodingException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Map getParameterMap() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public int getContentLength() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getProtocol() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public long getContentLengthLong() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getScheme() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getContentType() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getServerName() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public ServletInputStream getInputStream() throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public int getServerPort() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getParameter(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public BufferedReader getReader() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getParameterNames() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRemoteAddr() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String[] getParameterValues(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRemoteHost() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Map getParameterMap() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void setAttribute(String string, Object o) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getProtocol() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void removeAttribute(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getScheme() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Locale getLocale() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getServerName() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Enumeration getLocales() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public int getServerPort() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isSecure() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public BufferedReader getReader() throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public RequestDispatcher getRequestDispatcher(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRemoteAddr() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRealPath(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRemoteHost() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public int getRemotePort() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void setAttribute(String string, Object o) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getLocalName() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void removeAttribute(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getLocalAddr() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Locale getLocale() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public int getLocalPort() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getLocales() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public ServletContext getServletContext() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isSecure() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public AsyncContext startAsync() throws IllegalStateException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public RequestDispatcher getRequestDispatcher(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public AsyncContext startAsync(ServletRequest sr, ServletResponse sr1) throws IllegalStateException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRealPath(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isAsyncStarted() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public int getRemotePort() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isAsyncSupported() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getLocalName() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public AsyncContext getAsyncContext() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getLocalAddr() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int getLocalPort() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public ServletContext getServletContext() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public AsyncContext startAsync() throws IllegalStateException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public AsyncContext startAsync(ServletRequest sr, ServletResponse sr1) throws IllegalStateException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean isAsyncStarted() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public DispatcherType getDispatcherType() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + @Override + public boolean isAsyncSupported() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public AsyncContext getAsyncContext() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public DispatcherType getDispatcherType() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } } -} + + class HttpServletResponseMock implements HttpServletResponse { + ArrayList addedCookies = new ArrayList<>(); + + @Override + public void addCookie(Cookie cookie) { + addedCookies.add(cookie); + } + + @Override + public boolean containsHeader(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String encodeURL(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String encodeRedirectURL(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String encodeUrl(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String encodeRedirectUrl(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void sendError(int i, String string) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void sendError(int i) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void sendRedirect(String string) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setDateHeader(String string, long l) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void addDateHeader(String string, long l) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setHeader(String string, String string1) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void addHeader(String string, String string1) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setIntHeader(String string, int i) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void addIntHeader(String string, int i) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setStatus(int i) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setStatus(int i, String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int getStatus() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String getHeader(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Collection getHeaders(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Collection getHeaderNames() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String getCharacterEncoding() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String getContentType() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public ServletOutputStream getOutputStream() throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public PrintWriter getWriter() throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + @Override + public void setCharacterEncoding(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setContentLength(int i) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setContentLengthLong(long l) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setContentType(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setBufferSize(int i) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int getBufferSize() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void flushBuffer() throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void resetBuffer() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean isCommitted() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void reset() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setLocale(Locale locale) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Locale getLocale() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + } + + public static class QueueITTokenGenerator { + + public static String generateToken( + String eventId, + String secretKey) throws Exception { + + ArrayList paramList = new ArrayList<>(); + paramList.add(QueueParameterHelper.EventIdKey + QueueParameterHelper.KeyValueSeparatorChar + eventId); + paramList.add(QueueParameterHelper.RedirectTypeKey + QueueParameterHelper.KeyValueSeparatorChar + "debug"); + + String tokenWithoutHash = String.join(QueueParameterHelper.KeyValueSeparatorGroupChar, paramList); + String hash = HashHelper.generateSHA256Hash(secretKey, tokenWithoutHash); + String token = tokenWithoutHash + QueueParameterHelper.KeyValueSeparatorGroupChar + QueueParameterHelper.HashKey + QueueParameterHelper.KeyValueSeparatorChar + hash; + return token; + } + } } diff --git a/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java b/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java index 3fa06a9..144b51f 100644 --- a/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java @@ -8,16 +8,15 @@ import java.util.regex.Pattern; import static org.junit.Assert.assertTrue; import org.junit.Test; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class UserInQueueServiceTest { //ExtendableCookie Cookie @Test - public void validateRequest_ValidState_ExtendableCookie_NoCookieExtensionFromConfig_DoNotRedirectDoNotStoreCookieWithExtension() + public void validateQueueRequest_ValidState_ExtendableCookie_NoCookieExtensionFromConfig_DoNotRedirectDoNotStoreCookieWithExtension() throws Exception { - EventConfig config = new EventConfig(); + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e1"); config.setQueueDomain("testdomain.com"); config.setCookieValidityMinute(10); @@ -50,7 +49,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c }; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest("url", "token", config, "testCustomer", "key"); + RequestValidationResult result = testObject.validateQueueRequest("url", "token", config, "testCustomer", "key"); assertTrue(!result.doRedirect()); assertTrue(!conditions.get("isStoreWasCalled")); assertTrue(result.getEventId().equals("e1")); @@ -58,9 +57,9 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void validateRequest_ValidState_ExtendableCookie_CookieExtensionFromConfig_DoNotRedirectDoStoreCookieWithExtension() throws Exception { + public void validateQueueRequest_ValidState_ExtendableCookie_CookieExtensionFromConfig_DoNotRedirectDoStoreCookieWithExtension() throws Exception { - EventConfig config = new EventConfig(); + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e1"); config.setQueueDomain("testdomain.com"); config.setCookieValidityMinute(10); @@ -100,7 +99,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest("url", "token", config, "testCustomer", "key"); + RequestValidationResult result = testObject.validateQueueRequest("url", "token", config, "testCustomer", "key"); assertTrue(!result.doRedirect()); assertTrue(callInfo.get("firstCall").get("queueId").equals("queueId")); assertTrue(callInfo.get("firstCall").get("eventId").equals("e1")); @@ -110,10 +109,10 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void validateRequest_ValidState_NoExtendableCookie_DoNotRedirectDoNotStoreCookieWithExtension() + public void validateQueueRequest_ValidState_NoExtendableCookie_DoNotRedirectDoNotStoreCookieWithExtension() throws Exception { - EventConfig config = new EventConfig(); + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e1"); config.setQueueDomain("testdomain.com"); config.setCookieValidityMinute(10); @@ -146,7 +145,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c }; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest("url", "token", config, "testCustomer", "key"); + RequestValidationResult result = testObject.validateQueueRequest("url", "token", config, "testCustomer", "key"); assertTrue(!result.doRedirect()); assertTrue(!conditions.get("isStoreWasCalled")); assertTrue(result.getEventId().equals("e1")); @@ -154,8 +153,8 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void ValidateRequest_NoCookie_TampredToken_RedirectToErrorPageWithHashError_DoNotStoreCookie() throws Exception { - EventConfig config = new EventConfig(); + public void ValidateQueueRequest_NoCookie_TampredToken_RedirectToErrorPageWithHashError_DoNotStoreCookie() throws Exception { + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e1"); config.setQueueDomain("testDomain.com"); config.setCookieValidityMinute(10); @@ -201,7 +200,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c + "&t=" + URLEncoder.encode(targetUrl, "UTF-8"); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); + RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); assertTrue(result.doRedirect()); Pattern pattern = Pattern.compile("&ts=[^&]*"); @@ -218,8 +217,8 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void ValidateRequest_NoCookie_ExpiredTimeStampInToken_RedirectToErrorPageWithTimeStampError_DoNotStoreCookie() throws Exception { - EventConfig config = new EventConfig(); + public void ValidateQueueRequest_NoCookie_ExpiredTimeStampInToken_RedirectToErrorPageWithTimeStampError_DoNotStoreCookie() throws Exception { + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e1"); config.setQueueDomain("testDomain.com"); config.setCookieValidityMinute(10); @@ -266,7 +265,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c + "&t=" + URLEncoder.encode(targetUrl, "UTF-8"); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); + RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); assertTrue(result.doRedirect()); Pattern pattern = Pattern.compile("&ts=[^&]*"); @@ -283,8 +282,8 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void ValidateRequest_NoCookie_EventIdMismatch_RedirectToErrorPageWithEventIdMissMatchError_DoNotStoreCookie() throws Exception { - EventConfig config = new EventConfig(); + public void ValidateQueueRequest_NoCookie_EventIdMismatch_RedirectToErrorPageWithEventIdMissMatchError_DoNotStoreCookie() throws Exception { + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e2"); config.setQueueDomain("testDomain.com"); config.setCookieValidityMinute(10); @@ -331,7 +330,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c + "&t=" + URLEncoder.encode(targetUrl, "UTF-8"); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); + RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); assertTrue(result.doRedirect()); Pattern pattern = Pattern.compile("&ts=[^&]*"); @@ -348,8 +347,8 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void ValidateRequest_NoCookie_ValidToken_ExtendableCookie_DoNotRedirect_StoreExtendableCookie() throws Exception { - EventConfig config = new EventConfig(); + public void ValidateQueueRequest_NoCookie_ValidToken_ExtendableCookie_DoNotRedirect_StoreExtendableCookie() throws Exception { + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e1"); config.setCookieDomain(".testdomain.com"); config.setCookieValidityMinute(10); @@ -394,7 +393,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c String targetUrl = "http://test.test.com?b=h"; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); + RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); assertTrue(!result.doRedirect()); assertTrue(callInfo.get("firstCall").get("eventId").equals(config.getEventId())); assertTrue(callInfo.get("firstCall").get("isStateExtendable").equals(true)); @@ -404,8 +403,8 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void ValidateRequest_NoCookie_ValidToken_CookieValidityMinuteFromToken_DoNotRedirect_StoreNonExtendableCookie() throws Exception { - EventConfig config = new EventConfig(); + public void ValidateQueueRequest_NoCookie_ValidToken_CookieValidityMinuteFromToken_DoNotRedirect_StoreNonExtendableCookie() throws Exception { + QueueEventConfig config = new QueueEventConfig(); config.setEventId("eventid"); config.setCookieDomain(".testdomain.com"); config.setCookieValidityMinute(10); @@ -447,7 +446,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c String targetUrl = "http://test.test.com?b=h"; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); + RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); assertTrue(!result.doRedirect()); assertTrue(callInfo.get("firstCall").get("eventId").equals(config.getEventId())); assertTrue(callInfo.get("firstCall").get("isStateExtendable").equals(false)); @@ -458,8 +457,8 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void ValidateRequest_NoCookie_WithoutToken_RedirectToQueue() throws Exception { - EventConfig config = new EventConfig(); + public void ValidateQueueRequest_NoCookie_WithoutToken_RedirectToQueue() throws Exception { + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e1"); config.setQueueDomain("testDomain.com"); config.setCookieValidityMinute(10); @@ -502,7 +501,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c + "&t=" + URLEncoder.encode(targetUrl, "UTF-8"); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest(targetUrl, "", config, "testCustomer", "key"); + RequestValidationResult result = testObject.validateQueueRequest(targetUrl, "", config, "testCustomer", "key"); assertTrue(result.doRedirect()); assertTrue(result.getRedirectUrl().toUpperCase().equals(expectedErrorUrl.toUpperCase())); assertTrue(!conditions.get("isStoreWasCalled")); @@ -510,8 +509,8 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void ValidateRequest_NoCookie_WithoutToken_RedirectToQueue_NoTargetUrl() throws Exception { - EventConfig config = new EventConfig(); + public void ValidateQueueRequest_NoCookie_WithoutToken_RedirectToQueue_NoTargetUrl() throws Exception { + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e1"); config.setQueueDomain("testDomain.com"); config.setCookieValidityMinute(10); @@ -553,7 +552,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c + "&l=" + config.getLayoutName(); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest(null, "", config, "testCustomer", "key"); + RequestValidationResult result = testObject.validateQueueRequest(null, "", config, "testCustomer", "key"); assertTrue(result.doRedirect()); assertTrue(result.getRedirectUrl().toUpperCase().equals(expectedErrorUrl.toUpperCase())); assertTrue(!conditions.get("isStoreWasCalled")); @@ -561,8 +560,8 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c } @Test - public void ValidateRequest_NoCookie_InValidToken() throws Exception { - EventConfig config = new EventConfig(); + public void ValidateQueueRequest_NoCookie_InValidToken() throws Exception { + QueueEventConfig config = new QueueEventConfig(); config.setEventId("e1"); config.setQueueDomain("testDomain.com"); config.setCookieValidityMinute(10); @@ -605,12 +604,60 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c + "&t=" + URLEncoder.encode(targetUrl, "UTF-8"); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); - RequestValidationResult result = testObject.validateRequest(targetUrl, "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895", config, "testCustomer", "key"); + RequestValidationResult result = testObject.validateQueueRequest(targetUrl, "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895", config, "testCustomer", "key"); assertTrue(result.doRedirect()); assertTrue(result.getRedirectUrl().startsWith("https://testDomain.com/error/hash?c=testCustomer&e=e1&ver=v3-java-" + knownUserVersion + "&cver=10&l=testlayout&queueittoken=ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895&")); assertTrue(!conditions.get("isStoreWasCalled")); assertTrue(config.getEventId().equals(result.getEventId())); } + + @Test + public void validateCancelRequest() throws Exception { + CancelEventConfig config = new CancelEventConfig(); + config.setEventId("e1"); + config.setQueueDomain("testDomain.com"); + config.setCookieDomain("testdomain"); + config.setVersion(10); + + HashMap conditions = new HashMap<>(); + + IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override + public void store(String eventId, String queueId, boolean isStateExtendable, String cookieDomain, int cookieValidityMinute, String customerSecretKey) throws Exception { + throw new UnsupportedOperationException("Unsupported"); + } + + @Override + public StateInfo getState(String eventId, String customerSecretKey) { + return new StateInfo(true, "queueId", true, System.currentTimeMillis() / 1000L + 10 * 60); + } + + @Override + public void cancelQueueCookie(String eventId, String cookieDomain) { + conditions.put("cancelQueueCookieWasCalled", "eventId:" + eventId + ",cookieDomain:" + cookieDomain); + } + + @Override + public void extendQueueCookie(String eventId, int cookieValidityMinute, String cookieDomain, String secretKey) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + }; + + String knownUserVersion = UserInQueueService.SDK_VERSION; + String expectedUrl = "https://testDomain.com/cancel/testCustomer/e1/?c=testCustomer&e=e1" + + "&ver=v3-java-" + knownUserVersion + + "&cver=10" + + "&r=url"; + + UserInQueueService testObject = new UserInQueueService(cookieProviderMock); + RequestValidationResult result = testObject.validateCancelRequest("url", config, "testCustomer", "key"); + + assertTrue("eventId:e1,cookieDomain:testdomain".equals(conditions.get("cancelQueueCookieWasCalled"))); + assertTrue(result.doRedirect()); + assertTrue("queueId".equals(result.getQueueId())); + assertTrue(expectedUrl.equals(result.getRedirectUrl())); + assertTrue(config.getEventId().equals(result.getEventId())); + } public static class QueueITTokenGenerator { diff --git a/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java b/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java index de50880..12fc234 100644 --- a/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java @@ -20,7 +20,7 @@ public void store_getState_ExtendableCookie_CookieIsSaved() throws Exception { ICookieManager cookieManager = new ICookieManager() { @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { HashMap cookie = cookies.get(cookieName); cookie.put("cookieValue", cookieValue); cookie.put("cookieValue", cookieValue); @@ -58,7 +58,7 @@ public void store_getState_TamperedCookie_StateIsNotValid() throws Exception { ICookieManager cookieManager = new ICookieManager() { @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { cookies.put(cookieName, cookieValue); } @@ -91,7 +91,7 @@ public void store_getState_ExpiredCookie_StateIsNotValid() throws Exception { ICookieManager cookieManager = new ICookieManager() { @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { cookies.put(cookieName, cookieValue); } @@ -119,7 +119,7 @@ public void store_getState_DifferentEventId_StateIsNotValid() throws Exception { ICookieManager cookieManager = new ICookieManager() { @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { cookies.put(cookieName, cookieValue); } @@ -146,7 +146,7 @@ public void store_getState_InvalidCookie_StateIsNotValid() throws Exception { ICookieManager cookieManager = new ICookieManager() { @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { } @@ -167,7 +167,8 @@ public void cancelQueueCookie_Test() throws Exception { String eventId = "event1"; String secretKey = "secretKey"; String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc"; - + String cookieDomain = "testDomain"; + String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); HashMap> cookies = new HashMap<>(); cookies.put(cookieKey + "1", new HashMap<>()); @@ -177,7 +178,7 @@ public void cancelQueueCookie_Test() throws Exception { public int setCookieCallNumber = 0; @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { setCookieCallNumber++; HashMap cookie = cookies.get(cookieName + String.valueOf(setCookieCallNumber)); cookie.put("cookieValue", cookieValue); @@ -197,37 +198,14 @@ public String getCookie(String cookieName) { testObject.store(eventId, queueId, true, "cookieDomain", 10, secretKey); assertTrue(testObject.getState(eventId, secretKey).isValid()); - testObject.cancelQueueCookie(eventId, "cookieDomain"); + testObject.cancelQueueCookie(eventId, cookieDomain); assertTrue((int) cookies.get(cookieKey + "2").get("expiration") == 0); assertTrue(cookies.get(cookieKey + "2").get("cookieValue") == null); - assertTrue(cookies.get(cookieKey + "2").get("cookieDomain").equals("cookieDomain")); + assertTrue(cookies.get(cookieKey + "2").get("cookieDomain").equals(cookieDomain)); assertFalse(testObject.getState(eventId, secretKey).isValid()); } - @Test - public void cancelQueueCookie_CookieDoesNotExist_Test() { - String eventId = "event1"; - HashMap conditions = new HashMap<>(); - conditions.put("isSetCookieCalled", false); - ICookieManager cookieManager = new ICookieManager() { - @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { - conditions.replace("isSetCookieCalled", true); - } - - @Override - public String getCookie(String cookieName) { - return null; - } - }; - - UserInQueueStateCookieRepository testObject = new UserInQueueStateCookieRepository(cookieManager); - testObject.cancelQueueCookie(eventId, "cookieDomain"); - - assertFalse(Boolean.valueOf(String.valueOf(conditions.get("isSetCookieCalled")))); - } - @Test public void extendQueueCookie_CookietExist_Test() throws Exception { @@ -243,7 +221,7 @@ public void extendQueueCookie_CookietExist_Test() throws Exception { public int setCookieCallNumber = 0; @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { setCookieCallNumber++; HashMap cookie = cookies.get(cookieName + String.valueOf(setCookieCallNumber)); cookie.put("cookieValue", cookieValue); @@ -285,7 +263,7 @@ public void extendQueueCookie_CookieDoesNotExist_Test() { ICookieManager cookieManager = new ICookieManager() { @Override - public void setCookie(String cookieName, String cookieValue, int expiration, String cookieDomain) { + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { conditions.replace("isSetCookieCalled", true); }