From da96a7531d10ea5e560db6ba9af94af14b8eee9c Mon Sep 17 00:00:00 2001 From: Frederik Williams Date: Thu, 11 Jun 2020 21:40:24 +0200 Subject: [PATCH] version 3.6.1 --- .../knownuserv3/sdk/UserInQueueService.java | 92 +++++++---- .../sdk/UserInQueueStateCookieRepository.java | 15 +- .../knownuserv3/sdk/KnownUserTest.java | 10 +- .../sdk/UserInQueueServiceTest.java | 147 ++++++++++++++++-- .../UserInQueueStateCookieRepositoryTest.java | 25 +++ 5 files changed, 234 insertions(+), 55 deletions(-) diff --git a/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueService.java b/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueService.java index 6fc1d82..c5ac423 100644 --- a/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueService.java +++ b/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueService.java @@ -27,7 +27,7 @@ void extendQueueCookie( class UserInQueueService implements IUserInQueueService { - public static final String SDK_VERSION = "v3-java-" + "3.6.0"; + public static final String SDK_VERSION = "v3-java-" + "3.6.1"; public final IUserInQueueStateRepository _userInQueueStateRepository; public UserInQueueService(IUserInQueueStateRepository queueStateRepository) { @@ -55,35 +55,37 @@ public RequestValidationResult validateQueueRequest( } return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), stateInfo.getQueueId(), null, stateInfo.getRedirectType(), config.getActionName()); } - QueueUrlParams queueParmas = QueueParameterHelper.extractQueueParams(queueitToken); + QueueUrlParams queueParams = QueueParameterHelper.extractQueueParams(queueitToken); + RequestValidationResult requestValidationResult; + boolean isTokenValid = false; - if (queueParmas != null) { - return getQueueITTokenValidationResult(targetUrl, config, queueParmas, customerId, secretKey); - } else { - return cancelQueueCookieReturnQueueResult(targetUrl, config, customerId); + if (queueParams != null) { + TokenValidationResult tokenValidationResult = validateToken(config, queueParams, secretKey); + isTokenValid = tokenValidationResult.isValid(); + + if(isTokenValid){ + requestValidationResult = getValidTokenResult(config, queueParams, secretKey); + } + else{ + requestValidationResult = getErrorResult(customerId, targetUrl, config, queueParams, tokenValidationResult.getErrorCode()); + } } - } - - private RequestValidationResult getQueueITTokenValidationResult( - 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 cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "hash"); + else{ + requestValidationResult = getQueueResult(targetUrl, config, customerId); } - if (!config.getEventId().toUpperCase().equals(queueParams.getEventId().toUpperCase())) { - return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "eventid"); + if(stateInfo.isFound() && !isTokenValid){ + this._userInQueueStateRepository.cancelQueueCookie(config.getEventId(), config.getCookieDomain()); } - if (queueParams.getTimeStamp() < System.currentTimeMillis() / 1000L) { - return cancelQueueCookieReturnErrorResult(customerId, targetUrl, config, queueParams, "timestamp"); - } + return requestValidationResult; + } + private RequestValidationResult getValidTokenResult( + QueueEventConfig config, + QueueUrlParams queueParams, + String secretKey) throws Exception { + this._userInQueueStateRepository.store( config.getEventId(), queueParams.getQueueId(), @@ -101,15 +103,13 @@ private RequestValidationResult getQueueITTokenValidationResult( config.getActionName()); } - private RequestValidationResult cancelQueueCookieReturnErrorResult( + private RequestValidationResult getErrorResult( String customerId, String targetUrl, QueueEventConfig config, QueueUrlParams qParams, String errorCode) throws Exception { - this._userInQueueStateRepository.cancelQueueCookie(config.getEventId(), config.getCookieDomain()); - String query = getQueryString(customerId, config.getEventId(), config.getVersion(), config.getActionName(), config.getCulture(), config.getLayoutName()) + "&queueittoken=" + qParams.getQueueITToken() + "&ts=" + System.currentTimeMillis() / 1000L; @@ -122,12 +122,11 @@ private RequestValidationResult cancelQueueCookieReturnErrorResult( return new RequestValidationResult(ActionType.QUEUE_ACTION, config.getEventId(), null, redirectUrl, null, config.getActionName()); } - private RequestValidationResult cancelQueueCookieReturnQueueResult( + private RequestValidationResult getQueueResult( String targetUrl, QueueEventConfig config, String customerId) throws Exception { - 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)) { @@ -165,7 +164,25 @@ private String generateRedirectUrl(String queueDomain, String uriPath, String qu } return "https://" + queueDomain + uriPath + "?" + query; } + + private TokenValidationResult validateToken(QueueEventConfig config, QueueUrlParams queueParams, String secretKey) throws Exception { + String calculatedHash = HashHelper.generateSHA256Hash(secretKey, queueParams.getQueueITTokenWithoutHash()); + if (!calculatedHash.toUpperCase().equals(queueParams.getHashCode().toUpperCase())) { + return new TokenValidationResult(false, "hash"); + } + + if (!config.getEventId().toUpperCase().equals(queueParams.getEventId().toUpperCase())) { + return new TokenValidationResult(false, "eventid"); + } + + if (queueParams.getTimeStamp() < System.currentTimeMillis() / 1000L) { + return new TokenValidationResult(false, "timestamp"); + } + + return new TokenValidationResult(true, null); + } + @Override public void extendQueueCookie( String eventId, @@ -205,4 +222,23 @@ public RequestValidationResult validateCancelRequest( public RequestValidationResult getIgnoreActionResult(String actionName) { return new RequestValidationResult(ActionType.IGNORE_ACTION, null, null, null, null, actionName); } + + private class TokenValidationResult + { + private final boolean isValid; + private final String errorCode; + + public TokenValidationResult(boolean isValid, String errorCode){ + this.isValid = isValid; + this.errorCode = errorCode; + } + + public boolean isValid() { + return this.isValid; + } + + public String getErrorCode() { + return this.errorCode; + } + } } \ No newline at end of file diff --git a/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java b/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java index 8848e47..a13d3fa 100644 --- a/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java +++ b/SDK/src/main/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java @@ -157,19 +157,19 @@ public StateInfo getState(String eventId, int cookieValidityMinutes, String secr String cookieKey = getCookieKey(eventId); String cookieValue = this.cookieManager.getCookie(cookieKey); if (cookieValue == null) { - return new StateInfo(false, null, null, null); + return new StateInfo(false, false, null, null, null); } HashMap cookieNameValueMap = UserInQueueStateCookieRepository.getCookieNameValueMap(cookieValue); if (!isCookieValid(secretKey, cookieNameValueMap, eventId, cookieValidityMinutes, validateTime)) { - return new StateInfo(false, null, null, null); + return new StateInfo(true, false, null, null, null); } - return new StateInfo(true, cookieNameValueMap.get(QUEUE_ID_KEY), + return new StateInfo(true, true, cookieNameValueMap.get(QUEUE_ID_KEY), cookieNameValueMap.get(FIXED_COOKIE_VALIDITY_MINUTES_KEY), cookieNameValueMap.get(REDIRECT_TYPE_KEY)); } catch (NumberFormatException ex) { } - return new StateInfo(false, null, null, null); + return new StateInfo(true, false, null, null, null); } @Override @@ -211,13 +211,15 @@ public void reissueQueueCookie( class StateInfo { + private final boolean isFound; private final boolean isValid; private final String queueId; private final String redirectType; private final String fixedCookieValidityMinutes; - public StateInfo(boolean isValid, String queueid, String fixedCookieValidityMinutes, + public StateInfo(boolean isFound, boolean isValid, String queueid, String fixedCookieValidityMinutes, String redirectType) { + this.isFound = isFound; this.isValid = isValid; this.queueId = queueid; this.fixedCookieValidityMinutes = fixedCookieValidityMinutes; @@ -228,6 +230,9 @@ public String getQueueId() { return this.queueId; } + public boolean isFound() { + return this.isFound; + } public boolean isValid() { return this.isValid; } diff --git a/SDK/src/test/java/queueit/knownuserv3/sdk/KnownUserTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/KnownUserTest.java index af6225d..0e5ba5c 100644 --- a/SDK/src/test/java/queueit/knownuserv3/sdk/KnownUserTest.java +++ b/SDK/src/test/java/queueit/knownuserv3/sdk/KnownUserTest.java @@ -1386,7 +1386,7 @@ public void validateRequestByIntegrationConfig_Debug() throws Exception { 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("SdkVersion=" + UserInQueueService.SDK_VERSION)); assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion())); } @@ -1430,7 +1430,7 @@ public void ValidateRequestByIntegrationConfig_Debug_WithoutMatch() throws Excep 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("SdkVersion=" + UserInQueueService.SDK_VERSION)); assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion())); } @@ -1628,7 +1628,7 @@ public void validateRequestByIntegrationConfig_Debug_NullConfig() throws Excepti 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("SdkVersion=" + UserInQueueService.SDK_VERSION)); assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion())); assertTrue(decodedCookieValue.contains("Exception=customerIntegrationInfo can not be null.")); @@ -1797,7 +1797,7 @@ public void ResolveQueueRequestByLocalConfig_Debug() throws Exception { 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("SdkVersion=" + UserInQueueService.SDK_VERSION)); assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion())); } @@ -2105,7 +2105,7 @@ public void CancelRequestByLocalConfig_Debug_NullConfig() throws Exception { 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("SdkVersion=" + UserInQueueService.SDK_VERSION)); assertTrue(decodedCookieValue.contains("Runtime=" + GetRuntimeVersion())); assertTrue(decodedCookieValue.contains("Exception=cancelConfig can not be null.")); } diff --git a/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueServiceTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueServiceTest.java index 0270e80..a623ecf 100644 --- a/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueServiceTest.java +++ b/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueServiceTest.java @@ -47,7 +47,7 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(true, "queueId", null, "queue"); + return new StateInfo(true, true, "queueId", null, "queue"); } @Override @@ -99,7 +99,7 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(true, "queueId", null, "queue"); + return new StateInfo(true, true, "queueId", null, "queue"); } @@ -154,7 +154,7 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(true, "queueId", "3", "idle"); + return new StateInfo(true, true, "queueId", "3", "idle"); } @Override @@ -211,7 +211,7 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(false, null, null, null); + return new StateInfo(false, false, null, null, null); } @Override @@ -249,7 +249,7 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String assertTrue(config.getEventId().equals(result.getEventId())); assertTrue(!conditions.get("isStoreWasCalled")); assertEquals(result.getActionName(), config.getActionName()); - assertTrue(conditions.get("cancelQueueCookieWasCalled")); + assertTrue(conditions.get("cancelQueueCookieWasCalled") == null); } @Test @@ -284,7 +284,7 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(false, null, null, null); + return new StateInfo(false, false, null, null, null); } @Override @@ -322,7 +322,7 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String assertTrue(config.getEventId().equals(result.getEventId())); assertTrue(!conditions.get("isStoreWasCalled")); assertEquals(result.getActionName(), config.getActionName()); - assertTrue(conditions.get("cancelQueueCookie")); + assertTrue(conditions.get("cancelQueueCookie") == null); } @Test @@ -357,7 +357,7 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(false, null, null, null); + return new StateInfo(false, false, null, null, null); } @Override @@ -395,7 +395,7 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String assertTrue(config.getEventId().equals(result.getEventId())); assertTrue(!conditions.get("isStoreWasCalled")); assertEquals(result.getActionName(), config.getActionName()); - assertTrue(conditions.get("cancelQueueCookie")); + assertTrue(conditions.get("cancelQueueCookie") == null); } @Test @@ -428,7 +428,7 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(false, null, null, null); + return new StateInfo(false, false, null, null, null); } @Override @@ -496,7 +496,7 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(false, null, null, null); + return new StateInfo(false, false, null, null, null); } @Override @@ -562,7 +562,7 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(false, null, null, null); + return new StateInfo(false, false, null, null, null); } @Override @@ -586,7 +586,7 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String assertTrue(!conditions.get("isStoreWasCalled")); assertTrue(config.getEventId().equals(result.getEventId())); assertEquals(result.getActionName(), config.getActionName()); - assertTrue(conditions.get("cancelQueueCookie")); + assertTrue(conditions.get("cancelQueueCookie") == null); } @Test @@ -620,7 +620,63 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(false, null, null, null); + return new StateInfo(false, 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. + } + }; + + String knownUserVersion = UserInQueueService.SDK_VERSION; + 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"); + assertTrue(result.doRedirect()); + 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") == null); + } + + @Test + public void ValidateQueueRequest_InvalidCookie_WithoutToken_RedirectToQueue_NoTargetUrl() 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.setCookieDomain("testDomain"); + + final HashMap conditions = new HashMap(); + conditions.put("isStoreWasCalled", false); + + IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + + @Override + public void cancelQueueCookie(String eventId, String cookieDomain) { + conditions.put("cancelQueueCookie", true); + } + + @Override + 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) { + return new StateInfo(true, false, null, null, null); } @Override @@ -676,7 +732,64 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin @Override public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { - return new StateInfo(false, null, null, null); + return new StateInfo(false, 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. + } + }; + + String targetUrl = "http://test.test.com/?b=h"; + String knownUserVersion = UserInQueueService.SDK_VERSION; + 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"); + assertTrue(result.doRedirect()); + 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") == null); + } + + @Test + public void ValidateRequest_InvalidCookie_InValidToken() 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.setCookieDomain("testDomain"); + + final HashMap conditions = new HashMap(); + conditions.put("isStoreWasCalled", false); + + IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + + @Override + public void cancelQueueCookie(String eventId, String cookieDomain) { + conditions.put("cancelQueueCookie", true); + } + + @Override + 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) { + return new StateInfo(true, false, null, null, null); } @Override @@ -724,9 +837,9 @@ public void store(String eventId, String queueId, Integer fixedCookieValidityMin public StateInfo getState(String eventId, int cookieValidityMinutes, String customerSecretKey, boolean validateTime) { if (!validateTime) { - return new StateInfo(true, "queueId", null, "queue"); + return new StateInfo(true, true, "queueId", null, "queue"); } else { - return new StateInfo(false, null, null, null); + return new StateInfo(false, false, null, null, null); } } diff --git a/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java b/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java index 09f9cb1..63d3303 100644 --- a/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java +++ b/SDK/src/test/java/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java @@ -341,6 +341,7 @@ public String getCookie(String cookieName) { UserInQueueStateCookieRepository testObject = new UserInQueueStateCookieRepository(cookieManager); StateInfo cookieState = testObject.getState(eventId, 10, secretKey, true); assertTrue(cookieState.isValid()); + assertTrue(cookieState.isFound()); assertTrue(cookieState.getQueueId().equals(queueId)); assertTrue(cookieState.getRedirectType().equals("queue")); assertTrue(cookieState.isStateExtendable()); @@ -373,6 +374,7 @@ public String getCookie(String cookieName) { UserInQueueStateCookieRepository testObject = new UserInQueueStateCookieRepository(cookieManager); StateInfo cookieState = testObject.getState(eventId, 10, secretKey, true); assertTrue(cookieState.isValid()); + assertTrue(cookieState.isFound()); assertTrue(cookieState.getQueueId().equals(queueId)); assertTrue(cookieState.getRedirectType().equals("idle")); assertTrue(!cookieState.isStateExtendable()); @@ -405,6 +407,7 @@ public String getCookie(String cookieName) { UserInQueueStateCookieRepository testObject = new UserInQueueStateCookieRepository(cookieManager); StateInfo cookieState = testObject.getState(eventId, 10, secretKey, true); assertFalse(cookieState.isValid()); + assertTrue(cookieState.isFound()); } @Test @@ -433,6 +436,28 @@ public String getCookie(String cookieName) { UserInQueueStateCookieRepository testObject = new UserInQueueStateCookieRepository(cookieManager); StateInfo cookieState = testObject.getState(eventId, 3, secretKey, true); assertFalse(cookieState.isValid()); + assertTrue(cookieState.isFound()); + } + + @Test + public void getState_NoCookie_Test() { + String eventId = "event1"; + String secretKey = "4e1db821-a825-49da-acd0-5d376f2068db"; + + ICookieManager cookieManager = new ICookieManager() { + @Override + public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { + } + + @Override + public String getCookie(String cookieName) { + return null; + } + }; + UserInQueueStateCookieRepository testObject = new UserInQueueStateCookieRepository(cookieManager); + StateInfo cookieState = testObject.getState(eventId, 10, secretKey, true); + assertFalse(cookieState.isValid()); + assertFalse(cookieState.isFound()); } }