Exemple #1
0
        public void TestInfixEmptyMatcher_ignoreCase()
        {
            var matcher = WildcardMatcher.ValueOf("**");

            matcher.Matches("").Should().BeTrue();
            matcher.Matches("foo").Should().BeTrue();
        }
Exemple #2
0
        public void SimpleTestCaseSensitive()
        {
            var matcher = WildcardMatcher.ValueOf("(?-i)Foo");

            matcher.Matches("Foo").Should().BeTrue();
            matcher.Matches("foo").Should().BeFalse();
        }
Exemple #3
0
        public void TestMatchesInfix_caseSensitive()
        {
            var matcher = WildcardMatcher.ValueOf("(?-i)*foo*");

            matcher.Matches("foo").Should().BeTrue();
            matcher.Matches("FOO").Should().BeFalse();
        }
Exemple #4
0
        public void TestMatchesEquals()
        {
            var matcher = WildcardMatcher.ValueOf("foo");

            matcher.Matches("foo").Should().BeTrue();
            matcher.Matches("foobar").Should().BeFalse();
            matcher.Matches("bar").Should().BeFalse();
            matcher.Matches("barfoo").Should().BeFalse();
        }
Exemple #5
0
        public void TestMatchesStartsWith_ignoreCase()
        {
            var matcher = WildcardMatcher.ValueOf("foo*");

            matcher.Matches("foo").Should().BeTrue();
            matcher.Matches("foobar").Should().BeTrue();
            matcher.Matches("bar").Should().BeFalse();
            matcher.Matches("barfoo").Should().BeFalse();
        }
Exemple #6
0
        public void TestMatchesNoWildcard_ignoreCase()
        {
            var matcher = WildcardMatcher.ValueOf("foo");

            matcher.Matches("FO", "O").Should().BeTrue();
            matcher.Matches("FOO").Should().BeTrue();
            matcher.Matches("foO", "Bar").Should().BeFalse();
            matcher.Matches("foobar").Should().BeFalse();
        }
Exemple #7
0
        public void TestMatchesEndsWith_ignoreCase()
        {
            var matcher = WildcardMatcher.ValueOf("*foo");

            matcher.Matches("fOo").Should().BeTrue();
            matcher.Matches("foobar").Should().BeFalse();
            matcher.Matches("bar").Should().BeFalse();
            matcher.Matches("baRFoo").Should().BeTrue();
        }
Exemple #8
0
        public void TestMatchesEquals_ignoreCase()
        {
            var matcher = WildcardMatcher.ValueOf("foo");

            matcher.Matches("fOo").Should().BeTrue();
            matcher.Matches("foOBar").Should().BeFalse();
            matcher.Matches("BAR").Should().BeFalse();
            matcher.Matches("barfoo").Should().BeFalse();
        }
Exemple #9
0
        public void TestMatchesInfix_ignoreCase()
        {
            var matcher = WildcardMatcher.ValueOf("*foo*");

            matcher.Matches("FOO").Should().BeTrue();
            matcher.Matches("foOBar").Should().BeTrue();
            matcher.Matches("BAR").Should().BeFalse();
            matcher.Matches("baRFOo").Should().BeTrue();
            matcher.Matches("BARFOOBAZ").Should().BeTrue();
        }
Exemple #10
0
        public void TestMatchesInfixPartitionedString_allocationFree()
        {
            var matcher = WildcardMatcher.ValueOf("*foo*");

            // no allocations necessary
            matcher.Matches("foo", "bar").Should().BeTrue();
            matcher.Matches("bar", "foo").Should().BeTrue();
            matcher.Matches("barfoo", "baz").Should().BeTrue();
            matcher.Matches("ba", "rfoo").Should().BeTrue();
        }
Exemple #11
0
        public void TestCompoundWildcardMatcher()
        {
            var matcher = WildcardMatcher.ValueOf("*foo*foo*");

            matcher.Matches("foofoo").Should().BeTrue();
            matcher.Matches("foo/bar/foo").Should().BeTrue();
            matcher.Matches("/foo/bar/foo/bar").Should().BeTrue();

            matcher.Matches("foo").Should().BeFalse();
        }
Exemple #12
0
        public void TestMatchesNoWildcard()
        {
            var matcher = WildcardMatcher.ValueOf("foo");

            // requires concatenating the string
            matcher.Matches("fo", "o").Should().BeTrue();
            matcher.Matches("foo").Should().BeTrue();
            matcher.Matches("foo", "bar").Should().BeFalse();
            matcher.Matches("foobar").Should().BeFalse();
        }
Exemple #13
0
        public void TestMatchesInfixPartitionedString_notAllocationFree()
        {
            var matcher = WildcardMatcher.ValueOf("*foo*");

            // requires concatenating the string
            matcher.Matches("fo", "o").Should().BeTrue();
            matcher.Matches("fo", null).Should().BeFalse();
            matcher.Matches("barfo", "obaz").Should().BeTrue();
            matcher.Matches("bar", "baz").Should().BeFalse();
        }
Exemple #14
0
        public void TestMatchesPartitionedStringEndsWith()
        {
            var matcher = WildcardMatcher.ValueOf("*/bar/baz");

            matcher.Matches("/foo/bar/baz", "").Should().BeTrue();
            matcher.Matches("", "/foo/bar/baz").Should().BeTrue();
            matcher.Matches("/foo/bar", "/baz").Should().BeTrue();
            matcher.Matches("/foo", "/bar/baz").Should().BeTrue();
            matcher.Matches("/foo", "/bar/baz").Should().BeTrue();
            matcher.Matches("/bar", "/foo/baz").Should().BeFalse();
            matcher.Matches("/foo", "/foo/baz").Should().BeFalse();
        }
Exemple #15
0
        public void TestMatchesPartitionedStringEndsWith_ignoreCase()
        {
            var matcher = WildcardMatcher.ValueOf("*/bar/baz");

            matcher.Matches("/foO/BAR/Baz", "").Should().BeTrue();
            matcher.Matches("", "/foO/Bar/baz").Should().BeTrue();
            matcher.Matches("/FOo/bar", "/baz").Should().BeTrue();
            matcher.Matches("/foo", "/bar/BAZ").Should().BeTrue();
            matcher.Matches("/fOo", "/bAR/baz").Should().BeTrue();
            matcher.Matches("/bar", "/foO/baz").Should().BeFalse();
            matcher.Matches("/FOo", "/foo/baz").Should().BeFalse();
        }
Exemple #16
0
        public void TestWildcardInTheMiddle()
        {
            var matcher = WildcardMatcher.ValueOf("/foo/*/baz");

            matcher.Matches("/foo/*/baz").Should().BeTrue();
            matcher.Matches("/foo/bar/baz").Should().BeTrue();
            matcher.Matches("/foo/bar", "/baz").Should().BeTrue();
            matcher.Matches("/foo/bar/b", "az").Should().BeTrue();

            matcher.Matches("/foo/bar", "/boaz").Should().BeFalse();
            matcher.Matches("/foo/bar").Should().BeFalse();
        }
Exemple #17
0
 public void TestNeedleLongerThanHaystack()
 {
     WildcardMatcher.ValueOf("*foo").Matches("baz").Should().BeFalse();
     WildcardMatcher.ValueOf("*foob").Matches("baz").Should().BeFalse();
     WildcardMatcher.ValueOf("*fooba").Matches("baz").Should().BeFalse();
     WildcardMatcher.ValueOf("*foobar").Matches("baz").Should().BeFalse();
     WildcardMatcher.ValueOf("foo*").Matches("baz").Should().BeFalse();
     WildcardMatcher.ValueOf("foob*").Matches("baz").Should().BeFalse();
     WildcardMatcher.ValueOf("fooba*").Matches("baz").Should().BeFalse();
     WildcardMatcher.ValueOf("foobar*").Matches("baz").Should().BeFalse();
     WildcardMatcher.ValueOf("*foobar*").Matches("baz").Should().BeFalse();
 }
Exemple #18
0
        public void TestMatchesInfixPartitionedString_ignoreCase()
        {
            var matcher = WildcardMatcher.ValueOf("*foo*");

            // no allocations necessary
            matcher.Matches("foo", "BAR").Should().BeTrue();
            matcher.Matches("BAR", "foo").Should().BeTrue();
            matcher.Matches("baRFoo", "baz").Should().BeTrue();
            matcher.Matches("bA", "Rfoo").Should().BeTrue();
            matcher.Matches("fo", "O").Should().BeTrue();
            matcher.Matches("barFO", "obaz").Should().BeTrue();
            matcher.Matches("bar", "baz").Should().BeFalse();
        }
Exemple #19
0
        public void TestMatchBetween()
        {
            var matcher = WildcardMatcher.ValueOf("*foo*foo*");

            matcher.Matches("foofoo").Should().BeTrue();
            matcher.Matches("foofo", "o").Should().BeTrue();
            matcher.Matches("foof", "oo").Should().BeTrue();
            matcher.Matches("foo", "foo").Should().BeTrue();
            matcher.Matches("fo", "ofoo").Should().BeTrue();
            matcher.Matches("f", "oofoo").Should().BeTrue();
            matcher.Matches("foo/foo/foo/baz").Should().BeTrue();
            matcher.Matches("/foo/foo/baz").Should().BeTrue();
            matcher.Matches("/foo/foo").Should().BeTrue();

            matcher.Matches("foobar").Should().BeFalse();
        }
Exemple #20
0
            static DefaultValues()
            {
                SanitizeFieldNames = new List <WildcardMatcher>();
                foreach (var item in new List <string>
                {
                    "password",
                    "passwd",
                    "pwd",
                    "secret",
                    "*key",
                    "*token*",
                    "*session*",
                    "*credit*",
                    "*card*",
                    "authorization",
                    "set-cookie"
                })
                {
                    SanitizeFieldNames.Add(WildcardMatcher.ValueOf(item));
                }

                TransactionIgnoreUrls = new List <WildcardMatcher>();

                foreach (var item in new List <string>
                {
                    "/VAADIN/*",
                    "/heartbeat*",
                    "/favicon.ico",
                    "*.js",
                    "*.css",
                    "*.jpg",
                    "*.jpeg",
                    "*.png",
                    "*.gif",
                    "*.webp",
                    "*.svg",
                    "*.woff",
                    "*.woff2"
                })
                {
                    TransactionIgnoreUrls.Add(WildcardMatcher.ValueOf(item));
                }
            }
Exemple #21
0
 static DefaultValues()
 {
     SanitizeFieldNames = new List <WildcardMatcher>();
     foreach (var item in new List <string>
     {
         "password",
         "passwd",
         "pwd",
         "secret",
         "*key",
         "*token*",
         "*session*",
         "*credit*",
         "*card*",
         "authorization",
         "set-cookie"
     })
     {
         SanitizeFieldNames.Add(WildcardMatcher.ValueOf(item));
     }
 }
Exemple #22
0
        public void TestMatchAnyStartsWith()
        {
            var matcher1 = WildcardMatcher.ValueOf("foo*");
            var matcher2 = WildcardMatcher.ValueOf("bar*");

            WildcardMatcher.AnyMatch(new List <WildcardMatcher> {
                matcher1, matcher2
            }, "foo").Should().Be(matcher1);
            WildcardMatcher.AnyMatch(new List <WildcardMatcher> {
                matcher1, matcher2
            }, "bar").Should().Be(matcher2);
            WildcardMatcher.AnyMatch(new List <WildcardMatcher> {
                matcher1, matcher2
            }, "baz").Should().BeNull();
            WildcardMatcher.AnyMatch(new List <WildcardMatcher> {
                matcher1, matcher2
            }, "fo", "o").Should().Be(matcher1);
            WildcardMatcher.AnyMatch(new List <WildcardMatcher> {
                matcher1, matcher2
            }, "ba", "r").Should().Be(matcher2);
            WildcardMatcher.AnyMatch(new List <WildcardMatcher> {
                matcher1, matcher2
            }, "ba", "z").Should().BeNull();
        }
Exemple #23
0
 public void TestComplexExpressions()
 {
     WildcardMatcher.ValueOf("/foo/*/baz*").Matches("/foo/a/bar/b/baz").Should().BeTrue();
     WildcardMatcher.ValueOf("/foo/*/bar/*/baz").Matches("/foo/a/bar/b/baz").Should().BeTrue();
 }