Esempio n. 1
0
 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_getState_validCookieFormat_nonExtendable(self):
        eventId = "event1"
        secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db"
        cookieDomain = ".test.com"
        isCookieHttpOnly = False
        isCookieSecure = False
        queueId = "queueId"
        cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId)
        wfHandler = HttpContextProviderMock()
        testObject = UserInQueueStateCookieRepository(wfHandler)
        issueTime = str(QueueitHelpers.getCurrentTime())
        hashValue = UnitTestHelper.generateHash(eventId, queueId, 3, "idle",
                                                issueTime, secretKey)

        cookieValue = ("EventId=" + eventId + "&QueueId=" + queueId +
                       "&FixedValidityMins=3" + "&RedirectType=idle" +
                       "&IssueTime=" + issueTime + "&Hash=" + hashValue)

        wfHandler.setCookie(cookieKey, cookieValue,
                            QueueitHelpers.getCookieExpirationDate(),
                            cookieDomain, isCookieHttpOnly, isCookieSecure)

        state = testObject.getState(eventId, 10, secretKey, True)
        assert (not state.isStateExtendable())
        assert (state.isValid)
        assert (state.isFound)
        assert (state.queueId == queueId)
        assert (state.redirectType == "idle")
Esempio n. 3
0
 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'))