public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_UserAgent() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration() { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel() { Name = "integration1", Triggers = new List <TriggerModel>() { new TriggerModel() { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart>() { new TriggerPart() { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, IsIgnoreCase = true, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator }, new TriggerPart() { UrlPart = UrlPartType.PageUrl, ValidatorType = ValidatorType.UrlValidator, ValueToCompare = "test", Operator = ComparisonOperatorType.Contains }, new TriggerPart() { ValidatorType = ValidatorType.UserAgentValidator, ValueToCompare = "Googlebot", Operator = ComparisonOperatorType.Contains, IsIgnoreCase = true, IsNegative = true } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); var httpRequestMock = MockRepository.GenerateMock <HttpRequestBase>(); httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection() { new HttpCookie("c1", "Value1") }); httpRequestMock.Stub(r => r.UserAgent).Return("bot.html google.com googlebot test"); Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock) == null); }
public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_UserAgent() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel { Name = "integration1", Triggers = new List <TriggerModel> { new TriggerModel { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart> { new TriggerPart { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, IsIgnoreCase = true, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator }, new TriggerPart { UrlPart = UrlPartType.PageUrl, ValidatorType = ValidatorType.UrlValidator, ValueToCompare = "test", Operator = ComparisonOperatorType.Contains }, new TriggerPart { ValidatorType = ValidatorType.UserAgentValidator, ValueToCompare = "Googlebot", Operator = ComparisonOperatorType.Contains, IsIgnoreCase = true, IsNegative = true } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); var httpRequestMock = new KnownUserTest.MockHttpRequest { CookiesValue = new NameValueCollection { { "c1", "Value1" } }, UserAgent = "bot.html google.com googlebot test" }; Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock) == null); }
public static RequestValidationResult ValidateRequestByIntegrationConfig(string currentUrlWithoutQueueITToken, string queueitToken, CustomerIntegration customerIntegrationInfo, string customerId, string secretKey) { if (string.IsNullOrEmpty(currentUrlWithoutQueueITToken)) { throw new ArgumentException("currentUrlWithoutQueueITToken can not be null or empty."); } if (customerIntegrationInfo == null) { throw new ArgumentException("customerIntegrationInfo can not be null."); } var configEvaluater = new IntegrationEvaluator(); var matchedConfig = configEvaluater.GetMatchedIntegrationConfig( customerIntegrationInfo, currentUrlWithoutQueueITToken, GetHttpContextBase()?.Request?.Cookies); if (matchedConfig == null) { return(new RequestValidationResult()); } var targetUrl = ""; switch (matchedConfig.RedirectLogic) { case "ForcedTargetUrl": case "ForecedTargetUrl": targetUrl = matchedConfig.ForcedTargetUrl; break; case "EventTargetUrl": targetUrl = ""; break; default: targetUrl = currentUrlWithoutQueueITToken; break; } var eventConfig = new EventConfig() { QueueDomain = matchedConfig.QueueDomain, Culture = matchedConfig.Culture, EventId = matchedConfig.EventId, ExtendCookieValidity = matchedConfig.ExtendCookieValidity, LayoutName = matchedConfig.LayoutName, CookieValidityMinute = matchedConfig.CookieValidityMinute, CookieDomain = matchedConfig.CookieDomain, Version = customerIntegrationInfo.Version }; return(ValidateRequestByLocalEventConfig(targetUrl, queueitToken, eventConfig, customerId, secretKey)); }
public void GetMatchedIntegrationConfig_TwoTriggers_Matched() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration() { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel() { Name = "integration1", Triggers = new List <TriggerModel>() { new TriggerModel() { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart>() { new TriggerPart() { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator } } }, new TriggerModel() { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart>() { new TriggerPart() { UrlPart = UrlPartType.PageUrl, ValidatorType = ValidatorType.UrlValidator, ValueToCompare = "*", Operator = ComparisonOperatorType.Contains } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); var httpRequestMock = MockRepository.GenerateMock <HttpRequestBase>(); httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection()); httpRequestMock.Stub(r => r.UserAgent).Return(string.Empty); Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock).Name == "integration1", string.Empty); }
public void GetMatchedIntegrationConfig_OneTrigger_And_Matched() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration() { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel() { Name = "integration1", Triggers = new List <TriggerModel>() { new TriggerModel() { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart>() { new TriggerPart() { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, IsIgnoreCase = true, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator }, new TriggerPart() { UrlPart = UrlPartType.PageUrl, ValidatorType = ValidatorType.UrlValidator, ValueToCompare = "test", Operator = ComparisonOperatorType.Contains } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); var httpRequestMock = new KnownUserTest.MockHttpRequest() { CookiesValue = new NameValueCollection() { { "c1", "Value1" } } }; Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock).Name == "integration1"); }
public void GetMatchedIntegrationConfig_TwoTriggers_Matched() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration() { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel() { Name = "integration1", Triggers = new List <TriggerModel>() { new TriggerModel() { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart>() { new TriggerPart() { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator } } }, new TriggerModel() { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart>() { new TriggerPart() { UrlPart = UrlPartType.PageUrl, ValidatorType = ValidatorType.UrlValidator, ValueToCompare = "*", Operator = ComparisonOperatorType.Contains } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, new HttpCookieCollection() { }).Name == "integration1"); }
public void GetMatchedIntegrationConfig_TwoTriggers_NotMatched() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel { Name = "integration1", Triggers = new List <TriggerModel> { new TriggerModel { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart> { new TriggerPart { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator } } }, new TriggerModel { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart> { new TriggerPart { UrlPart = UrlPartType.PageUrl, ValidatorType = ValidatorType.UrlValidator, ValueToCompare = "tesT", Operator = ComparisonOperatorType.Contains } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); var httpRequestMock = new KnownUserTest.MockHttpRequest(); Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock) == null); }
public void GetMatchedIntegrationConfig_OneTrigger_Or_NotMatched() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration() { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel() { Name = "integration1", Triggers = new List <TriggerModel>() { new TriggerModel() { LogicalOperator = LogicalOperatorType.Or, TriggerParts = new List <TriggerPart>() { new TriggerPart() { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator }, new TriggerPart() { UrlPart = UrlPartType.PageUrl, ValidatorType = ValidatorType.UrlValidator, IsIgnoreCase = true, IsNegative = true, ValueToCompare = "tesT", Operator = ComparisonOperatorType.Contains } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, new HttpCookieCollection() { new HttpCookie("c2", "value1") }) == null); }
public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration() { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel() { Triggers = new List <TriggerModel>() { new TriggerModel() { LogicalOperator = LogicalOperatorType.Or, TriggerParts = new List <TriggerPart>() { new TriggerPart() { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator }, new TriggerPart() { ValidatorType = ValidatorType.UserAgentValidator, ValueToCompare = "test", Operator = ComparisonOperatorType.Contains } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, new KnownUserTest.MockHttpRequest()) == null); }
public static RequestValidationResult ValidateRequestByIntegrationConfig( string currentUrlWithoutQueueITToken, string queueitToken, CustomerIntegration customerIntegrationInfo, string customerId, string secretKey) { var debugEntries = new Dictionary <string, string>(); try { var isDebug = GetIsDebug(queueitToken, secretKey); if (isDebug) { debugEntries["ConfigVersion"] = customerIntegrationInfo.Version.ToString(); debugEntries["PureUrl"] = currentUrlWithoutQueueITToken; debugEntries["QueueitToken"] = queueitToken; debugEntries["OriginalUrl"] = GetHttpContextProvider().HttpRequest.Url.AbsoluteUri; LogExtraRequestDetails(debugEntries); } if (string.IsNullOrEmpty(currentUrlWithoutQueueITToken)) { throw new ArgumentException("currentUrlWithoutQueueITToken can not be null or empty."); } if (customerIntegrationInfo == null) { throw new ArgumentException("customerIntegrationInfo can not be null."); } var configEvaluater = new IntegrationEvaluator(); var matchedConfig = configEvaluater.GetMatchedIntegrationConfig( customerIntegrationInfo, currentUrlWithoutQueueITToken, GetHttpContextProvider().HttpRequest); if (isDebug) { debugEntries["MatchedConfig"] = matchedConfig != null ? matchedConfig.Name : "NULL"; } if (matchedConfig == null) { return(new RequestValidationResult(null)); } switch (matchedConfig.ActionType ?? string.Empty) { case "": //baackward compatibility case ActionType.QueueAction: { return(HandleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo, customerId, secretKey, debugEntries, matchedConfig)); } case ActionType.CancelAction: { return(HandleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo, customerId, secretKey, debugEntries, matchedConfig)); } default: //default IgnoreAction { return(HandleIgnoreAction()); } } } finally { SetDebugCookie(debugEntries); } }
public static RequestValidationResult ValidateRequestByIntegrationConfig( string currentUrlWithoutQueueITToken, string queueitToken, CustomerIntegration customerIntegrationInfo, string customerId, string secretKey) { var debugEntries = new Dictionary <string, string>(); var connectorDiagnostics = ConnectorDiagnostics.Verify(customerId, secretKey, queueitToken); if (connectorDiagnostics.HasError) { return(connectorDiagnostics.ValidationResult); } try { if (connectorDiagnostics.IsEnabled) { debugEntries["SdkVersion"] = UserInQueueService.SDK_VERSION; debugEntries["Runtime"] = GetRuntime(); debugEntries["ConfigVersion"] = customerIntegrationInfo != null?customerIntegrationInfo.Version.ToString() : "NULL"; debugEntries["PureUrl"] = currentUrlWithoutQueueITToken; debugEntries["QueueitToken"] = queueitToken; debugEntries["OriginalUrl"] = GetHttpContextProvider().HttpRequest.Url.AbsoluteUri; LogExtraRequestDetails(debugEntries); } if (string.IsNullOrEmpty(currentUrlWithoutQueueITToken)) { throw new ArgumentException("currentUrlWithoutQueueITToken can not be null or empty."); } if (customerIntegrationInfo == null) { throw new ArgumentException("customerIntegrationInfo can not be null."); } var configEvaluater = new IntegrationEvaluator(); var matchedConfig = configEvaluater.GetMatchedIntegrationConfig( customerIntegrationInfo, currentUrlWithoutQueueITToken, GetHttpContextProvider().HttpRequest); if (connectorDiagnostics.IsEnabled) { debugEntries["MatchedConfig"] = matchedConfig != null ? matchedConfig.Name : "NULL"; } if (matchedConfig == null) { return(new RequestValidationResult(null)); } switch (matchedConfig.ActionType ?? string.Empty) { case "": //backward compatibility case ActionType.QueueAction: { return(HandleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo, customerId, secretKey, debugEntries, matchedConfig, connectorDiagnostics.IsEnabled)); } case ActionType.CancelAction: { return(HandleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo, customerId, secretKey, debugEntries, matchedConfig, connectorDiagnostics.IsEnabled)); } default: { return(HandleIgnoreAction(matchedConfig.Name)); } } } catch (Exception e) { if (connectorDiagnostics.IsEnabled) { debugEntries["Exception"] = e.Message; } throw; } finally { SetDebugCookie(debugEntries); } }
public void GetMatchedIntegrationConfig_ThreeIntegrationsInOrder_SecondMatched() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel { Name = "integration0", Triggers = new List <TriggerModel> { new TriggerModel { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart> { new TriggerPart { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator } } } } }, new IntegrationConfigModel { Name = "integration1", Triggers = new List <TriggerModel> { new TriggerModel { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart> { new TriggerPart { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, ValueToCompare = "Value1", ValidatorType = ValidatorType.CookieValidator } } } } }, new IntegrationConfigModel { Name = "integration2", Triggers = new List <TriggerModel> { new TriggerModel { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart> { new TriggerPart { UrlPart = UrlPartType.PageUrl, Operator = ComparisonOperatorType.Contains, ValueToCompare = "test", ValidatorType = ValidatorType.UrlValidator } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); var httpRequestMock = new KnownUserTest.MockHttpRequest { CookiesValue = new NameValueCollection { { "c1", "Value1" } } }; Assert.False(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock).Name == "integration2"); }
public void GetMatchedIntegrationConfig_ThreeIntegrationsInOrder_SecondMatched() { var testObject = new IntegrationEvaluator(); var customerIntegration = new CustomerIntegration() { Integrations = new List <IntegrationConfigModel> { new IntegrationConfigModel() { Name = "integration0", Triggers = new List <TriggerModel>() { new TriggerModel() { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart>() { new TriggerPart() { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, ValueToCompare = "value1", ValidatorType = ValidatorType.CookieValidator } } } } }, new IntegrationConfigModel() { Name = "integration1", Triggers = new List <TriggerModel>() { new TriggerModel() { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart>() { new TriggerPart() { CookieName = "c1", Operator = ComparisonOperatorType.EqualS, ValueToCompare = "Value1", ValidatorType = ValidatorType.CookieValidator } } } } }, new IntegrationConfigModel() { Name = "integration2", Triggers = new List <TriggerModel>() { new TriggerModel() { LogicalOperator = LogicalOperatorType.And, TriggerParts = new List <TriggerPart>() { new TriggerPart() { UrlPart = UrlPartType.PageUrl, Operator = ComparisonOperatorType.Contains, ValueToCompare = "test", ValidatorType = ValidatorType.UrlValidator } } } } } } }; var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); var httpRequestMock = MockRepository.GenerateMock <HttpRequestBase>(); Assert.False(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, new HttpCookieCollection() { new HttpCookie("c1") { Value = "Value1" } }).Name == "integration2"); }