コード例 #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
 // Returns user information, or the type of user if not a known user.
 static string getUserInfo(Google.Apis.DriveActivity.v2.Data.User user)
 {
     if (user.KnownUser != null)
     {
         KnownUser knownUser = user.KnownUser;
         bool      isMe      = knownUser.IsCurrentUser ?? false;
         return(isMe ? "people/me" : knownUser.PersonName);
     }
     return(getOneOf(user));
 }
コード例 #4
0
 // Returns user information, or the type of user if not a known user.
 static string GetUserInfo(User user)
 {
     if (user.KnownUser != null)
     {
         KnownUser knownUser = user.KnownUser;
         bool      isMe      = knownUser.IsCurrentUser ?? false;
         return(isMe ? "people/me" : knownUser.PersonName);
     }
     return(GetOneOf(user));
 }
コード例 #5
0
        public void ValidateRequestByIntegrationConfig_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

            KnownUser._UserInQueueService = (mock);

            TriggerPart triggerPart = new TriggerPart();

            triggerPart.Operator       = "Contains";
            triggerPart.ValueToCompare = "event1";
            triggerPart.UrlPart        = "PageUrl";
            triggerPart.ValidatorType  = "UrlValidator";
            triggerPart.IsNegative     = false;
            triggerPart.IsIgnoreCase   = true;

            TriggerModel trigger = new TriggerModel();

            trigger.LogicalOperator = "And";
            trigger.TriggerParts    = new TriggerPart[] { triggerPart };

            IntegrationConfigModel config = new IntegrationConfigModel();

            config.Name = "event1action";
            //config.ActionType = "Queue";
            config.EventId              = "event1";
            config.CookieDomain         = ".test.com";
            config.LayoutName           = "Christmas Layout by Queue-it";
            config.Culture              = "da-DK";
            config.ExtendCookieValidity = true;
            config.CookieValidityMinute = 20;
            config.Triggers             = new TriggerModel[] { trigger };
            config.QueueDomain          = "knownusertest.queue-it.net";
            config.RedirectLogic        = "AllowTParameter";
            config.ForcedTargetUrl      = "";

            CustomerIntegration customerIntegration = new CustomerIntegration();

            customerIntegration.Integrations = new IntegrationConfigModel[] { config };
            customerIntegration.Version      = 3;

            // Act
            KnownUser.ValidateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", "secretKey");

            // Assert
            Assert.True(mock.validateRequestCalls.Count == 1);
            Assert.Equal("http://test.com?event1=true", mock.validateRequestCalls[0][0]);
            Assert.Equal("queueitToken", mock.validateRequestCalls[0][1]);
            Assert.Equal(".test.com:Christmas Layout by Queue-it:da-DK:event1:knownusertest.queue-it.net:true:20:3", mock.validateRequestCalls[0][2]);
            Assert.Equal("customerId", mock.validateRequestCalls[0][3]);
            Assert.Equal("secretKey", mock.validateRequestCalls[0][4]);
        }
コード例 #6
0
        public void CancelQueueCookie_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

            KnownUser._UserInQueueService = (mock);

            // Act
            KnownUser.CancelQueueCookie("eventId");

            // Assert
            Assert.Equal("eventId", mock.cancelQueueCookieCalls[0][0]);
        }
コード例 #7
0
        public void ExtendQueueCookie_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

            KnownUser._UserInQueueService = (mock);

            // Act
            KnownUser.ExtendQueueCookie("eventId", 20, "secretKey");

            // Assert
            Assert.Equal("eventId", mock.extendQueueCookieCalls[0][0]);
            Assert.Equal("20", mock.extendQueueCookieCalls[0][1]);
            Assert.Equal("secretKey", mock.extendQueueCookieCalls[0][2]);
        }
コード例 #8
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
            }
        }
コード例 #9
0
        public void ValidateRequestByIntegrationConfig_NotMatch_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

            KnownUser._UserInQueueService = (mock);

            CustomerIntegration customerIntegration = new CustomerIntegration();

            customerIntegration.Integrations = new IntegrationConfigModel[0];
            customerIntegration.Version      = 3;

            // Act
            RequestValidationResult result = KnownUser.ValidateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", "secretKey");

            // Assert
            Assert.True(mock.validateRequestCalls.Count == 0);
            Assert.False(result.DoRedirect);
        }
コード例 #10
0
        private void DoValidation()
        {
            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 integrationConfig = IntegrationConfigProvider.GetCachedIntegrationConfig(customerId);


                //Verify if the user has been through the queue
                var validationResult = KnownUser.ValidateRequestByIntegrationConfig(pureUrl, queueitToken, integrationConfig, 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
                //Use your own logging framework to log the Exception
                //This was a configuration exception, so we let the user continue
            }
        }
コード例 #11
0
        public void ExtendQueueCookie_NullEventId_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

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

            // Act
            try
            {
                KnownUser.ExtendQueueCookie(null, 0, null);
            }
            catch (ArgumentException ex)
            {
                exceptionWasThrown = ex.Message == "eventId can not be null or empty.";
            }

            // Assert
            Assert.True(mock.extendQueueCookieCalls.Count == 0);
            Assert.True(exceptionWasThrown);
        }
コード例 #12
0
        public void ValidateRequestByIntegrationConfig_EmptyIntegrationsConfig_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

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

            // Act
            try
            {
                KnownUser.ValidateRequestByIntegrationConfig("currentUrl", "queueitToken", null, null, null);
            }
            catch (Exception ex)
            {
                exceptionWasThrown = ex.Message == "customerIntegrationInfo can not be null.";
            }

            // Assert
            Assert.True(mock.validateRequestCalls.Count == 0);
            Assert.True(exceptionWasThrown);
        }
コード例 #13
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);
        }
コード例 #14
0
        public void ExtendQueueCookie_InvalidCookieValidityMinutes_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

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

            // Act
            try
            {
                KnownUser.ExtendQueueCookie("eventId", 0, null);
            }
            catch (ArgumentException ex)
            {
                exceptionWasThrown = ex.Message == "cookieValidityMinute should be greater than 0.";
            }

            // Assert
            Assert.True(mock.extendQueueCookieCalls.Count == 0);
            Assert.True(exceptionWasThrown);
        }
コード例 #15
0
        public async Task <KnownUser> GetOrCreateKnownUserForDiscordUser(DiscordUser discordUser)
        {
            // Get user (if present)
            var knownUser = await _selfcareDb.KnownUsers.Where(kn => kn.DiscordId == discordUser.Id)
                            .FirstOrDefaultAsync();

            // Record user if not present
            if (knownUser == null)
            {
                // Create db user from discord user
                knownUser = new KnownUser
                {
                    DiscordId     = discordUser.Id,
                    Username      = discordUser.Username,
                    Discriminator = discordUser.Discriminator
                };

                // Add to database
                _selfcareDb.KnownUsers.Add(knownUser);
                await _selfcareDb.SaveChangesAsync();
            }

            return(knownUser);
        }