コード例 #1
0
        public void ValidateRequestByLocalEventConfig_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

            KnownUser._UserInQueueService = (mock);

            EventConfig eventConfig = new EventConfig();

            eventConfig.CookieDomain         = "cookieDomain";
            eventConfig.LayoutName           = "layoutName";
            eventConfig.Culture              = "culture";
            eventConfig.EventId              = "eventId";
            eventConfig.QueueDomain          = "queueDomain";
            eventConfig.ExtendCookieValidity = true;
            eventConfig.CookieValidityMinute = 10;
            eventConfig.Version              = 12;

            // Act
            KnownUser.ValidateRequestByLocalEventConfig("targetUrl", "queueitToken", eventConfig, "customerId", "secretKey");

            // Assert
            Assert.Equal("targetUrl", mock.validateRequestCalls[0][0]);
            Assert.Equal("queueitToken", mock.validateRequestCalls[0][1]);
            Assert.Equal("cookieDomain:layoutName:culture:eventId:queueDomain:true:10:12", mock.validateRequestCalls[0][2]);
            Assert.Equal("customerId", mock.validateRequestCalls[0][3]);
            Assert.Equal("secretKey", mock.validateRequestCalls[0][4]);
        }
コード例 #2
0
        public void ValidateRequestByLocalEventConfig_InvalidCookieValidityMinute_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

            KnownUser._UserInQueueService = (mock);
            bool exceptionWasThrown = false;

            EventConfig eventConfig = new EventConfig();

            eventConfig.CookieDomain         = "cookieDomain";
            eventConfig.LayoutName           = "layoutName";
            eventConfig.Culture              = "culture";
            eventConfig.EventId              = "eventId";
            eventConfig.QueueDomain          = "queueDomain";
            eventConfig.ExtendCookieValidity = true;
            //eventConfig.CookieValidityMinute = 10;
            eventConfig.Version = 12;

            // Act
            try
            {
                KnownUser.ValidateRequestByLocalEventConfig("targetUrl", "queueitToken", eventConfig, "customerId", "secretKey");
            }
            catch (ArgumentException ex)
            {
                exceptionWasThrown = ex.Message == "CookieValidityMinute from eventConfig should be greater than 0.";
            }

            // Assert
            Assert.True(mock.validateRequestCalls.Count == 0);
            Assert.True(exceptionWasThrown);
        }
コード例 #3
0
        private void DoValidationByLocalEventConfig()
        {
            try
            {
                var customerId = "Your Queue-it customer ID";
                var secretKey  = "Your 72 char secrete key as specified in Go Queue-it self-service platform";

                var queueitToken = Request.QueryString[KnownUser.QueueITTokenKey];
                var pureUrl      = Regex.Replace(Request.Url.ToString(), @"([\?&])(" + KnownUser.QueueITTokenKey + "=[^&]*)", string.Empty, RegexOptions.IgnoreCase);
                var eventConfig  = new EventConfig()
                {
                    EventId              = "event1",             //ID of the queue to use
                    CookieDomain         = ".mydomain.com",      //Optional - Domain name where the Queue-it session cookie should be saved. Default is to save on the domain of the request
                    QueueDomain          = "queue.mydomain.com", //Optional - Domian name of the queue. Default is [CustomerId].queue-it.net
                    CookieValidityMinute = 15,                   //Optional - Validity of the Queue-it session cookie. Default is 10 minutes
                    ExtendCookieValidity = false,                //Optional - Should the Queue-it session cookie validity time be extended each time the validation runs? Default is true.
                    Culture              = "en-US",              //Optional - Culture of the queue ticket layout in the format specified here: https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx Default is to use what is specified on Event
                    LayoutName           = "MyCustomLayoutName"  //Optional - Name of the queue ticket layout - e.g. "Default layout by Queue-it". Default is to use what is specified on the Event
                };

                //Verify if the user has been through the queue
                var validationResult = KnownUser.ValidateRequestByLocalEventConfig(pureUrl, queueitToken, eventConfig, customerId, secretKey);

                if (validationResult.DoRedirect)
                {
                    //Send the user to the queue - either becuase hash was missing or becuase is was invalid
                    Response.Redirect(validationResult.RedirectUrl);
                }
                else
                {
                    //Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token
                    if (HttpContext.Current.Request.Url.ToString().Contains(KnownUser.QueueITTokenKey))
                    {
                        Response.Redirect(pureUrl);
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
                //Response.Redirect will raise System.Threading.ThreadAbortException to end the exceution, no need to log the error
            }
            catch (Exception ex)
            {
                //There was an error validationg the request
                //Please log the error and let user continue
            }
        }
コード例 #4
0
        public void ValidateRequestByLocalEventConfig_NullEventConfig_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

            KnownUser._UserInQueueService = (mock);
            bool exceptionWasThrown = false;

            // Act
            try
            {
                KnownUser.ValidateRequestByLocalEventConfig("targetUrl", "queueitToken", null, "customerId", "secretKey");
            }
            catch (ArgumentException ex)
            {
                exceptionWasThrown = ex.Message == "eventConfig can not be null.";
            }

            // Assert
            Assert.True(mock.validateRequestCalls.Count == 0);
            Assert.True(exceptionWasThrown);
        }