Example #1
0
    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)
Example #2
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'))
Example #3
0
 def test_NoCookie_NoValidToken_WithoutToken_RedirectToQueue(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 (._~-) !*|'\""
     url = "http://test.test.com?b=h"
     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"+"&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')
     assert (result.queueId == None)
     assert (result.redirectUrl.upper() == expectedRedirectUrl.upper())
     assert (queueConfig.actionName == result.actionName)
     assert (not userInQueueStateCookieRepositoryMock.expectCallAny(
         'cancelQueueCookie'))
Example #4
0
    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'))