コード例 #1
0
        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);
        }
コード例 #2
0
 public OrdersController(IWebApiCaller webApiCaller, ICookieHelper cookieHelper, ISecurityHelper securityHelper)
 {
     WebApiCaller   = webApiCaller;
     CookieHelper   = cookieHelper;
     SecurityHelper = securityHelper;
     CurrentUser    = SecurityHelper.GetSessionUser(CookieHelper.GetCookie <string>("CurrentUser"));
 }
コード例 #3
0
ファイル: UserController.cs プロジェクト: jason0100/Temple
        /// <summary>
        /// 讀取組態用
        /// </summary>

        public UserController(IConfiguration config, ICallApi callApi, IHttpContextAccessor httpContextAccessor, ICookieHelper cookieHelper)
        {
            _config              = config;
            _callApi             = callApi;
            _httpContextAccessor = httpContextAccessor;
            _cookieHelper        = cookieHelper;
        }
コード例 #4
0
        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;
        }
コード例 #5
0
 public ApiController(IConfiguration configuration, ICookieHelper cookieHelper, IJWTHelper JWTHelper, ICryptoHelper cryptoHelper)
 {
     _configuration = configuration;
     _cookieHelper  = cookieHelper;
     _JWTHelper     = JWTHelper;
     _cryptoHelper  = cryptoHelper;
 }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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;
        }
コード例 #10
0
 public SecurityService(IPrincipal principal, ApplicationDbContext context, IUserService userService, UserManager <ApplicationUser> userManager, ICookieHelper cookieHelper)
 {
     _principal    = principal;
     _context      = context;
     _userService  = userService;
     _userManager  = userManager;
     _cookieHelper = cookieHelper;
 }
コード例 #11
0
 public AuthenticateController(IWebApiCaller webApiCaller, ICookieHelper cookieHelper, IUserAgentHelper userAgentHelper, ISecurityHelper securityHelper, IConfiguration configuration)
 {
     WebApiCaller    = webApiCaller;
     CookieHelper    = cookieHelper;
     SecurityHelper  = securityHelper;
     UserAgentHelper = userAgentHelper;
     Configuration   = configuration;
 }
コード例 #12
0
 public AccountController(ICookieHelper cookieHelper, ILogger logger,
                          IDataContextFactory dataContextFactory, IEmailService emailService)
 {
     _cookieHelper       = cookieHelper;
     _logger             = logger;
     _dataContextFactory = dataContextFactory;
     _emailService       = emailService;
 }
コード例 #13
0
 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();
 }
コード例 #14
0
 public AccountController(ICookieHelper cookieHelper, ILogger logger, 
     IDataContextFactory dataContextFactory, IEmailService emailService)
 {
     _cookieHelper = cookieHelper;
     _logger = logger;
     _dataContextFactory = dataContextFactory;
     _emailService = emailService;
 }
コード例 #15
0
        public void ToDashboardViewModel_WhenCalled_AssertHttpContextWasCalledOnHttpContextAccessor()
        {
            ICookieHelper sut = CreateSut();

            sut.ToDashboardViewModel();

            _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Once);
        }
コード例 #16
0
 public OrderController(ICookieHelper cookieHelper,
                        IAdvertisementPlanService advertisementPlanService,
                        IGraphicDesigningPlanService graphicDesigningPlanService)
 {
     _cookieHelper                = cookieHelper;
     _advertisementPlanService    = advertisementPlanService;
     _graphicDesigningPlanService = graphicDesigningPlanService;
 }
コード例 #17
0
        public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_ReturnsNull()
        {
            ICookieHelper sut = CreateSut(hasHttpContext: false);

            DashboardViewModel result = sut.ToDashboardViewModel();

            Assert.IsNull(result);
        }
コード例 #18
0
        public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_AssertToValueWasNotCalledOnContentHelperWithCookieValue()
        {
            ICookieHelper sut = CreateSut(hasHttpContext: false);

            sut.ToDashboardViewModel();

            _contentHelperMock.Verify(m => m.ToValue(It.IsAny <string>()), Times.Never);
        }
コード例 #19
0
        public DashboardSettingsViewModelBuilder(ICookieHelper cookieHelper)
        {
            if (cookieHelper == null)
            {
                throw new ArgumentNullException(nameof(cookieHelper));
            }

            _cookieHelper = cookieHelper;
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        public void ToDashboardViewModel_WhenHttpContextWasReturnedButHttpRequestWasNotReturned_ReturnsNull()
        {
            HttpContext   httpContext = BuildHttpContext(false);
            ICookieHelper sut         = CreateSut(httpContext: httpContext);

            DashboardViewModel result = sut.ToDashboardViewModel();

            Assert.IsNull(result);
        }
コード例 #22
0
        public void ToDashboardViewModel_WhenHttpContextWasReturned_AssertRequestWasCalledOnReturnedHttpContext()
        {
            Mock <HttpContext> httpContextMock = BuildHttpContextMock();
            ICookieHelper      sut             = CreateSut(httpContext: httpContextMock.Object);

            sut.ToDashboardViewModel();

            httpContextMock.Verify(m => m.Request, Times.Once);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        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);
        }
コード例 #28
0
        public void ToCookie_WhenCalledWithDashboardSettingsViewModel_AssertHttpContextWasCalledOnHttpContextAccessor()
        {
            ICookieHelper sut = CreateSut();

            DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random);

            sut.ToCookie(dashboardSettingsViewModel);

            _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Exactly(2));
        }
コード例 #29
0
ファイル: BugController.cs プロジェクト: pear171902790/Bug
 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;
 }
コード例 #30
0
        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);
        }
コード例 #31
0
        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);
        }
コード例 #32
0
        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);
        }
コード例 #33
0
 public ProjectController(
         IUserLogic userLogic,
         IProjectLogic projectLogic, 
         ICookieHelper cookieHelper,
         IUserProjectRoleRelationLogic userProjectRoleRelationLogic,
         IRoleLogic roleLogic
     )
 {
     _userLogic = userLogic;
     _projectLogic = projectLogic;
     _cookieHelper = cookieHelper;
     _userProjectRoleRelationLogic = userProjectRoleRelationLogic;
     _roleLogic = roleLogic;
 }
コード例 #34
0
 public AccountController(IUserLogic userLogic, ICookieHelper cookieHelper)
 {
     _userLogic = userLogic;
     _cookieHelper = cookieHelper;
 }
コード例 #35
0
ファイル: UploadController.cs プロジェクト: pear171902790/Bug
 public UploadController(IUserLogic userLogic,ICookieHelper cookieHelper)
 {
     _userLogic = userLogic;
     _cookieHelper = cookieHelper;
 }