public void ValidateRequest_ValidState_NoExtendableCookie_DoNotRedirectDoNotStoreCookieWithExtension() { var cookieProviderMock = Substitute.For <IUserInQueueStateRepository>(); string queueId = "queueId"; var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = true, ActionName = "QueueAction" }; var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db"; cookieProviderMock.GetState("", 10, "") .ReturnsForAnyArgs(new StateInfo(true, true, queueId, 3, "idle")); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest("url", "token", config, "testCustomer", customerKey); Assert.True(result.QueueId == queueId); Assert.True(result.RedirectType == "idle"); Assert.True(!result.DoRedirect); cookieProviderMock.DidNotReceiveWithAnyArgs().Store(null, null, 0, null, "", null); Assert.True(config.EventId == result.EventId); Assert.True(result.ActionName == config.ActionName); cookieProviderMock.Received().GetState("e1", 10, customerKey); cookieProviderMock.DidNotReceiveWithAnyArgs().CancelQueueCookie(config.EventId, config.CookieDomain); }
public void ValidateRequest_InvalidCookie_WithoutToken_RedirectToQueue_CancelCookie() { var cookieProviderMock = Substitute.For <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = false, Culture = null, LayoutName = "testlayout", Version = 10, ActionName = "QueueAction" }; cookieProviderMock.GetState("", 0, "").ReturnsForAnyArgs(new StateInfo(true, false, "", null, null)); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var knownUserVersion = UserInQueueService.SDK_VERSION; var expectedUrl = $"https://testDomain.com/?c=testCustomer&e=e1" + $"&ver={knownUserVersion}" + $"&cver=10" + $"&man=QueueAction" + $"&l={config.LayoutName}"; var result = testObject.ValidateQueueRequest(null, "", config, "testCustomer", "key"); Assert.True(result.DoRedirect); Assert.True(result.RedirectUrl.ToUpper() == expectedUrl.ToUpper()); cookieProviderMock.DidNotReceiveWithAnyArgs().Store(null, null, null, null, null, null); Assert.True(config.EventId == result.EventId); Assert.Equal(config.ActionName, result.ActionName); cookieProviderMock.Received().CancelQueueCookie(config.EventId, config.CookieDomain); }
public void ValidateRequest_InvalidCookie_InvalidToken_CancelCookie() { var cookieProviderMock = Substitute.For <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = false, Culture = null, LayoutName = "testlayout", Version = 10, ActionName = "QueueAction" }; cookieProviderMock.GetState("", 0, "").ReturnsForAnyArgs(new StateInfo(true, false, null, null, null)); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var targetUrl = "http://test.test.com?b=h"; var knownUserVersion = UserInQueueService.SDK_VERSION; var result = testObject.ValidateQueueRequest(targetUrl, "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895", config, "testCustomer", "key"); Assert.True(result.DoRedirect); Assert.StartsWith($"https://testDomain.com/error/hash/?c=testCustomer&e=e1&ver={knownUserVersion}&cver=10&man=QueueAction&l=testlayout&queueittoken=ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895&", result.RedirectUrl); cookieProviderMock.DidNotReceiveWithAnyArgs().Store(null, null, null, null, null, null); Assert.True(config.EventId == result.EventId); Assert.Equal(config.ActionName, result.ActionName); cookieProviderMock.Received().CancelQueueCookie(config.EventId, config.CookieDomain); }
public void ValidateRequest_NoCookie_InValidToken() { var cookieProviderMock = MockRepository.GenerateMock <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = false, Culture = null, LayoutName = "testlayout", Version = 10 }; cookieProviderMock.Stub(stub => stub.GetState("", 0, "")).IgnoreArguments().Return(new StateInfo(false, null, null, null)); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var targetUrl = "http://test.test.com?b=h"; var knownUserVersion = UserInQueueService.SDK_VERSION; var expectedUrl = $"https://testDomain.com?c=testCustomer&e=e1" + $"&ver=v3-aspnet-{knownUserVersion}" + $"&cver=10" + $"&l={config.LayoutName}" + $"&t={HttpUtility.UrlEncode(targetUrl)}"; var result = testObject.ValidateQueueRequest(targetUrl, "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895", config, "testCustomer", "key"); Assert.True(result.DoRedirect); Assert.True(result.RedirectUrl.StartsWith($"https://testDomain.com/error/hash/?c=testCustomer&e=e1&ver=v3-aspnet-{knownUserVersion}&cver=10&l=testlayout&queueittoken=ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895&")); cookieProviderMock.AssertWasNotCalled(stub => stub.Store(null, null, null, null, null, null), options => options.IgnoreArguments()); Assert.True(config.EventId == result.EventId); }
public void ValidateRequest_ValidState_NoExtendableCookie_DoNotRedirectDoNotStoreCookieWithExtension() { var cookieProviderMock = MockRepository.GenerateMock <IUserInQueueStateRepository>(); string queueId = "queueId"; var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = true }; var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db"; cookieProviderMock.Stub(stub => stub.GetState("", 10, "")) .IgnoreArguments().Return(new StateInfo(true, queueId, 3, "idle")); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest("url", "token", config, "testCustomer", customerKey); Assert.True(result.QueueId == queueId); Assert.True(result.RedirectType == "idle"); Assert.True(!result.DoRedirect); cookieProviderMock.AssertWasNotCalled(stub => stub.Store(null, null, 0, null, "", null), options => options.IgnoreArguments()); Assert.True(config.EventId == result.EventId); cookieProviderMock.AssertWasCalled(stub => stub.GetState("e1", 10, customerKey)); }
public void ValidateRequest_ValidState_ExtendableCookie_NoCookieExtensionFromConfig_DoNotRedirectDoNotStoreCookieWithExtension() { var cookieProviderMock = Substitute.For <IUserInQueueStateRepository>(); string queueId = "queueId"; var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain", CookieValidityMinute = 10, ExtendCookieValidity = false, ActionName = "QueueAction" }; cookieProviderMock.GetState("", 0, "") .ReturnsForAnyArgs(new StateInfo(true, true, queueId, null, "idle")); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest("url", "token", config, "testCustomer", "key"); Assert.True(!result.DoRedirect); Assert.True(result.QueueId == queueId); Assert.True(result.RedirectType == "idle"); Assert.True(result.ActionName == config.ActionName); cookieProviderMock.DidNotReceiveWithAnyArgs().Store("", queueId, null, "", false, false, "", ""); Assert.True(config.EventId == result.EventId); cookieProviderMock.DidNotReceiveWithAnyArgs().CancelQueueCookie(config.EventId, config.CookieDomain, config.IsCookieHttpOnly, config.IsCookieSecure); }
public void ValidateRequest_NoCookie_WithoutToken_RedirectToQueue_NotargetUrl() { var cookieProviderMock = MockRepository.GenerateMock <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = false, Culture = null, LayoutName = "testlayout", Version = 10 }; cookieProviderMock.Stub(stub => stub.GetState("", 0, "")).IgnoreArguments().Return(new StateInfo(false, "", null, null)); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var knownUserVersion = UserInQueueService.SDK_VERSION; var expectedUrl = $"https://testDomain.com?c=testCustomer&e=e1" + $"&ver=v3-aspnet-{knownUserVersion}" + $"&cver=10" + $"&l={config.LayoutName}"; var result = testObject.ValidateQueueRequest(null, "", config, "testCustomer", "key"); Assert.True(result.DoRedirect); Assert.True(result.RedirectUrl.ToUpper() == expectedUrl.ToUpper()); cookieProviderMock.AssertWasNotCalled(stub => stub.Store(null, null, null, null, null, null), options => options.IgnoreArguments()); Assert.True(config.EventId == result.EventId); }
public void ValidateRequest_NoCookie_EventIdMismatch_RedirectToErrorPageWithEventIdMissMatchError_DoNotStoreCookie() { var cookieProviderMock = Substitute.For <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "e2", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = false, Version = 10, ActionName = "QueueAction" }; var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db"; var queueId = "iopdb821-a825-49da-acd0-5d376f2068db"; cookieProviderMock.GetState("", 10, "").ReturnsForAnyArgs(new StateInfo(false, false, "", null, "")); string hash = ""; var queueitToken = QueueITTokenGenerator.GenerateToken( DateTime.UtcNow.AddHours(1), "e1", queueId, true, null, customerKey, out hash, "queue" ); var targetUrl = "http://test.test.com?b=h"; var knownUserVersion = UserInQueueService.SDK_VERSION; var expectedMan = Uri.EscapeDataString(config.ActionName); var expectedErrorUrl = $"https://testDomain.com/error/eventid/?c=testCustomer&e=e2" + $"&ver={knownUserVersion}" + "&cver=10" + $"&man=QueueAction" + $"&queueittoken={queueitToken}" + $"&t={Uri.EscapeDataString(targetUrl)}"; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); Assert.True(result.DoRedirect); var regex = new Regex("&ts=[^&]*"); var match = regex.Match(result.RedirectUrl); var serverTimestamp = DateTimeHelper.GetDateTimeFromUnixTimeStamp(match.Value.Replace("&ts=", "").Replace("&", "")); Assert.True(DateTime.UtcNow.Subtract(serverTimestamp) < TimeSpan.FromSeconds(10)); var redirectUrl = regex.Replace(result.RedirectUrl, ""); Assert.True(redirectUrl.ToUpper() == expectedErrorUrl.ToUpper()); Assert.True(config.EventId == result.EventId); Assert.Equal(config.ActionName, result.ActionName); cookieProviderMock.DidNotReceiveWithAnyArgs().Store("", "", null, "", null, ""); cookieProviderMock.DidNotReceiveWithAnyArgs().CancelQueueCookie(config.EventId, config.CookieDomain); }
public void ValidateRequest_NoCookie_TampredToken_RedirectToErrorPageWithHashError_DoNotStoreCookie() { Exception expectedException = new Exception(); var cookieProviderMock = MockRepository.GenerateMock <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = false, Version = 100 }; var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db"; var queueId = "iopdb821-a825-49da-acd0-5d376f2068db"; cookieProviderMock.Stub(stub => stub.GetState("", 10, "")).IgnoreArguments().Return(new StateInfo(false, "", null, "")); string hash = ""; var queueitToken = QueueITTokenGenerator.GenerateToken( DateTime.UtcNow.AddHours(1), "e1", queueId, false, 20, customerKey, out hash, "idle"); queueitToken = queueitToken.Replace("False", "True"); var targetUrl = "http://test.test.com?b=h"; var knownUserVersion = UserInQueueService.SDK_VERSION; var expectedErrorUrl = $"https://testDomain.com/error/hash/?c=testCustomer&e=e1" + $"&ver=v3-aspnet-{knownUserVersion}" + $"&cver=100" + $"&queueittoken={queueitToken}" + $"&t={HttpUtility.UrlEncode(targetUrl)}"; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); Assert.True(result.DoRedirect); var regex = new Regex("&ts=[^&]*"); var match = regex.Match(result.RedirectUrl); var serverTimestamp = DateTimeHelper.GetDateTimeFromUnixTimeStamp(match.Value.Replace("&ts=", "").Replace("&", "")); Assert.True(DateTime.UtcNow.Subtract(serverTimestamp) < TimeSpan.FromSeconds(10)); var redirectUrl = regex.Replace(result.RedirectUrl, ""); Assert.True(redirectUrl.ToUpper() == expectedErrorUrl.ToUpper()); Assert.True(config.EventId == result.EventId); cookieProviderMock.AssertWasNotCalled(stub => stub.Store("", "", null, "", "", ""), options => options.IgnoreArguments()); }
public void ValidateRequest_NoCookie_ValidToken_ExtendableCookie_DoNotRedirect_StoreExtendableCookie() { var cookieProviderMock = Substitute.For <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = false, ActionName = "QueueAction" }; var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db"; var queueId = "iopdb821-a825-49da-acd0-5d376f2068db"; cookieProviderMock.GetState("", 10, "").ReturnsForAnyArgs(new StateInfo(false, false, "", null, "")); string hash = ""; var queueitToken = QueueITTokenGenerator.GenerateToken( DateTime.UtcNow.AddHours(1), "e1", queueId, true, null, customerKey, out hash, "queue"); var targetUrl = "http://test.test.com?b=h"; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); Assert.True(!result.DoRedirect); cookieProviderMock.Received().Store( "e1", queueId, null, config.CookieDomain, config.IsCookieHttpOnly, config.IsCookieSecure, "queue", customerKey); Assert.True(result.QueueId == queueId); Assert.True(result.RedirectType == "queue"); Assert.True(config.EventId == result.EventId); cookieProviderMock.DidNotReceiveWithAnyArgs().CancelQueueCookie(config.EventId, config.CookieDomain, config.IsCookieHttpOnly, config.IsCookieSecure); }
public void ValidateRequest_NoCookie_ValidToken_ExtendableCookie_DoNotRedirect_StoreExtendableCookie() { var cookieProviderMock = MockRepository.GenerateMock <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = false }; var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db"; var queueId = "iopdb821-a825-49da-acd0-5d376f2068db"; cookieProviderMock.Stub(stub => stub.GetState("", 10, "")).IgnoreArguments().Return(new StateInfo(false, "", null, "")); string hash = ""; var queueitToken = QueueITTokenGenerator.GenerateToken( DateTime.UtcNow.AddHours(1), "e1", queueId, true, null, customerKey, out hash, "queue"); var targetUrl = "http://test.test.com?b=h"; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); Assert.True(!result.DoRedirect); cookieProviderMock.AssertWasCalled(stub => stub.Store( Arg <string> .Is.Equal("e1"), Arg <string> .Is.Equal(queueId), Arg <int?> .Is.Equal(null), Arg <string> .Is.Equal(config.CookieDomain), Arg <string> .Is.Equal("queue"), Arg <string> .Is.Equal(customerKey), Arg <bool?> .Is.Equal(null))); Assert.True(result.QueueId == queueId); Assert.True(result.RedirectType == "queue"); Assert.True(config.EventId == result.EventId); }
public void ValidateRequest_NoCookie_ValidToken_CookieValidityMinuteFromToken_DoNotRedirect_StoreNonExtendableCookie() { var cookieProviderMock = Substitute.For <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "eventid", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = true, ActionName = "QueueAction" }; var customerKey = "secretekeyofuser"; var queueId = "f8757c2d-34c2-4639-bef2-1736cdd30bbb"; cookieProviderMock.GetState("", 10, "").ReturnsForAnyArgs(new StateInfo(false, false, "", null, "")); var queueitToken = "e_eventid~q_f8757c2d-34c2-4639-bef2-1736cdd30bbb~ri_34678c2d-34c2-4639-bef2-1736cdd30bbb~ts_1797033600~ce_False~cv_3~rt_DirectLink~h_5ee2babc3ac9fae9d80d5e64675710c371876386e77209f771007dc3e093e326"; var targetUrl = "http://test.test.com?b=h"; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); Assert.True(!result.DoRedirect); Assert.True(result.QueueId == queueId); Assert.True(result.RedirectType == "DirectLink"); Assert.True(config.EventId == result.EventId); cookieProviderMock.Received().Store( "eventid", queueId, 3, config.CookieDomain, "DirectLink", customerKey); cookieProviderMock.DidNotReceiveWithAnyArgs().CancelQueueCookie(config.EventId, config.CookieDomain); }
public void ValidateRequest_NoCookie_ValidToken_CookieValidityMinuteFromToken_DoNotRedirect_StoreNonExtendableCookie() { var cookieProviderMock = MockRepository.GenerateMock <IUserInQueueStateRepository>(); var config = new QueueEventConfig() { EventId = "eventid", QueueDomain = "testDomain.com", CookieValidityMinute = 10, ExtendCookieValidity = true }; var customerKey = "secretekeyofuser"; var queueId = "f8757c2d-34c2-4639-bef2-1736cdd30bbb"; cookieProviderMock.Stub(stub => stub.GetState("", 10, "")).IgnoreArguments().Return(new StateInfo(false, "", null, "")); var queueitToken = "e_eventid~q_f8757c2d-34c2-4639-bef2-1736cdd30bbb~ri_34678c2d-34c2-4639-bef2-1736cdd30bbb~ts_1797033600~ce_False~cv_3~rt_DirectLink~h_5ee2babc3ac9fae9d80d5e64675710c371876386e77209f771007dc3e093e326"; var targetUrl = "http://test.test.com?b=h"; UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest(targetUrl, queueitToken, config, "testCustomer", customerKey); Assert.True(!result.DoRedirect); Assert.True(result.QueueId == queueId); Assert.True(result.RedirectType == "DirectLink"); Assert.True(config.EventId == result.EventId); cookieProviderMock.AssertWasCalled(stub => stub.Store( Arg <string> .Is.Equal("eventid"), Arg <string> .Is.Equal(queueId), Arg <int?> .Is.Equal(3), Arg <string> .Is.Equal(config.CookieDomain), Arg <string> .Is.Equal("DirectLink"), Arg <string> .Is.Equal(customerKey), Arg <bool?> .Is.Equal(null))); }
public void ValidateRequest_ValidState_ExtendableCookie_CookieExtensionFromConfig_DoNotRedirectDoStoreCookieWithExtension() { var cookieProviderMock = MockRepository.GenerateMock <IUserInQueueStateRepository>(); string queueId = "queueId"; var config = new QueueEventConfig() { EventId = "e1", QueueDomain = "testdomain", CookieValidityMinute = 20, ExtendCookieValidity = true, CookieDomain = ".testdomain.com" }; cookieProviderMock.Stub(stub => stub.GetState("", 20, "")) .IgnoreArguments().Return(new StateInfo(true, queueId, null, "disabled")); UserInQueueService testObject = new UserInQueueService(cookieProviderMock); var result = testObject.ValidateQueueRequest("url", "token", config, "testCustomer", "key"); Assert.True(!result.DoRedirect); Assert.True(result.QueueId == queueId); Assert.True(result.RedirectType == "disabled"); cookieProviderMock.AssertWasCalled(stub => stub.Store( Arg <string> .Is.Equal("e1"), Arg <string> .Is.Equal(queueId), Arg <int?> .Is.Equal(null), Arg <string> .Is.Equal(config.CookieDomain), Arg <string> .Is.Equal("disabled"), Arg <string> .Is.Equal("key"), Arg <bool?> .Is.Equal(null))); cookieProviderMock.AssertWasCalled(stub => stub.GetState("e1", 20, "key")); Assert.True(config.EventId == result.EventId); }