public CreateRoleStatementTests()
        {
            var container = new ServiceContainer();

            var securityManager = new Mock <IRoleManager>();

            securityManager.Setup(x =>
                                  x.CreateRoleAsync(It.IsNotNull <string>()))
            .Callback <string>(x => createdRole = x)
            .Returns <string>(x => Task.FromResult(true));
            securityManager.Setup(x => x.GetUserRolesAsync(It.Is <string>(u => u == "user2")))
            .Returns <string>(x => Task.FromResult <IEnumerable <Role> >(new[] { new Role("admin_group") }));

            container.RegisterInstance <IRoleManager>(securityManager.Object);

            var cache = new PrivilegesCache(null);

            cache.SetSystemPrivileges("admin_group", SqlPrivileges.Admin);

            container.RegisterInstance <IAccessController>(cache);

            var systemContext = new Mock <IContext>();

            systemContext.SetupGet(x => x.Scope)
            .Returns(container);

            adminContext           = MockedSession.Create(systemContext.Object, User.System);
            userContext            = MockedSession.Create(systemContext.Object, new User("user1"));
            userInAdminRoleContext = MockedSession.Create(systemContext.Object, new User("user2"));
        }
Пример #2
0
        public GrantObjectPrivilegesStatementTests()
        {
            var container = new ServiceContainer();

            var userManager = new Mock <IUserManager>();

            userManager.Setup(x => x.UserExistsAsync(It.IsNotNull <string>()))
            .Returns <string>(x => Task.FromResult(true));

            var grantManager = new Mock <IGrantManager>();

            grantManager.Setup(x => x.GrantToUserAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsNotNull <ObjectName>(),
                                                       It.IsAny <Privilege>(), It.IsAny <bool>()))
            .Callback <string, string, ObjectName, Privilege, bool>((granter, grantee, obj, priv, option) =>
                                                                    grant = new Grant(granter, grantee, obj, priv, option))
            .Returns <string, string, ObjectName, Privilege, bool>((a, b, c, d, e) => Task.FromResult(true));


            var securityManager = new Mock <IRoleManager>();

            securityManager.Setup(x => x.GetUserRolesAsync(It.Is <string>(u => u == "user2")))
            .Returns <string>(x => Task.FromResult <IEnumerable <Role> >(new[] { new Role("admin_group") }));

            container.RegisterInstance <IRoleManager>(securityManager.Object);
            container.RegisterInstance <IUserManager>(userManager.Object);
            container.RegisterInstance <IGrantManager>(grantManager.Object);

            var cache = new PrivilegesCache(null);

            cache.SetSystemPrivileges("admin_group", SqlPrivileges.Admin);

            container.RegisterInstance <IAccessController>(cache);

            var objManager = new Mock <IDbObjectManager>();

            objManager.Setup(x => x.ObjectExistsAsync(It.IsNotNull <ObjectName>()))
            .Returns <ObjectName>(x => Task.FromResult(true));

            container.RegisterInstance <IDbObjectManager>(objManager.Object);

            var systemContext = new Mock <IContext>();

            systemContext.SetupGet(x => x.Scope)
            .Returns(container);

            adminContext           = MockedSession.Create(systemContext.Object, User.System);
            userContext            = MockedSession.Create(systemContext.Object, new User("user1"));
            userInAdminRoleContext = MockedSession.Create(systemContext.Object, new User("user2"));
        }
        public SetAccountStatusTests()
        {
            var container = new ServiceContainer();

            var userManager = new Mock <IUserManager>();

            userManager.Setup(x => x.GetUserStatusAsync(It.IsAny <string>()))
            .Returns <string>(x => Task.FromResult(UserStatus.Unlocked));
            userManager.Setup(x => x.UserExistsAsync(It.IsNotNull <string>()))
            .Returns(Task.FromResult(true));
            userManager.Setup(x => x.SetUserStatusAsync(It.IsNotNull <string>(), It.IsAny <UserStatus>()))
            .Callback <string, UserStatus>((x, y) => {
                userSet   = x;
                newStatus = y;
            })
            .Returns(Task.FromResult(true));


            var securityManager = new Mock <IRoleManager>();

            securityManager.Setup(x => x.GetUserRolesAsync(It.Is <string>(u => u == "user2")))
            .Returns <string>(x => Task.FromResult <IEnumerable <Role> >(new[] { new Role("admin_group") }));

            container.RegisterInstance <IRoleManager>(securityManager.Object);
            container.RegisterInstance <IUserManager>(userManager.Object);

            var cache = new PrivilegesCache(null);

            cache.SetSystemPrivileges("admin_group", SqlPrivileges.Admin);

            container.RegisterInstance <IAccessController>(cache);

            var systemContext = new Mock <IContext>();

            systemContext.SetupGet(x => x.Scope)
            .Returns(container);

            adminContext           = MockedSession.Create(systemContext.Object, User.System);
            userContext            = MockedSession.Create(systemContext.Object, new User("user1"));
            userInAdminRoleContext = MockedSession.Create(systemContext.Object, new User("user2"));
        }