Exemple #1
0
        public async Task CanSearch(string filter, string dn)
        {
            using (var client = new LdapClient(Hostname))
            {
                var result = await client.SearchAsync("dc=example,dc=com", SearchScope.SingleLevel, filter, CancellationToken.None);

                var entry = Assert.Single(result.Entries);
                Assert.Equal(dn, entry.ObjectName.ToString());
                Assert.Empty(result.References);
                result = await client.SearchAsync("dc=example,dc=com", SearchScope.BaseObject, filter, CancellationToken.None);

                Assert.Empty(result.Entries);
                Assert.Empty(result.References);
            }
        }
Exemple #2
0
        public async Task CanReadEntry()
        {
            using (var client = new LdapClient(Hostname))
            {
                var result = await client.SearchAsync("uid=tesla,dc=example,dc=com", SearchScope.BaseObject, null, CancellationToken.None);

                var entry = Assert.Single(result.Entries);
                Assert.Equal("uid=tesla,dc=example,dc=com", entry.ObjectName.ToString());
                Assert.Empty(result.References);
            }
        }
Exemple #3
0
        public async Task CanSearchWithAttributes(string filter, string dn, string attributeName, string attribute, string expectedAttributeName = null)
        {
            using (var client = new LdapClient(Hostname))
            {
                var result = await client.SearchAsync("dc=example,dc=com", SearchScope.SingleLevel, filter, new [] { attributeName }, CancellationToken.None);

                var entry = Assert.Single(result.Entries);
                Assert.Equal(dn, entry.ObjectName.ToString());
                Assert.Empty(result.References);
                if (!String.IsNullOrEmpty(attribute))
                {
                    var attr = Assert.Single(entry.Attributes);
                    Assert.Equal(expectedAttributeName ?? attributeName, attr.Type.ToString());
                    var attrValue = Assert.Single(attr.Values);
                    Assert.Equal(attribute, Encoding.UTF8.GetString(attrValue.Span));
                }
                else
                {
                    Assert.Empty(entry.Attributes);
                }
            }
        }