示例#1
0
        public void TestUacFilterNullValue()
        {
            var filter = new UacAttributeFilter();

            var job = new JobElement();

            var attrib = new AttributeElement();

            var searchResult = SearchResultFactory.Construct(new
            {
                userAccountControl = 0
            });

            var result = (bool)filter.Execute(null, searchResult, job, attrib);

            Assert.IsTrue(result);
        }
        public void TestReadLdapMissingAttribute()
        {
            var filter = new ReadLdapFilter();
            var attrib = new AttributeElement
            {
                Name = "NotFound"
            };

            // mock the ldap search result
            var result = SearchResultFactory.Construct(new
            {
                givenName = "Thomas"
            });

            var value = filter.Execute(null, result, null, attrib);

            Assert.IsNull(value);
        }
示例#3
0
        public void TestUacFilterIsInactive()
        {
            var filter = new UacAttributeFilter();

            var job = new JobElement();

            var attrib = new AttributeElement();

            var searchResult = SearchResultFactory.Construct(new
            {
                userAccountControl = 0
            });

            const int currentValue = 0x0002;
            var       result       = (bool)filter.Execute(currentValue, searchResult, job, attrib);

            Assert.IsFalse(result);
        }
        public void TestReadLdapValue()
        {
            var filter = new ReadLdapFilter();
            var attrib = new AttributeElement
            {
                Name = "givenName"
            };

            // mock the ldap search result
            var result = SearchResultFactory.Construct(new
            {
                givenName = "Thomas"
            });


            var value = filter.Execute(null, result, null, attrib);

            Assert.AreEqual(value, "Thomas");
        }
        public void TestGroupFilterWithPrefix()
        {
            var result = SearchResultFactory.Construct(new
            {
                sAMAccountName = "leetho0",
                manager        = "Mike Gilbert",
                department     = "development",
                givenName      = "Thomas",
                sn             = "Lee",
                memberOf       = new string[] {
                    "CN=Administrators,Ou=Groups,Ou=Epublish,DC=saig,DC=frd,DC=global",
                    "CN=C360-Users,Ou=Groups,Ou=Epublish,DC=saig,DC=frd,DC=global"
                }
            });

            var job = new JobElement();

            // list of allowed groups
            job.Groups.Add("Users");

            // prefix to remove
            job.RemoveGroupPrefix = "C360-";

            // attributes of the result that should be mapped
            job.Attributes.Add("sAMAccountName");
            job.Attributes.Add("manager");
            job.Attributes.Add("department");
            job.Attributes.Add("givenName");
            job.Attributes.Add("sn");
            var memberOf = job.Attributes.Add("memberOf");

            var groupFilter = new GroupsAttributeFilter();
            var val         = groupFilter.Execute(null, result, job, memberOf);

            Assert.True(val is Dictionary <string, string>);
            var groups = (Dictionary <string, string>)val;

            Assert.AreEqual("Users", groups["CN=C360-Users,Ou=Groups,Ou=Epublish,DC=saig,DC=frd,DC=global"]);
        }
        public void TestBuildActiveDirectoryUser()
        {
            var logger                 = ContainerFactory.GetContainer().GetInstance <ILogger>();
            var config                 = ContainerFactory.GetContainer().GetInstance <IConfigurationService>().GetConfig();
            var jobConfig              = config.Jobs[0];
            var userFilterFactory      = new UserFilterFactory();
            var attributeFilterFactory = new AttributeFilterFactory();
            var service                = new ActiveDirectoryService(logger, userFilterFactory, attributeFilterFactory);

            var searchResult = SearchResultFactory.Construct(new
            {
                sAMAccountName = "leetho0",
                manager        = "Mike Gilbert",
                department     = "development",
                givenName      = "Thomas",
                sn             = "Lee"
            });

            var filters = new Dictionary <string, IAttributeFilter>();

            var user = service.BuildActiveDirectoryUser(searchResult, jobConfig, filters);

            Assert.AreEqual(user.Attributes["sAMAccountName"], "leetho0");
        }