def test_ValidateQueueRequest_ValidState_ExtendableCookie_NoCookieExtensionFromConfig_DoNotRedirectDoNotStoreCookieWithExtension( self): queueConfig = QueueEventConfig() queueConfig.eventId = "e1" queueConfig.queueDomain = "testDomain" queueConfig.cookieDomain = "testDomain" queueConfig.cookieValidityMinute = 10 queueConfig.extendCookieValidity = False queueConfig.actionName = "QueueAction" httpContextProviderMock = HttpContextProviderMock() userInQueueStateCookieRepositoryMock = UserInQueueStateCookieRepositoryMock( httpContextProviderMock) userInQueueStateCookieRepositoryMock.arrayReturns['getState'].append( StateInfo(True, True, "queueId", None, "idle")) testObject = UserInQueueService(httpContextProviderMock, userInQueueStateCookieRepositoryMock) result = testObject.validateQueueRequest("url", "token", queueConfig, "customerid", "key") assert (not result.doRedirect()) assert (result.queueId == "queueId") assert ( not userInQueueStateCookieRepositoryMock.expectCallAny('store')) assert (userInQueueStateCookieRepositoryMock.expectCall( 'getState', 1, ["e1", 10, 'key', True])) assert (queueConfig.actionName == result.actionName) assert (not userInQueueStateCookieRepositoryMock.expectCallAny( 'cancelQueueCookie'))
def test_validateRequest_InvalidCookie_InvalidToken_CancelCookie(self): config = QueueEventConfig() config.eventId = "e1" config.queueDomain = "testDomain.com" config.cookieValidityMinute = 10 config.extendCookieValidity = False config.version = 10 config.culture = None config.layoutName = 'testlayout' config.actionName = "QueueAction" targetUrl = "http://test.test.com?b=h" knownUserVersion = UserInQueueService.SDK_VERSION httpContextProviderMock = HttpContextProviderMock() userInQueueStateCookieRepositoryMock = UserInQueueStateCookieRepositoryMock( httpContextProviderMock) userInQueueStateCookieRepositoryMock.arrayReturns['getState'].append( StateInfo(True, False, None, None, None)) testObject = UserInQueueService(httpContextProviderMock, userInQueueStateCookieRepositoryMock) result = testObject.validateQueueRequest( targetUrl, "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895", config, "testCustomer", "key") assert (result.doRedirect()) assert (result.redirectUrl.startswith( "https://testDomain.com/error/hash/?c=testCustomer&e=e1&ver={0}&kupver=mock&cver=10&man=QueueAction&l=testlayout&queueittoken=ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895&" .format(knownUserVersion))) assert ( not userInQueueStateCookieRepositoryMock.expectCallAny('store')) assert (result.eventId == config.eventId) assert (result.actionName == config.actionName) assert (userInQueueStateCookieRepositoryMock.expectCallAny( 'cancelQueueCookie'))
def test_validateCancelRequest(self): cancelConfig = CancelEventConfig() cancelConfig.eventId = "e1" cancelConfig.queueDomain = "testDomain.com" cancelConfig.cookieDomain = "my-cookie-domain" cancelConfig.version = 10 cancelConfig.actionName = "TestCancelAction" url = "http://test.test.com?b=h" httpContextProviderMock = HttpContextProviderMock() userInQueueStateCookieRepositoryMock = UserInQueueStateCookieRepositoryMock( httpContextProviderMock) userInQueueStateCookieRepositoryMock.arrayReturns['getState'].append( StateInfo(True, True, "queueId", 3, "idle")) expectedUrl = ( "https://testDomain.com/cancel/testCustomer/e1/queueId?" + "c=testCustomer" + "&e=e1" + "&ver=" + UserInQueueService.SDK_VERSION + "&kupver=mock" + "&cver=10" + "&man=" + cancelConfig.actionName + "&r=" + QueueitHelpers.urlEncode(url)) testObject = UserInQueueService(httpContextProviderMock, userInQueueStateCookieRepositoryMock) result = testObject.validateCancelRequest(url, cancelConfig, "testCustomer", "key") assert (userInQueueStateCookieRepositoryMock.expectCall( 'cancelQueueCookie', 1, ["e1", 'my-cookie-domain', False, False])) assert (result.doRedirect()) assert (result.queueId == "queueId") assert (result.eventId == 'e1') assert (expectedUrl == result.redirectUrl) assert (cancelConfig.actionName == result.actionName)
def test_ValidateQueueRequest_NoCookie_InValidToken(self): key = "4e1db821-a825-49da-acd0-5d376f2068db" queueConfig = QueueEventConfig() queueConfig.eventId = "e1" queueConfig.queueDomain = "testDomain.com" queueConfig.cookieValidityMinute = 10 queueConfig.extendCookieValidity = True queueConfig.version = 11 queueConfig.culture = 'en-US' queueConfig.layoutName = 'testlayout' queueConfig.actionName = "QueueAction" url = "http://test.test.com?b=h" httpContextProviderMock = HttpContextProviderMock() userInQueueStateCookieRepositoryMock = UserInQueueStateCookieRepositoryMock( httpContextProviderMock) userInQueueStateCookieRepositoryMock.arrayReturns['getState'].append( StateInfo(False, False, None, None, None)) testObject = UserInQueueService(httpContextProviderMock, userInQueueStateCookieRepositoryMock) result = testObject.validateQueueRequest( url, "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895", queueConfig, "testCustomer", key) assert ( not userInQueueStateCookieRepositoryMock.expectCallAny('store')) assert (result.doRedirect()) assert (result.eventId == 'e1') assert (result.queueId == None) assert (result.redirectUrl.startswith( "https://testDomain.com/error/hash/?c=testCustomer&e=e1")) assert (queueConfig.actionName == result.actionName) assert (not userInQueueStateCookieRepositoryMock.expectCallAny( 'cancelQueueCookie'))
def test_ValidateQueueRequest_NoCookie_ValidToken_ExtendableCookie_DoNotRedirect_StoreExtendableCookie( self): key = "4e1db821-a825-49da-acd0-5d376f2068db" queueConfig = QueueEventConfig() queueConfig.eventId = "e1" queueConfig.queueDomain = "testDomain.com" queueConfig.cookieValidityMinute = 10 queueConfig.cookieDomain = "testDomain" queueConfig.extendCookieValidity = True queueConfig.version = 11 queueConfig.actionName = "QueueAction" url = "http://test.test.com?b=h" httpContextProviderMock = HttpContextProviderMock() userInQueueStateCookieRepositoryMock = UserInQueueStateCookieRepositoryMock( httpContextProviderMock) userInQueueStateCookieRepositoryMock.arrayReturns['getState'].append( StateInfo(False, False, None, None, None)) token = TestHelper.generateHash( 'e1', 'queueId', str((QueueitHelpers.getCurrentTime() + (3 * 60))), 'true', None, 'queue', key) testObject = UserInQueueService(httpContextProviderMock, userInQueueStateCookieRepositoryMock) result = testObject.validateQueueRequest(url, token, queueConfig, "testCustomer", key) assert (not result.doRedirect()) assert (result.eventId == 'e1') assert (result.queueId == 'queueId') assert (result.redirectType == 'queue') assert (userInQueueStateCookieRepositoryMock.expectCall( 'store', 1, ["e1", 'queueId', None, 'testDomain', False, False, 'queue', key])) assert (queueConfig.actionName == result.actionName) assert (not userInQueueStateCookieRepositoryMock.expectCallAny( 'cancelQueueCookie'))
def test_ValidateQueueRequest_NoCookie_TampredToken_RedirectToErrorPageWithHashError_DoNotStoreCookie( self): key = "4e1db821-a825-49da-acd0-5d376f2068db" queueConfig = QueueEventConfig() queueConfig.eventId = "e1" queueConfig.queueDomain = "testDomain.com" queueConfig.cookieValidityMinute = 10 queueConfig.extendCookieValidity = True queueConfig.version = 11 queueConfig.actionName = "Queue Action (._~-) !*|'\"" url = "http://test.test.com?b=h" httpContextProviderMock = HttpContextProviderMock() userInQueueStateCookieRepositoryMock = UserInQueueStateCookieRepositoryMock( httpContextProviderMock) userInQueueStateCookieRepositoryMock.arrayReturns['getState'].append( StateInfo(False, False, None, None, None)) token = TestHelper.generateHash( 'e1', 'queueId', str((QueueitHelpers.getCurrentTime() + (3 * 60))), 'False', None, 'idle', key) token = token.replace("False", 'True') expectedErrorUrl = "https://testDomain.com/error/hash/?c=testCustomer&e=e1" + \ "&ver=" + UserInQueueService.SDK_VERSION + \ "&kupver=mock" + \ "&cver=11" + \ "&man=" + QueueitHelpers.urlEncode(queueConfig.actionName) + \ "&queueittoken=" + token + \ "&t=" + QueueitHelpers.urlEncode(url) testObject = UserInQueueService(httpContextProviderMock, userInQueueStateCookieRepositoryMock) result = testObject.validateQueueRequest(url, token, queueConfig, "testCustomer", key) assert ( not userInQueueStateCookieRepositoryMock.expectCallAny('store')) assert (result.doRedirect()) assert (result.eventId == 'e1') matches = re.search("&ts=[^&]*", result.redirectUrl) timestamp = matches.group(0).replace("&ts=", "") timestamp = timestamp.replace("&", "") assert (QueueitHelpers.getCurrentTime() - int(timestamp) < 100) urlWithoutTimeStamp = re.sub("&ts=[^&]*", "", result.redirectUrl) assert (urlWithoutTimeStamp.upper() == expectedErrorUrl.upper()) assert (queueConfig.actionName == result.actionName) assert (queueConfig.actionName == result.actionName) assert (not userInQueueStateCookieRepositoryMock.expectCallAny( 'cancelQueueCookie')) assert ( not userInQueueStateCookieRepositoryMock.expectCallAny('store'))
def test_ValidateRequest_NoCookie_WithoutToken_RedirectToQueue_NotargetUrl( self): key = "4e1db821-a825-49da-acd0-5d376f2068db" queueConfig = QueueEventConfig() queueConfig.eventId = "e1" queueConfig.queueDomain = "testDomain.com" queueConfig.cookieValidityMinute = 10 queueConfig.extendCookieValidity = True queueConfig.version = 11 queueConfig.culture = 'en-US' queueConfig.layoutName = 'testlayout' queueConfig.actionName = "Queue Action (._~-) !*|'\"" httpContextProviderMock = HttpContextProviderMock() userInQueueStateCookieRepositoryMock = UserInQueueStateCookieRepositoryMock( httpContextProviderMock) userInQueueStateCookieRepositoryMock.arrayReturns['getState'].append( StateInfo(False, False, None, None, None)) token = "" expectedRedirectUrl = "https://testDomain.com/?c=testCustomer&e=e1" + \ "&ver=" + UserInQueueService.SDK_VERSION + \ "&kupver=mock" + \ "&cver=11" + \ "&man=" + QueueitHelpers.urlEncode(queueConfig.actionName) + \ "&cid=en-US" + \ "&l=testlayout" testObject = UserInQueueService(httpContextProviderMock, userInQueueStateCookieRepositoryMock) result = testObject.validateQueueRequest(None, token, queueConfig, "testCustomer", key) assert ( not userInQueueStateCookieRepositoryMock.expectCallAny('store')) assert (result.doRedirect()) assert (result.eventId == 'e1') assert (result.queueId == None) assert (result.redirectUrl.upper() == expectedRedirectUrl.upper()) assert (queueConfig.actionName == result.actionName) assert (not userInQueueStateCookieRepositoryMock.expectCallAny( 'cancelQueueCookie'))
def test_validateRequest_InvalidCookie_WithoutToken_RedirectToQueue_CancelCookie( self): config = QueueEventConfig() config.eventId = "e1" config.queueDomain = "testDomain.com" config.cookieValidityMinute = 10 config.extendCookieValidity = False config.version = 11 config.culture = None config.layoutName = 'testlayout' config.actionName = "QueueAction" expectedUrl = "https://testDomain.com/?c=testCustomer&e=e1" + \ "&ver=" + UserInQueueService.SDK_VERSION + \ "&kupver=mock" + \ "&cver=11" + \ "&man=" + QueueitHelpers.urlEncode(config.actionName) + \ "&l=testlayout" httpContextProviderMock = HttpContextProviderMock() userInQueueStateCookieRepositoryMock = UserInQueueStateCookieRepositoryMock( httpContextProviderMock) userInQueueStateCookieRepositoryMock.arrayReturns['getState'].append( StateInfo(True, False, None, None, None)) testObject = UserInQueueService(httpContextProviderMock, userInQueueStateCookieRepositoryMock) result = testObject.validateQueueRequest(None, "", config, "testCustomer", "key") assert (result.doRedirect()) assert (result.redirectUrl.upper() == expectedUrl.upper()) assert ( not userInQueueStateCookieRepositoryMock.expectCallAny('store')) assert (result.eventId == config.eventId) assert (result.actionName == config.actionName) assert (userInQueueStateCookieRepositoryMock.expectCallAny( 'cancelQueueCookie'))