Ejemplo n.º 1
0
        public void FilterCookieDomains()
        {
            var validDomains = new[] {
                // 1st level
                "localhost",
                // 2nd level
                "google.com",
                // 3rd level wildcard subdomains
                ".google.com",
                // 3rd level
                "maps.google.com",
                ".maps.google.com",
            };

            foreach (string validDomain in validDomains)
            {
                Assert.IsNotNull(CookieFilters.FilterDomain(validDomain), $"Domain \"{validDomain}\" filtered bad but should be good");
            }

            // Normalized Wildcard Domains
            //
            // 1st level with wildcard will be normalized to
            var normalizedDomains = new Dictionary <string, string> {
                { "  .localhost", "localhost" }
            };

            foreach (var normalizedDomain in normalizedDomains)
            {
                string filteredNormalizedDomain = CookieFilters.FilterDomain(normalizedDomain.Key);
                Assert.AreEqual(normalizedDomain.Value, filteredNormalizedDomain, "Invalid first level cookie domain normalization");
            }

            // Invalid Domains
            //
            var invalidDomains = new[] {
                "    ",
                null,
                "\r\n\t\t",
                "\n\n "
            };

            foreach (string invalidDomain in invalidDomains)
            {
                Assert.IsNull(CookieFilters.FilterDomain(invalidDomain), $"Domain \"{invalidDomain}\" filtered good but it should be bad");
            }
        }
Ejemplo n.º 2
0
        public void FilterCookieDomains()
        {
            var validDomains = new[] {
                // 1st level
                "localhost",
                // 2nd level
                "google.com",
                // 3rd level wildcard subdomains
                ".google.com",
                // 3rd level
                "maps.google.com",
                ".maps.google.com",
            };

            foreach (string validDomain in validDomains)
            {
                Assert.NotNull(CookieFilters.FilterDomain(validDomain));
            }

            // Normalized Wildcard Domains
            //
            // 1st level with wildcard will be normalized to
            var normalizedDomains = new Dictionary <string, string> {
                { "  .localhost", "localhost" }
            };

            foreach (var normalizedDomain in normalizedDomains)
            {
                string filteredNormalizedDomain = CookieFilters.FilterDomain(normalizedDomain.Key);
                Assert.Equal(normalizedDomain.Value, filteredNormalizedDomain);
            }

            // Invalid Domains
            //
            var invalidDomains = new[] {
                "    ",
                null,
                "\r\n\t\t",
                "\n\n "
            };

            foreach (string invalidDomain in invalidDomains)
            {
                Assert.Null(CookieFilters.FilterDomain(invalidDomain));
            }
        }
Ejemplo n.º 3
0
        public void FilterCookies()
        {
            var list = new Dictionary <string, string> {
                {
                    "MS_LOGIN_COOKIE_10151=-1,R,L,null,; Expires=Sun, 30-Dec-18 16:57:13 GMT; Path=/RemovedPath",
                    "MS_LOGIN_COOKIE_10151=-1,R,L,null%2C; Expires=Sun, 30-Dec-18 16:57:13 GMT; Path=/"
                },
                {
                    "MS_LOGIN_COOKIE_10151=-1,R,L,null,; Expires=Sun, 30-Dec-18 16:57:13 GMT; Path=/",
                    "MS_LOGIN_COOKIE_10151=-1,R,L,null%2C; Expires=Sun, 30-Dec-18 16:57:13 GMT; Path=/"
                }
            };

            foreach (var item in list)
            {
                Assert.AreEqual(CookieFilters.Filter(item.Key), item.Value);
            }
        }