public void NoShellsGiveNoMatch()
        {
            var table = new RunningShellTable();
            var match = table.Match("localhost", "/yadda");

            Assert.Null(match);
        }
        public void IPv6AddressesAreSupported()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "[::abc]"
            };
            var settingsB = new ShellSettings {
                Name = "Beta", RequestUrlHost = "[::1]:123"
            };

            table.Add(settings);
            table.Add(settingsA);
            table.Add(settingsB);

            Assert.Equal(settingsA, table.Match(new HostString("::abc"), "/foo/bar"));
            Assert.Equal(settingsA, table.Match(new HostString("[::abc]"), "/foo/bar"));
            Assert.Equal(settingsA, table.Match(new HostString("[::ABC]"), "/foo/bar"));
            Assert.Equal(settingsA, table.Match(new HostString("[::abc]:"), "/foo/bar"));
            Assert.Equal(settingsA, table.Match(new HostString("[::abc]:123"), "/foo/bar"));

            Assert.Equal(settingsB, table.Match(new HostString("[::1]:123"), "/foo/bar"));

            Assert.Equal(settings, table.Match(new HostString("[::1]:321"), "/foo/bar"));
            Assert.Equal(settings, table.Match(new HostString("[::1]:"), "/foo/bar"));
            Assert.Equal(settings, table.Match(new HostString("[::1]"), "/foo/bar"));
            Assert.Equal(settings, table.Match(new HostString("::1"), "/foo/bar"));
            Assert.Equal(settings, table.Match(new HostString(":"), "/foo/bar"));

            Assert.Null(table.Match(new HostString("::1"), "/foo/bar", false));
        }
Esempio n. 3
0
        public void NoShellsGiveNoMatch()
        {
            var table = new RunningShellTable();
            var match = table.Match(new StubHttpContext());

            Assert.That(match, Is.Null);
        }
Esempio n. 4
0
        public void LongestMatchingHostHasPriority()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "www.example.com"
            };
            var settingsB = new ShellSettings {
                Name = "Beta", RequestUrlHost = "*.example.com"
            };
            var settingsG = new ShellSettings {
                Name = "Gamma", RequestUrlHost = "wiki.example.com"
            };

            table.Add(settings);
            table.Add(settingsA);
            table.Add(settingsB);
            table.Add(settingsG);

            Assert.Equal(settingsA, table.Match("www.example.com", "/foo/bar"));
            Assert.Equal(settingsG, table.Match("wiki.example.com", "/foo/bar"));
            Assert.Equal(settingsB, table.Match("username.example.com", "/foo/bar"));
            Assert.Equal(settings, table.Match("localhost", "/foo/bar"));
        }
Esempio n. 5
0
        public void HostContainsSpaces()
        {
            var table         = new RunningShellTable();
            var settingsAlpha = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "   a.example.com,  b.example.com     "
            };

            table.Add(settingsAlpha);

            Assert.Equal(settingsAlpha, table.Match("a.example.com", "/foo/bar"));
            Assert.Equal(settingsAlpha, table.Match("b.example.com", "/foo/bar"));
        }
Esempio n. 6
0
        public void PathAloneWillMatch()
        {
            var table     = new RunningShellTable();
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlPrefix = "foo"
            };

            table.Add(settingsA);

            Assert.Equal(settingsA, table.Match("wiki.example.com", "/foo/bar"));
            Assert.Null(table.Match("wiki.example.com", "/bar/foo"));
        }
Esempio n. 7
0
        public void DefaultShellMatchesAllPortsByDefault()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };

            table.Add(settings);
            var match = table.Match("localhost:443", "/yadda");

            Assert.Equal(settings, match);
        }
Esempio n. 8
0
        public void PortAreIgnoredIfNotSetInSettings()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "a.example.com"
            };

            table.Add(settings);
            table.Add(settingsA);
            Assert.Equal(settingsA, table.Match("a.example.com:80", "/foo/bar"));
            Assert.Equal(settings, table.Match("foo.com:80", "/foo/bar"));
        }
Esempio n. 9
0
        public void PathAlsoCausesMatch()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlPrefix = "foo"
            };

            table.Add(settings);
            table.Add(settingsA);
            var match = table.Match("a.example.com", "/foo/bar");

            Assert.Equal(settingsA, match);
        }
Esempio n. 10
0
        public void NonDefaultCatchallWillFallbackIfNothingElseMatches()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName, RequestUrlHost = "www.example.com"
            };
            var settingsA = new ShellSettings {
                Name = "Alpha"
            };

            table.Add(settings);
            table.Add(settingsA);
            var match = table.Match("b.example.com", "/foo/bar");

            Assert.Equal(settingsA, match);
        }
Esempio n. 11
0
        public void DefaultWontFallbackIfItHasCriteria()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName, RequestUrlHost = "www.example.com"
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "a.example.com"
            };

            table.Add(settings);
            table.Add(settingsA);
            var match = table.Match("b.example.com", "/foo/bar");

            Assert.Null(match);
        }
Esempio n. 12
0
        public void AnotherShellMatchesByHostHeader()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "a.example.com"
            };

            table.Add(settings);
            table.Add(settingsA);
            var match = table.Match("a.example.com", "/foo/bar");

            Assert.Equal(settingsA, match);
        }
Esempio n. 13
0
        public void DefaultStillCatchesWhenOtherShellsMiss()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "a.example.com"
            };

            table.Add(settings);
            table.Add(settingsA);
            var match = table.Match("b.example.com", "/foo/bar");

            Assert.Equal(settings, match);
        }
Esempio n. 14
0
        public void ShouldNotFallBackToDefault()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "a.example.com"
            };

            table.Add(settings);
            table.Add(settingsA);
            Assert.Equal(settingsA, table.Match("a.example.com", "/foo/bar"));
            Assert.Equal(settings, table.Match("foo.com", "/foo/bar"));
            Assert.Null(table.Match("foo.com", "/foo/bar", false));
        }
Esempio n. 15
0
        public void DefaultWillCatchRequestsIfItMatchesCriteria()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName, RequestUrlHost = "www.example.com"
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "a.example.com"
            };

            table.Add(settings);
            table.Add(settingsA);
            var match = table.Match("www.example.com", "/foo/bar");

            Assert.Equal(settings, match);
        }
Esempio n. 16
0
        public void HostNameMatchesRightmostIfStar()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "*.example.com"
            };

            table.Add(settings);
            table.Add(settingsA);
            Assert.Equal(settingsA, table.Match("www.example.com", "/foo/bar"));
            Assert.Equal(settingsA, table.Match("wiki.example.com", "/foo/bar"));
            Assert.Equal(settingsA, table.Match("example.com", "/foo/bar"));
            Assert.Equal(settings, table.Match("localhost", "/foo/bar"));
        }
Esempio n. 17
0
        public void MultipleHostsOnShellAreAdded()
        {
            var table         = new RunningShellTable();
            var settingsAlpha = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "a.example.com,b.example.com"
            };
            var settingsBeta = new ShellSettings {
                Name = "Beta", RequestUrlHost = "c.example.com,d.example.com,e.example.com"
            };

            table.Add(settingsAlpha);
            table.Add(settingsBeta);

            Assert.Equal(settingsAlpha, table.Match("a.example.com", "/foo/bar"));
            Assert.Equal(settingsAlpha, table.Match("b.example.com", "/foo/bar"));
            Assert.Equal(settingsBeta, table.Match("c.example.com", "/foo/bar"));
            Assert.Equal(settingsBeta, table.Match("d.example.com", "/foo/bar"));
            Assert.Equal(settingsBeta, table.Match("e.example.com", "/foo/bar"));
        }
Esempio n. 18
0
        public void PathAndHostMustBothMatch()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName, RequestUrlHost = "www.example.com",
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "wiki.example.com", RequestUrlPrefix = "foo"
            };
            var settingsB = new ShellSettings {
                Name = "Beta", RequestUrlHost = "wiki.example.com", RequestUrlPrefix = "bar"
            };
            var settingsG = new ShellSettings {
                Name = "Gamma", RequestUrlHost = "wiki.example.com"
            };
            var settingsD = new ShellSettings {
                Name = "Delta", RequestUrlPrefix = "Quux"
            };

            table.Add(settings);
            table.Add(settingsA);
            table.Add(settingsB);
            table.Add(settingsG);
            table.Add(settingsD);

            Assert.Equal(settingsA, table.Match("wiki.example.com", "/foo/bar"));
            Assert.Equal(settingsB, table.Match("wiki.example.com", "/bar/foo"));
            Assert.Equal(settingsG, table.Match("wiki.example.com", "/"));
            Assert.Equal(settingsG, table.Match("wiki.example.com", "/baaz"));
            Assert.Equal(settings, table.Match("www.example.com", "/foo/bar"));
            Assert.Equal(settings, table.Match("www.example.com", "/bar/foo"));
            Assert.Equal(settings, table.Match("www.example.com", "/baaz"));
            Assert.Null(table.Match("a.example.com", "/foo/bar"));

            Assert.Equal(settingsG, table.Match("wiki.example.com", "/quux/quad"));
            Assert.Equal(settings, table.Match("www.example.com", "/quux/quad"));
            Assert.Equal(settingsD, table.Match("a.example.com", "/quux/quad"));
            Assert.Equal(settingsG, table.Match("wiki.example.com", "/yarg"));
            Assert.Equal(settings, table.Match("www.example.com", "/yarg"));
            Assert.Null(table.Match("a.example.com", "/yarg"));
        }
Esempio n. 19
0
        public void PortAreNotIgnoredIfSetInSettings()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "a.example.com:80"
            };
            var settingsB = new ShellSettings {
                Name = "Beta", RequestUrlHost = "a.example.com:8080"
            };

            table.Add(settings);
            table.Add(settingsA);
            table.Add(settingsB);
            Assert.Equal(settingsA, table.Match("a.example.com:80", "/foo/bar"));
            Assert.Equal(settingsB, table.Match("a.example.com:8080", "/foo/bar"));
            Assert.Equal(settings, table.Match("a.example.com:123", "/foo/bar"));
            Assert.Null(table.Match("a.example.com:123", "/foo/bar", false));
        }
Esempio n. 20
0
        public void PathAndHostMustMatchOnFullUrl()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName, RequestUrlHost = "www.example.com",
            };
            var settingsB = new ShellSettings {
                Name = "Beta", RequestUrlHost = "wiki.example.com", RequestUrlPrefix = "bar"
            };
            var settingsG = new ShellSettings {
                Name = "Gamma", RequestUrlHost = "wiki.example.com"
            };

            table.Add(settings);
            table.Add(settingsB);
            table.Add(settingsG);

            Assert.Equal(settingsB, table.Match("wiki.example.com", "/bar/foo"));
            Assert.Equal(settingsG, table.Match("wiki.example.com", "/"));
            Assert.Equal(settingsG, table.Match("wiki.example.com", "/baaz"));
            Assert.Equal(settingsG, table.Match("wiki.example.com", "/barbaz"));
        }
Esempio n. 21
0
        public void ShellNameUsedToDistinctThingsAsTheyAreAdded()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "removed.example.com"
            };
            var settingsB = new ShellSettings {
                Name = "Alpha", RequestUrlHost = "added.example.com"
            };

            table.Add(settings);
            table.Add(settingsA);
            table.Remove(settingsA);
            table.Add(settingsB);

            Assert.Equal(settings, table.Match("removed.example.com", "/foo/bar"));
            Assert.Equal(settingsB, table.Match("added.example.com", "/foo/bar"));
            Assert.Equal(settings, table.Match("localhost", "/foo/bar"));
        }
Esempio n. 22
0
        public void DefaultCatchallIsFallbackEvenWhenOthersAreUnqualified()
        {
            var table    = new RunningShellTable();
            var settings = new ShellSettings {
                Name = ShellHelper.DefaultShellName
            };
            var settingsA = new ShellSettings {
                Name = "Alpha"
            };
            var settingsB = new ShellSettings {
                Name = "Beta", RequestUrlHost = "b.example.com"
            };
            var settingsG = new ShellSettings {
                Name = "Gamma"
            };

            table.Add(settings);
            table.Add(settingsA);
            table.Add(settingsB);
            table.Add(settingsG);
            var match = table.Match("a.example.com", "/foo/bar");

            Assert.Equal(settings, match);
        }