public void ToCookie_WhenCalledWithDashboardSettingsViewModelWithRedditAccessTokenAndResponseCookiesWasReturnedButCookieValueToStoreWasReturned_AssertAppendWasCalledOnReturnedResponseCookies() { bool isHttps = _random.Next(100) > 50; HttpRequest httpRequest = BuildHttpRequest(isHttps); string cookieValueToStore = Guid.NewGuid().ToString("D"); Mock <IResponseCookies> responseCookiesMock = BuildResponseCookiesMock(); HttpResponse httpResponse = BuildHttpResponse(responseCookies: responseCookiesMock.Object); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest, httpResponse: httpResponse); ICookieHelper sut = CreateSut(cookieValueToStore: cookieValueToStore, httpContext: httpContext); int expiresIn = _random.Next(5, 60) * 60; DateTime received = DateTime.UtcNow; string redditAccessTokenAsBase64 = BuildRedditAccessTokenAsBase64(_random, expiresIn, received); DateTime expires = received.AddSeconds(expiresIn).ToLocalTime(); DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, redditAccessTokenAsBase64); sut.ToCookie(dashboardSettingsViewModel); responseCookiesMock.Verify(m => m.Append( It.Is <string>(value => string.CompareOrdinal(value, DashboardSettingsViewModel.CookieName) == 0), It.Is <string>(value => string.CompareOrdinal(value, BuildBase64String(cookieValueToStore)) == 0), It.Is <CookieOptions>(value => value != null && value.Expires >= expires.AddSeconds(-5) && value.Expires <= expires.AddSeconds(5) && value.Secure == isHttps && value.SameSite == SameSiteMode.None)), Times.Once); }
public OrdersController(IWebApiCaller webApiCaller, ICookieHelper cookieHelper, ISecurityHelper securityHelper) { WebApiCaller = webApiCaller; CookieHelper = cookieHelper; SecurityHelper = securityHelper; CurrentUser = SecurityHelper.GetSessionUser(CookieHelper.GetCookie <string>("CurrentUser")); }
/// <summary> /// 讀取組態用 /// </summary> public UserController(IConfiguration config, ICallApi callApi, IHttpContextAccessor httpContextAccessor, ICookieHelper cookieHelper) { _config = config; _callApi = callApi; _httpContextAccessor = httpContextAccessor; _cookieHelper = cookieHelper; }
public HomeController(IDashboardFactory dashboardFactory, IViewModelBuilder <DashboardViewModel, IDashboard> dashboardViewModelBuilder, IModelExporter <DashboardExportModel, IDashboard> dashboardModelExporter, IRedditAccessTokenProviderFactory redditAccessTokenProviderFactory, IContentHelper contentHelper, ICookieHelper cookieHelper) { if (dashboardFactory == null) { throw new ArgumentNullException(nameof(dashboardFactory)); } if (dashboardViewModelBuilder == null) { throw new ArgumentNullException(nameof(dashboardViewModelBuilder)); } if (dashboardModelExporter == null) { throw new ArgumentNullException(nameof(dashboardModelExporter)); } if (redditAccessTokenProviderFactory == null) { throw new ArgumentNullException(nameof(redditAccessTokenProviderFactory)); } if (contentHelper == null) { throw new ArgumentNullException(nameof(contentHelper)); } if (cookieHelper == null) { throw new ArgumentNullException(nameof(cookieHelper)); } _dashboardFactory = dashboardFactory; _dashboardViewModelBuilder = dashboardViewModelBuilder; _dashboardModelExporter = dashboardModelExporter; _redditAccessTokenProviderFactory = redditAccessTokenProviderFactory; _contentHelper = contentHelper; _cookieHelper = cookieHelper; }
public ApiController(IConfiguration configuration, ICookieHelper cookieHelper, IJWTHelper JWTHelper, ICryptoHelper cryptoHelper) { _configuration = configuration; _cookieHelper = cookieHelper; _JWTHelper = JWTHelper; _cryptoHelper = cryptoHelper; }
public async Task Invoke(HttpContext context) { try { IHeaderDictionary headers = context.Request.Headers; ICookieHelper _cookieHelper = context.GetInstanceFromContext <ICookieHelper>(); IJWTHelper _JWTHelper = context.GetInstanceFromContext <IJWTHelper>(); ICryptoHelper _cryptoHelper = context.GetInstanceFromContext <ICryptoHelper>(); string cookieName = _cookieHelper.GetCookieName(); if (!_cookieHelper.isCookieDeleted(cookieName)) { string updatedToken = _JWTHelper.updateJWTToken(); string encryptedToken = _cryptoHelper.encrypt(updatedToken); _cookieHelper.UpdateCookie(encryptedToken); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { await _next.Invoke(context); } }
public void ApplyRules(IDashboardRules rules, ICookieHelper cookieHelper) { if (rules == null) { throw new ArgumentNullException(nameof(rules)); } if (cookieHelper == null) { throw new ArgumentNullException(nameof(cookieHelper)); } try { AllowNsfwContent = rules.AllowNsfwContent; if (AllowNsfwContent) { return; } IncludeNsfwContent = null; OnlyNsfwContent = null; } finally { cookieHelper.ToCookie(this); } }
public async Task Invoke(HttpContext context) { try { IHeaderDictionary headers = context.Request.Headers; ICookieHelper _cookieHelper = context.GetInstanceFromContext <ICookieHelper>(); IJWTHelper _JWTHelper = context.GetInstanceFromContext <IJWTHelper>(); ICryptoHelper _cryptoHelper = context.GetInstanceFromContext <ICryptoHelper>(); string cookie = _cookieHelper.GetCookie(_cookieHelper.GetCookieName()); // Get JWT from request header. string hdrJWT = _JWTHelper.getBearerHeaderValue(headers); // If header doesn't have a JWT but the cookie does, add the cookie's JWT to the header. if (String.IsNullOrEmpty(hdrJWT) && !String.IsNullOrEmpty(cookie)) { string decryptedJWTToken = _cryptoHelper.decrypt(cookie); _JWTHelper.setClaimsFromCookie(decryptedJWTToken); string bearerToken = string.Format("Bearer {0}", cookie); headers.SetCommaSeparatedValues("Authorization", bearerToken); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { await _next.Invoke(context); } }
public DashboardViewModelBuilder(IEnumerable <IViewModelBuilder> viewModelBuilderCollection, IHtmlHelper htmlHelper, IHttpHelper httpHelper, ICookieHelper cookieHelper) { if (viewModelBuilderCollection == null) { throw new ArgumentNullException(nameof(viewModelBuilderCollection)); } if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (httpHelper == null) { throw new ArgumentNullException(nameof(httpHelper)); } if (cookieHelper == null) { throw new ArgumentNullException(nameof(cookieHelper)); } IViewModelBuilder[] viewModelBuilderArray = viewModelBuilderCollection.ToArray(); _newsToInformationViewModelBuilder = viewModelBuilderArray.OfType <IViewModelBuilder <InformationViewModel, INews> >().Single(); _systemErrorViewModelBuilder = viewModelBuilderArray.OfType <IViewModelBuilder <SystemErrorViewModel, ISystemError> >().Single(); _dashboardSettingsViewModelBuilder = viewModelBuilderArray.OfType <IViewModelBuilder <DashboardSettingsViewModel, IDashboardSettings> >().Single(); _redditAuthenticatedUserToObjectViewModelBuilder = viewModelBuilderArray.OfType <IViewModelBuilder <ObjectViewModel <IRedditAuthenticatedUser>, IRedditAuthenticatedUser> >().Single(); _redditSubredditToObjectViewModelBuilder = viewModelBuilderArray.OfType <IViewModelBuilder <ObjectViewModel <IRedditSubreddit>, IRedditSubreddit> >().Single(); _redditLinkToInformationViewModelBuilder = viewModelBuilderArray.OfType <IViewModelBuilder <InformationViewModel, IRedditLink> >().Single(); _htmlHelper = htmlHelper; _httpHelper = httpHelper; _cookieHelper = cookieHelper; }
public SecurityService(IPrincipal principal, ApplicationDbContext context, IUserService userService, UserManager <ApplicationUser> userManager, ICookieHelper cookieHelper) { _principal = principal; _context = context; _userService = userService; _userManager = userManager; _cookieHelper = cookieHelper; }
public AuthenticateController(IWebApiCaller webApiCaller, ICookieHelper cookieHelper, IUserAgentHelper userAgentHelper, ISecurityHelper securityHelper, IConfiguration configuration) { WebApiCaller = webApiCaller; CookieHelper = cookieHelper; SecurityHelper = securityHelper; UserAgentHelper = userAgentHelper; Configuration = configuration; }
public AccountController(ICookieHelper cookieHelper, ILogger logger, IDataContextFactory dataContextFactory, IEmailService emailService) { _cookieHelper = cookieHelper; _logger = logger; _dataContextFactory = dataContextFactory; _emailService = emailService; }
public MailIdFilter(IMailId mailId, Lazy <ITrackingService> trackingService, IMarketingConnectorManager connectorManager) { _mailId = mailId; _trackingService = trackingService; _connectorManager = connectorManager; // Seems the default ICookieHelper isn't registered in the container, not sure why _cookieHelper = new CookieHelper(); }
public void ToDashboardViewModel_WhenCalled_AssertHttpContextWasCalledOnHttpContextAccessor() { ICookieHelper sut = CreateSut(); sut.ToDashboardViewModel(); _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Once); }
public OrderController(ICookieHelper cookieHelper, IAdvertisementPlanService advertisementPlanService, IGraphicDesigningPlanService graphicDesigningPlanService) { _cookieHelper = cookieHelper; _advertisementPlanService = advertisementPlanService; _graphicDesigningPlanService = graphicDesigningPlanService; }
public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_ReturnsNull() { ICookieHelper sut = CreateSut(hasHttpContext: false); DashboardViewModel result = sut.ToDashboardViewModel(); Assert.IsNull(result); }
public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_AssertToValueWasNotCalledOnContentHelperWithCookieValue() { ICookieHelper sut = CreateSut(hasHttpContext: false); sut.ToDashboardViewModel(); _contentHelperMock.Verify(m => m.ToValue(It.IsAny <string>()), Times.Never); }
public DashboardSettingsViewModelBuilder(ICookieHelper cookieHelper) { if (cookieHelper == null) { throw new ArgumentNullException(nameof(cookieHelper)); } _cookieHelper = cookieHelper; }
public void ToDashboardViewModel_WhenHttpContextWasReturnedButHttpRequestWasNotReturned_AssertToDashboardViewModelWasNotCalledOnContentHelperWithByteArray() { HttpContext httpContext = BuildHttpContext(false); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardViewModel(); _contentHelperMock.Verify(m => m.ToDashboardViewModel(It.IsAny <byte[]>()), Times.Never); }
public void ToDashboardViewModel_WhenHttpContextWasReturnedButHttpRequestWasNotReturned_ReturnsNull() { HttpContext httpContext = BuildHttpContext(false); ICookieHelper sut = CreateSut(httpContext: httpContext); DashboardViewModel result = sut.ToDashboardViewModel(); Assert.IsNull(result); }
public void ToDashboardViewModel_WhenHttpContextWasReturned_AssertRequestWasCalledOnReturnedHttpContext() { Mock <HttpContext> httpContextMock = BuildHttpContextMock(); ICookieHelper sut = CreateSut(httpContext: httpContextMock.Object); sut.ToDashboardViewModel(); httpContextMock.Verify(m => m.Request, Times.Once); }
public void ToCookie_WhenCalledWithDashboardViewModelAndDashboardViewModelWasConvertedToByteArray_AssertToBase64StringWasCalledOnContentHelperWithValueString() { ICookieHelper sut = CreateSut(); DashboardViewModel dashboardViewModel = BuildDashboardViewModel(); sut.ToCookie(dashboardViewModel); _contentHelperMock.Verify(m => m.ToBase64String(It.Is <string>(value => string.IsNullOrWhiteSpace(value) == false && _memoryCacheKeyRegex.IsMatch(value))), Times.Once); }
public void ToCookie_WhenCalledWithDashboardViewModelAndDashboardViewModelWasNotConvertedToByteArray_AssertCreateEntryWasNotCalledOnMemoryCache() { ICookieHelper sut = CreateSut(false); DashboardViewModel dashboardViewModel = BuildDashboardViewModel(); sut.ToCookie(dashboardViewModel); _memoryCacheMock.Verify(m => m.CreateEntry(It.IsAny <object>()), Times.Never); }
public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_AssertTryGetValueWasNotCalledOnMemoryCache() { ICookieHelper sut = CreateSut(hasHttpContext: false); sut.ToDashboardViewModel(); object outValue; _memoryCacheMock.Verify(m => m.TryGetValue(It.IsAny <object>(), out outValue), Times.Never); }
public void ToCookie_WhenCalledWithDashboardViewModelAndDashboardViewModelWasConvertedToByteArray_AssertCreateEntryWasCalledOnMemoryCache() { ICookieHelper sut = CreateSut(); DashboardViewModel dashboardViewModel = BuildDashboardViewModel(); sut.ToCookie(dashboardViewModel); _memoryCacheMock.Verify(m => m.CreateEntry(It.Is <object>(value => value != null && _memoryCacheKeyRegex.IsMatch((string)value))), Times.Once); }
public void ToDashboardViewModel_WhenHttpRequestWasReturnedButRequestCookieCollectionWasNotReturned_AssertToValueWasNotCalledOnContentHelperWithCookieValue() { HttpRequest httpRequest = BuildHttpRequest(hasRequestCookieCollection: false); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardViewModel(); _contentHelperMock.Verify(m => m.ToValue(It.IsAny <string>()), Times.Never); }
public void ToCookie_WhenCalledWithDashboardSettingsViewModel_AssertHttpContextWasCalledOnHttpContextAccessor() { ICookieHelper sut = CreateSut(); DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random); sut.ToCookie(dashboardSettingsViewModel); _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Exactly(2)); }
public BugController(ICookieHelper cookieHelper, IProjectLogic projectLogic, IBugLogic bugLogic, IBugStatusLogic bugStatusLogic, IUserProjectRoleRelationLogic userProjectRoleRelationLogic, IUserLogic userLogic, IBugCommentLogic bugCommentLogic) { _cookieHelper = cookieHelper; _projectLogic = projectLogic; _bugLogic = bugLogic; _bugStatusLogic = bugStatusLogic; _userProjectRoleRelationLogic = userProjectRoleRelationLogic; _userLogic = userLogic; _bugCommentLogic = bugCommentLogic; }
public void ToDashboardSettingsViewModel_WhenHttpRequestWasReturnedButRequestCookieCollectionWasNotReturned_ReturnsNull() { HttpRequest httpRequest = BuildHttpRequest(hasRequestCookieCollection: false); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(); Assert.IsNull(result); }
public void ToCookie_WhenCalledWithDashboardSettingsViewModelAndHttpContextWasNotReturned_AssertToBase64StringWasNotCalledOnContentHelperWithDashboardSettingsViewModel() { ICookieHelper sut = CreateSut(hasHttpContext: false); DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random); sut.ToCookie(dashboardSettingsViewModel); _contentHelperMock.Verify(m => m.ToBase64String(It.IsAny <DashboardSettingsViewModel>()), Times.Never); }
public void ToCookie_WhenCalledWithDashboardViewModelAndDashboardViewModelWasNotConvertedToByteArray_AssertToBase64StringWasNotCalledOnContentHelperWithValueString() { ICookieHelper sut = CreateSut(false); DashboardViewModel dashboardViewModel = BuildDashboardViewModel(); sut.ToCookie(dashboardViewModel); _contentHelperMock.Verify(m => m.ToBase64String(It.IsAny <string>()), Times.Never); }
public ProjectController( IUserLogic userLogic, IProjectLogic projectLogic, ICookieHelper cookieHelper, IUserProjectRoleRelationLogic userProjectRoleRelationLogic, IRoleLogic roleLogic ) { _userLogic = userLogic; _projectLogic = projectLogic; _cookieHelper = cookieHelper; _userProjectRoleRelationLogic = userProjectRoleRelationLogic; _roleLogic = roleLogic; }
public AccountController(IUserLogic userLogic, ICookieHelper cookieHelper) { _userLogic = userLogic; _cookieHelper = cookieHelper; }
public UploadController(IUserLogic userLogic,ICookieHelper cookieHelper) { _userLogic = userLogic; _cookieHelper = cookieHelper; }