diff --git a/.gitignore b/.gitignore
index 7b00f01..817c2c3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@
/SDK/nbproject/private
/SDK/build
/SDK/dist
+/.vs
+/SDK/target
diff --git a/SDK/.classpath b/SDK/.classpath
new file mode 100644
index 0000000..0ca1374
--- /dev/null
+++ b/SDK/.classpath
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SDK/.project b/SDK/.project
new file mode 100644
index 0000000..eb1a254
--- /dev/null
+++ b/SDK/.project
@@ -0,0 +1,23 @@
+
+
+ y
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/SDK/.settings/org.eclipse.core.resources.prefs b/SDK/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..29abf99
--- /dev/null
+++ b/SDK/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
+encoding//src/test/java=UTF-8
+encoding//src/test/resources=UTF-8
+encoding/=UTF-8
diff --git a/SDK/.settings/org.eclipse.jdt.apt.core.prefs b/SDK/.settings/org.eclipse.jdt.apt.core.prefs
new file mode 100644
index 0000000..d4313d4
--- /dev/null
+++ b/SDK/.settings/org.eclipse.jdt.apt.core.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.apt.aptEnabled=false
diff --git a/SDK/.settings/org.eclipse.jdt.core.prefs b/SDK/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..b5e07ce
--- /dev/null
+++ b/SDK/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,17 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.processAnnotations=disabled
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/SDK/.settings/org.eclipse.m2e.core.prefs b/SDK/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/SDK/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/SDK/nbproject/build-impl.xml b/SDK/nbproject/build-impl.xml
deleted file mode 100644
index a14899c..0000000
--- a/SDK/nbproject/build-impl.xml
+++ /dev/null
@@ -1,1042 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set src.dir
- Must set test.src.dir
- Must set build.dir
- Must set dist.dir
- Must set build.classes.dir
- Must set dist.javadoc.dir
- Must set build.test.classes.dir
- Must set build.test.results.dir
- Must set build.classes.excludes
- Must set dist.jar
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set JVM to use for profiling in profiler.info.jvm
- Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- To run this application from the command line without Ant, try:
-
-
-
-
-
-
- java -cp "${run.classpath.with.dist.jar}" ${main.class}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- To run this application from the command line without Ant, try:
-
- java -jar "${dist.jar.resolved}"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set run.class
-
-
-
- Must select one file in the IDE or set run.class
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set debug.class
-
-
-
-
- Must select one file in the IDE or set debug.class
-
-
-
-
- Must set fix.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set profile.class
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Some tests failed; see details above.
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set test.includes
-
-
-
- Some tests failed; see details above.
-
-
-
-
- Must select one file in the IDE or set test.class
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set applet.url
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set applet.url
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SDK/nbproject/genfiles.properties b/SDK/nbproject/genfiles.properties
deleted file mode 100644
index efac672..0000000
--- a/SDK/nbproject/genfiles.properties
+++ /dev/null
@@ -1,8 +0,0 @@
-build.xml.data.CRC32=4f4bbae4
-build.xml.script.CRC32=edafd639
-build.xml.stylesheet.CRC32=28e38971@1.44.1.45
-# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
-# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=4f4bbae4
-nbproject/build-impl.xml.script.CRC32=6eb04d1d
-nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45
diff --git a/SDK/nbproject/project.properties b/SDK/nbproject/project.properties
deleted file mode 100644
index f7f5cf8..0000000
--- a/SDK/nbproject/project.properties
+++ /dev/null
@@ -1,74 +0,0 @@
-annotation.processing.enabled=true
-annotation.processing.enabled.in.editor=false
-annotation.processing.run.all.processors=true
-annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
-application.title=SDK
-application.vendor=queueit
-build.classes.dir=${build.dir}/classes
-build.classes.excludes=**/*.java,**/*.form
-# This directory is removed when the project is cleaned:
-build.dir=build
-build.generated.dir=${build.dir}/generated
-build.generated.sources.dir=${build.dir}/generated-sources
-# Only compile against the classpath explicitly listed here:
-build.sysclasspath=ignore
-build.test.classes.dir=${build.dir}/test/classes
-build.test.results.dir=${build.dir}/test/results
-# Uncomment to specify the preferred debugger connection transport:
-#debug.transport=dt_socket
-debug.classpath=\
- ${run.classpath}
-debug.test.classpath=\
- ${run.test.classpath}
-# This directory is removed when the project is cleaned:
-dist.dir=dist
-dist.jar=${dist.dir}/SDK.jar
-dist.javadoc.dir=${dist.dir}/javadoc
-endorsed.classpath=
-excludes=
-file.reference.javax.servlet-api.jar=libs/javax.servlet-api.jar
-includes=**
-jar.compress=false
-javac.classpath=\
- ${file.reference.javax.servlet-api.jar}
-# Space-separated list of extra javac options
-javac.compilerargs=
-javac.deprecation=false
-javac.processorpath=\
- ${javac.classpath}
-javac.source=1.6
-javac.target=1.6
-javac.test.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}:\
- ${libs.junit_4.classpath}:\
- ${libs.hamcrest.classpath}
-javac.test.processorpath=\
- ${javac.test.classpath}
-javadoc.additionalparam=
-javadoc.author=false
-javadoc.encoding=${source.encoding}
-javadoc.noindex=false
-javadoc.nonavbar=false
-javadoc.notree=false
-javadoc.private=false
-javadoc.splitindex=true
-javadoc.use=true
-javadoc.version=false
-javadoc.windowtitle=
-meta.inf.dir=${src.dir}/META-INF
-mkdist.disabled=true
-platform.active=default_platform
-run.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}
-# Space-separated list of JVM arguments used when running the project
-# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
-# or test-sys-prop.name=value to set system properties for unit tests):
-run.jvmargs=
-run.test.classpath=\
- ${javac.test.classpath}:\
- ${build.test.classes.dir}
-source.encoding=UTF-8
-src.dir=src
-test.src.dir=test
diff --git a/SDK/nbproject/project.xml b/SDK/nbproject/project.xml
deleted file mode 100644
index c79c34b..0000000
--- a/SDK/nbproject/project.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
- org.netbeans.modules.java.j2seproject
-
-
- SDK
-
-
-
-
-
-
-
-
-
diff --git a/SDK/pom.xml b/SDK/pom.xml
new file mode 100644
index 0000000..380df67
--- /dev/null
+++ b/SDK/pom.xml
@@ -0,0 +1,51 @@
+
+
+
+ UTF-8
+
+ 4.0.0
+
+ x
+ y
+ 1.0
+
+
+
+ junit
+ junit
+ 4.12
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.0.1
+ provided
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.5.1
+
+ 1.8
+ 1.8
+
+
+
+ maven-surefire-plugin
+ 3.0.0-M3
+
+ 1.8
+ 1.8
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SDK/build.xml b/SDK/src/build.xml
similarity index 100%
rename from SDK/build.xml
rename to SDK/src/build.xml
diff --git a/SDK/libs/hamcrest-core-1.3.jar b/SDK/src/main/java/queueit/knownuserv3/resources/hamcrest-core-1.3.jar
similarity index 100%
rename from SDK/libs/hamcrest-core-1.3.jar
rename to SDK/src/main/java/queueit/knownuserv3/resources/hamcrest-core-1.3.jar
diff --git a/SDK/libs/javax.servlet-api.jar b/SDK/src/main/java/queueit/knownuserv3/resources/javax.servlet-api.jar
similarity index 100%
rename from SDK/libs/javax.servlet-api.jar
rename to SDK/src/main/java/queueit/knownuserv3/resources/javax.servlet-api.jar
diff --git a/SDK/src/queueit/knownuserv3/sdk/CancelEventConfig.java b/SDK/src/main/java/queueit/knownuserv3/sdk/CancelEventConfig.java
similarity index 77%
rename from SDK/src/queueit/knownuserv3/sdk/CancelEventConfig.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/CancelEventConfig.java
index fe800e2..fe228c5 100644
--- a/SDK/src/queueit/knownuserv3/sdk/CancelEventConfig.java
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/CancelEventConfig.java
@@ -6,6 +6,7 @@ public class CancelEventConfig {
private String queueDomain;
private String cookieDomain;
private int version;
+ private String actionName = "unspecified";
public String getEventId() {
return eventId;
@@ -15,6 +16,10 @@ public void setEventId(String eventId) {
this.eventId = eventId;
}
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+
public String getQueueDomain() {
return queueDomain;
}
@@ -42,12 +47,17 @@ public void setVersion(int version) {
public CancelEventConfig() {
this.version = -1;
}
+
+ public String getActionName() {
+ return actionName;
+ }
@Override
public String toString() {
return "EventId:" + eventId
+ "&Version:" + version
+ "&QueueDomain:" + queueDomain
- + "&CookieDomain:" + cookieDomain;
+ + "&CookieDomain:" + cookieDomain
+ + "&ActionName:" + actionName;
}
}
diff --git a/SDK/src/queueit/knownuserv3/sdk/Constants.java b/SDK/src/main/java/queueit/knownuserv3/sdk/Constants.java
similarity index 100%
rename from SDK/src/queueit/knownuserv3/sdk/Constants.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/Constants.java
diff --git a/SDK/src/queueit/knownuserv3/sdk/KnownUser.java b/SDK/src/main/java/queueit/knownuserv3/sdk/KnownUser.java
similarity index 62%
rename from SDK/src/queueit/knownuserv3/sdk/KnownUser.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/KnownUser.java
index 3ced801..9c6e13a 100644
--- a/SDK/src/queueit/knownuserv3/sdk/KnownUser.java
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/KnownUser.java
@@ -22,10 +22,10 @@ public class KnownUser {
private static IUserInQueueService _userInQueueService;
private static IUserInQueueService getUserInQueueService(HttpServletRequest request, HttpServletResponse response) {
+
if (_userInQueueService == null) {
return new UserInQueueService(new UserInQueueStateCookieRepository(new CookieManager(request, response)));
}
-
return _userInQueueService;
}
@@ -37,85 +37,118 @@ static void setUserInQueueService(IUserInQueueService mockUserInQueueService) {
}
public static RequestValidationResult validateRequestByIntegrationConfig(String currentUrlWithoutQueueITToken,
- String queueitToken, CustomerIntegration customerIntegrationInfo,
- String customerId, HttpServletRequest request,
- HttpServletResponse response, String secretKey) throws Exception {
+ String queueitToken, CustomerIntegration customerIntegrationInfo, String customerId,
+ HttpServletRequest request, HttpServletResponse response, String secretKey) throws Exception {
+
+ Map debugEntries = new HashMap();
- Map debugEntries = new HashMap();
+ ConnectorDiagnostics connectorDiagnostics = ConnectorDiagnostics.Verify(customerId, secretKey, queueitToken);
+
+ if (connectorDiagnostics.hasError) {
+ return connectorDiagnostics.validationResult;
+ }
try {
- boolean isDebug = getIsDebug(queueitToken, secretKey);
- if (isDebug) {
- debugEntries.put("ConfigVersion", Integer.toString(customerIntegrationInfo.Version));
+ if (connectorDiagnostics.isEnabled) {
+ debugEntries.put("SdkVersion", UserInQueueService.SDK_VERSION);
+ debugEntries.put("Runtime", GetRuntime());
+ String conVer = (customerIntegrationInfo != null) ? Integer.toString(customerIntegrationInfo.Version) : "NULL";
+ debugEntries.put("ConfigVersion", conVer);
debugEntries.put("PureUrl", currentUrlWithoutQueueITToken);
debugEntries.put("QueueitToken", queueitToken);
debugEntries.put("OriginalUrl", getOriginalUrl(request));
+
logMoreRequestDetails(debugEntries, request);
}
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();
- IntegrationConfigModel matchedConfig = configEvaluater.getMatchedIntegrationConfig(
- customerIntegrationInfo, currentUrlWithoutQueueITToken, request);
+ IntegrationConfigModel matchedConfig = configEvaluater.getMatchedIntegrationConfig(customerIntegrationInfo,
+ currentUrlWithoutQueueITToken, request);
- if (isDebug) {
- String matchedConfigName = (matchedConfig != null) ? matchedConfig.Name : "NULL";
- debugEntries.put("MatchedConfig", matchedConfigName);
+ if (connectorDiagnostics.isEnabled) {
+ String matchedConf = (matchedConfig != null) ? matchedConfig.Name : "NULL";
+ debugEntries.put("MatchedConfig", matchedConf);
}
if (matchedConfig == null) {
- return new RequestValidationResult(null, null, null, null, null);
+ return new RequestValidationResult(null, null, null, null, null, null);
}
// unspecified or 'Queue' specified
- if (Utils.isNullOrWhiteSpace(matchedConfig.ActionType) || ActionType.QUEUE_ACTION.equals(matchedConfig.ActionType)) {
- return handleQueueAction(matchedConfig, currentUrlWithoutQueueITToken, customerIntegrationInfo, queueitToken, customerId, request, response, secretKey, debugEntries);
+ if (Utils.isNullOrWhiteSpace(matchedConfig.ActionType)
+ || ActionType.QUEUE_ACTION.equals(matchedConfig.ActionType)) {
+ return handleQueueAction(matchedConfig, currentUrlWithoutQueueITToken, customerIntegrationInfo,
+ queueitToken, customerId, request, response, secretKey, debugEntries, connectorDiagnostics.isEnabled);
+
} else if (ActionType.CANCEL_ACTION.equals(matchedConfig.ActionType)) {
- return handleCancelAction(matchedConfig, customerIntegrationInfo, currentUrlWithoutQueueITToken, queueitToken, customerId, request, response, secretKey, debugEntries);
- } // for all unknown types default to 'Ignore'
+ return handleCancelAction(matchedConfig, customerIntegrationInfo, currentUrlWithoutQueueITToken,
+ queueitToken, customerId, request, response, secretKey, debugEntries, connectorDiagnostics.isEnabled);
+ }
+
+ // for all unknown types default to 'Ignore'
else {
- return handleIgnoreAction(request, response);
+ return handleIgnoreAction(request, response, matchedConfig.Name);
}
- } finally {
+ }
+ catch (Exception e) {
+ if (connectorDiagnostics.isEnabled) {
+ debugEntries.put("Exception", e.getMessage());
+ }
+ throw e;
+ }
+ finally {
setDebugCookie(debugEntries, request, response);
}
}
- public static RequestValidationResult cancelRequestByLocalConfig(
- String targetUrl, String queueitToken, CancelEventConfig cancelConfig,
- String customerId, HttpServletRequest request,
- HttpServletResponse response, String secretKey) throws Exception {
+ public static RequestValidationResult cancelRequestByLocalConfig(String targetUrl, String queueitToken,
+ CancelEventConfig cancelConfig, String customerId, HttpServletRequest request, HttpServletResponse response,
+ String secretKey) throws Exception {
+
+ Map debugEntries = new HashMap();
- Map debugEntries = new HashMap();
+ ConnectorDiagnostics connectorDiagnostics = ConnectorDiagnostics.Verify(customerId, secretKey, queueitToken);
+
+ if (connectorDiagnostics.hasError) {
+ return connectorDiagnostics.validationResult;
+ }
try {
- targetUrl = generateTargetUrl(targetUrl, request);
- return cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, request, response, secretKey, debugEntries);
- } finally {
+ return cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, request, response,
+ secretKey, debugEntries, connectorDiagnostics.isEnabled);
+ }
+ catch (Exception e) {
+ if(connectorDiagnostics.isEnabled) {
+ debugEntries.put("Exception", e.getMessage());
+ }
+ throw e;
+ }
+ 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 {
+ private static RequestValidationResult cancelRequestByLocalConfig(String targetUrl, String queueitToken,
+ CancelEventConfig cancelConfig, String customerId, HttpServletRequest request, HttpServletResponse response,
+ String secretKey, Map debugEntries, boolean isDebug) throws Exception {
+
+ targetUrl = generateTargetUrl(targetUrl, request);
- boolean isDebug = getIsDebug(queueitToken, secretKey);
if (isDebug) {
+ debugEntries.put("SdkVersion", UserInQueueService.SDK_VERSION);
+ debugEntries.put("Runtime", GetRuntime());
debugEntries.put("TargetUrl", targetUrl);
debugEntries.put("QueueitToken", queueitToken);
- debugEntries.put("CancelConfig", cancelConfig != null ? cancelConfig.toString() : "NULL");
+ debugEntries.put("CancelConfig", (cancelConfig != null) ? cancelConfig.toString() : "NULL");
debugEntries.put("OriginalUrl", getOriginalUrl(request));
logMoreRequestDetails(debugEntries, request);
}
@@ -140,39 +173,55 @@ private static RequestValidationResult cancelRequestByLocalConfig(
}
IUserInQueueService userInQueueService = getUserInQueueService(request, response);
- RequestValidationResult result = userInQueueService.validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey);
+ RequestValidationResult result = userInQueueService.validateCancelRequest(targetUrl, cancelConfig, customerId,
+ secretKey);
result.isAjaxResult = isQueueAjaxCall(request);
return result;
}
public static RequestValidationResult resolveQueueRequestByLocalConfig(
- String targetUrl, String queueitToken, QueueEventConfig queueConfig,
- String customerId, HttpServletRequest request,
- HttpServletResponse response, String secretKey) throws Exception {
+ String targetUrl, String queueitToken,
+ QueueEventConfig queueConfig, String customerId, HttpServletRequest request, HttpServletResponse response,
+ String secretKey) throws Exception {
+
+ ConnectorDiagnostics connectorDiagnostics = ConnectorDiagnostics.Verify(customerId, secretKey, queueitToken);
+
+ if (connectorDiagnostics.hasError) {
+ return connectorDiagnostics.validationResult;
+ }
- Map debugEntries = new HashMap();
+ Map debugEntries = new HashMap();
try {
targetUrl = generateTargetUrl(targetUrl, request);
- return resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, request, response, secretKey, debugEntries);
- } finally {
+
+ return resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, request, response,
+ secretKey, debugEntries, connectorDiagnostics.isEnabled);
+ }
+ catch (Exception e) {
+ if(connectorDiagnostics.isEnabled) {
+ debugEntries.put("Exception", e.getMessage());
+ }
+ throw e;
+ }
+ 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 {
+ private static RequestValidationResult resolveQueueRequestByLocalConfig(String targetUrl, String queueitToken,
+ QueueEventConfig queueConfig, String customerId, HttpServletRequest request, HttpServletResponse response,
+ String secretKey, Map debugEntries, boolean isDebug) throws Exception {
- boolean isDebug = getIsDebug(queueitToken, secretKey);
if (isDebug) {
+ debugEntries.put("SdkVersion", UserInQueueService.SDK_VERSION);
+ debugEntries.put("Runtime", GetRuntime());
debugEntries.put("TargetUrl", targetUrl);
debugEntries.put("QueueitToken", queueitToken);
- debugEntries.put("QueueConfig", queueConfig != null ? queueConfig.toString() : "NULL");
+ debugEntries.put("QueueConfig", (queueConfig != null) ? queueConfig.toString() : "NULL");
debugEntries.put("OriginalUrl", getOriginalUrl(request));
+
logMoreRequestDetails(debugEntries, request);
}
@@ -199,18 +248,15 @@ private static RequestValidationResult resolveQueueRequestByLocalConfig(
}
IUserInQueueService userInQueueService = getUserInQueueService(request, response);
- RequestValidationResult result = userInQueueService.validateQueueRequest(targetUrl, queueitToken, queueConfig, customerId, secretKey);
+ RequestValidationResult result = userInQueueService.validateQueueRequest(targetUrl, queueitToken, queueConfig,
+ customerId, secretKey);
result.isAjaxResult = isQueueAjaxCall(request);
return result;
}
- public static void extendQueueCookie(String eventId,
- int cookieValidityMinute,
- String cookieDomain,
- HttpServletRequest request,
- HttpServletResponse response,
- String secretKey) throws Exception {
+ public static void extendQueueCookie(String eventId, int cookieValidityMinute, String cookieDomain,
+ HttpServletRequest request, HttpServletResponse response, String secretKey) throws Exception {
if (Utils.isNullOrWhiteSpace(eventId)) {
throw new Exception("eventId can not be null or empty.");
@@ -226,7 +272,9 @@ public static void extendQueueCookie(String eventId,
userInQueueService.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey);
}
- private static void setDebugCookie(Map debugEntries, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
+ private static void setDebugCookie(Map debugEntries, HttpServletRequest request,
+ HttpServletResponse response) throws UnsupportedEncodingException {
+
if (debugEntries.isEmpty()) {
return;
}
@@ -243,36 +291,35 @@ private static void setDebugCookie(Map debugEntries, HttpServlet
}
private static void logMoreRequestDetails(Map debugEntries, HttpServletRequest request) {
+
TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Quoted "Z" to indicate UTC, no timezone offset
+ // Quoted "Z" to indicate UTC, no timezone offset
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());
debugEntries.put("ServerUtcTime", nowAsISO);
debugEntries.put("RequestIP", request.getRemoteAddr());
debugEntries.put("RequestHttpHeader_Via", request.getHeader("via") != null ? request.getHeader("via") : "");
- debugEntries.put("RequestHttpHeader_Forwarded", request.getHeader("forwarded") != null ? request.getHeader("forwarded") : "");
- debugEntries.put("RequestHttpHeader_XForwardedFor", request.getHeader("x-forwarded-for") != null ? request.getHeader("x-forwarded-for") : "");
- debugEntries.put("RequestHttpHeader_XForwardedHost", request.getHeader("x-forwarded-host") != null ? request.getHeader("x-forwarded-host") : "");
- debugEntries.put("RequestHttpHeader_XForwardedProto", request.getHeader("x-forwarded-proto") != null ? request.getHeader("x-forwarded-proto") : "");
- }
-
- 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;
+ debugEntries.put("RequestHttpHeader_Forwarded",
+ request.getHeader("forwarded") != null ? request.getHeader("forwarded") : "");
+ debugEntries.put("RequestHttpHeader_XForwardedFor",
+ request.getHeader("x-forwarded-for") != null ? request.getHeader("x-forwarded-for") : "");
+ debugEntries.put("RequestHttpHeader_XForwardedHost",
+ request.getHeader("x-forwarded-host") != null ? request.getHeader("x-forwarded-host") : "");
+ debugEntries.put("RequestHttpHeader_XForwardedProto",
+ request.getHeader("x-forwarded-proto") != null ? request.getHeader("x-forwarded-proto") : "");
}
private static String getOriginalUrl(HttpServletRequest request) {
- return (request.getQueryString() != null)
- ? request.getRequestURL().toString() + "?" + request.getQueryString()
+ return (request.getQueryString() != null) ? request.getRequestURL().toString() + "?" + request.getQueryString()
: request.getRequestURL().toString();
}
- private static RequestValidationResult handleQueueAction(IntegrationConfigModel matchedConfig, String currentUrlWithoutQueueITToken, CustomerIntegration customerIntegrationInfo, String queueitToken, String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey, Map debugEntries) throws Exception {
+ private static RequestValidationResult handleQueueAction(IntegrationConfigModel matchedConfig,
+ String currentUrlWithoutQueueITToken, CustomerIntegration customerIntegrationInfo, String queueitToken,
+ String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey,
+ Map debugEntries, boolean isDebug) throws Exception {
String targetUrl;
if ("ForecedTargetUrl".equals(matchedConfig.RedirectLogic) || // support for typo
@@ -293,32 +340,42 @@ private static RequestValidationResult handleQueueAction(IntegrationConfigModel
queueConfig.setCookieValidityMinute(matchedConfig.CookieValidityMinute);
queueConfig.setCookieDomain(matchedConfig.CookieDomain);
queueConfig.setVersion(customerIntegrationInfo.Version);
+ queueConfig.setActionName(matchedConfig.Name);
- return resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, request, response, secretKey, debugEntries);
+ return resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, request, response,
+ secretKey, debugEntries, isDebug);
}
- private static RequestValidationResult handleCancelAction(IntegrationConfigModel matchedConfig, CustomerIntegration customerIntegrationInfo, String currentUrlWithoutQueueITToken, String queueitToken, String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey, Map debugEntries) throws Exception {
+ private static RequestValidationResult handleCancelAction(IntegrationConfigModel matchedConfig,
+ CustomerIntegration customerIntegrationInfo, String currentUrlWithoutQueueITToken, String queueitToken,
+ String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey,
+ Map debugEntries, boolean isDebug) throws Exception {
+
CancelEventConfig cancelConfig = new CancelEventConfig();
cancelConfig.setQueueDomain(matchedConfig.QueueDomain);
cancelConfig.setEventId(matchedConfig.EventId);
cancelConfig.setCookieDomain(matchedConfig.CookieDomain);
cancelConfig.setVersion(customerIntegrationInfo.Version);
+ cancelConfig.setActionName(matchedConfig.Name);
String targetUrl = generateTargetUrl(currentUrlWithoutQueueITToken, request);
- return cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, request, response, secretKey, debugEntries);
+
+ return cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, request, response,
+ secretKey, debugEntries, isDebug);
}
- private static RequestValidationResult handleIgnoreAction(HttpServletRequest request, HttpServletResponse response) {
+ private static RequestValidationResult handleIgnoreAction(HttpServletRequest request, HttpServletResponse response,
+ String actionName) {
+
IUserInQueueService userInQueueService = getUserInQueueService(request, response);
- RequestValidationResult result = userInQueueService.getIgnoreActionResult();
+ RequestValidationResult result = userInQueueService.getIgnoreActionResult(actionName);
result.isAjaxResult = isQueueAjaxCall(request);
return result;
}
private static String generateTargetUrl(String originalTargetUrl, HttpServletRequest request) {
try {
- return !isQueueAjaxCall(request)
- ? originalTargetUrl
+ return !isQueueAjaxCall(request) ? originalTargetUrl
: URLDecoder.decode(request.getHeader(QueueITAjaxHeaderKey), "UTF-8");
} catch (UnsupportedEncodingException e) {
}
@@ -328,6 +385,14 @@ private static String generateTargetUrl(String originalTargetUrl, HttpServletReq
private static boolean isQueueAjaxCall(HttpServletRequest request) {
return !Utils.isNullOrWhiteSpace(request.getHeader(QueueITAjaxHeaderKey));
}
+
+ public static String GetRuntime() {
+ try {
+ return System.getProperty("java.runtime.version");
+ } catch (Exception ex) {
+ return "unknown";
+ }
+ }
}
interface ICookieManager {
@@ -387,7 +452,7 @@ public String getCookie(String cookieName) {
if (cookie.getName().equals(cookieName)) {
try {
return URLDecoder.decode(cookie.getValue(), "UTF-8");
- } catch (UnsupportedEncodingException ex) {
+ } catch (Exception ex) {
}
}
}
diff --git a/SDK/src/queueit/knownuserv3/sdk/QueueEventConfig.java b/SDK/src/main/java/queueit/knownuserv3/sdk/QueueEventConfig.java
similarity index 87%
rename from SDK/src/queueit/knownuserv3/sdk/QueueEventConfig.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/QueueEventConfig.java
index c970173..b06935d 100644
--- a/SDK/src/queueit/knownuserv3/sdk/QueueEventConfig.java
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/QueueEventConfig.java
@@ -10,6 +10,7 @@ public class QueueEventConfig {
private int cookieValidityMinute;
private String cookieDomain;
private int version;
+ private String actionName = "unspecified";
public String getEventId() {
return eventId;
@@ -19,6 +20,10 @@ public void setEventId(String eventId) {
this.eventId = eventId;
}
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+
public String getLayoutName() {
return layoutName;
}
@@ -78,6 +83,10 @@ public void setVersion(int version) {
public QueueEventConfig() {
this.version = -1;
}
+
+ public String getActionName() {
+ return actionName;
+ }
@Override
public String toString() {
@@ -88,6 +97,7 @@ public String toString() {
+ "&ExtendCookieValidity:" + extendCookieValidity
+ "&CookieValidityMinute:" + cookieValidityMinute
+ "&LayoutName:" + layoutName
- + "&Culture:" + culture;
+ + "&Culture:" + culture
+ + "&ActionName:" + actionName;
}
}
diff --git a/SDK/src/main/java/queueit/knownuserv3/sdk/QueueITHelpers.java b/SDK/src/main/java/queueit/knownuserv3/sdk/QueueITHelpers.java
new file mode 100644
index 0000000..e8d7dc6
--- /dev/null
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/QueueITHelpers.java
@@ -0,0 +1,315 @@
+package queueit.knownuserv3.sdk;
+
+import java.util.AbstractCollection;
+import java.util.Iterator;
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.lang.Exception;
+import java.net.URLEncoder;
+
+class Utils {
+
+ public static boolean isNullOrWhiteSpace(String str) {
+ return str == null || str.trim().length() == 0;
+ }
+
+ public static boolean isInteger(String value) {
+ try {
+ Integer.parseInt(value);
+ return true;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ public static boolean isLong(String value) {
+ try {
+ Long.parseLong(value);
+ return true;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ public static String join(String delimiter, AbstractCollection s) {
+ if (s == null || s.isEmpty()) {
+ return "";
+ }
+ Iterator iter = s.iterator();
+ StringBuilder builder = new StringBuilder(iter.next());
+ while (iter.hasNext()) {
+ builder.append(delimiter).append(iter.next());
+ }
+ return builder.toString();
+ }
+
+ public static String encodeUrl(String arg) {
+ try {
+ String value = URLEncoder.encode(arg, "UTF-8").replaceAll("\\+", "%20").replaceAll("&", "\\%26")
+ .replaceAll("!", "\\%21").replaceAll("'", "\\%27").replaceAll("\\(", "\\%28")
+ .replaceAll("~", "\\%7E").replaceAll("\\|", "\\%7C").replaceAll("\\)", "\\%29")
+ .replaceAll("\\*", "\\%2A");
+ return value;
+ } catch (Exception e) {
+ return arg;
+ }
+ }
+}
+
+class ConnectorDiagnostics {
+ public boolean isEnabled;
+ public boolean hasError;
+ public RequestValidationResult validationResult;
+
+ public boolean getIsEnabled() {
+ return this.isEnabled;
+ }
+
+ public void setIsEnabled(boolean isEnabled) {
+ this.isEnabled = isEnabled;
+ }
+
+ public boolean getHasError() {
+ return this.hasError;
+ }
+
+ public void setHasError(boolean hasError) {
+ this.hasError = hasError;
+ }
+
+ public RequestValidationResult getValidationResult() {
+ return this.validationResult;
+ }
+
+ public void setValidationResult(RequestValidationResult validationResult) {
+ this.validationResult = validationResult;
+ }
+
+ private void SetStateWithTokenError(String customerId, String errorCode) {
+ hasError = true;
+ String redirectUrl = "https://" + customerId + ".api2.queue-it.net/" + customerId
+ + "/diagnostics/connector/error/?code=" + errorCode;
+
+ validationResult = new RequestValidationResult("ConnectorDiagnosticsRedirect", null, null, redirectUrl, null,
+ null);
+ }
+
+ private void SetStateWithSetupError() {
+ hasError = true;
+ validationResult = new RequestValidationResult("ConnectorDiagnosticsRedirect", null, null,
+ "https://api2.queue-it.net/diagnostics/connector/error/?code=setup", null, null);
+ }
+
+ public static ConnectorDiagnostics Verify(String customerId, String secretKey, String queueitToken){
+
+ ConnectorDiagnostics diagnostics = new ConnectorDiagnostics();
+
+ QueueUrlParams qParams = QueueParameterHelper.extractQueueParams(queueitToken);
+
+ if (qParams == null) {
+ return diagnostics;
+ }
+
+ if (qParams.getRedirectType() == null) {
+ return diagnostics;
+ }
+
+ if (!"debug".equals(qParams.getRedirectType())) {
+ return diagnostics;
+ }
+
+ if (Utils.isNullOrWhiteSpace(customerId) || Utils.isNullOrWhiteSpace(secretKey)) {
+ diagnostics.SetStateWithSetupError();
+ return diagnostics;
+ }
+
+ String calculatedHash = HashHelper.generateSHA256Hash(secretKey, qParams.getQueueITTokenWithoutHash());
+
+ if (!calculatedHash.toUpperCase().equals(qParams.getHashCode().toUpperCase())) {
+ diagnostics.SetStateWithTokenError(customerId, "hash");
+ return diagnostics;
+ }
+
+ if (qParams.getTimeStamp() < System.currentTimeMillis() / 1000L) {
+ diagnostics.SetStateWithTokenError(customerId, "timestamp");
+ return diagnostics;
+ }
+
+ diagnostics.isEnabled = true;
+
+ return diagnostics;
+ }
+}
+
+class QueueParameterHelper {
+
+ public static final String TimeStampKey = "ts";
+ public static final String ExtendableCookieKey = "ce";
+ public static final String CookieValidityMinutesKey = "cv";
+ public static final String HashKey = "h";
+ public static final String QueueIdKey = "q";
+ public static final String RedirectTypeKey = "rt";
+ public static final String EventIdKey = "e";
+ public static final String KeyValueSeparatorChar = "_";
+ public static final String KeyValueSeparatorGroupChar = "~";
+
+ public static QueueUrlParams extractQueueParams(String queueitToken) {
+
+ if (Utils.isNullOrWhiteSpace(queueitToken)) {
+ return null;
+ }
+ QueueUrlParams result = new QueueUrlParams();
+ result.setQueueITToken(queueitToken);
+
+ String[] paramList = queueitToken.split(KeyValueSeparatorGroupChar);
+ for (String paramKeyValue : paramList) {
+ String[] keyValueArr = paramKeyValue.split(KeyValueSeparatorChar);
+
+ if (keyValueArr.length != 2)
+ continue;
+
+ if (HashKey.equals(keyValueArr[0])) {
+ result.setHashCode(keyValueArr[1]);
+ } else if (TimeStampKey.equals(keyValueArr[0])) {
+ if (Utils.isLong(keyValueArr[1])) {
+ result.setTimeStamp(Long.parseLong(keyValueArr[1]));
+ }
+ } else if (CookieValidityMinutesKey.equals(keyValueArr[0])) {
+ if (Utils.isInteger(keyValueArr[1])) {
+ result.setCookieValidityMinutes(Integer.parseInt(keyValueArr[1]));
+ }
+ } else if (EventIdKey.equals(keyValueArr[0])) {
+ result.setEventId(keyValueArr[1]);
+ } else if (QueueIdKey.equals(keyValueArr[0])) {
+ result.setQueueId(keyValueArr[1]);
+ } else if (ExtendableCookieKey.equals(keyValueArr[0])) {
+ result.setExtendableCookie(Boolean.parseBoolean(keyValueArr[1]));
+ } else if (RedirectTypeKey.equals(keyValueArr[0])) {
+ result.setRedirectType(keyValueArr[1]);
+ }
+ }
+ String queueITTokenWithoutHash = result.getQueueITToken()
+ .replace(KeyValueSeparatorGroupChar + HashKey + KeyValueSeparatorChar + result.getHashCode(), "");
+ result.setQueueITTokenWithoutHash(queueITTokenWithoutHash);
+ return result;
+ }
+}
+
+class HashHelper {
+
+ public static String generateSHA256Hash(String secretKey, String stringToHash) {
+ try {
+ byte[] secretKeyBytes = secretKey.getBytes("UTF-8");
+ SecretKeySpec signingKey = new SecretKeySpec(secretKeyBytes, "HmacSHA256");
+ Mac mac = Mac.getInstance("HmacSHA256");
+ mac.init(signingKey);
+ byte[] bytes = stringToHash.getBytes("UTF-8");
+ byte[] rawHmac = mac.doFinal(bytes);
+ StringBuilder sb = new StringBuilder();
+ for (byte b : rawHmac) {
+ sb.append(String.format("%1$02x", b));
+ }
+
+ return sb.toString();
+ }
+ catch (Exception e) {
+ return "";
+ }
+ }
+}
+
+class QueueUrlParams {
+
+ private String eventId;
+ private String hashCode;
+ private boolean extendableCookie;
+ private String queueITToken;
+ private String queueITTokenWithoutHash;
+ private Integer cookieValidityMinutes;
+ private long timeStamp;
+ private String queueId;
+ private String redirectType;
+
+ public QueueUrlParams() {
+ this.eventId = "";
+ this.hashCode = "";
+ this.extendableCookie = false;
+ this.queueITToken = "";
+ this.queueITTokenWithoutHash = "";
+ this.cookieValidityMinutes = null;
+ this.timeStamp = 0;
+ this.queueId = "";
+ }
+
+ public String getEventId() {
+ return this.eventId;
+ }
+
+ public void setEventId(String eventId) {
+ this.eventId = eventId;
+ }
+
+ public String getHashCode() {
+ return this.hashCode;
+ }
+
+ public void setHashCode(String hashCode) {
+ this.hashCode = hashCode;
+ }
+
+ public boolean getExtendableCookie() {
+ return this.extendableCookie;
+ }
+
+ public void setExtendableCookie(boolean extendableCookie) {
+ this.extendableCookie = extendableCookie;
+ }
+
+ public Integer getCookieValidityMinutes() {
+ return this.cookieValidityMinutes;
+ }
+
+ public void setCookieValidityMinutes(Integer cookieValidityMinute) {
+ this.cookieValidityMinutes = cookieValidityMinute;
+ }
+
+ public String getQueueITToken() {
+ return this.queueITToken;
+ }
+
+ public void setQueueITToken(String queueITToken) {
+ this.queueITToken = queueITToken;
+ }
+
+ public String getQueueITTokenWithoutHash() {
+ return this.queueITTokenWithoutHash;
+ }
+
+ public void setQueueITTokenWithoutHash(String queueITTokenWithoutHash) {
+ this.queueITTokenWithoutHash = queueITTokenWithoutHash;
+ }
+
+ public long getTimeStamp() {
+ return this.timeStamp;
+ }
+
+ public void setTimeStamp(long timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+
+ public void setQueueId(String queueId) {
+ this.queueId = 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/main/java/queueit/knownuserv3/sdk/RequestValidationResult.java
similarity index 76%
rename from SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/RequestValidationResult.java
index 4fdba52..cf306ca 100644
--- a/SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/RequestValidationResult.java
@@ -10,14 +10,16 @@ public class RequestValidationResult {
private String redirectUrl;
private String queueId;
private String redirectType;
- public boolean isAjaxResult;
+ private String actionName;
+ public boolean isAjaxResult;
- public RequestValidationResult(String actionType, String eventId, String queueId, String redirectUrl, String redirectType) {
+ public RequestValidationResult(String actionType, String eventId, String queueId, String redirectUrl, String redirectType, String actionName) {
this.actionType = actionType;
this.eventId = eventId;
this.queueId = queueId;
this.redirectUrl = redirectUrl;
this.redirectType = redirectType;
+ this.actionName = actionName;
}
public String getActionType() {
@@ -57,11 +59,18 @@ public String getAjaxRedirectUrl() {
}
return "";
}
+ public String getActionName() {
+ return this.actionName;
+ }
}
class KnowUserException extends Exception {
+ /**
+ * The serializable class KnowUserException does not declare a static final serialVersionUID field of type long
+ */
+ private static final long serialVersionUID = 1L;
- public KnowUserException(String message) {
+ public KnowUserException(String message) {
super(message);
}
diff --git a/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java b/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueService.java
similarity index 52%
rename from SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueService.java
index 8609bfc..6fc1d82 100644
--- a/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueService.java
@@ -1,6 +1,4 @@
package queueit.knownuserv3.sdk;
-
-import java.net.URLEncoder;
import java.util.ArrayList;
interface IUserInQueueService {
@@ -24,13 +22,13 @@ void extendQueueCookie(
String cookieDomain,
String secretKey);
- RequestValidationResult getIgnoreActionResult();
+ RequestValidationResult getIgnoreActionResult(String actionName);
}
class UserInQueueService implements IUserInQueueService {
- public static final String SDK_VERSION = "3.5.2";
- private final IUserInQueueStateRepository _userInQueueStateRepository;
+ public static final String SDK_VERSION = "v3-java-" + "3.6.0";
+ public final IUserInQueueStateRepository _userInQueueStateRepository;
public UserInQueueService(IUserInQueueStateRepository queueStateRepository) {
this._userInQueueStateRepository = queueStateRepository;
@@ -43,7 +41,8 @@ public RequestValidationResult validateQueueRequest(
QueueEventConfig config,
String customerId,
String secretKey) throws Exception {
- StateInfo stateInfo = this._userInQueueStateRepository.getState(config.getEventId(), config.getCookieValidityMinute(), secretKey, true);
+ StateInfo stateInfo = this._userInQueueStateRepository.getState(config.getEventId(), config.getCookieValidityMinute(), secretKey, true);
+
if (stateInfo.isValid()) {
if (stateInfo.isStateExtendable() && config.getExtendCookieValidity()) {
this._userInQueueStateRepository.store(
@@ -54,36 +53,35 @@ public RequestValidationResult validateQueueRequest(
stateInfo.getRedirectType(),
secretKey);
}
- return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), stateInfo.getQueueId(), null, stateInfo.getRedirectType());
- }
-
+ return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), stateInfo.getQueueId(), null, stateInfo.getRedirectType(), config.getActionName());
+ }
QueueUrlParams queueParmas = QueueParameterHelper.extractQueueParams(queueitToken);
if (queueParmas != null) {
- return getQueueITTokenValidationResult(targetUrl, config.getEventId(), config, queueParmas, customerId, secretKey);
+ return getQueueITTokenValidationResult(targetUrl, config, queueParmas, customerId, secretKey);
} else {
- return getInQueueRedirectResult(targetUrl, config, customerId);
+ return cancelQueueCookieReturnQueueResult(targetUrl, config, customerId);
}
}
private RequestValidationResult getQueueITTokenValidationResult(
- String targetUrl,
- String eventId,
+ String targetUrl,
QueueEventConfig config,
QueueUrlParams queueParams,
String customerId,
String secretKey) throws Exception {
+
String calculatedHash = HashHelper.generateSHA256Hash(secretKey, queueParams.getQueueITTokenWithoutHash());
if (!calculatedHash.toUpperCase().equals(queueParams.getHashCode().toUpperCase())) {
- return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "hash");
+ return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "hash");
}
- if (!eventId.toUpperCase().equals(queueParams.getEventId().toUpperCase())) {
- return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "eventid");
+ if (!config.getEventId().toUpperCase().equals(queueParams.getEventId().toUpperCase())) {
+ return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "eventid");
}
if (queueParams.getTimeStamp() < System.currentTimeMillis() / 1000L) {
- return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "timestamp");
+ return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "timestamp");
}
this._userInQueueStateRepository.store(
@@ -94,67 +92,80 @@ private RequestValidationResult getQueueITTokenValidationResult(
queueParams.getRedirectType(),
secretKey);
- return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), queueParams.getQueueId(), null, queueParams.getRedirectType());
+ return new RequestValidationResult(
+ ActionType.QUEUE_ACTION,
+ config.getEventId(),
+ queueParams.getQueueId(),
+ null,
+ queueParams.getRedirectType(),
+ config.getActionName());
}
- private RequestValidationResult getVaidationErrorResult(
+ private RequestValidationResult cancelQueueCookieReturnErrorResult(
String customerId,
String targetUrl,
QueueEventConfig config,
QueueUrlParams qParams,
- String errorCode) throws Exception {
+ String errorCode) throws Exception {
+
+ this._userInQueueStateRepository.cancelQueueCookie(config.getEventId(), config.getCookieDomain());
- String query = getQueryString(customerId, config.getEventId(), config.getVersion(), config.getCulture(), config.getLayoutName())
- + "&queueittoken=" + qParams.getQueueITToken()
- + "&ts=" + System.currentTimeMillis() / 1000L;
+ String query = getQueryString(customerId, config.getEventId(), config.getVersion(), config.getActionName(), config.getCulture(), config.getLayoutName())
+ + "&queueittoken=" + qParams.getQueueITToken() + "&ts=" + System.currentTimeMillis() / 1000L;
+
if (!Utils.isNullOrWhiteSpace(targetUrl)) {
- query += "&t=" + URLEncoder.encode(targetUrl, "UTF-8");
- }
- String domainAlias = config.getQueueDomain();
- if (!domainAlias.endsWith("/")) {
- domainAlias = domainAlias + "/";
+ query += "&t=" + Utils.encodeUrl(targetUrl);
}
- String redirectUrl = "https://" + domainAlias + "error/" + errorCode + "/?" + query;
- return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), null, redirectUrl, null);
+
+ String redirectUrl = generateRedirectUrl(config.getQueueDomain(), "error/" + errorCode + "/", query);
+
+ return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), null, redirectUrl, null, config.getActionName());
}
- private RequestValidationResult getInQueueRedirectResult(
+ private RequestValidationResult cancelQueueCookieReturnQueueResult(
String targetUrl,
QueueEventConfig config,
String customerId) throws Exception {
-
- String redirectUrl = "https://" + config.getQueueDomain() + "?"
- + getQueryString(customerId, config.getEventId(), config.getVersion(), config.getCulture(), config.getLayoutName());
+
+ this._userInQueueStateRepository.cancelQueueCookie(config.getEventId(), config.getCookieDomain());
+ String query = getQueryString(customerId, config.getEventId(), config.getVersion(), config.getActionName(), config.getCulture(), config.getLayoutName());
+
if (!Utils.isNullOrWhiteSpace(targetUrl)) {
- redirectUrl += "&t=" + URLEncoder.encode(targetUrl, "UTF-8");
- }
+ query += "&t=" + Utils.encodeUrl(targetUrl);
- return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), null, redirectUrl, null);
+ }
+ String redirectUrl = generateRedirectUrl(config.getQueueDomain(), "", query);
+
+ return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), null, redirectUrl, null, config.getActionName());
}
-
- private String getQueryString(
- String customerId,
- 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(eventId, "UTF-8"));
- queryStringList.add("ver=v3-java-" + URLEncoder.encode(SDK_VERSION, "UTF-8"));
- queryStringList.add("cver=" + URLEncoder.encode(String.valueOf(configVersion), "UTF-8"));
+
+ private String getQueryString(String customerId, String eventId, int configVersion, String actionName, String culture, String layoutName) throws Exception {
+
+ ArrayList queryStringList = new ArrayList();
+ queryStringList.add("c=" + Utils.encodeUrl(customerId));
+ queryStringList.add("e=" + Utils.encodeUrl(eventId));
+ queryStringList.add("ver=" + Utils.encodeUrl(SDK_VERSION));
+ queryStringList.add("cver=" + Utils.encodeUrl(String.valueOf(configVersion)));
+ queryStringList.add("man=" + Utils.encodeUrl(actionName));
if (!Utils.isNullOrWhiteSpace(culture)) {
- queryStringList.add("cid=" + URLEncoder.encode(culture, "UTF-8"));
+ queryStringList.add("cid=" + Utils.encodeUrl(culture));
}
if (!Utils.isNullOrWhiteSpace(layoutName)) {
- queryStringList.add("l=" + URLEncoder.encode(layoutName, "UTF-8"));
+ queryStringList.add("l=" + Utils.encodeUrl(layoutName));
}
return Utils.join("&", queryStringList);
}
+ private String generateRedirectUrl(String queueDomain, String uriPath, String query) throws Exception{
+ if (!queueDomain.endsWith("/")) {
+ queueDomain = queueDomain + "/";
+ }
+ return "https://" + queueDomain + uriPath + "?" + query;
+ }
+
@Override
public void extendQueueCookie(
String eventId,
@@ -175,28 +186,23 @@ public RequestValidationResult validateCancelRequest(
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 uriPath = "cancel/"+ customerId + "/" + config.getEventId() + "/";
+
+ String query = getQueryString(customerId, config.getEventId(), config.getVersion(), config.getActionName(), null, null);
+
+ if (!Utils.isNullOrWhiteSpace(targetUrl)) {
+ query += "&r=" + Utils.encodeUrl(targetUrl);
}
-
- 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, state.getRedirectType());
+ String redirectUrl = generateRedirectUrl(config.getQueueDomain(), uriPath, query);
+
+ return new RequestValidationResult(ActionType.CANCEL_ACTION, config.getEventId(), state.getQueueId(), redirectUrl, state.getRedirectType(), config.getActionName());
} else {
- return new RequestValidationResult(ActionType.CANCEL_ACTION, config.getEventId(), null, null, null);
+ return new RequestValidationResult(ActionType.CANCEL_ACTION, config.getEventId(), null, null, null, config.getActionName());
}
}
@Override
- public RequestValidationResult getIgnoreActionResult() {
- return new RequestValidationResult(ActionType.IGNORE_ACTION, null, null, null, null);
+ public RequestValidationResult getIgnoreActionResult(String actionName) {
+ return new RequestValidationResult(ActionType.IGNORE_ACTION, null, null, null, null, actionName);
}
-}
+}
\ No newline at end of file
diff --git a/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java b/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java
similarity index 98%
rename from SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java
index 759b513..8848e47 100644
--- a/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java
@@ -139,7 +139,7 @@ private Boolean isCookieValid(
}
public static HashMap getCookieNameValueMap(String cookieValue) {
- HashMap result = new HashMap();
+ HashMap result = new HashMap();
String[] cookieNameValues = cookieValue.split("&");
for (int i = 0; i < cookieNameValues.length; ++i) {
@@ -196,13 +196,10 @@ public void reissueQueueCookie(
if (!isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValidityMinutes, true)) {
return;
}
-
- String issueTime = Long.toString(System.currentTimeMillis() / 1000L);
Integer fixedCookieValidityMinutes = null;
if (cookieNameValueMap.containsKey(FIXED_COOKIE_VALIDITY_MINUTES_KEY)) {
fixedCookieValidityMinutes = Integer.valueOf(cookieNameValueMap.get(FIXED_COOKIE_VALIDITY_MINUTES_KEY));
}
-
String cookieValue = createCookieValue(eventId, cookieNameValueMap.get(QUEUE_ID_KEY),
fixedCookieValidityMinutes, cookieNameValueMap.get(REDIRECT_TYPE_KEY), secretKey);
this.cookieManager.setCookie(cookieKey, cookieValue, 24 * 60 * 60, cookieDomain);
diff --git a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/Constants.java b/SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/Constants.java
similarity index 84%
rename from SDK/src/queueit/knownuserv3/sdk/integrationconfig/Constants.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/Constants.java
index d9a5b89..f9b0afe 100644
--- a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/Constants.java
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/Constants.java
@@ -19,9 +19,6 @@ final class ComparisonOperatorType {
public static final String EQUALS = "Equals";
public static final String CONTAINS = "Contains";
- public static final String STARTS_WITH = "StartsWith";
- public static final String ENDS_WITH = "EndsWith";
- public static final String MATCHES_WITH = "MatchesWith";
public static final String EQUALS_ANY = "EqualsAny";
public static final String CONTAINS_ANY = "ContainsAny";
}
diff --git a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/CustomerIntegration.java b/SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/CustomerIntegration.java
similarity index 100%
rename from SDK/src/queueit/knownuserv3/sdk/integrationconfig/CustomerIntegration.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/CustomerIntegration.java
diff --git a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java b/SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java
similarity index 91%
rename from SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java
index 4cf7390..0ae74ed 100644
--- a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/IntegrationConfigModel.java
@@ -13,5 +13,5 @@ public class IntegrationConfigModel {
public String RedirectLogic;
public String ForcedTargetUrl;
public String ActionType;
- public TriggerModel[] Triggers;
+ public TriggerModel[] Triggers;
}
diff --git a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java b/SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java
similarity index 79%
rename from SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java
index 93c0509..555aefa 100644
--- a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java
+++ b/SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java
@@ -1,9 +1,9 @@
package queueit.knownuserv3.sdk.integrationconfig;
+
import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.http.Cookie;
-import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
interface IIntegrationEvaluator {
@@ -172,13 +172,8 @@ public static boolean evaluate(
return equals(value, valueToCompare, isNegative, isIgnoreCase);
} else if (ComparisonOperatorType.CONTAINS.equals(opt)) {
return contains(value, valueToCompare, isNegative, isIgnoreCase);
- } else if (ComparisonOperatorType.STARTS_WITH.equals(opt)) {
- return startsWith(value, valueToCompare, isNegative, isIgnoreCase);
- } else if (ComparisonOperatorType.ENDS_WITH.equals(opt)) {
- return endsWith(value, valueToCompare, isNegative, isIgnoreCase);
- } else if (ComparisonOperatorType.MATCHES_WITH.equals(opt)) {
- return matchesWith(value, valueToCompare, isNegative, isIgnoreCase);
- } else if (ComparisonOperatorType.EQUALS_ANY.equals(opt)) {
+ }
+ else if (ComparisonOperatorType.EQUALS_ANY.equals(opt)) {
return equalsAny(value, valuesToCompare, isNegative, isIgnoreCase);
} else if (ComparisonOperatorType.CONTAINS_ANY.equals(opt)) {
return containsAny(value, valuesToCompare, isNegative, isIgnoreCase);
@@ -188,12 +183,12 @@ public static boolean evaluate(
}
private static boolean contains(String value, String valueToCompare, boolean isNegative, boolean ignoreCase) {
- if (valueToCompare.equals("*")) {
+ if (valueToCompare.equals("*") && value != null && !value.isEmpty()) {
return true;
}
boolean evaluation;
if (ignoreCase) {
- evaluation = value.toUpperCase().contains(valueToCompare.toUpperCase());
+ evaluation = value.toUpperCase().contains(valueToCompare.toUpperCase());
} else {
evaluation = value.contains(valueToCompare);
}
@@ -220,54 +215,6 @@ private static boolean equals(String value, String valueToCompare, boolean isNeg
}
}
- private static boolean endsWith(String value, String valueToCompare, boolean isNegative, boolean ignoreCase) {
- boolean evaluation;
-
- if (ignoreCase) {
- evaluation = value.toUpperCase().endsWith(valueToCompare.toUpperCase());
- } else {
- evaluation = value.endsWith(valueToCompare);
- }
-
- if (isNegative) {
- return !evaluation;
- } else {
- return evaluation;
- }
- }
-
- private static boolean startsWith(String value, String valueToCompare, boolean isNegative, boolean ignoreCase) {
- boolean evaluation;
-
- if (ignoreCase) {
- evaluation = value.toUpperCase().startsWith(valueToCompare.toUpperCase());
- } else {
- evaluation = value.startsWith(valueToCompare);
- }
-
- if (isNegative) {
- return !evaluation;
- } else {
- return evaluation;
- }
- }
-
- private static boolean matchesWith(String value, String valueToCompare, boolean isNegative, boolean isIgnoreCase) {
- Pattern pattern;
- if (isIgnoreCase) {
- pattern = Pattern.compile(valueToCompare, Pattern.CASE_INSENSITIVE);
- } else {
- pattern = Pattern.compile(valueToCompare);
- }
-
- boolean evaluation = pattern.matcher(value).matches();
- if (isNegative) {
- return !evaluation;
- } else {
- return evaluation;
- }
- }
-
private static boolean equalsAny(String value, String[] valuesToCompare, boolean isNegative, boolean isIgnoreCase) {
for (String valueToCompare : valuesToCompare) {
if (equals(value, valueToCompare, false, isIgnoreCase)) {
diff --git a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/TriggerModel.java b/SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/TriggerModel.java
similarity index 100%
rename from SDK/src/queueit/knownuserv3/sdk/integrationconfig/TriggerModel.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/TriggerModel.java
diff --git a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/TriggerPart.java b/SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/TriggerPart.java
similarity index 100%
rename from SDK/src/queueit/knownuserv3/sdk/integrationconfig/TriggerPart.java
rename to SDK/src/main/java/queueit/knownuserv3/sdk/integrationconfig/TriggerPart.java
diff --git a/SDK/src/main/resources/hamcrest-core-1.3.jar b/SDK/src/main/resources/hamcrest-core-1.3.jar
new file mode 100644
index 0000000..9d5fe16
Binary files /dev/null and b/SDK/src/main/resources/hamcrest-core-1.3.jar differ
diff --git a/SDK/src/main/resources/javax.servlet-api.jar b/SDK/src/main/resources/javax.servlet-api.jar
new file mode 100644
index 0000000..8161e88
Binary files /dev/null and b/SDK/src/main/resources/javax.servlet-api.jar differ
diff --git a/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java b/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java
deleted file mode 100644
index 6cd17ab..0000000
--- a/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java
+++ /dev/null
@@ -1,215 +0,0 @@
-package queueit.knownuserv3.sdk;
-
-import java.util.AbstractCollection;
-import java.util.Iterator;
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-
-class Utils {
-
- public static boolean isNullOrWhiteSpace(String str) {
- return str == null || str.trim().length() == 0;
- }
-
- public static boolean isInteger(String value) {
- try {
- Integer.parseInt(value);
- return true;
- } catch (NumberFormatException e) {
- return false;
- }
- }
-
- public static boolean isLong(String value) {
- try {
- Long.parseLong(value);
- return true;
- } catch (NumberFormatException e) {
- return false;
- }
- }
-
- public static String join(String delimiter, AbstractCollection s) {
- if (s == null || s.isEmpty()) {
- return "";
- }
- Iterator iter = s.iterator();
- StringBuilder builder = new StringBuilder(iter.next());
- while (iter.hasNext()) {
- builder.append(delimiter).append(iter.next());
- }
- return builder.toString();
- }
-}
-
-class QueueParameterHelper {
-
- public static final String TimeStampKey = "ts";
- public static final String ExtendableCookieKey = "ce";
- public static final String CookieValidityMinutesKey = "cv";
- public static final String HashKey = "h";
- public static final String QueueIdKey = "q";
- public static final String RedirectTypeKey = "rt";
- public static final String EventIdKey = "e";
- public static final String KeyValueSeparatorChar = "_";
- public static final String KeyValueSeparatorGroupChar = "~";
-
- public static QueueUrlParams extractQueueParams(String queueitToken) {
- try {
- if (Utils.isNullOrWhiteSpace(queueitToken)) {
- return null;
- }
-
- QueueUrlParams result = new QueueUrlParams();
- result.setQueueITToken(queueitToken);
-
- String[] paramList = queueitToken.split(KeyValueSeparatorGroupChar);
- for (String paramKeyValue : paramList) {
- String[] keyValueArr = paramKeyValue.split(KeyValueSeparatorChar);
-
- if (TimeStampKey.equals(keyValueArr[0])) {
- if (Utils.isLong(keyValueArr[1])) {
- result.setTimeStamp(Long.parseLong(keyValueArr[1]));
- } else {
- result.setTimeStamp(0);
- }
- } else if (CookieValidityMinutesKey.equals(keyValueArr[0])) {
- if (Utils.isInteger(keyValueArr[1])) {
- result.setCookieValidityMinutes(Integer.parseInt(keyValueArr[1]));
- } else {
- result.setCookieValidityMinutes(null);
- }
- } else if (EventIdKey.equals(keyValueArr[0])) {
- result.setEventId(keyValueArr[1]);
- } else if (QueueIdKey.equals(keyValueArr[0])) {
- result.setQueueId(keyValueArr[1]);
- } else if (ExtendableCookieKey.equals(keyValueArr[0])) {
- result.setExtendableCookie(Boolean.parseBoolean(keyValueArr[1]));
- } else if (HashKey.equals(keyValueArr[0])) {
- result.setHashCode(keyValueArr[1]);
- } else if (RedirectTypeKey.equals(keyValueArr[0])) {
- result.setRedirectType(keyValueArr[1]);
- }
- }
- String queueITTokenWithoutHash = result.getQueueITToken().replace(KeyValueSeparatorGroupChar + HashKey + KeyValueSeparatorChar + result.getHashCode(), "");
- result.setQueueITTokenWithoutHash(queueITTokenWithoutHash);
- return result;
- } catch (Exception ex) {
- return null;
- }
- }
-}
-
-class HashHelper {
-
- public static String generateSHA256Hash(String secretKey, String stringToHash) throws Exception {
- byte[] secretKeyBytes = secretKey.getBytes("UTF-8");
- SecretKeySpec signingKey = new SecretKeySpec(secretKeyBytes, "HmacSHA256");
- Mac mac = Mac.getInstance("HmacSHA256");
- mac.init(signingKey);
- byte[] bytes = stringToHash.getBytes("UTF-8");
- byte[] rawHmac = mac.doFinal(bytes);
- StringBuilder sb = new StringBuilder();
- for (byte b : rawHmac) {
- sb.append(String.format("%1$02x", b));
- }
-
- return sb.toString();
- }
-}
-
-class QueueUrlParams {
-
- private String eventId;
- private String hashCode;
- private boolean extendableCookie;
- private String queueITToken;
- private String queueITTokenWithoutHash;
- private Integer cookieValidityMinutes;
- private long timeStamp;
- private String queueId;
- private String redirectType;
-
- public QueueUrlParams() {
- this.eventId = "";
- this.hashCode = "";
- this.extendableCookie = false;
- this.queueITToken = "";
- this.queueITTokenWithoutHash = "";
- this.cookieValidityMinutes = null;
- this.timeStamp = 0;
- this.queueId = "";
- }
-
- public String getEventId() {
- return this.eventId;
- }
-
- public void setEventId(String eventId) {
- this.eventId = eventId;
- }
-
- public String getHashCode() {
- return this.hashCode;
- }
-
- public void setHashCode(String hashCode) {
- this.hashCode = hashCode;
- }
-
- public boolean getExtendableCookie() {
- return this.extendableCookie;
- }
-
- public void setExtendableCookie(boolean extendableCookie) {
- this.extendableCookie = extendableCookie;
- }
-
- public Integer getCookieValidityMinutes() {
- return this.cookieValidityMinutes;
- }
-
- public void setCookieValidityMinutes(Integer cookieValidityMinute) {
- this.cookieValidityMinutes = cookieValidityMinute;
- }
-
- public String getQueueITToken() {
- return this.queueITToken;
- }
-
- public void setQueueITToken(String queueITToken) {
- this.queueITToken = queueITToken;
- }
-
- public String getQueueITTokenWithoutHash() {
- return this.queueITTokenWithoutHash;
- }
-
- public void setQueueITTokenWithoutHash(String queueITTokenWithoutHash) {
- this.queueITTokenWithoutHash = queueITTokenWithoutHash;
- }
-
- public long getTimeStamp() {
- return this.timeStamp;
- }
-
- public void setTimeStamp(long timeStamp) {
- this.timeStamp = timeStamp;
- }
-
- public void setQueueId(String queueId) {
- this.queueId = 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/test/java/queueit/knownuserv3/resources/hamcrest-core-1.3.jar b/SDK/src/test/java/queueit/knownuserv3/resources/hamcrest-core-1.3.jar
new file mode 100644
index 0000000..9d5fe16
Binary files /dev/null and b/SDK/src/test/java/queueit/knownuserv3/resources/hamcrest-core-1.3.jar differ
diff --git a/SDK/src/test/java/queueit/knownuserv3/resources/javax.servlet-api.jar b/SDK/src/test/java/queueit/knownuserv3/resources/javax.servlet-api.jar
new file mode 100644
index 0000000..8161e88
Binary files /dev/null and b/SDK/src/test/java/queueit/knownuserv3/resources/javax.servlet-api.jar differ
diff --git a/SDK/src/test/java/queueit/knownuserv3/sdk/HashHelperTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/HashHelperTest.java
new file mode 100644
index 0000000..8000d9e
--- /dev/null
+++ b/SDK/src/test/java/queueit/knownuserv3/sdk/HashHelperTest.java
@@ -0,0 +1,22 @@
+package queueit.knownuserv3.sdk;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+public class HashHelperTest {
+
+ @Test
+ public void generateSHA256Hash() {
+ final String key = "528f01d4-30f9-4753-95b3-2c8c33966abc";
+ final String stringToHash = "ts_1480593661~cv_10~ce_false~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895~c_customerid~e_eventid~rt_disabled";
+
+ assertTrue(HashHelper.generateSHA256Hash(key, stringToHash).equals("286a17fb82009d8556465b2f0880a8e5e9565b42490669f4b8f1b93b7d6ddd51"));
+ }
+
+ @Test
+ public void generateSHA256Hash_empty_value_to_hash() {
+ final String key = "528f01d4-30f9-4753-95b3-2c8c33966abc";
+ final String stringToHash = "";
+
+ assertTrue(HashHelper.generateSHA256Hash(key, stringToHash).equals("eea56ce827b37369656f502c5a418cce5959d078ef2993589274ed7b26828d8b"));
+ }
+}
diff --git a/SDK/src/test/java/queueit/knownuserv3/sdk/KnownUserTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/KnownUserTest.java
new file mode 100644
index 0000000..af6225d
--- /dev/null
+++ b/SDK/src/test/java/queueit/knownuserv3/sdk/KnownUserTest.java
@@ -0,0 +1,2891 @@
+package queueit.knownuserv3.sdk;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import javax.servlet.AsyncContext;
+import javax.servlet.DispatcherType;
+import javax.servlet.RequestDispatcher;
+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;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.Part;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+import queueit.knownuserv3.sdk.UserInQueueServiceTest.QueueITTokenGenerator;
+import queueit.knownuserv3.sdk.integrationconfig.CustomerIntegration;
+import queueit.knownuserv3.sdk.integrationconfig.IntegrationConfigModel;
+import queueit.knownuserv3.sdk.integrationconfig.TriggerModel;
+import queueit.knownuserv3.sdk.integrationconfig.TriggerPart;
+
+public class KnownUserTest {
+
+ class UserInQueueServiceMock implements IUserInQueueService {
+
+ public ArrayList> validateQueueRequestCalls = new ArrayList>();
+ public boolean validateQueueRequestRaiseException = false;
+ public ArrayList> validateCancelRequestCalls = new ArrayList>();
+ public boolean validateCancelRequestRaiseException = false;
+ public ArrayList> extendQueueCookieCalls = new ArrayList>();
+ public ArrayList> getIgnoreActionResultCalls = new ArrayList>();
+
+ @Override
+ 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);
+ args.add(config.getCookieDomain() + ":" + config.getLayoutName() + ":" + config.getCulture() + ":"
+ + config.getEventId() + ":" + config.getQueueDomain() + ":" + config.getExtendCookieValidity() + ":"
+ + config.getCookieValidityMinute() + ":" + config.getVersion() + ":" + config.getActionName());
+ args.add(customerId);
+ args.add(secretKey);
+ validateQueueRequestCalls.add(args);
+
+ if(this.validateQueueRequestRaiseException == true ){
+ throw new Exception("exception");
+ }
+ else{
+ return new RequestValidationResult("Queue", "", "", "", "", "");
+ }
+}
+
+ @Override
+ public RequestValidationResult validateCancelRequest(String targetUrl, CancelEventConfig config,
+ String customerId, String secretKey) throws Exception {
+
+ ArrayList args = new ArrayList();
+ args.add(targetUrl);
+ args.add(config.getCookieDomain() + ":" + config.getEventId() + ":" + config.getQueueDomain() + ":"
+ + config.getVersion() + ":" + config.getActionName());
+ args.add(customerId);
+ args.add(secretKey);
+ validateCancelRequestCalls.add(args);
+
+ if(this.validateCancelRequestRaiseException == true ){
+ throw new Exception("exception");
+ }
+ else{
+ return new RequestValidationResult("Cancel", "", "", "", "", "");
+ }
+ }
+
+ @Override
+ public void extendQueueCookie(String eventId, int cookieValidityMinute, String cookieDomain, String secretKey) {
+ ArrayList args = new ArrayList();
+ args.add(eventId);
+ args.add(Integer.toString(cookieValidityMinute));
+ args.add(cookieDomain);
+ args.add(secretKey);
+ extendQueueCookieCalls.add(args);
+ }
+
+ @Override
+ public RequestValidationResult getIgnoreActionResult(String actionName) {
+ ArrayList args = new ArrayList();
+ args.add(actionName);
+ getIgnoreActionResultCalls.add(args);
+ return new RequestValidationResult("Ignore", "", "", "", "", "");
+ }
+ }
+
+ @Test
+ public void cancelRequestByLocalConfigTest() throws Exception {
+ // Arrange
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ CancelEventConfig cancelEventConfig = new CancelEventConfig();
+ cancelEventConfig.setCookieDomain("cookiedomain");
+ cancelEventConfig.setEventId("eventid");
+ cancelEventConfig.setQueueDomain("queuedomain");
+ cancelEventConfig.setVersion(1);
+ cancelEventConfig.setActionName("cancelAction");
+
+ // Act
+ RequestValidationResult result = KnownUser.cancelRequestByLocalConfig("url", "queueitToken", cancelEventConfig,
+ "customerid", requestMock, responseMock, "secretkey");
+
+ // Assert
+ assertTrue("url".equals(mock.validateCancelRequestCalls.get(0).get(0)));
+ assertTrue("cookiedomain:eventid:queuedomain:1:cancelAction"
+ .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)));
+ assertFalse(result.isAjaxResult);
+ }
+
+ @Test
+ public void CancelRequestByLocalConfig_AjaxCall_Test() throws Exception {
+ // Arrange
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.Headers.put("x-queueit-ajaxpageurl", "http%3A%2F%2Furl");
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ CancelEventConfig cancelEventConfig = new CancelEventConfig();
+ cancelEventConfig.setCookieDomain("cookiedomain");
+ cancelEventConfig.setEventId("eventid");
+ cancelEventConfig.setQueueDomain("queuedomain");
+ cancelEventConfig.setVersion(1);
+ cancelEventConfig.setActionName("cancelAction");
+
+ // Act
+ RequestValidationResult result = KnownUser.cancelRequestByLocalConfig("url", "queueitToken", cancelEventConfig,
+ "customerid", requestMock, null, "secretkey");
+
+ // Assert
+ assertTrue("http://url".equals(mock.validateCancelRequestCalls.get(0).get(0)));
+ assertTrue("cookiedomain:eventid:queuedomain:1:cancelAction"
+ .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)));
+ assertTrue(result.isAjaxResult);
+ }
+
+ @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);
+ cancelEventConfig.setActionName("cancelAction");
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.RequestURL = "requestUrl";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "eventId", false, null, secretKey, "debug");
+
+ KnownUser.cancelRequestByLocalConfig("url", queueittoken, cancelEventConfig, "customerId", requestMock,
+ responseMock, secretKey);
+
+ // Assert
+ assertTrue(responseMock.addedCookies.size() == 1);
+ assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
+ assertTrue(decodedCookieValue.contains("CancelConfig=EventId:eventid"));
+ assertTrue(decodedCookieValue.contains("&Version:1"));
+ assertTrue(decodedCookieValue.contains("&QueueDomain:queuedomain"));
+ assertTrue(decodedCookieValue.contains("&CookieDomain:cookiedomain"));
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(decodedCookieValue.contains("TargetUrl=url"));
+ assertTrue(decodedCookieValue.contains("RequestIP=80.35.35.34"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_Via=1.1 example.com"));
+ assertTrue(
+ decodedCookieValue.contains("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedProto=https"));
+ assertTrue(decodedCookieValue.contains("&ActionName:cancelAction"));
+ }
+
+ @Test
+ 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",
+ new HttpServletRequestMock(), 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",
+ new HttpServletRequestMock(), 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.cancelRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId",
+ new HttpServletRequestMock(), null, "secretKey");
+ } catch (Exception ex) {
+ 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,
+ new HttpServletRequestMock(), 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",
+ new HttpServletRequestMock(), null, null);
+ } catch (Exception ex) {
+ exceptionWasThrown = "secretKey can not be null or empty.".equals(ex.getMessage());
+ }
+
+ // Assert
+ 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",
+ new HttpServletRequestMock(), 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
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ // Act
+ try {
+ KnownUser.extendQueueCookie(null, 0, null, null, null, null);
+ } catch (Exception ex) {
+ exceptionWasThrown = "eventId can not be null or empty.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.extendQueueCookieCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void extendQueueCookieInvalidCookieValidityMinutesTest() {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ // Act
+ try {
+ KnownUser.extendQueueCookie("eventId", 0, null, null, null, null);
+ } catch (Exception ex) {
+ exceptionWasThrown = "cookieValidityMinute should be greater than 0.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.extendQueueCookieCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void extendQueueCookieNullSecretKeyTest() {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ // Act
+ try {
+ KnownUser.extendQueueCookie("eventId", 20, null, null, null, null);
+ } catch (Exception ex) {
+ exceptionWasThrown = "secretKey can not be null or empty.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.extendQueueCookieCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void extendQueueCookieTest() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ // Act
+ KnownUser.extendQueueCookie("eventId", 20, "cookieDomain", null, null, "secretKey");
+
+ // Assert
+ assertTrue("eventId".equals(mock.extendQueueCookieCalls.get(0).get(0)));
+ assertTrue("20".equals(mock.extendQueueCookieCalls.get(0).get(1)));
+ assertTrue("cookieDomain".equals(mock.extendQueueCookieCalls.get(0).get(2)));
+ assertTrue("secretKey".equals(mock.extendQueueCookieCalls.get(0).get(3)));
+ }
+
+ @Test
+ public void resolveQueueRequestByLocalConfigNullCustomerIdTest() {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ // Act
+ try {
+ KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, null,
+ new HttpServletRequestMock(), null, "secretKey");
+ } catch (Exception ex) {
+ exceptionWasThrown = "customerId can not be null or empty.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void resolveQueueRequestByLocalConfigNullSecretKeyTest() {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ // Act
+ try {
+ KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId",
+ new HttpServletRequestMock(), null, null);
+ } catch (Exception ex) {
+ exceptionWasThrown = "secretKey can not be null or empty.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void resolveQueueRequestByLocalConfigNullEventConfigTest() {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ // Act
+ try {
+ KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId",
+ new HttpServletRequestMock(), null, "secretKey");
+ } catch (Exception ex) {
+ exceptionWasThrown = "eventConfig can not be null.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void resolveQueueRequestByLocalConfigNullEventIdTest() {
+
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setCookieDomain("cookieDomain");
+ eventConfig.setLayoutName("layoutName");
+ eventConfig.setCulture("culture");
+ eventConfig.setQueueDomain("queueDomain");
+ eventConfig.setExtendCookieValidity(true);
+ eventConfig.setCookieValidityMinute(10);
+ eventConfig.setVersion(12);
+
+ // Act
+ try {
+ KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId",
+ new HttpServletRequestMock(), null, "secretKey");
+ } catch (Exception ex) {
+ exceptionWasThrown = "EventId from queueConfig can not be null or empty.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void resolveQueueRequestByLocalConfigNullQueueDomainTest() {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setCookieDomain("cookieDomain");
+ eventConfig.setLayoutName("layoutName");
+ eventConfig.setCulture("culture");
+ eventConfig.setEventId("eventId");
+ eventConfig.setExtendCookieValidity(true);
+ eventConfig.setCookieValidityMinute(10);
+ eventConfig.setVersion(12);
+ eventConfig.setActionName("queueAction");
+
+ // Act
+ try {
+ KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId",
+ new HttpServletRequestMock(), null, "secretKey");
+ } catch (Exception ex) {
+ exceptionWasThrown = "QueueDomain from queueConfig can not be null or empty.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void resolveQueueRequestByLocalConfigInvalidCookieValidityMinuteTest() {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setCookieDomain("cookieDomain");
+ eventConfig.setLayoutName("layoutName");
+ eventConfig.setCulture("culture");
+ eventConfig.setEventId("eventId");
+ eventConfig.setQueueDomain("queueDomain");
+ eventConfig.setExtendCookieValidity(true);
+ eventConfig.setVersion(12);
+
+ // Act
+ try {
+ KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId",
+ new HttpServletRequestMock(), null, "secretKey");
+ } catch (Exception ex) {
+ exceptionWasThrown = "cookieValidityMinute from queueConfig should be greater than 0."
+ .equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void resolveQueueRequestByLocalConfigTest() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setCookieDomain("cookieDomain");
+ eventConfig.setLayoutName("layoutName");
+ eventConfig.setCulture("culture");
+ eventConfig.setEventId("eventId");
+ eventConfig.setQueueDomain("queueDomain");
+ eventConfig.setExtendCookieValidity(true);
+ eventConfig.setCookieValidityMinute(10);
+ eventConfig.setVersion(12);
+ eventConfig.setActionName("queueAction");
+ // Act
+ RequestValidationResult result = KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken",
+ eventConfig, "customerId", new HttpServletRequestMock(), null, "secretKey");
+
+ // Assert
+ 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:queueAction"
+ .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)));
+ assertFalse(result.isAjaxResult);
+ }
+
+ @Test
+ public void resolveQueueRequestByLocalConfigAjaxCallTest() throws Exception {
+ // Arrange
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.Headers.put("x-queueit-ajaxpageurl", "http%3A%2F%2Furl");
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setCookieDomain("cookieDomain");
+ eventConfig.setLayoutName("layoutName");
+ eventConfig.setCulture("culture");
+ eventConfig.setEventId("eventId");
+ eventConfig.setQueueDomain("queueDomain");
+ eventConfig.setExtendCookieValidity(true);
+ eventConfig.setCookieValidityMinute(10);
+ eventConfig.setVersion(12);
+ eventConfig.setActionName("queueAction");
+
+ // Act
+ RequestValidationResult result = KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken",
+ eventConfig, "customerId", requestMock, null, "secretKey");
+
+ // Assert
+ assertTrue("http://url".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:queueAction"
+ .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)));
+ assertTrue(result.isAjaxResult);
+ }
+
+ @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);
+ queueConfig.setActionName("queueAction");
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.RequestURL = "requestUrl";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "eventId", false, null, secretKey, "debug");
+
+ KnownUser.resolveQueueRequestByLocalConfig("targetUrl", queueittoken, queueConfig, "customerId", requestMock,
+ responseMock, secretKey);
+
+ // Assert
+ assertTrue(responseMock.addedCookies.size() == 1);
+ assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
+ assertTrue(decodedCookieValue.contains("QueueConfig=EventId:eventId"));
+ assertTrue(decodedCookieValue.contains("&Version:12"));
+ assertTrue(decodedCookieValue.contains("&QueueDomain:queueDomain"));
+ assertTrue(decodedCookieValue.contains("&CookieDomain:cookieDomain"));
+ assertTrue(decodedCookieValue.contains("&ExtendCookieValidity:true"));
+ assertTrue(decodedCookieValue.contains("&CookieValidityMinute:10"));
+ assertTrue(decodedCookieValue.contains("&LayoutName:layoutName"));
+ assertTrue(decodedCookieValue.contains("&Culture:culture"));
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(decodedCookieValue.contains("TargetUrl=targetUrl"));
+ assertTrue(decodedCookieValue.contains("RequestIP=80.35.35.34"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_Via=1.1 example.com"));
+ assertTrue(
+ decodedCookieValue.contains("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedProto=https"));
+ assertTrue(decodedCookieValue.contains("&ActionName:" + queueConfig.getActionName()));
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigEmptyCurrentUrlTest() {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ // Act
+ try {
+ KnownUser.validateRequestByIntegrationConfig("", null, null, null, null, null, null);
+ } catch (Exception ex) {
+ exceptionWasThrown = "currentUrlWithoutQueueITToken can not be null or empty.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigEmptyIntegrationsConfigTest() {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ // Act
+ try {
+ KnownUser.validateRequestByIntegrationConfig("currentUrl", "queueitToken", null, null,
+ new HttpServletRequestMock(), null, null);
+ } catch (Exception ex) {
+ exceptionWasThrown = "customerIntegrationInfo can not be null.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.isEmpty());
+ assertTrue(exceptionWasThrown);
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigQueueActionTest() 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 httpContextMock = new HttpServletRequestMock();
+ httpContextMock.UserAgent = "googlebot";
+
+ // Act
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ "queueitToken", customerIntegration, "customerId", httpContextMock, null, "secretKey");
+
+ // Assert
+ 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:event1action"
+ .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)));
+ assertFalse(result.isAjaxResult);
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigQueueActionAjaxCallTest() 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.Headers.put("x-queueit-ajaxpageurl", "http%3A%2F%2Furl");
+
+ // Act
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ "queueitToken", customerIntegration, "customerId", requestMock, null, "secretKey");
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.size() == 1);
+ assertTrue("http://url".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:event1action"
+ .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)));
+ assertTrue(result.isAjaxResult);
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigDebugCookieLoggingTest() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ // region
+ 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";
+ Date date = new Date();
+ date = addDays(date, 1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "eventId", true, 20, secretKey, "debug");
+
+ KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ queueittoken, customerIntegration, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(responseMock.addedCookies.size() == 1);
+ assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
+ assertTrue(decodedCookieValue.contains("PureUrl=http://test.com?event1=true"));
+ assertTrue(decodedCookieValue.contains("ConfigVersion=3"));
+ assertTrue(decodedCookieValue.contains("QueueConfig=EventId:event1"));
+ assertTrue(decodedCookieValue.contains("&Version:3"));
+ assertTrue(decodedCookieValue.contains("&QueueDomain:knownusertest.queue-it.net"));
+ assertTrue(decodedCookieValue.contains("&CookieDomain:.test.com"));
+ assertTrue(decodedCookieValue.contains("&ExtendCookieValidity:true"));
+ assertTrue(decodedCookieValue.contains("&CookieValidityMinute:20"));
+ assertTrue(decodedCookieValue.contains("&LayoutName:Christmas Layout by Queue-it"));
+ assertTrue(decodedCookieValue.contains("&Culture:da-DK"));
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(decodedCookieValue.contains("TargetUrl=http://test.com?event1=true"));
+ assertTrue(decodedCookieValue.contains("MatchedConfig=event1action"));
+ assertTrue(decodedCookieValue.contains("&ActionName:" + config.Name));
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigNotMatchTest() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[0];
+ customerIntegration.Version = 3;
+
+ // Act
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey");
+
+ // Assert
+ 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";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "eventId", true, 20, secretKey, "debug");
+
+ KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", queueittoken, customerIntegration,
+ "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(responseMock.addedCookies.size() == 1);
+ assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
+ assertTrue(decodedCookieValue.contains("PureUrl=http://test.com?event1=true"));
+ assertTrue(decodedCookieValue.contains("ConfigVersion=3"));
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(decodedCookieValue.contains("RequestIP=80.35.35.34"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_Via=1.1 example.com"));
+ assertTrue(
+ decodedCookieValue.contains("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080"));
+ assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedProto=https"));
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigForcedTargeturlTest() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ TriggerPart triggerPart = new TriggerPart();
+ triggerPart.Operator = "Contains";
+ triggerPart.ValueToCompare = "event1";
+ triggerPart.UrlPart = "PageUrl";
+ triggerPart.ValidatorType = "UrlValidator";
+ triggerPart.IsNegative = false;
+ triggerPart.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart };
+
+ 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 = "ForcedTargetUrl";
+ config.ForcedTargetUrl = "http://forcedtargeturl.com";
+ config.ActionType = ActionType.QUEUE_ACTION;
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] { config };
+ customerIntegration.Version = 3;
+
+ // Act
+ KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration,
+ "customerId", new HttpServletRequestMock(), null, "secretKey");
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.size() == 1);
+ assertTrue("http://forcedtargeturl.com".equals(mock.validateQueueRequestCalls.get(0).get(0)));
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigForecedTargeturlTest() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ TriggerPart triggerPart = new TriggerPart();
+ triggerPart.Operator = "Contains";
+ triggerPart.ValueToCompare = "event1";
+ triggerPart.UrlPart = "PageUrl";
+ triggerPart.ValidatorType = "UrlValidator";
+ triggerPart.IsNegative = false;
+ triggerPart.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart };
+
+ 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 = "ForecedTargetUrl";
+ config.ForcedTargetUrl = "http://forcedtargeturl.com";
+ config.ActionType = ActionType.QUEUE_ACTION;
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] { config };
+ customerIntegration.Version = 3;
+
+ // Act
+ KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration,
+ "customerId", new HttpServletRequestMock(), null, "secretKey");
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.size() == 1);
+ assertTrue("http://forcedtargeturl.com".equals(mock.validateQueueRequestCalls.get(0).get(0)));
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigEventTargetUrl() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ TriggerPart triggerPart = new TriggerPart();
+ triggerPart.Operator = "Contains";
+ triggerPart.ValueToCompare = "event1";
+ triggerPart.UrlPart = "PageUrl";
+ triggerPart.ValidatorType = "UrlValidator";
+ triggerPart.IsNegative = false;
+ triggerPart.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart };
+
+ 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 = "EventTargetUrl";
+ config.ActionType = ActionType.QUEUE_ACTION;
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] { config };
+ customerIntegration.Version = 3;
+
+ // Act
+ KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration,
+ "customerId", new HttpServletRequestMock(), null, "secretKey");
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.size() == 1);
+ assertTrue("".equals(mock.validateQueueRequestCalls.get(0).get(0)));
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigIgnoreAction() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ TriggerPart triggerPart = new TriggerPart();
+ triggerPart.Operator = "Contains";
+ triggerPart.ValueToCompare = "event1";
+ triggerPart.UrlPart = "PageUrl";
+ triggerPart.ValidatorType = "UrlValidator";
+ triggerPart.IsNegative = false;
+ triggerPart.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart };
+
+ IntegrationConfigModel config = new IntegrationConfigModel();
+ config.Name = "event1action";
+ config.EventId = "event1";
+ config.CookieDomain = "cookiedomain";
+ config.Triggers = new TriggerModel[] { trigger };
+ config.QueueDomain = "queuedomain";
+ config.ActionType = ActionType.IGNORE_ACTION;
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] { config };
+ customerIntegration.Version = 3;
+
+ // Act
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey");
+
+ // Assert
+ assertTrue(mock.getIgnoreActionResultCalls.size() == 1);
+ assertFalse(result.isAjaxResult);
+ assertTrue(mock.getIgnoreActionResultCalls.get(0).get(0) == config.Name);
+
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigAjaxCallIgnoreAction() throws Exception {
+ // Arrange
+ TriggerPart triggerPart = new TriggerPart();
+ triggerPart.Operator = "Contains";
+ triggerPart.ValueToCompare = "event1";
+ triggerPart.UrlPart = "PageUrl";
+ triggerPart.ValidatorType = "UrlValidator";
+ triggerPart.IsNegative = false;
+ triggerPart.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart };
+
+ IntegrationConfigModel config = new IntegrationConfigModel();
+ config.Name = "event1action";
+ config.EventId = "event1";
+ config.CookieDomain = "cookiedomain";
+ config.Triggers = new TriggerModel[] { trigger };
+ config.QueueDomain = "queuedomain";
+ config.ActionType = ActionType.IGNORE_ACTION;
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] { config };
+ customerIntegration.Version = 3;
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.Headers.put("x-queueit-ajaxpageurl", "url");
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ // Act
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ "queueitToken", customerIntegration, "customerId", requestMock, null, "secretKey");
+
+ // Assert
+ assertTrue(mock.getIgnoreActionResultCalls.size() == 1);
+ assertTrue(result.isAjaxResult);
+ assertTrue(mock.getIgnoreActionResultCalls.get(0).get(0) == config.Name);
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigCancelAction() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ TriggerPart triggerPart = new TriggerPart();
+ triggerPart.Operator = "Contains";
+ triggerPart.ValueToCompare = "event1";
+ triggerPart.UrlPart = "PageUrl";
+ triggerPart.ValidatorType = "UrlValidator";
+ triggerPart.IsNegative = false;
+ triggerPart.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart };
+
+ 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;
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] { config };
+ customerIntegration.Version = 3;
+
+ // Act
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey");
+
+ // Assert
+ assertTrue("http://test.com?event1=true".equals(mock.validateCancelRequestCalls.get(0).get(0)));
+ assertTrue(
+ "cookiedomain:event1:queuedomain:3:event1action".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)));
+ assertFalse(result.isAjaxResult);
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfigAjaxCallCancelAction() throws Exception {
+ // Arrange
+ TriggerPart triggerPart = new TriggerPart();
+ triggerPart.Operator = "Contains";
+ triggerPart.ValueToCompare = "event1";
+ triggerPart.UrlPart = "PageUrl";
+ triggerPart.ValidatorType = "UrlValidator";
+ triggerPart.IsNegative = false;
+ triggerPart.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart };
+
+ 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;
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] { config };
+ customerIntegration.Version = 3;
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.Headers.put("x-queueit-ajaxpageurl", "http%3A%2F%2Furl");
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ // Act
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ "queueitToken", customerIntegration, "customerId", requestMock, null, "secretKey");
+
+ // Assert
+ assertTrue("http://url".equals(mock.validateCancelRequestCalls.get(0).get(0)));
+ assertTrue(
+ "cookiedomain:event1:queuedomain:3:event1action".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)));
+ assertTrue(result.isAjaxResult);
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfig_Debug() 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;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart1 };
+
+ 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 = "";
+
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] { config };
+ customerIntegration.Version = 3;
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.UserAgent = "googlebot";
+ requestMock.RequestURL = "requestUrl";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "eventId", true, 20, secretKey, "debug");
+
+ KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ queueittoken, customerIntegration, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(responseMock.addedCookies.size() == 1);
+ assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("PureUrl=http://test.com?event1=true"));
+ assertTrue(decodedCookieValue.contains("ConfigVersion=3"));
+ assertTrue(decodedCookieValue.contains("MatchedConfig=event1action"));
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
+ assertTrue(decodedCookieValue.contains("TargetUrl=http://test.com?event1=true"));
+ assertTrue(decodedCookieValue.contains("QueueConfig=EventId:event1"));
+ assertTrue(decodedCookieValue.contains("&Version:3"));
+ assertTrue(decodedCookieValue.contains("&QueueDomain:knownusertest.queue-it.net"));
+ assertTrue(decodedCookieValue.contains("&CookieDomain:.test.com"));
+ assertTrue(decodedCookieValue.contains("&ExtendCookieValidity:true"));
+ assertTrue(decodedCookieValue.contains("&CookieValidityMinute:20"));
+ assertTrue(decodedCookieValue.contains("&LayoutName:Christmas Layout by Queue-it"));
+ assertTrue(decodedCookieValue.contains("&Culture:da-DK"));
+ assertTrue(decodedCookieValue.contains("&ActionName:" + config.Name));
+ assertTrue(decodedCookieValue.contains("SdkVersion=v3-java-3.6.0"));
+ assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion()));
+ }
+
+ @Test
+ public void ValidateRequestByIntegrationConfig_Debug_WithoutMatch() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] {};
+ customerIntegration.Version = 10;
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.RequestURL = "http://test.com/?event1=true&queueittoken=queueittokenvalue";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+ // endregion
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ queueittoken, customerIntegration, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(responseMock.addedCookies.size() == 1);
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("PureUrl=http://test.com?event1=true"));
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(decodedCookieValue.contains("ConfigVersion=10"));
+ assertTrue(
+ decodedCookieValue.contains("OriginalUrl=http://test.com/?event1=true&queueittoken=queueittokenvalue"));
+ assertTrue(decodedCookieValue.contains("MatchedConfig=NULL"));
+ assertTrue(decodedCookieValue.contains("SdkVersion=v3-java-3.6.0"));
+ assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion()));
+ }
+
+ @Test
+ public void ValidateRequestByIntegrationConfig_Exception_NoDebugToken_NoDebugCookie() throws Exception {
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ //region
+ 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;
+ //endregion
+
+ HttpServletRequestMock httpContextMock = new HttpServletRequestMock();
+ httpContextMock.UserAgent = "googlebot";
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ mock.validateQueueRequestRaiseException = true;
+
+ // Act
+ try {
+ KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ "queueitToken", customerIntegration, "customerId", httpContextMock, responseMock, "secretKey");
+ } catch (Exception ex) {
+ assertTrue("exception".equals(ex.getMessage()));
+ }
+
+ // Assert
+ assertTrue(responseMock.addedCookies.size() == 0);
+ assertTrue(mock.validateQueueRequestCalls.size() > 0);
+ }
+
+ @Test
+ public void ResolveQueueRequestByLocalConfigTest_Exception_NoDebugToken_NoDebugCookie() throws Exception {
+
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ HttpServletRequestMock httpContextMock = new HttpServletRequestMock();
+ httpContextMock.UserAgent = "googlebot";
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setCookieDomain("cookieDomain");
+ eventConfig.setLayoutName("layoutName");
+ eventConfig.setCulture("culture");
+ eventConfig.setEventId("eventId");
+ eventConfig.setQueueDomain("queueDomain");
+ eventConfig.setExtendCookieValidity(true);
+ eventConfig.setCookieValidityMinute(10);
+ eventConfig.setVersion(12);
+ eventConfig.setActionName("queueAction");
+
+ mock.validateQueueRequestRaiseException = true;
+
+ // Act
+ try {
+ KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken",
+ eventConfig, "customerId", new HttpServletRequestMock(), responseMock, "secretKey");
+ }
+ catch (Exception ex) {
+ assertTrue("exception".equals(ex.getMessage()));
+ }
+
+ // Assert
+ assertTrue(mock.validateQueueRequestCalls.size() > 0);
+ assertTrue(responseMock.addedCookies.size() == 0);
+ }
+
+ @Test
+ public void CancelRequestByLocalConfig_Exception_NoDebugToken_NoDebugCookie()
+ {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ HttpServletRequestMock httpContextMock = new HttpServletRequestMock();
+ httpContextMock.UserAgent = "googlebot";
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ CancelEventConfig cancelEventConfig = new CancelEventConfig();
+ cancelEventConfig.setCookieDomain("cookiedomain");
+ cancelEventConfig.setEventId("eventid");
+ cancelEventConfig.setQueueDomain("queuedomain");
+ cancelEventConfig.setVersion(1);
+ cancelEventConfig.setActionName("cancelAction");
+
+ mock.validateQueueRequestRaiseException = true;
+
+ //Act
+ try {
+ KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", cancelEventConfig, "customerid", requestMock, responseMock, "secretkey");
+ }
+ catch (Exception ex) {
+ assertTrue("exception".equals(ex.getMessage()));
+ }
+
+ // Assert
+ assertTrue(mock.validateCancelRequestCalls.size() > 0);
+ assertTrue(responseMock.addedCookies.size() == 0);
+ }
+
+ @Test
+ public void validateRequestByIntegrationConfig_Debug_NullConfig() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ TriggerPart triggerPart1 = new TriggerPart();
+ triggerPart1.Operator = "Contains";
+ triggerPart1.ValueToCompare = "event1";
+ triggerPart1.UrlPart = "PageUrl";
+ triggerPart1.ValidatorType = "UrlValidator";
+ triggerPart1.IsNegative = false;
+ triggerPart1.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart1 };
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ requestMock.RequestURL = "requestUrl";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "eventId", true, 20, secretKey, "debug");
+
+ try {
+ KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", queueittoken, null,
+ "customerId", requestMock, responseMock, secretKey);
+ } catch (Exception ex) {
+ exceptionWasThrown = "customerIntegrationInfo can not be null.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(exceptionWasThrown);
+ assertTrue(responseMock.addedCookies.size() == 1);
+ assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("SdkVersion=" + UserInQueueService.SDK_VERSION));
+ assertTrue(decodedCookieValue.contains("PureUrl=http://test.com?event1=true"));
+ assertTrue(decodedCookieValue.contains("ConfigVersion=NULL"));
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
+ assertTrue(decodedCookieValue.contains("SdkVersion=v3-java-3.6.0"));
+ assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion()));
+ assertTrue(decodedCookieValue.contains("Exception=customerIntegrationInfo can not be null."));
+
+ }
+
+ @Test
+ public void ValidateRequestByIntegrationConfig_Debug_Missing_CustomerId() throws Exception {
+
+ // Arrange
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+
+ // Act
+ String secretKey = "secretKey";
+ Date date = new Date();
+ date = addDays(date, 1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ queueittoken, customerIntegration, null, requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(result.getRedirectUrl().equals("https://api2.queue-it.net/diagnostics/connector/error/?code=setup"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void ValidateRequestByIntegrationConfig_Debug_Missing_Secretkey() throws Exception {
+
+ // Arrange
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+
+ // Act
+ String secretKey = "secretKey";
+ Date date = new Date();
+ date = addDays(date, 1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ queueittoken, customerIntegration, "customerId", requestMock, responseMock, null);
+
+ // Assert
+ assertTrue(result.getRedirectUrl().equals("https://api2.queue-it.net/diagnostics/connector/error/?code=setup"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+
+ }
+
+ @Test
+ public void ValidateRequestByIntegrationConfig_Debug_ExpiredToken() throws Exception {
+
+ // Arrange
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+
+ // Act
+ String secretKey = "secretKey";
+ Date date = new Date();
+ date = addDays(date, -1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ queueittoken, customerIntegration, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(result.getRedirectUrl()
+ .equals("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=timestamp"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void ValidateRequestByIntegrationConfig_Debug_ModifiedToken() throws Exception {
+
+ // Arrange
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+
+ // Act
+ String secretKey = "secretKey";
+ Date date = new Date();
+ date = addDays(date, 1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug") + "invalid-hash";
+
+ RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
+ queueittoken, customerIntegration, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(result.getRedirectUrl()
+ .equals("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=hash"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void ResolveQueueRequestByLocalConfig_Debug() throws Exception {
+
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.RequestURL = "http://test.com/?event1=true&queueittoken=queueittokenvalue";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setCookieDomain("cookieDomain");
+ eventConfig.setLayoutName("layoutName");
+ eventConfig.setCulture("culture");
+ eventConfig.setEventId("eventId");
+ eventConfig.setQueueDomain("queueDomain");
+ eventConfig.setExtendCookieValidity(true);
+ eventConfig.setCookieValidityMinute(10);
+ eventConfig.setVersion(12);
+ eventConfig.setActionName("QueueAction");
+
+ // Act
+ String secretKey = "secretKey";
+ Date date = new Date();
+ date = addDays(date, 1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, eventConfig, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(
+ decodedCookieValue.contains("OriginalUrl=http://test.com/?event1=true&queueittoken=queueittokenvalue"));
+ assertTrue(decodedCookieValue.contains("TargetUrl=http://test.com?event1=true"));
+ assertTrue(decodedCookieValue.contains(
+ "QueueConfig=EventId:eventId&Version:12&QueueDomain:queueDomain&CookieDomain:cookieDomain&ExtendCookieValidity:true&CookieValidityMinute:10&LayoutName:layoutName&Culture:culture&ActionName:"
+ + eventConfig.getActionName()));
+ assertTrue(decodedCookieValue.contains("SdkVersion=v3-java-3.6.0"));
+ assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion()));
+ }
+
+ @Test
+ public void ResolveQueueRequestByLocalConfig_Debug_NullConfig() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ TriggerPart triggerPart1 = new TriggerPart();
+ triggerPart1.Operator = "Contains";
+ triggerPart1.ValueToCompare = "event1";
+ triggerPart1.UrlPart = "PageUrl";
+ triggerPart1.ValidatorType = "UrlValidator";
+ triggerPart1.IsNegative = false;
+ triggerPart1.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart1 };
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.RequestURL = "http://test.com/?event1=true&queueittoken=queueittokenvalue";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ try {
+ KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true", queueittoken, null, "customerId",
+ requestMock, responseMock, secretKey);
+ } catch (Exception ex) {
+ exceptionWasThrown = "eventConfig can not be null.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(exceptionWasThrown);
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(
+ decodedCookieValue.contains("OriginalUrl=http://test.com/?event1=true&queueittoken=queueittokenvalue"));
+ assertTrue(decodedCookieValue.contains("QueueConfig=NULL"));
+ assertTrue(decodedCookieValue.contains("Exception=eventConfig can not be null."));
+ }
+
+ @Test
+ public void ResolveQueueRequestByLocalConfig_Debug_Missing_CustomerId() throws Exception {
+
+ // Arrange
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setEventId("event1");
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, -1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ RequestValidationResult result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, eventConfig, null, requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(result.getRedirectUrl().equals("https://api2.queue-it.net/diagnostics/connector/error/?code=setup"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void ResolveQueueRequestByLocalConfig_Debug_Missing_SecretKey() throws Exception {
+
+ // Arrange
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setEventId("event1");
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, -1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ RequestValidationResult result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, eventConfig, "customerId", requestMock, responseMock, null);
+
+ // Assert
+ assertTrue(result.getRedirectUrl().equals("https://api2.queue-it.net/diagnostics/connector/error/?code=setup"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void ResolveQueueRequestByLocalConfig_Debug_ExpiredToken() throws Exception {
+
+ // Arrange
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setEventId("event1");
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, -1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ RequestValidationResult result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, eventConfig, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(result.getRedirectUrl()
+ .equals("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=timestamp"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void ResolveQueueRequestByLocalConfig_Debug_ModifiedToken() throws Exception {
+
+ // Arrange
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ QueueEventConfig eventConfig = new QueueEventConfig();
+ eventConfig.setCookieDomain("cookieDomain");
+ eventConfig.setLayoutName("layoutName");
+ eventConfig.setCulture("culture");
+ eventConfig.setQueueDomain("queueDomain");
+ eventConfig.setExtendCookieValidity(true);
+ eventConfig.setCookieValidityMinute(10);
+ eventConfig.setVersion(12);
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug") + "invalid-hash";
+
+ RequestValidationResult result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, eventConfig, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(result.getRedirectUrl()
+ .equals("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=hash"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void CancelRequestByLocalConfig_Debug() 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;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart1 };
+
+ 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 = "";
+
+ CustomerIntegration customerIntegration = new CustomerIntegration();
+ customerIntegration.Integrations = new IntegrationConfigModel[] { config };
+ customerIntegration.Version = 3;
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.RequestURL = "http://test.com/?event1=true&queueittoken=queueittokenvalue";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ CancelEventConfig cancelEventConfig = new CancelEventConfig();
+ cancelEventConfig.setCookieDomain("cookiedomain");
+ cancelEventConfig.setEventId("eventId");
+ cancelEventConfig.setQueueDomain("queuedomain");
+ cancelEventConfig.setVersion(12);
+ cancelEventConfig.setActionName("cancelAction");
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "eventId", true, null, secretKey, "debug");
+
+ KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, cancelEventConfig, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(responseMock.addedCookies.size() == 1);
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(
+ decodedCookieValue.contains("OriginalUrl=http://test.com/?event1=true&queueittoken=queueittokenvalue"));
+ assertTrue(decodedCookieValue.contains("TargetUrl=http://test.com?event1=true"));
+
+ String configvalues = "CancelConfig=EventId:eventId&Version:12&QueueDomain:queuedomain&CookieDomain:cookiedomain&ActionName:"
+ + cancelEventConfig.getActionName();
+ assertTrue(decodedCookieValue.contains(configvalues));
+ }
+
+ @Test
+ public void CancelRequestByLocalConfig_Debug_NullConfig() throws Exception {
+ // Arrange
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+ boolean exceptionWasThrown = false;
+
+ TriggerPart triggerPart1 = new TriggerPart();
+ triggerPart1.Operator = "Contains";
+ triggerPart1.ValueToCompare = "event1";
+ triggerPart1.UrlPart = "PageUrl";
+ triggerPart1.ValidatorType = "UrlValidator";
+ triggerPart1.IsNegative = false;
+ triggerPart1.IsIgnoreCase = true;
+
+ TriggerModel trigger = new TriggerModel();
+ trigger.LogicalOperator = "And";
+ trigger.TriggerParts = new TriggerPart[] { triggerPart1 };
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.RequestURL = "http://test.com/?event1=true&queueittoken=queueittokenvalue";
+ requestMock.RemoteAddr = "80.35.35.34";
+ requestMock.Headers.put("via", "1.1 example.com");
+ requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
+ requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
+ requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
+ requestMock.Headers.put("x-forwarded-proto", "https");
+
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "eventId", true, null, secretKey, "debug");
+
+ try {
+ KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, null, "customerId", requestMock, responseMock, secretKey);
+ } catch (Exception ex) {
+ exceptionWasThrown = "cancelConfig can not be null.".equals(ex.getMessage());
+ }
+
+ // Assert
+ assertTrue(exceptionWasThrown);
+ assertTrue(responseMock.addedCookies.size() == 1);
+ String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
+ assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
+ assertTrue(
+ decodedCookieValue.contains("OriginalUrl=http://test.com/?event1=true&queueittoken=queueittokenvalue"));
+ assertTrue(decodedCookieValue.contains("CancelConfig=NULL"));
+ assertTrue(decodedCookieValue.contains("SdkVersion=v3-java-3.6.0"));
+ assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion()));
+ assertTrue(decodedCookieValue.contains("Exception=cancelConfig can not be null."));
+ }
+
+ @Test
+ public void CancelRequestByLocalConfig_Debug_Missing_CustomerId() throws Exception {
+
+ // Assert
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CancelEventConfig cancelEventConfig = new CancelEventConfig();
+ cancelEventConfig.setCookieDomain("cookiedomain");
+ cancelEventConfig.setEventId("event1");
+ cancelEventConfig.setQueueDomain("queuedomain");
+ cancelEventConfig.setVersion(1);
+ cancelEventConfig.setActionName("cancelAction");
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ RequestValidationResult result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, cancelEventConfig, null, requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(result.getRedirectUrl().equals("https://api2.queue-it.net/diagnostics/connector/error/?code=setup"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void CancelRequestByLocalConfig_Debug_Missing_SecretKey() throws Exception {
+
+ // Assert
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CancelEventConfig cancelEventConfig = new CancelEventConfig();
+ cancelEventConfig.setCookieDomain("cookiedomain");
+ cancelEventConfig.setEventId("event1");
+ cancelEventConfig.setQueueDomain("queuedomain");
+ cancelEventConfig.setVersion(1);
+ cancelEventConfig.setActionName("cancelAction");
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, 1);
+
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ RequestValidationResult result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, cancelEventConfig, "customerId", requestMock, responseMock, null);
+
+ // Assert
+ assertTrue(result.getRedirectUrl().equals("https://api2.queue-it.net/diagnostics/connector/error/?code=setup"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void CancelRequestByLocalConfig_Debug_ExpiredToken() throws Exception {
+
+ // Arrange
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CancelEventConfig cancelEventConfig = new CancelEventConfig();
+ cancelEventConfig.setCookieDomain("cookiedomain");
+ cancelEventConfig.setEventId("eventid");
+ cancelEventConfig.setQueueDomain("queuedomain");
+ cancelEventConfig.setVersion(1);
+ cancelEventConfig.setActionName("cancelAction");
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ date = addDays(date, -1);
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug");
+
+ RequestValidationResult result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, cancelEventConfig, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(result.getRedirectUrl()
+ .equals("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=timestamp"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ @Test
+ public void CancelRequestByLocalConfig_Debug_ModifiedToken() throws Exception {
+
+ // Assert
+ HttpServletResponseMock responseMock = new HttpServletResponseMock();
+
+ HttpServletRequestMock requestMock = new HttpServletRequestMock();
+ requestMock.Headers.put("x-queueit-ajaxpageurl", "http%3A%2F%2Furl");
+
+ UserInQueueServiceMock mock = new UserInQueueServiceMock();
+ KnownUser.setUserInQueueService(mock);
+
+ CancelEventConfig cancelEventConfig = new CancelEventConfig();
+ cancelEventConfig.setCookieDomain("cookiedomain");
+ cancelEventConfig.setEventId("eventid");
+ cancelEventConfig.setQueueDomain("queuedomain");
+ cancelEventConfig.setVersion(1);
+ cancelEventConfig.setActionName("cancelAction");
+
+ // Act
+ String secretKey = "secretkey";
+ Date date = new Date();
+ String queueittoken = QueueITTokenGenerator.generateToken(date, "event1", true, null, secretKey, "debug")
+ + "invalid-hash";
+
+ RequestValidationResult result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true",
+ queueittoken, cancelEventConfig, "customerId", requestMock, responseMock, secretKey);
+
+ // Assert
+ assertTrue(result.getRedirectUrl()
+ .equals("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=hash"));
+ assertTrue(responseMock.addedCookies.isEmpty());
+ }
+
+ class HttpServletRequestMock implements HttpServletRequest {
+
+ public Cookie[] CookiesValue;
+ public String UserAgent;
+ public String RequestURL;
+ public String QueryString;
+ public String RemoteAddr;
+ public HashMap Headers;
+
+ public HttpServletRequestMock() {
+ this.Headers = new HashMap();
+ }
+
+ @Override
+ public String getAuthType() {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
+ }
+
+ @Override
+ public Cookie[] getCookies() {
+ return this.CookiesValue;
+ }
+
+ @Override
+ public long getDateHeader(String string) {
+ 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;
+ }
+
+ String value = (String) this.Headers.get(key);
+
+ if (value == null) {
+ value = "";
+ }
+
+ return value;
+ }
+
+ @Override
+ public Enumeration getHeaders(String string) {
+ 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 int getIntHeader(String string) {
+ 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 getPathInfo() {
+ 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 String getContextPath() {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
+ }
+
+ @Override
+ public String getQueryString() {
+ return this.QueryString;
+ }
+
+ @Override
+ public String getRemoteUser() {
+ 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 Principal getUserPrincipal() {
+ 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 getRequestURI() {
+ 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 String getServletPath() {
+ 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 HttpSession getSession() {
+ 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 boolean isRequestedSessionIdFromCookie() {
+ 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 boolean isRequestedSessionIdFromUrl() {
+ 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 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 logout() throws ServletException {
+ 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 Part getPart(String string) throws IOException, ServletException {
+ 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 Enumeration getAttributeNames() {
+ 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 setCharacterEncoding(String string) throws UnsupportedEncodingException {
+ 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 getContentType() {
+ 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 String getParameter(String string) {
+ 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[] getParameterValues(String string) {
+ 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 String getProtocol() {
+ 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 getServerName() {
+ 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 BufferedReader getReader() throws IOException {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
+ }
+
+ @Override
+ public String getRemoteAddr() {
+ return RemoteAddr;
+ }
+
+ @Override
+ public String getRemoteHost() {
+ 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 void removeAttribute(String string) {
+ 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 Enumeration getLocales() {
+ 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 RequestDispatcher getRequestDispatcher(String string) {
+ 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 int getRemotePort() {
+ 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 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 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 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 Date addDays(Date date, int days) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+ cal.add(Calendar.DATE, days); // minus number would decrement the days
+ return cal.getTime();
+ }
+
+ public static String GetRuntimeVersion() {
+ return KnownUser.GetRuntime();
+ }
+}
diff --git a/SDK/test/queueit/knownuserv3/sdk/UrlParameterProviderTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/UrlParameterProviderTest.java
similarity index 53%
rename from SDK/test/queueit/knownuserv3/sdk/UrlParameterProviderTest.java
rename to SDK/src/test/java/queueit/knownuserv3/sdk/UrlParameterProviderTest.java
index f27b4ee..36ac538 100644
--- a/SDK/test/queueit/knownuserv3/sdk/UrlParameterProviderTest.java
+++ b/SDK/src/test/java/queueit/knownuserv3/sdk/UrlParameterProviderTest.java
@@ -14,6 +14,7 @@ public void TryExtractQueueParams_Test() {
assertTrue("eventid".equals(queueParameter.getEventId()));
assertTrue(queueParameter.getCookieValidityMinutes() == 10);
assertTrue(queueParameter.getExtendableCookie() == false);
+ assertTrue("944c1f44-60dd-4e37-aabc-f3e4bb1c8895".equals(queueParameter.getQueueId()));
assertTrue("218b734e-d5be-4b60-ad66-9b1b326266e2".equals(queueParameter.getHashCode()));
assertTrue(queueitToken.equals(queueParameter.getQueueITToken()));
assertTrue("ts_1480593661~cv_10~ce_false~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895~c_customerid~e_eventid~rt_disabled".equals(queueParameter.getQueueITTokenWithoutHash()));
@@ -21,14 +22,38 @@ public void TryExtractQueueParams_Test() {
@Test
public void TryExtractQueueParams_NotValidFormat_Test() {
- String queueitToken = "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895";
+ String queueitToken = "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895~h_218b734e-d5be-4b60-ad66-9b1b326266e2";
+ String queueitTokenWithoutHash = "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895";
QueueUrlParams queueParameter = QueueParameterHelper.extractQueueParams(queueitToken);
assertTrue(queueParameter.getTimeStamp() == 0);
assertTrue("".equals(queueParameter.getEventId()));
assertTrue(queueParameter.getCookieValidityMinutes() == null);
assertTrue(queueParameter.getExtendableCookie() == false);
+ assertTrue("944c1f44-60dd-4e37-aabc-f3e4bb1c8895".equals(queueParameter.getQueueId()));
+ assertTrue("218b734e-d5be-4b60-ad66-9b1b326266e2".equals(queueParameter.getHashCode()));
+ assertTrue(queueitToken.equals(queueParameter.getQueueITToken()));
+ assertTrue(queueitTokenWithoutHash.equals(queueParameter.getQueueITTokenWithoutHash()));
+ }
+
+ @Test
+ public void TryExtractQueueParams_Using_QueueitToken_With_No_Values_Test() {
+ String queueitToken = "e~q~ts~ce~rt~h";
+
+ QueueUrlParams queueParameter = QueueParameterHelper.extractQueueParams(queueitToken);
+ assertTrue(queueParameter.getTimeStamp() == 0);
+ assertTrue("".equals(queueParameter.getEventId()));
+ assertTrue(queueParameter.getCookieValidityMinutes() == null);
+ assertTrue(queueParameter.getExtendableCookie() == false);
+ assertTrue("".equals(queueParameter.getQueueId()));
assertTrue("".equals(queueParameter.getHashCode()));
assertTrue(queueitToken.equals(queueParameter.getQueueITToken()));
+ assertTrue(queueitToken.equals(queueParameter.getQueueITTokenWithoutHash()));
+ }
+
+ @Test
+ public void TryExtractQueueParams_Using_No_QueueitToken_Expect_Null() {
+ QueueUrlParams queueParameter = QueueParameterHelper.extractQueueParams("");
+ assertTrue(queueParameter == null);
}
}
diff --git a/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueServiceTest.java
similarity index 65%
rename from SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java
rename to SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueServiceTest.java
index 1d1c6ac..0270e80 100644
--- a/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java
+++ b/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueServiceTest.java
@@ -1,3 +1,4 @@
+
package queueit.knownuserv3.sdk;
import java.net.URLEncoder;
@@ -6,6 +7,7 @@
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -13,7 +15,7 @@
public class UserInQueueServiceTest {
- //ExtendableCookie Cookie
+ // ExtendableCookie Cookie
@Test
public void validateQueueRequest_ValidState_ExtendableCookie_NoCookieExtensionFromConfig_DoNotRedirectDoNotStoreCookieWithExtension()
throws Exception {
@@ -23,31 +25,36 @@ public void validateQueueRequest_ValidState_ExtendableCookie_NoCookieExtensionFr
config.setQueueDomain("testdomain.com");
config.setCookieValidityMinute(10);
config.setExtendCookieValidity(false);
+ config.setActionName("QueueAction");
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
conditions.put("isStoreWasCalled", false);
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomainString,
- String redirectType, String customerSecretKey) throws Exception {
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes,
+ String cookieDomainString, String redirectType, String customerSecretKey) throws Exception {
conditions.put("isStoreWasCalled", true);
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(true, "queueId", null, "queue");
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
@@ -58,10 +65,12 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
assertTrue(result.getEventId().equals("e1"));
assertTrue(result.getQueueId().equals("queueId"));
assertTrue(result.getRedirectType().equals("queue"));
+ assertEquals(result.getActionName(), config.getActionName());
}
@Test
- public void validateQueueRequest_ValidState_ExtendableCookie_CookieExtensionFromConfig_DoNotRedirect_DoStoreCookieWithExtension() throws Exception {
+ public void validateQueueRequest_ValidState_ExtendableCookie_CookieExtensionFromConfig_DoNotRedirect_DoStoreCookieWithExtension()
+ throws Exception {
QueueEventConfig config = new QueueEventConfig();
config.setEventId("e1");
@@ -69,13 +78,15 @@ public void validateQueueRequest_ValidState_ExtendableCookie_CookieExtensionFrom
config.setCookieValidityMinute(10);
config.setExtendCookieValidity(true);
config.setCookieDomain(".testdomain.com");
- final HashMap> callInfo = new HashMap();
- callInfo.put("firstCall", new HashMap());
+ config.setActionName("QueueAction");
+ final HashMap> callInfo = new HashMap>();
+ callInfo.put("firstCall", new HashMap());
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception {
- HashMap info = new HashMap();
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
+ String redirectType, String customerSecretKey) throws Exception {
+ HashMap info = new HashMap();
info.put("eventId", eventId);
info.put("fixedCookieValidityMinutes", fixedCookieValidityMinutes);
info.put("redirectType", redirectType);
@@ -86,19 +97,23 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(true, "queueId", null, "queue");
}
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
@@ -111,6 +126,7 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
assertTrue(callInfo.get("firstCall").get("redirectType").equals("queue"));
assertTrue(callInfo.get("firstCall").get("customerSecretKey").equals("key"));
assertTrue(callInfo.get("firstCall").get("cookieDomain").equals(".testdomain.com"));
+ assertEquals(result.getActionName(), config.getActionName());
}
@Test
@@ -122,31 +138,36 @@ public void validateQueueRequest_ValidState_NoExtendableCookie_DoNotRedirect_DoN
config.setQueueDomain("testdomain.com");
config.setCookieValidityMinute(10);
config.setExtendCookieValidity(true);
+ config.setActionName("QueueAction");
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
conditions.put("isStoreWasCalled", false);
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception {
- HashMap info = new HashMap();
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
+ String redirectType, String customerSecretKey) throws Exception {
conditions.put("isStoreWasCalled", true);
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(true, "queueId", "3", "idle");
}
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
@@ -156,40 +177,48 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
assertTrue(!conditions.get("isStoreWasCalled"));
assertTrue(result.getEventId().equals("e1"));
assertTrue(result.getQueueId().equals("queueId"));
+ assertEquals(result.getActionName(), config.getActionName());
}
@Test
- public void ValidateQueueRequest_NoCookie_TampredToken_RedirectToErrorPageWithHashError_DoNotStoreCookie() throws Exception {
+ public void ValidateQueueRequest_NoCookie_TampredToken_RedirectToErrorPageWithHashError_DoNotStoreCookie()
+ throws Exception {
QueueEventConfig config = new QueueEventConfig();
config.setEventId("e1");
config.setQueueDomain("testDomain.com");
config.setCookieValidityMinute(10);
config.setExtendCookieValidity(false);
config.setVersion(100);
+ config.setActionName("QueueAction");
+ config.setCookieDomain("TestDomain");
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
conditions.put("isStoreWasCalled", false);
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ conditions.put("cancelQueueCookieWasCalled", true);
}
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception {
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
+ String redirectType, String customerSecretKey) throws Exception {
conditions.put("isStoreWasCalled", true);
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(false, null, null, null);
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
@@ -199,14 +228,13 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
String targetUrl = "http://test.test.com?b=h";
String knownUserVersion = UserInQueueService.SDK_VERSION;
- String expectedErrorUrl = "https://testDomain.com/error/hash/?c=testCustomer&e=e1"
- + "&ver=v3-java-" + knownUserVersion
- + "&cver=100"
- + "&queueittoken=" + queueitToken
- + "&t=" + URLEncoder.encode(targetUrl, "UTF-8");
+ String expectedErrorUrl = "https://testDomain.com/error/hash/?c=testCustomer&e=e1" + "&ver=" + knownUserVersion
+ + "&cver=100" + "&man=" + config.getActionName() + "&queueittoken=" + queueitToken + "&t="
+ + URLEncoder.encode(targetUrl, "UTF-8");
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
- RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey);
+ RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config,
+ "testCustomer", customerKey);
assertTrue(result.doRedirect());
Pattern pattern = Pattern.compile("&ts=[^&]*");
@@ -220,41 +248,50 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
assertTrue(redirectUrl.toUpperCase().equals(expectedErrorUrl.toUpperCase()));
assertTrue(config.getEventId().equals(result.getEventId()));
assertTrue(!conditions.get("isStoreWasCalled"));
+ assertEquals(result.getActionName(), config.getActionName());
+ assertTrue(conditions.get("cancelQueueCookieWasCalled"));
}
@Test
- public void ValidateQueueRequest_NoCookie_ExpiredTimeStampInToken_RedirectToErrorPageWithTimeStampError_DoNotStoreCookie() throws Exception {
+ public void ValidateQueueRequest_NoCookie_ExpiredTimeStampInToken_RedirectToErrorPageWithTimeStampError_DoNotStoreCookie()
+ throws Exception {
QueueEventConfig config = new QueueEventConfig();
config.setEventId("e1");
config.setQueueDomain("testDomain.com");
config.setCookieValidityMinute(10);
config.setExtendCookieValidity(false);
config.setVersion(100);
+ config.setActionName("QueueAction");
+ config.setCookieDomain("testDomain");
String customerKey = "4e1db821-a825-49da-acd0-5d376f2068db";
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
conditions.put("isStoreWasCalled", false);
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ conditions.put("cancelQueueCookie", true);
}
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception {
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
+ String redirectType, String customerSecretKey) throws Exception {
conditions.put("isStoreWasCalled", true);
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(false, null, null, null);
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
@@ -264,14 +301,13 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
String targetUrl = "http://test.test.com?b=h";
String knownUserVersion = UserInQueueService.SDK_VERSION;
- String expectedErrorUrl = "https://testDomain.com/error/timestamp/?c=testCustomer&e=e1"
- + "&ver=v3-java-" + knownUserVersion
- + "&cver=100"
- + "&queueittoken=" + queueitToken
+ String expectedErrorUrl = "https://testDomain.com/error/timestamp/?c=testCustomer&e=e1" + "&ver="
+ + knownUserVersion + "&cver=100" + "&man=" + config.getActionName() + "&queueittoken=" + queueitToken
+ "&t=" + URLEncoder.encode(targetUrl, "UTF-8");
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
- RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey);
+ RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config,
+ "testCustomer", customerKey);
assertTrue(result.doRedirect());
Pattern pattern = Pattern.compile("&ts=[^&]*");
@@ -285,41 +321,50 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
assertTrue(redirectUrl.toUpperCase().equals(expectedErrorUrl.toUpperCase()));
assertTrue(config.getEventId().equals(result.getEventId()));
assertTrue(!conditions.get("isStoreWasCalled"));
+ assertEquals(result.getActionName(), config.getActionName());
+ assertTrue(conditions.get("cancelQueueCookie"));
}
@Test
- public void ValidateQueueRequest_NoCookie_EventIdMismatch_RedirectToErrorPageWithEventIdMissMatchError_DoNotStoreCookie() throws Exception {
+ public void ValidateQueueRequest_NoCookie_EventIdMismatch_RedirectToErrorPageWithEventIdMissMatchError_DoNotStoreCookie()
+ throws Exception {
QueueEventConfig config = new QueueEventConfig();
config.setEventId("e2");
config.setQueueDomain("testDomain.com");
config.setCookieValidityMinute(10);
config.setExtendCookieValidity(false);
config.setVersion(10);
+ config.setActionName("QueueAction");
+ config.setCookieDomain("testDomain");
String customerKey = "4e1db821-a825-49da-acd0-5d376f2068db";
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
conditions.put("isStoreWasCalled", false);
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ conditions.put("cancelQueueCookie", true);
}
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception {
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
+ String redirectType, String customerSecretKey) throws Exception {
conditions.put("isStoreWasCalled", true);
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(false, null, null, null);
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
@@ -329,14 +374,13 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
String targetUrl = "http://test.test.com?b=h";
String knownUserVersion = UserInQueueService.SDK_VERSION;
- String expectedErrorUrl = "https://testDomain.com/error/eventid/?c=testCustomer&e=e2"
- + "&ver=v3-java-" + knownUserVersion
- + "&cver=10"
- + "&queueittoken=" + queueitToken
+ String expectedErrorUrl = "https://testDomain.com/error/eventid/?c=testCustomer&e=e2" + "&ver="
+ + knownUserVersion + "&cver=10" + "&man=" + config.getActionName() + "&queueittoken=" + queueitToken
+ "&t=" + URLEncoder.encode(targetUrl, "UTF-8");
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
- RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey);
+ RequestValidationResult result = testObject.validateQueueRequest(targetUrl, queueitToken, config,
+ "testCustomer", customerKey);
assertTrue(result.doRedirect());
Pattern pattern = Pattern.compile("&ts=[^&]*");
@@ -350,25 +394,29 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
assertTrue(redirectUrl.toUpperCase().equals(expectedErrorUrl.toUpperCase()));
assertTrue(config.getEventId().equals(result.getEventId()));
assertTrue(!conditions.get("isStoreWasCalled"));
+ assertEquals(result.getActionName(), config.getActionName());
+ assertTrue(conditions.get("cancelQueueCookie"));
}
@Test
- public void ValidateQueueRequest_NoCookie_ValidToken_ExtendableCookie_DoNotRedirect_StoreExtendableCookie() throws Exception {
+ public void ValidateQueueRequest_NoCookie_ValidToken_ExtendableCookie_DoNotRedirect_StoreExtendableCookie()
+ throws Exception {
QueueEventConfig config = new QueueEventConfig();
config.setEventId("e1");
config.setCookieDomain(".testdomain.com");
config.setCookieValidityMinute(10);
config.setExtendCookieValidity(false);
+ config.setActionName("QueueAction");
String customerKey = "4e1db821-a825-49da-acd0-5d376f2068db";
- final HashMap> callInfo = new HashMap();
- callInfo.put("firstCall", new HashMap());
+ final HashMap> callInfo = new HashMap>();
+ callInfo.put("firstCall", new HashMap());
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
String redirectType, String customerSecretKey) throws Exception {
- HashMap info = new HashMap();
+ HashMap info = new HashMap();
info.put("eventId", eventId);
info.put("fixedCookieValidityMinutes", fixedCookieValidityMinutes);
info.put("cookieDomain", cookieDomain);
@@ -378,18 +426,24 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(false, null, null, null);
}
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ HashMap obj = new HashMap();
+ obj.put("eventId", eventId);
+ obj.put("cookieDomain", cookieDomain);
+ callInfo.put("cancelQueueCookieWasCalled", obj);
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
@@ -400,32 +454,37 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
String targetUrl = "http://test.test.com?b=h";
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
- RequestValidationResult result = testObject.validateQueueRequest(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("fixedCookieValidityMinutes") == null);
assertTrue(callInfo.get("firstCall").get("cookieDomain").equals(config.getCookieDomain()));
assertTrue(callInfo.get("firstCall").get("redirectType").equals("queue"));
assertTrue(callInfo.get("firstCall").get("customerSecretKey").equals(customerKey));
+ assertEquals(result.getActionName(), config.getActionName());
+ assertTrue(callInfo.get("cancelQueueCookieWasCalled") == null);
}
@Test
- public void ValidateQueueRequest_NoCookie_ValidToken_CookieValidityMinuteFromToken_DoNotRedirect_StoreNonExtendableCookie() throws Exception {
+ public void ValidateQueueRequest_NoCookie_ValidToken_CookieValidityMinuteFromToken_DoNotRedirect_StoreNonExtendableCookie()
+ throws Exception {
QueueEventConfig config = new QueueEventConfig();
config.setEventId("eventid");
- config.setCookieDomain(".testdomain.com");
config.setCookieValidityMinute(10);
config.setExtendCookieValidity(true);
+ config.setActionName("QueueAction");
+ config.setCookieDomain("testDomain");
String customerKey = "secretekeyofuser";
- final HashMap> callInfo = new HashMap();
- callInfo.put("firstCall", new HashMap());
+ final HashMap> callInfo = new HashMap>();
+ callInfo.put("firstCall", new HashMap());
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
String redirectType, String customerSecretKey) throws Exception {
- HashMap info = new HashMap();
+ HashMap info = new HashMap();
info.put("eventId", eventId);
info.put("fixedCookieValidityMinutes", fixedCookieValidityMinutes);
info.put("cookieDomain", cookieDomain);
@@ -435,18 +494,24 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(false, null, null, null);
}
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ HashMap obj = new HashMap();
+ obj.put("eventId", eventId);
+ obj.put("cookieDomain", cookieDomain);
+ callInfo.put("cancelQueueCookieWasCalled", obj);
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
@@ -454,7 +519,8 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
String targetUrl = "http://test.test.com?b=h";
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
- RequestValidationResult result = testObject.validateQueueRequest(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("redirectType").equals("DirectLink"));
@@ -462,51 +528,56 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
assertTrue(callInfo.get("firstCall").get("fixedCookieValidityMinutes").equals(3));
assertTrue(callInfo.get("firstCall").get("customerSecretKey").equals(customerKey));
assertTrue(config.getEventId().equals(result.getEventId()));
+ assertEquals(result.getActionName(), config.getActionName());
+ assertTrue(callInfo.get("cancelQueueCookieWasCalled") == null);
}
@Test
public void ValidateQueueRequest_NoCookie_WithoutToken_RedirectToQueue() throws Exception {
QueueEventConfig config = new QueueEventConfig();
config.setEventId("e1");
- config.setQueueDomain("testDomain.com");
config.setCookieValidityMinute(10);
config.setExtendCookieValidity(false);
config.setLayoutName("testlayout");
config.setVersion(10);
+ config.setActionName("QueueAction");
+ config.setQueueDomain("testDomain.com");
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
conditions.put("isStoreWasCalled", false);
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ conditions.put("cancelQueueCookie", true);
}
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception {
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
+ String redirectType, String customerSecretKey) throws Exception {
conditions.put("isStoreWasCalled", true);
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(false, null, null, null);
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
String targetUrl = "http://test.test.com?b=h";
String knownUserVersion = UserInQueueService.SDK_VERSION;
- String expectedErrorUrl = "https://testDomain.com?c=testCustomer&e=e1"
- + "&ver=v3-java-" + knownUserVersion
- + "&cver=10"
- + "&l=" + config.getLayoutName()
- + "&t=" + URLEncoder.encode(targetUrl, "UTF-8");
+ String expectedErrorUrl = "https://testDomain.com/?c=testCustomer&e=e1" + "&ver=" + knownUserVersion
+ + "&cver=10" + "&man=" + config.getActionName() + "&l=" + config.getLayoutName() + "&t="
+ + URLEncoder.encode(targetUrl, "UTF-8");
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
RequestValidationResult result = testObject.validateQueueRequest(targetUrl, "", config, "testCustomer", "key");
@@ -514,6 +585,8 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
assertTrue(result.getRedirectUrl().toUpperCase().equals(expectedErrorUrl.toUpperCase()));
assertTrue(!conditions.get("isStoreWasCalled"));
assertTrue(config.getEventId().equals(result.getEventId()));
+ assertEquals(result.getActionName(), config.getActionName());
+ assertTrue(conditions.get("cancelQueueCookie"));
}
@Test
@@ -525,38 +598,42 @@ public void ValidateQueueRequest_NoCookie_WithoutToken_RedirectToQueue_NoTargetU
config.setExtendCookieValidity(false);
config.setLayoutName("testlayout");
config.setVersion(10);
+ config.setActionName("QueueAction");
+ config.setCookieDomain("testDomain");
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
conditions.put("isStoreWasCalled", false);
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ conditions.put("cancelQueueCookie", true);
}
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception {
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
+ String redirectType, String customerSecretKey) throws Exception {
conditions.put("isStoreWasCalled", true);
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(false, null, null, null);
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, 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 expectedErrorUrl = "https://testDomain.com?c=testCustomer&e=e1"
- + "&ver=v3-java-" + knownUserVersion
- + "&cver=10"
- + "&l=" + config.getLayoutName();
+ String expectedErrorUrl = "https://testDomain.com/?c=testCustomer&e=e1" + "&ver=" + knownUserVersion
+ + "&cver=10" + "&man=" + config.getActionName() + "&l=" + config.getLayoutName();
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
RequestValidationResult result = testObject.validateQueueRequest(null, "", config, "testCustomer", "key");
@@ -564,6 +641,8 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String
assertTrue(result.getRedirectUrl().toUpperCase().equals(expectedErrorUrl.toUpperCase()));
assertTrue(!conditions.get("isStoreWasCalled"));
assertTrue(config.getEventId().equals(result.getEventId()));
+ assertEquals(result.getActionName(), config.getActionName());
+ assertTrue(conditions.get("cancelQueueCookie"));
}
@Test
@@ -575,47 +654,52 @@ public void ValidateQueueRequest_NoCookie_InValidToken() throws Exception {
config.setExtendCookieValidity(false);
config.setLayoutName("testlayout");
config.setVersion(10);
+ config.setActionName("QueueAction");
+ config.setCookieDomain("testDomain");
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
conditions.put("isStoreWasCalled", false);
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
public void cancelQueueCookie(String eventId, String cookieDomain) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ conditions.put("cancelQueueCookie", true);
}
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception {
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
+ String redirectType, String customerSecretKey) throws Exception {
conditions.put("isStoreWasCalled", true);
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
return new StateInfo(false, null, null, null);
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
};
- String targetUrl = "http://test.test.com?b=h";
+ String targetUrl = "http://test.test.com/?b=h";
String knownUserVersion = UserInQueueService.SDK_VERSION;
- String expectedErrorUrl = "https://testDomain.com?c=testCustomer&e=e1"
- + "&ver=v3-" + knownUserVersion
- + "&cver=10"
- + "&l=" + config.getLayoutName()
- + "&t=" + URLEncoder.encode(targetUrl, "UTF-8");
-
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
- RequestValidationResult result = testObject.validateQueueRequest(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(result.getRedirectUrl().startsWith("https://testDomain.com/error/hash/?c=testCustomer&e=e1&ver="
+ + knownUserVersion + "&cver=10&man=" + config.getActionName()
+ + "&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()));
+ assertEquals(result.getActionName(), config.getActionName());
+ assertTrue(conditions.get("cancelQueueCookie"));
}
@Test
@@ -625,17 +709,20 @@ public void validateCancelRequest() throws Exception {
config.setQueueDomain("testDomain.com");
config.setCookieDomain("testdomain");
config.setVersion(10);
+ config.setActionName("Queue Action (._~-) &!*|'\"");
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() {
@Override
- public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception {
+ public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain,
+ String redirectType, String customerSecretKey) throws Exception {
}
@Override
- public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) {
+ public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey,
+ boolean validateTime) {
if (!validateTime) {
return new StateInfo(true, "queueId", null, "queue");
} else {
@@ -644,8 +731,10 @@ public StateInfo getState(String eventId, int cookieValidityMinutes, String cust
}
@Override
- public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain, String secretKey) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String cookieDomain,
+ String secretKey) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods,
+ // choose Tools | Templates.
}
@Override
@@ -654,10 +743,9 @@ public void cancelQueueCookie(String eventId, String cookieDomain) {
}
};
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";
+ String expectedMan = "Queue%20Action%20%28._%7E-%29%20%26%21%2A%7C%27%22";
+ String expectedUrl = "https://testDomain.com/cancel/testCustomer/e1/?c=testCustomer&e=e1" + "&ver="
+ + knownUserVersion + "&cver=10" + "&man=" + expectedMan + "&r=url";
UserInQueueService testObject = new UserInQueueService(cookieProviderMock);
RequestValidationResult result = testObject.validateCancelRequest("url", config, "testCustomer", "key");
@@ -665,42 +753,49 @@ public void cancelQueueCookie(String eventId, String cookieDomain) {
assertTrue("eventId:e1,cookieDomain:testdomain".equals(conditions.get("cancelQueueCookieWasCalled")));
assertTrue(result.doRedirect());
assertTrue("queueId".equals(result.getQueueId()));
- assertTrue(expectedUrl.equals(result.getRedirectUrl()));
+ String expUrl = expectedUrl.toLowerCase();
+ String rdrUrl = result.getRedirectUrl().toLowerCase();
+ assertTrue(expUrl.equals(rdrUrl));
assertTrue(config.getEventId().equals(result.getEventId()));
+ assertEquals(result.getActionName(), config.getActionName());
}
@Test
public void getIgnoreRequest() throws Exception {
UserInQueueService testObject = new UserInQueueService(null);
- RequestValidationResult result = testObject.getIgnoreActionResult();
+ RequestValidationResult result = testObject.getIgnoreActionResult("TestIgnoreAction");
assertTrue(ActionType.IGNORE_ACTION.equals(result.getActionType()));
assertFalse(result.doRedirect());
assertNull(result.getEventId());
assertNull(result.getQueueId());
assertNull(result.getRedirectUrl());
+ assertEquals(result.getActionName(), "TestIgnoreAction");
}
public static class QueueITTokenGenerator {
- public static String generateToken(
- Date timeStamp,
- String eventId,
- boolean extendableCookie,
- Integer cookieValidityMinute,
- String secretKey,
- String redirectType) throws Exception {
- ArrayList paramList = new ArrayList();
- paramList.add(QueueParameterHelper.TimeStampKey + QueueParameterHelper.KeyValueSeparatorChar + GetUnixTimestamp(timeStamp));
+ public static String generateToken(Date timeStamp, String eventId, boolean extendableCookie,
+ Integer cookieValidityMinute, String secretKey, String redirectType) {
+
+ ArrayList paramList = new ArrayList();
+
+ paramList.add(QueueParameterHelper.TimeStampKey + QueueParameterHelper.KeyValueSeparatorChar
+ + GetUnixTimestamp(timeStamp));
if (cookieValidityMinute != null) {
- paramList.add(QueueParameterHelper.CookieValidityMinutesKey + QueueParameterHelper.KeyValueSeparatorChar + cookieValidityMinute);
+ paramList.add(QueueParameterHelper.CookieValidityMinutesKey + QueueParameterHelper.KeyValueSeparatorChar
+ + cookieValidityMinute);
}
paramList.add(QueueParameterHelper.EventIdKey + QueueParameterHelper.KeyValueSeparatorChar + eventId);
- paramList.add(QueueParameterHelper.ExtendableCookieKey + QueueParameterHelper.KeyValueSeparatorChar + extendableCookie);
- paramList.add(QueueParameterHelper.RedirectTypeKey + QueueParameterHelper.KeyValueSeparatorChar + redirectType);
+ paramList.add(QueueParameterHelper.ExtendableCookieKey + QueueParameterHelper.KeyValueSeparatorChar
+ + extendableCookie);
+ paramList.add(
+ QueueParameterHelper.RedirectTypeKey + QueueParameterHelper.KeyValueSeparatorChar + redirectType);
String tokenWithoutHash = Utils.join(QueueParameterHelper.KeyValueSeparatorGroupChar, paramList);
String hash = HashHelper.generateSHA256Hash(secretKey, tokenWithoutHash);
- String token = tokenWithoutHash + QueueParameterHelper.KeyValueSeparatorGroupChar + QueueParameterHelper.HashKey + QueueParameterHelper.KeyValueSeparatorChar + hash;
+ String token = tokenWithoutHash + QueueParameterHelper.KeyValueSeparatorGroupChar
+ + QueueParameterHelper.HashKey + QueueParameterHelper.KeyValueSeparatorChar + hash;
+
return token;
}
diff --git a/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java
similarity index 94%
rename from SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java
rename to SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java
index 37b8a4d..09f9cb1 100644
--- a/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java
+++ b/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java
@@ -15,8 +15,8 @@ public void store_getState_ExtendableCookie_CookieIsSaved() throws Exception {
String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc";
String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
int cookieValidity = 10;
- final HashMap> cookies = new HashMap();
- cookies.put(cookieKey, new HashMap());
+ final HashMap> cookies = new HashMap>();
+ cookies.put(cookieKey, new HashMap());
ICookieManager cookieManager = new ICookieManager() {
@@ -57,7 +57,7 @@ public void store_getState_TamperedCookie_StateIsNotValid() throws Exception {
String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc";
String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
int cookieValidity = 10;
- final HashMap cookies = new HashMap();
+ final HashMap cookies = new HashMap();
ICookieManager cookieManager = new ICookieManager() {
@@ -91,7 +91,7 @@ public void store_getState_ExpiredCookie_StateIsNotValid_Queue() throws Exceptio
String secretKey = "4e1db821-a825-49da-acd0-5d376f2068db";
String cookieDomain = ".test.com";
String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc";
- final HashMap cookies = new HashMap();
+ final HashMap cookies = new HashMap();
ICookieManager cookieManager = new ICookieManager() {
@@ -118,7 +118,7 @@ public void store_getState_ExpiredCookie_StateIsNotValid_Idle() throws Exception
String secretKey = "4e1db821-a825-49da-acd0-5d376f2068db";
String cookieDomain = ".test.com";
String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc";
- final HashMap cookies = new HashMap();
+ final HashMap cookies = new HashMap();
ICookieManager cookieManager = new ICookieManager() {
@@ -145,9 +145,8 @@ public void store_getState_DifferentEventId_StateIsNotValid() throws Exception {
String secretKey = "4e1db821-a825-49da-acd0-5d376f2068db";
String cookieDomain = ".test.com";
String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc";
- String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
-
- final HashMap cookies = new HashMap();
+
+ final HashMap cookies = new HashMap();
ICookieManager cookieManager = new ICookieManager() {
@@ -203,9 +202,9 @@ public void cancelQueueCookie_Test() throws Exception {
String cookieDomain = "testDomain";
String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
- final HashMap> cookies = new HashMap();
- cookies.put(cookieKey + "1", new HashMap());
- cookies.put(cookieKey + "2", new HashMap());
+ final HashMap> cookies = new HashMap>();
+ cookies.put(cookieKey + "1", new HashMap());
+ cookies.put(cookieKey + "2", new HashMap());
ICookieManager cookieManager = new ICookieManager() {
@@ -240,20 +239,18 @@ public String getCookie(String cookieName) {
}
@Test
- public void extendQueueCookie_CookietExist_Test() throws Exception {
+ public void extendQueueCookie_CookietExist_Test() {
String eventId = "event1";
String secretKey = "secretKey";
String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc";
- String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
- final HashMap cookie = new HashMap();
+ final HashMap cookie = new HashMap();
Long issueTime = (System.currentTimeMillis() / 1000L - 120);
String hash = HashHelper.generateSHA256Hash(secretKey, eventId + queueId + "3" + "idle" + String.valueOf(issueTime));
final String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&FixedValidityMins=3&RedirectType=idle&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash;
ICookieManager cookieManager = new ICookieManager() {
- public int setCookieCallNumber = 0;
boolean isSetCookieCalled = false;
@Override
@@ -297,7 +294,7 @@ public void extendQueueCookie_CookieDoesNotExist_Test() {
String eventId = "event1";
String secretKey = "secretKey";
- final HashMap conditions = new HashMap();
+ final HashMap conditions = new HashMap();
conditions.put("isSetCookieCalled", false);
ICookieManager cookieManager = new ICookieManager() {
@@ -318,7 +315,7 @@ public String getCookie(String cookieName) {
}
@Test
- public void getState_ValidCookieFormat_Extendable_Test() throws Exception {
+ public void getState_ValidCookieFormat_Extendable_Test() {
String eventId = "event1";
String secretKey = "secretKey";
@@ -350,7 +347,7 @@ public String getCookie(String cookieName) {
}
@Test
- public void getState_ValidCookieFormat_NonExtendable_Test() throws Exception {
+ public void getState_ValidCookieFormat_NonExtendable_Test() {
String eventId = "event1";
String secretKey = "secretKey";
@@ -382,7 +379,7 @@ public String getCookie(String cookieName) {
}
@Test
- public void getState_OldCookie_InValid_ExpiredCookie_Extendable_Test() throws Exception {
+ public void getState_OldCookie_InValid_ExpiredCookie_Extendable_Test() {
String eventId = "event1";
String secretKey = "secretKey";
@@ -411,7 +408,7 @@ public String getCookie(String cookieName) {
}
@Test
- public void getState_OldCookie_InValid_ExpiredCookie_NonExtendable_Test() throws Exception {
+ public void getState_OldCookie_InValid_ExpiredCookie_NonExtendable_Test() {
String eventId = "event1";
String secretKey = "secretKey";
String queueId = "f8757c2d-34c2-4639-bef2-1736cdd30bbb";
diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java
similarity index 67%
rename from SDK/test/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java
rename to SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java
index 4d53e5c..2e59b48 100644
--- a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java
+++ b/SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java
@@ -26,30 +26,6 @@ public void Evaluate_Contains() {
assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.CONTAINS, false, false, "test_dsdsdsdtest1", "*", null));
}
- @Test
- public void Evaluate_StartsWith() {
- assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.STARTS_WITH, false, false, "test1_test1_test", "test1", null));
- assertFalse(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.STARTS_WITH, false, false, "test1_test1_test", "Test1", null));
- assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.STARTS_WITH, false, true, "test1_test1_test", "Test1", null));
- assertFalse(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.STARTS_WITH, true, true, "test1_test1_test", "Test1", null));
- }
-
- @Test
- public void Evaluate_EndsWith() {
- assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ENDS_WITH, false, false, "test1_test1_testshop", "shop", null));
- assertFalse(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ENDS_WITH, false, false, "test1_test1_testshop2", "shop", null));
- assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ENDS_WITH, false, true, "test1_test1_testshop", "Shop", null));
- assertFalse(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ENDS_WITH, true, true, "test1_test1_testshop", "Shop", null));
- }
-
- @Test
- public void Evaluate_MatchesWith() {
- assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.MATCHES_WITH, false, false, "test1_test1_testshop", ".*shop.*", null));
- assertFalse(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.MATCHES_WITH, false, false, "test1_test1_testshop2", ".*Shop.*", null));
- assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.MATCHES_WITH, false, true, "test1_test1_testshop", ".*Shop.*", null));
- assertFalse(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.MATCHES_WITH, true, true, "test1_test1_testshop", ".*Shop.*", null));
- }
-
@Test
public void Evaluate_EqualsAny() {
assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EQUALS_ANY, false, false, "test1", null, new String[]{"test1"}));
diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/CookieValidatorHelperTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/CookieValidatorHelperTest.java
similarity index 100%
rename from SDK/test/queueit/knownuserv3/sdk/integrationconfig/CookieValidatorHelperTest.java
rename to SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/CookieValidatorHelperTest.java
diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/HttpHeaderHelperTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/HttpHeaderHelperTest.java
similarity index 100%
rename from SDK/test/queueit/knownuserv3/sdk/integrationconfig/HttpHeaderHelperTest.java
rename to SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/HttpHeaderHelperTest.java
diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluatorTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluatorTest.java
similarity index 100%
rename from SDK/test/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluatorTest.java
rename to SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluatorTest.java
diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/UrlValidatorHelperTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/UrlValidatorHelperTest.java
similarity index 100%
rename from SDK/test/queueit/knownuserv3/sdk/integrationconfig/UrlValidatorHelperTest.java
rename to SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/UrlValidatorHelperTest.java
diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/UserAgentValidatorHelperTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/UserAgentValidatorHelperTest.java
similarity index 100%
rename from SDK/test/queueit/knownuserv3/sdk/integrationconfig/UserAgentValidatorHelperTest.java
rename to SDK/src/test/java/queueit/knownuserv3/sdk/integrationconfig/UserAgentValidatorHelperTest.java
diff --git a/SDK/src/test/java/queueit/knownuserv3/sdk/resources/hamcrest-core-1.3.jar b/SDK/src/test/java/queueit/knownuserv3/sdk/resources/hamcrest-core-1.3.jar
new file mode 100644
index 0000000..9d5fe16
Binary files /dev/null and b/SDK/src/test/java/queueit/knownuserv3/sdk/resources/hamcrest-core-1.3.jar differ
diff --git a/SDK/src/test/java/queueit/knownuserv3/sdk/resources/javax.servlet-api.jar b/SDK/src/test/java/queueit/knownuserv3/sdk/resources/javax.servlet-api.jar
new file mode 100644
index 0000000..8161e88
Binary files /dev/null and b/SDK/src/test/java/queueit/knownuserv3/sdk/resources/javax.servlet-api.jar differ
diff --git a/SDK/src/test/resources/hamcrest-core-1.3.jar b/SDK/src/test/resources/hamcrest-core-1.3.jar
new file mode 100644
index 0000000..9d5fe16
Binary files /dev/null and b/SDK/src/test/resources/hamcrest-core-1.3.jar differ
diff --git a/SDK/src/test/resources/javax.servlet-api.jar b/SDK/src/test/resources/javax.servlet-api.jar
new file mode 100644
index 0000000..8161e88
Binary files /dev/null and b/SDK/src/test/resources/javax.servlet-api.jar differ
diff --git a/SDK/test/queueit/knownuserv3/sdk/HashHelperTest.java b/SDK/test/queueit/knownuserv3/sdk/HashHelperTest.java
deleted file mode 100644
index 5e6496f..0000000
--- a/SDK/test/queueit/knownuserv3/sdk/HashHelperTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package queueit.knownuserv3.sdk;
-
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-
-public class HashHelperTest {
-
- @Test
- public void generateSHA256Hash() throws Exception {
- String key = "528f01d4-30f9-4753-95b3-2c8c33966abc";
- String stringToHash = "ts_1480593661~cv_10~ce_false~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895~c_customerid~e_eventid~rt_disabled";
-
- assertTrue(HashHelper.generateSHA256Hash(key, stringToHash).equals("286a17fb82009d8556465b2f0880a8e5e9565b42490669f4b8f1b93b7d6ddd51"));
- }
-}
diff --git a/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java b/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java
deleted file mode 100644
index afbd31e..0000000
--- a/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java
+++ /dev/null
@@ -1,1795 +0,0 @@
-package queueit.knownuserv3.sdk;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import javax.servlet.AsyncContext;
-import javax.servlet.DispatcherType;
-import javax.servlet.RequestDispatcher;
-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;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.Part;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-import queueit.knownuserv3.sdk.integrationconfig.CustomerIntegration;
-import queueit.knownuserv3.sdk.integrationconfig.IntegrationConfigModel;
-import queueit.knownuserv3.sdk.integrationconfig.TriggerModel;
-import queueit.knownuserv3.sdk.integrationconfig.TriggerPart;
-
-public class KnownUserTest {
-
- class UserInQueueServiceMock implements IUserInQueueService {
-
- public ArrayList> validateQueueRequestCalls = new ArrayList();
- public ArrayList> validateCancelRequestCalls = new ArrayList();
- public ArrayList> extendQueueCookieCalls = new ArrayList();
- public ArrayList> getIgnoreActionResultCalls = new ArrayList();
-
- @Override
- 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);
- args.add(config.getCookieDomain() + ":"
- + config.getLayoutName() + ":"
- + config.getCulture() + ":"
- + config.getEventId() + ":"
- + config.getQueueDomain() + ":"
- + config.getExtendCookieValidity() + ":"
- + config.getCookieValidityMinute() + ":"
- + config.getVersion());
- args.add(customerId);
- args.add(secretKey);
- validateQueueRequestCalls.add(args);
-
- return new RequestValidationResult("Queue", "", "", "", "");
- }
-
- @Override
- public RequestValidationResult validateCancelRequest(
- String targetUrl,
- CancelEventConfig config,
- String customerId,
- String secretKey) throws Exception {
-
- ArrayList args = new ArrayList();
- args.add(targetUrl);
- args.add(config.getCookieDomain() + ":"
- + config.getEventId() + ":"
- + config.getQueueDomain() + ":"
- + config.getVersion());
- args.add(customerId);
- args.add(secretKey);
- validateCancelRequestCalls.add(args);
-
- return new RequestValidationResult("Cancel", "", "", "", "");
- }
-
- @Override
- public void extendQueueCookie(String eventId, int cookieValidityMinute, String cookieDomain, String secretKey) {
- ArrayList args = new ArrayList();
- args.add(eventId);
- args.add(Integer.toString(cookieValidityMinute));
- args.add(cookieDomain);
- args.add(secretKey);
- extendQueueCookieCalls.add(args);
- }
-
- @Override
- public RequestValidationResult getIgnoreActionResult() {
- getIgnoreActionResultCalls.add(new ArrayList());
- return new RequestValidationResult("Ignore", "", "", "", "");
- }
- }
-
- @Test
- public void cancelRequestByLocalConfigTest() throws Exception {
- // Arrange
- HttpServletRequestMock requestMock = new HttpServletRequestMock();
- HttpServletResponseMock responseMock = new HttpServletResponseMock();
-
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- CancelEventConfig cancelEventConfig = new CancelEventConfig();
- cancelEventConfig.setCookieDomain("cookiedomain");
- cancelEventConfig.setEventId("eventid");
- cancelEventConfig.setQueueDomain("queuedomain");
- cancelEventConfig.setVersion(1);
-
- // Act
- RequestValidationResult result = KnownUser.cancelRequestByLocalConfig("url", "queueitToken", cancelEventConfig, "customerid", requestMock, responseMock, "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)));
- assertFalse(result.isAjaxResult);
- }
-
- @Test
- public void CancelRequestByLocalConfig_AjaxCall_Test() throws Exception {
- // Arrange
- HttpServletRequestMock requestMock = new HttpServletRequestMock();
- requestMock.Headers.put("x-queueit-ajaxpageurl", "http%3A%2F%2Furl");
-
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- CancelEventConfig cancelEventConfig = new CancelEventConfig();
- cancelEventConfig.setCookieDomain("cookiedomain");
- cancelEventConfig.setEventId("eventid");
- cancelEventConfig.setQueueDomain("queuedomain");
- cancelEventConfig.setVersion(1);
-
- // Act
- RequestValidationResult result = KnownUser.cancelRequestByLocalConfig("url", "queueitToken", cancelEventConfig, "customerid", requestMock, null, "secretkey");
-
- // Assert
- assertTrue("http://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)));
- assertTrue(result.isAjaxResult);
- }
-
- @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";
- requestMock.RemoteAddr = "80.35.35.34";
- requestMock.Headers.put("via", "1.1 example.com");
- requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
- requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
- requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
- requestMock.Headers.put("x-forwarded-proto", "https");
-
- HttpServletResponseMock responseMock = new HttpServletResponseMock();
-
- // Act
- String secretKey = "secretkey";
- String queueittoken = QueueITTokenGenerator.generateToken("eventId", secretKey);
-
- KnownUser.cancelRequestByLocalConfig("url", queueittoken, cancelEventConfig, "customerId", requestMock, responseMock, secretKey);
-
- // Assert
- assertTrue(responseMock.addedCookies.size() == 1);
- assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
- String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
- assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
- assertTrue(decodedCookieValue.contains("CancelConfig=EventId:eventid"));
- assertTrue(decodedCookieValue.contains("&Version:1"));
- assertTrue(decodedCookieValue.contains("&QueueDomain:queuedomain"));
- assertTrue(decodedCookieValue.contains("&CookieDomain:cookiedomain"));
- assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
- assertTrue(decodedCookieValue.contains("TargetUrl=url"));
- assertTrue(decodedCookieValue.contains("RequestIP=80.35.35.34"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_Via=1.1 example.com"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedProto=https"));
- }
-
- @Test
- 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", new HttpServletRequestMock(), 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", new HttpServletRequestMock(), 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.cancelRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId", new HttpServletRequestMock(), null, "secretKey");
- } catch (Exception ex) {
- 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, new HttpServletRequestMock(), 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", new HttpServletRequestMock(), null, null);
- } catch (Exception ex) {
- exceptionWasThrown = "secretKey can not be null or empty.".equals(ex.getMessage());
- }
-
- // Assert
- 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", new HttpServletRequestMock(), 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
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- // Act
- try {
- KnownUser.extendQueueCookie(null, 0, null, null, null, null);
- } catch (Exception ex) {
- exceptionWasThrown = "eventId can not be null or empty.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.extendQueueCookieCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void extendQueueCookieInvalidCookieValidityMinutesTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- // Act
- try {
- KnownUser.extendQueueCookie("eventId", 0, null, null, null, null);
- } catch (Exception ex) {
- exceptionWasThrown = "cookieValidityMinute should be greater than 0.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.extendQueueCookieCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void extendQueueCookieNullSecretKeyTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- // Act
- try {
- KnownUser.extendQueueCookie("eventId", 20, null, null, null, null);
- } catch (Exception ex) {
- exceptionWasThrown = "secretKey can not be null or empty.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.extendQueueCookieCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void extendQueueCookieTest() throws Exception {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- // Act
- KnownUser.extendQueueCookie("eventId", 20, "cookieDomain", null, null, "secretKey");
-
- // Assert
- assertTrue("eventId".equals(mock.extendQueueCookieCalls.get(0).get(0)));
- assertTrue("20".equals(mock.extendQueueCookieCalls.get(0).get(1)));
- assertTrue("cookieDomain".equals(mock.extendQueueCookieCalls.get(0).get(2)));
- assertTrue("secretKey".equals(mock.extendQueueCookieCalls.get(0).get(3)));
- }
-
- @Test
- public void resolveQueueRequestByLocalConfigNullCustomerIdTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- // Act
- try {
- KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, null, new HttpServletRequestMock(), null, "secretKey");
- } catch (Exception ex) {
- exceptionWasThrown = "customerId can not be null or empty.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void resolveQueueRequestByLocalConfigNullSecretKeyTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- // Act
- try {
- KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId", new HttpServletRequestMock(), null, null);
- } catch (Exception ex) {
- exceptionWasThrown = "secretKey can not be null or empty.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void resolveQueueRequestByLocalConfigNullEventConfigTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- // Act
- try {
- KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId", new HttpServletRequestMock(), null, "secretKey");
- } catch (Exception ex) {
- exceptionWasThrown = "eventConfig can not be null.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void resolveQueueRequestByLocalConfigNullEventIdTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- QueueEventConfig eventConfig = new QueueEventConfig();
- eventConfig.setCookieDomain("cookieDomain");
- eventConfig.setLayoutName("layoutName");
- eventConfig.setCulture("culture");
- //eventConfig.setEventId("eventId");
- eventConfig.setQueueDomain("queueDomain");
- eventConfig.setExtendCookieValidity(true);
- eventConfig.setCookieValidityMinute(10);
- eventConfig.setVersion(12);
-
- // Act
- try {
- KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId", new HttpServletRequestMock(), null, "secretKey");
- } catch (Exception ex) {
- exceptionWasThrown = "EventId from queueConfig can not be null or empty.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void resolveQueueRequestByLocalConfigNullQueueDomainTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- QueueEventConfig eventConfig = new QueueEventConfig();
- eventConfig.setCookieDomain("cookieDomain");
- eventConfig.setLayoutName("layoutName");
- eventConfig.setCulture("culture");
- eventConfig.setEventId("eventId");
- //eventConfig.setQueueDomain("queueDomain");
- eventConfig.setExtendCookieValidity(true);
- eventConfig.setCookieValidityMinute(10);
- eventConfig.setVersion(12);
-
- // Act
- try {
- KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId", new HttpServletRequestMock(), null, "secretKey");
- } catch (Exception ex) {
- exceptionWasThrown = "QueueDomain from queueConfig can not be null or empty.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void resolveQueueRequestByLocalConfigInvalidCookieValidityMinuteTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- QueueEventConfig eventConfig = new QueueEventConfig();
- eventConfig.setCookieDomain("cookieDomain");
- eventConfig.setLayoutName("layoutName");
- eventConfig.setCulture("culture");
- eventConfig.setEventId("eventId");
- eventConfig.setQueueDomain("queueDomain");
- eventConfig.setExtendCookieValidity(true);
- //eventConfig.setCookieValidityMinute(10);
- eventConfig.setVersion(12);
-
- // Act
- try {
- KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId", new HttpServletRequestMock(), null, "secretKey");
- } catch (Exception ex) {
- exceptionWasThrown = "cookieValidityMinute from queueConfig should be greater than 0.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void resolveQueueRequestByLocalConfigTest() throws Exception {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- QueueEventConfig eventConfig = new QueueEventConfig();
- eventConfig.setCookieDomain("cookieDomain");
- eventConfig.setLayoutName("layoutName");
- eventConfig.setCulture("culture");
- eventConfig.setEventId("eventId");
- eventConfig.setQueueDomain("queueDomain");
- eventConfig.setExtendCookieValidity(true);
- eventConfig.setCookieValidityMinute(10);
- eventConfig.setVersion(12);
-
- // Act
- RequestValidationResult result = KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId", new HttpServletRequestMock(), null, "secretKey");
-
- // Assert
- 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)));
- assertFalse(result.isAjaxResult);
- }
-
- @Test
- public void resolveQueueRequestByLocalConfigAjaxCallTest() throws Exception {
- // Arrange
- HttpServletRequestMock requestMock = new HttpServletRequestMock();
- requestMock.Headers.put("x-queueit-ajaxpageurl", "http%3A%2F%2Furl");
-
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- QueueEventConfig eventConfig = new QueueEventConfig();
- eventConfig.setCookieDomain("cookieDomain");
- eventConfig.setLayoutName("layoutName");
- eventConfig.setCulture("culture");
- eventConfig.setEventId("eventId");
- eventConfig.setQueueDomain("queueDomain");
- eventConfig.setExtendCookieValidity(true);
- eventConfig.setCookieValidityMinute(10);
- eventConfig.setVersion(12);
-
- // Act
- RequestValidationResult result = KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", eventConfig, "customerId", requestMock, null, "secretKey");
-
- // Assert
- assertTrue("http://url".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)));
- assertTrue(result.isAjaxResult);
- }
-
- @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";
- requestMock.RemoteAddr = "80.35.35.34";
- requestMock.Headers.put("via", "1.1 example.com");
- requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
- requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
- requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
- requestMock.Headers.put("x-forwarded-proto", "https");
-
- HttpServletResponseMock responseMock = new HttpServletResponseMock();
-
- // Act
- String secretKey = "secretkey";
- String queueittoken = QueueITTokenGenerator.generateToken("eventId", secretKey);
-
- KnownUser.resolveQueueRequestByLocalConfig("targetUrl", queueittoken, queueConfig, "customerId", requestMock, responseMock, secretKey);
-
- // Assert
- assertTrue(responseMock.addedCookies.size() == 1);
- assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
- String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
- assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
- assertTrue(decodedCookieValue.contains("QueueConfig=EventId:eventId"));
- assertTrue(decodedCookieValue.contains("&Version:12"));
- assertTrue(decodedCookieValue.contains("&QueueDomain:queueDomain"));
- assertTrue(decodedCookieValue.contains("&CookieDomain:cookieDomain"));
- assertTrue(decodedCookieValue.contains("&ExtendCookieValidity:true"));
- assertTrue(decodedCookieValue.contains("&CookieValidityMinute:10"));
- assertTrue(decodedCookieValue.contains("&LayoutName:layoutName"));
- assertTrue(decodedCookieValue.contains("&Culture:culture"));
- assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
- assertTrue(decodedCookieValue.contains("TargetUrl=targetUrl"));
- assertTrue(decodedCookieValue.contains("RequestIP=80.35.35.34"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_Via=1.1 example.com"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedProto=https"));
- }
-
- @Test
- public void validateRequestByIntegrationConfigEmptyCurrentUrlTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- // Act
- try {
- KnownUser.validateRequestByIntegrationConfig("", null, null, null, null, null, null);
- } catch (Exception ex) {
- exceptionWasThrown = "currentUrlWithoutQueueITToken can not be null or empty.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void validateRequestByIntegrationConfigEmptyIntegrationsConfigTest() {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
- boolean exceptionWasThrown = false;
-
- // Act
- try {
- KnownUser.validateRequestByIntegrationConfig("currentUrl", "queueitToken", null, null, new HttpServletRequestMock(), null, null);
- } catch (Exception ex) {
- exceptionWasThrown = "customerIntegrationInfo can not be null.".equals(ex.getMessage());
- }
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.isEmpty());
- assertTrue(exceptionWasThrown);
- }
-
- @Test
- public void validateRequestByIntegrationConfigQueueActionTest() 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 httpContextMock = new HttpServletRequestMock();
- httpContextMock.UserAgent = "googlebot";
-
- // Act
- RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", httpContextMock, null, "secretKey");
-
- // Assert
- 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)));
- assertFalse(result.isAjaxResult);
- }
-
- @Test
- public void validateRequestByIntegrationConfigQueueActionAjaxCallTest() 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.Headers.put("x-queueit-ajaxpageurl", "http%3A%2F%2Furl");
-
- // Act
- RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", requestMock, null, "secretKey");
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.size() == 1);
- assertTrue("http://url".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)));
- assertTrue(result.isAjaxResult);
- }
-
- @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
- assertTrue(responseMock.addedCookies.size() == 1);
- assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
- String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
- assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
- assertTrue(decodedCookieValue.contains("PureUrl=http://test.com?event1=true"));
- assertTrue(decodedCookieValue.contains("ConfigVersion=3"));
- assertTrue(decodedCookieValue.contains("QueueConfig=EventId:event1"));
- assertTrue(decodedCookieValue.contains("&Version:3"));
- assertTrue(decodedCookieValue.contains("&QueueDomain:knownusertest.queue-it.net"));
- assertTrue(decodedCookieValue.contains("&CookieDomain:.test.com"));
- assertTrue(decodedCookieValue.contains("&ExtendCookieValidity:true"));
- assertTrue(decodedCookieValue.contains("&CookieValidityMinute:20"));
- assertTrue(decodedCookieValue.contains("&LayoutName:Christmas Layout by Queue-it"));
- assertTrue(decodedCookieValue.contains("&Culture:da-DK"));
- assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
- assertTrue(decodedCookieValue.contains("TargetUrl=http://test.com?event1=true"));
- assertTrue(decodedCookieValue.contains("MatchedConfig=event1action"));
- }
-
- @Test
- public void validateRequestByIntegrationConfigNotMatchTest() throws Exception {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- CustomerIntegration customerIntegration = new CustomerIntegration();
- customerIntegration.Integrations = new IntegrationConfigModel[0];
- customerIntegration.Version = 3;
-
- // Act
- RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey");
-
- // Assert
- 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";
- requestMock.RemoteAddr = "80.35.35.34";
- requestMock.Headers.put("via", "1.1 example.com");
- requestMock.Headers.put("forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43");
- requestMock.Headers.put("x-forwarded-for", "129.78.138.66, 129.78.64.103");
- requestMock.Headers.put("x-forwarded-host", "en.wikipedia.org:8080");
- requestMock.Headers.put("x-forwarded-proto", "https");
-
- 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
- assertTrue(responseMock.addedCookies.size() == 1);
- assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey));
- String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8");
- assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl"));
- assertTrue(decodedCookieValue.contains("PureUrl=http://test.com?event1=true"));
- assertTrue(decodedCookieValue.contains("ConfigVersion=3"));
- assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken));
- assertTrue(decodedCookieValue.contains("RequestIP=80.35.35.34"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_Via=1.1 example.com"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080"));
- assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedProto=https"));
- }
-
- @Test
- public void validateRequestByIntegrationConfigForcedTargeturlTest() throws Exception {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- TriggerPart triggerPart = new TriggerPart();
- triggerPart.Operator = "Contains";
- triggerPart.ValueToCompare = "event1";
- triggerPart.UrlPart = "PageUrl";
- triggerPart.ValidatorType = "UrlValidator";
- triggerPart.IsNegative = false;
- triggerPart.IsIgnoreCase = true;
-
- TriggerModel trigger = new TriggerModel();
- trigger.LogicalOperator = "And";
- trigger.TriggerParts = new TriggerPart[]{triggerPart};
-
- 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 = "ForcedTargetUrl";
- config.ForcedTargetUrl = "http://forcedtargeturl.com";
- config.ActionType = ActionType.QUEUE_ACTION;
-
- CustomerIntegration customerIntegration = new CustomerIntegration();
- customerIntegration.Integrations = new IntegrationConfigModel[]{config};
- customerIntegration.Version = 3;
-
- // Act
- KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey");
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.size() == 1);
- assertTrue("http://forcedtargeturl.com".equals(mock.validateQueueRequestCalls.get(0).get(0)));
- }
-
- @Test
- public void validateRequestByIntegrationConfigForecedTargeturlTest() throws Exception {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- TriggerPart triggerPart = new TriggerPart();
- triggerPart.Operator = "Contains";
- triggerPart.ValueToCompare = "event1";
- triggerPart.UrlPart = "PageUrl";
- triggerPart.ValidatorType = "UrlValidator";
- triggerPart.IsNegative = false;
- triggerPart.IsIgnoreCase = true;
-
- TriggerModel trigger = new TriggerModel();
- trigger.LogicalOperator = "And";
- trigger.TriggerParts = new TriggerPart[]{triggerPart};
-
- 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 = "ForecedTargetUrl";
- config.ForcedTargetUrl = "http://forcedtargeturl.com";
- config.ActionType = ActionType.QUEUE_ACTION;
-
- CustomerIntegration customerIntegration = new CustomerIntegration();
- customerIntegration.Integrations = new IntegrationConfigModel[]{config};
- customerIntegration.Version = 3;
-
- // Act
- KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey");
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.size() == 1);
- assertTrue("http://forcedtargeturl.com".equals(mock.validateQueueRequestCalls.get(0).get(0)));
- }
-
- @Test
- public void validateRequestByIntegrationConfigEventTargetUrl() throws Exception {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- TriggerPart triggerPart = new TriggerPart();
- triggerPart.Operator = "Contains";
- triggerPart.ValueToCompare = "event1";
- triggerPart.UrlPart = "PageUrl";
- triggerPart.ValidatorType = "UrlValidator";
- triggerPart.IsNegative = false;
- triggerPart.IsIgnoreCase = true;
-
- TriggerModel trigger = new TriggerModel();
- trigger.LogicalOperator = "And";
- trigger.TriggerParts = new TriggerPart[]{triggerPart};
-
- 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 = "EventTargetUrl";
- config.ActionType = ActionType.QUEUE_ACTION;
-
- CustomerIntegration customerIntegration = new CustomerIntegration();
- customerIntegration.Integrations = new IntegrationConfigModel[]{config};
- customerIntegration.Version = 3;
-
- // Act
- KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey");
-
- // Assert
- assertTrue(mock.validateQueueRequestCalls.size() == 1);
- assertTrue("".equals(mock.validateQueueRequestCalls.get(0).get(0)));
- }
-
- @Test
- public void validateRequestByIntegrationConfigIgnoreAction() throws Exception {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- TriggerPart triggerPart = new TriggerPart();
- triggerPart.Operator = "Contains";
- triggerPart.ValueToCompare = "event1";
- triggerPart.UrlPart = "PageUrl";
- triggerPart.ValidatorType = "UrlValidator";
- triggerPart.IsNegative = false;
- triggerPart.IsIgnoreCase = true;
-
- TriggerModel trigger = new TriggerModel();
- trigger.LogicalOperator = "And";
- trigger.TriggerParts = new TriggerPart[]{triggerPart};
-
- IntegrationConfigModel config = new IntegrationConfigModel();
- config.Name = "event1action";
- config.EventId = "event1";
- config.CookieDomain = "cookiedomain";
- config.Triggers = new TriggerModel[]{trigger};
- config.QueueDomain = "queuedomain";
- config.ActionType = ActionType.IGNORE_ACTION;
-
- CustomerIntegration customerIntegration = new CustomerIntegration();
- customerIntegration.Integrations = new IntegrationConfigModel[]{config};
- customerIntegration.Version = 3;
-
- // Act
- RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey");
-
- // Assert
- assertTrue(mock.getIgnoreActionResultCalls.size() == 1);
- assertFalse(result.isAjaxResult);
- }
-
- @Test
- public void validateRequestByIntegrationConfigAjaxCallIgnoreAction() throws Exception {
- // Arrange
- TriggerPart triggerPart = new TriggerPart();
- triggerPart.Operator = "Contains";
- triggerPart.ValueToCompare = "event1";
- triggerPart.UrlPart = "PageUrl";
- triggerPart.ValidatorType = "UrlValidator";
- triggerPart.IsNegative = false;
- triggerPart.IsIgnoreCase = true;
-
- TriggerModel trigger = new TriggerModel();
- trigger.LogicalOperator = "And";
- trigger.TriggerParts = new TriggerPart[]{triggerPart};
-
- IntegrationConfigModel config = new IntegrationConfigModel();
- config.Name = "event1action";
- config.EventId = "event1";
- config.CookieDomain = "cookiedomain";
- config.Triggers = new TriggerModel[]{trigger};
- config.QueueDomain = "queuedomain";
- config.ActionType = ActionType.IGNORE_ACTION;
-
- CustomerIntegration customerIntegration = new CustomerIntegration();
- customerIntegration.Integrations = new IntegrationConfigModel[]{config};
- customerIntegration.Version = 3;
-
- HttpServletRequestMock requestMock = new HttpServletRequestMock();
- requestMock.Headers.put("x-queueit-ajaxpageurl", "url");
-
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- // Act
- RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", requestMock, null, "secretKey");
-
- // Assert
- assertTrue(mock.getIgnoreActionResultCalls.size() == 1);
- assertTrue(result.isAjaxResult);
- }
-
- @Test
- public void validateRequestByIntegrationConfigCancelAction() throws Exception {
- // Arrange
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- TriggerPart triggerPart = new TriggerPart();
- triggerPart.Operator = "Contains";
- triggerPart.ValueToCompare = "event1";
- triggerPart.UrlPart = "PageUrl";
- triggerPart.ValidatorType = "UrlValidator";
- triggerPart.IsNegative = false;
- triggerPart.IsIgnoreCase = true;
-
- TriggerModel trigger = new TriggerModel();
- trigger.LogicalOperator = "And";
- trigger.TriggerParts = new TriggerPart[]{triggerPart};
-
- 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;
-
- CustomerIntegration customerIntegration = new CustomerIntegration();
- customerIntegration.Integrations = new IntegrationConfigModel[]{config};
- customerIntegration.Version = 3;
-
- // Act
- RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", new HttpServletRequestMock(), null, "secretKey");
-
- // 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)));
- assertFalse(result.isAjaxResult);
- }
-
- @Test
- public void validateRequestByIntegrationConfigAjaxCallCancelAction() throws Exception {
- // Arrange
- TriggerPart triggerPart = new TriggerPart();
- triggerPart.Operator = "Contains";
- triggerPart.ValueToCompare = "event1";
- triggerPart.UrlPart = "PageUrl";
- triggerPart.ValidatorType = "UrlValidator";
- triggerPart.IsNegative = false;
- triggerPart.IsIgnoreCase = true;
-
- TriggerModel trigger = new TriggerModel();
- trigger.LogicalOperator = "And";
- trigger.TriggerParts = new TriggerPart[]{triggerPart};
-
- 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;
-
- CustomerIntegration customerIntegration = new CustomerIntegration();
- customerIntegration.Integrations = new IntegrationConfigModel[]{config};
- customerIntegration.Version = 3;
-
- HttpServletRequestMock requestMock = new HttpServletRequestMock();
- requestMock.Headers.put("x-queueit-ajaxpageurl", "http%3A%2F%2Furl");
-
- UserInQueueServiceMock mock = new UserInQueueServiceMock();
- KnownUser.setUserInQueueService(mock);
-
- // Act
- RequestValidationResult result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", requestMock, null, "secretKey");
-
- // Assert
- assertTrue("http://url".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)));
- assertTrue(result.isAjaxResult);
- }
-
- class HttpServletRequestMock implements HttpServletRequest {
-
- public Cookie[] CookiesValue;
- public String UserAgent;
- public String RequestURL;
- public String QueryString;
- public String RemoteAddr;
- public HashMap Headers;
-
- public HttpServletRequestMock() {
- this.Headers = new HashMap();
- }
-
- @Override
- public String getAuthType() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- @Override
- public Cookie[] getCookies() {
- return this.CookiesValue;
- }
-
- @Override
- public long getDateHeader(String string) {
- 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;
- }
-
- String value = (String) this.Headers.get(key);
-
- if (value == null) {
- value = "";
- }
-
- return value;
- }
-
- @Override
- public Enumeration getHeaders(String string) {
- 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 int getIntHeader(String string) {
- 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 getPathInfo() {
- 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 String getContextPath() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- @Override
- public String getQueryString() {
- return this.QueryString;
- }
-
- @Override
- public String getRemoteUser() {
- 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 Principal getUserPrincipal() {
- 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 getRequestURI() {
- 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 String getServletPath() {
- 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 HttpSession getSession() {
- 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 boolean isRequestedSessionIdFromCookie() {
- 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 boolean isRequestedSessionIdFromUrl() {
- 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 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 logout() throws ServletException {
- 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 Part getPart(String string) throws IOException, ServletException {
- 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 Enumeration getAttributeNames() {
- 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 setCharacterEncoding(String string) throws UnsupportedEncodingException {
- 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 getContentType() {
- 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 String getParameter(String string) {
- 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[] getParameterValues(String string) {
- 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 String getProtocol() {
- 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 getServerName() {
- 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 BufferedReader getReader() throws IOException {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- @Override
- public String getRemoteAddr() {
- return RemoteAddr;
- }
-
- @Override
- public String getRemoteHost() {
- 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 void removeAttribute(String string) {
- 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 Enumeration getLocales() {
- 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 RequestDispatcher getRequestDispatcher(String string) {
- 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 int getRemotePort() {
- 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 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 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 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 = Utils.join(QueueParameterHelper.KeyValueSeparatorGroupChar, paramList);
- String hash = HashHelper.generateSHA256Hash(secretKey, tokenWithoutHash);
- String token = tokenWithoutHash + QueueParameterHelper.KeyValueSeparatorGroupChar + QueueParameterHelper.HashKey + QueueParameterHelper.KeyValueSeparatorChar + hash;
- return token;
- }
- }
-}