예제 #1
0
        public void ShouldWork()
        {
            IAclProvider categories = new MemoryProvider();
            IAclProvider widgets    = new MemoryProvider();
            IAclProvider urls       = new MemoryProvider();

            widgets.SetAcls(
                new Deny("/", "read", "*"),
                new Allow("/", "read", "g1")
                );
            urls.SetAcls(
                new Allow("/c", "read", "g2"),
                new Deny("/c", "read", "g3"),
                new Allow("/d", "read", "g3"),
                new Deny("/d", "read", "*"),
                new Deny("/", "read", "g2")
                );

            RouterProvider router = new RouterProvider();

            router.Register("/a", widgets);
            router.Register("/a/b", urls);
            AclManager.DefaultProvider = router;

            Assert.AreEqual(5, router.GetAcls("/a/b/c", "read").Count());
            Assert.AreEqual(5, router.GetAcls("/a/b/d", "read").Count());

            Assert.IsTrue(AclManager.IsAllowed("/a/b/c", "read", "g1", "g2"));
            Assert.IsFalse(AclManager.IsAllowed("/a/b/c", "read", "g1", "g3"));
            Assert.IsTrue(AclManager.IsAllowed("/a/b/d", "read", "g3"));

            Assert.IsTrue(AclManager.IsAllowed("/a/b/d", "read", "g1", "g3"));
            Assert.IsFalse(AclManager.IsAllowed("/a/b/d", "read", "g1", "g2"));
            Assert.IsFalse(AclManager.IsAllowed("/a/b/c", "read", "g3"));
        }