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]); }
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); }
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 } }
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); }