public void HandleSameSiteCookieCompatibility_CustomFilter_ExecutesSuccessfully(SameSiteMode initialSameSiteMode, SameSiteMode expectedSameSiteMode, bool expectedEventCalled, string userAgent)
        {
            _httpContext.Request.Headers.Add(Constants.UserAgent, userAgent);
            var appendCookieOptions = new CookieOptions()
            {
                SameSite = initialSameSiteMode
            };
            var deleteCookieOptions = new CookieOptions()
            {
                SameSite = initialSameSiteMode
            };
            var appendCookieContext = new AppendCookieContext(_httpContext, appendCookieOptions, _cookieName, _cookieValue);
            var deleteCookieContext = new DeleteCookieContext(_httpContext, deleteCookieOptions, _cookieName);
            var appendEventCalled   = false;
            var deleteEventCalled   = false;

            _cookiePolicyOptions.HandleSameSiteCookieCompatibility((userAgent) =>
            {
                appendEventCalled = true;
                return(CookiePolicyOptionsExtensions.DisallowsSameSiteNone(userAgent));
            });

            Assert.Equal(SameSiteMode.Unspecified, _cookiePolicyOptions.MinimumSameSitePolicy);

            _cookiePolicyOptions.OnAppendCookie(appendCookieContext);
            Assert.Equal(expectedSameSiteMode, appendCookieOptions.SameSite);
            Assert.Equal(expectedEventCalled, appendEventCalled);

            _cookiePolicyOptions.HandleSameSiteCookieCompatibility((userAgent) =>
            {
                deleteEventCalled = true;
                return(CookiePolicyOptionsExtensions.DisallowsSameSiteNone(userAgent));
            });

            _cookiePolicyOptions.OnDeleteCookie(deleteCookieContext);
            Assert.Equal(expectedSameSiteMode, deleteCookieOptions.SameSite);
            Assert.Equal(expectedEventCalled, deleteEventCalled);
        }
Пример #2
0
        public void DisallowsSameSiteNone_VariousUserAgents_ExecutesSuccessfully(bool expectedResult, string userAgent)
        {
            var actualResult = CookiePolicyOptionsExtensions.DisallowsSameSiteNone(userAgent);

            Assert.Equal(expectedResult, actualResult);
        }