Example #1
0
 public Task InitializeAsync()
 {
     _entriesTask = Task.WhenAll(
         Enumerable.Range(1, (Pages * PageSize) + (_random.Next() % PageSize))
         .Select(x => LdapOps.AddEntryAsync(CnPrefix)));
     return(_entriesTask);
 }
        public void AddEntry_AlreadyExists_ShouldThrowEntryAlreadyExists()
        {
            var ldapEntry = LdapOps.AddEntry();

            var ldapException = Assert.Throws <LdapException>(
                () => TestHelper.WithAuthenticatedLdapConnection(ldapConnection => { ldapConnection.Add(ldapEntry); }));

            Assert.Equal(LdapException.EntryAlreadyExists, ldapException.ResultCode);
        }
Example #3
0
        public async Task AddEntry_AlreadyExists_ShouldThrowEntryAlreadyExists()
        {
            var ldapEntry = await LdapOps.AddEntryAsync();

            var ldapException = await Assert.ThrowsAsync <LdapException>(
                async() => await TestHelper.WithAuthenticatedLdapConnectionAsync(async ldapConnection => { await ldapConnection.AddAsync(ldapEntry); }));

            Assert.Equal(LdapException.EntryAlreadyExists, ldapException.ResultCode);
        }
        public void AddEntry_NotExisting_ShouldWork()
        {
            var ldapEntry = LdapEntryHelper.NewLdapEntry();

            TestHelper.WithAuthenticatedLdapConnection(ldapConnection => { ldapConnection.Add(ldapEntry); });

            var readEntry = LdapOps.GetEntry(ldapEntry.Dn);

            ldapEntry.AssertSameAs(readEntry);
        }
Example #5
0
        public void Delete_OfExistingEntry_ShouldWork()
        {
            var existingEntry = LdapOps.AddEntry();

            TestHelper.WithAuthenticatedLdapConnection(ldapConnection => { ldapConnection.Delete(existingEntry.Dn); });

            var retrivedEntry = LdapOps.GetEntry(existingEntry.Dn);

            Assert.Null(retrivedEntry);
        }
        public async Task Delete_OfExistingEntry_ShouldWork()
        {
            var existingEntry = await LdapOps.AddEntryAsync();

            await TestHelper.WithAuthenticatedLdapConnectionAsync(async ldapConnection => { await ldapConnection.DeleteAsync(existingEntry.Dn); });

            var retrievedEntry = await LdapOps.GetEntryAsync(existingEntry.Dn);

            Assert.Null(retrievedEntry);
        }
Example #7
0
        public async Task AddEntry_NotExisting_ShouldWork()
        {
            var ldapEntry = LdapEntryHelper.NewLdapEntry();

            await TestHelper.WithAuthenticatedLdapConnectionAsync(async ldapConnection => { await ldapConnection.AddAsync(ldapEntry); });

            var readEntry = await LdapOps.GetEntryAsync(ldapEntry.Dn);

            ldapEntry.AssertSameAs(readEntry);
        }
Example #8
0
        public async Task Can_Search_ByCn()
        {
            const int noOfEntries = 10;
            var       ldapEntries = Enumerable.Range(1, noOfEntries).Select(x => LdapOps.AddEntryAsync().GetAwaiter().GetResult()).ToList();
            var       ldapEntry   = ldapEntries[new Random().Next() % noOfEntries];
            await TestHelper.WithAuthenticatedLdapConnectionAsync(
                async ldapConnection =>
            {
                var lsc     = await ldapConnection.SearchAsync(TestsConfig.LdapServer.BaseDn, LdapConnection.ScopeSub, "cn=" + ldapEntry.GetAttribute("cn").StringValue, null, false);
                var entries = await lsc.ToListAsync();

                Assert.Single(entries);
                ldapEntry.AssertSameAs(entries[0]);
            });
        }
        public void AddNewAttribute_ToExistingEntry_ShouldWork()
        {
            var          existingEntry = LdapOps.AddEntry();
            var          value         = Guid.NewGuid().ToString();
            const string attrName      = "description";

            TestHelper.WithAuthenticatedLdapConnection(ldapConnection =>
            {
                var newAttribute = new LdapAttribute(attrName, value);
                var modification = new LdapModification(LdapModification.ADD, newAttribute);
                ldapConnection.Modify(existingEntry.DN, modification);
            });

            var modifiedEntry = LdapOps.GetEntry(existingEntry.DN);

            Assert.Equal(value, modifiedEntry.getAttribute(attrName).StringValue);
        }
        public void ModifyAttributeValue_OfExistingEntry_ShouldWork()
        {
            var          existingEntry = LdapOps.AddEntry();
            var          value         = Guid.NewGuid().ToString();
            const string attrName      = "givenName";

            TestHelper.WithAuthenticatedLdapConnection(ldapConnection =>
            {
                var modifiedAttribute = new LdapAttribute(attrName, value);
                var modification      = new LdapModification(LdapModification.Replace, modifiedAttribute);
                ldapConnection.Modify(existingEntry.Dn, modification);
            });

            var modifiedEntry = LdapOps.GetEntry(existingEntry.Dn);

            Assert.Equal(value, modifiedEntry.GetAttribute(attrName).StringValue);
        }
Example #11
0
        public async Task AddNewAttribute_ToExistingEntry_ShouldWork()
        {
            var existingEntry = await LdapOps.AddEntryAsync();

            var          value    = Guid.NewGuid().ToString();
            const string attrName = "description";

            await TestHelper.WithAuthenticatedLdapConnectionAsync(async ldapConnection =>
            {
                var newAttribute = new LdapAttribute(attrName, value);
                var modification = new LdapModification(LdapModification.Add, newAttribute);
                await ldapConnection.ModifyAsync(existingEntry.Dn, modification);
            });

            var modifiedEntry = await LdapOps.GetEntryAsync(existingEntry.Dn);

            Assert.Equal(value, modifiedEntry.GetAttribute(attrName).StringValue);
        }
Example #12
0
        public void Rename_ExistingEntry_ShouldWork()
        {
            var entry = LdapOps.AddEntry();
            var newCn = Guid.NewGuid().ToString();

            TestHelper.WithAuthenticatedLdapConnection(ldapConnection =>
            {
                ldapConnection.Rename(entry.Dn, "cn=" + newCn, true);
            });

            Assert.Null(LdapOps.GetEntry(entry.Dn));
            var renamedEntry = LdapOps.GetEntry(TestHelper.BuildDn(newCn));

            Assert.NotNull(renamedEntry);
            entry.GetAttributeSet().AssertSameAs(renamedEntry.GetAttributeSet(), new List <string> {
                "cn"
            });
        }
        public void ModifyPassword_OfExistingEntry_ShouldWork()
        {
            var existingEntry = LdapOps.AddEntry();
            var newPassword   = "******" + new Random().Next();

            TestHelper.WithAuthenticatedLdapConnection(ldapConnection =>
            {
                var newAttribute = new LdapAttribute("userPassword", newPassword);
                var modification = new LdapModification(LdapModification.Replace, newAttribute);
                ldapConnection.Modify(existingEntry.Dn, modification);
            });

            TestHelper.WithLdapConnection(
                ldapConnection =>
            {
                ldapConnection.Bind(existingEntry.Dn, newPassword);
            });
        }
Example #14
0
        public async Task Rename_ExistingEntry_ShouldWork()
        {
            var entry = await LdapOps.AddEntryAsync();

            var newCn = Guid.NewGuid().ToString();

            await TestHelper.WithAuthenticatedLdapConnectionAsync(async ldapConnection =>
            {
                await ldapConnection.RenameAsync(entry.Dn, "cn=" + newCn, true);
            });

            Assert.Null(await LdapOps.GetEntryAsync(entry.Dn));
            var renamedEntry = await LdapOps.GetEntryAsync(TestHelper.BuildDn(newCn));

            Assert.NotNull(renamedEntry);
            entry.GetAttributeSet().AssertSameAs(renamedEntry.GetAttributeSet(), new List <string> {
                "cn"
            });
        }
Example #15
0
        public void Can_Search_ByCn()
        {
            const int noOfEntries = 10;
            var       ldapEntries = Enumerable.Range(1, noOfEntries).Select(x => LdapOps.AddEntry()).ToList();
            var       ldapEntry   = ldapEntries[new Random().Next() % noOfEntries];

            TestHelper.WithAuthenticatedLdapConnection(
                ldapConnection =>
            {
                var lsc     = ldapConnection.Search(TestsConfig.LdapServer.BaseDn, LdapConnection.SCOPE_SUB, "cn=" + ldapEntry.getAttribute("cn").StringValue, null, false);
                var entries = new List <LdapEntry>();
                while (lsc.hasMore())
                {
                    entries.Add(lsc.next());
                }
                Assert.Equal(1, entries.Count);
                ldapEntry.AssertSameAs(entries[0]);
            });
        }
        public async Task ModifyPassword_OfExistingEntry_ShouldWork()
        {
            var existingEntry = await LdapOps.AddEntryAsync();

            var newPassword = "******" + new Random().Next();

            await TestHelper.WithAuthenticatedLdapConnectionAsync(async ldapConnection =>
            {
                var newAttribute = new LdapAttribute("userPassword", newPassword);
                var modification = new LdapModification(LdapModification.Replace, newAttribute);
                await ldapConnection.ModifyAsync(existingEntry.Dn, modification);
            });

            await TestHelper.WithLdapConnectionAsync(
                async ldapConnection =>
            {
                await ldapConnection.BindAsync(existingEntry.Dn, newPassword);
            });
        }
 public PagedSearchTestsFixture()
 {
     CnPrefix = _random.Next().ToString();
     Entries  = Enumerable.Range(1, Pages * PageSize + _random.Next() % PageSize).Select(x => LdapOps.AddEntry(CnPrefix)).ToList();
 }
        public void Search_when_paging_using_VirtualListViewControl_returns_expected_results()
        {
            const int pages           = 10;
            const int pageSize        = 50;
            var       cnPrefix        = new Random().Next().ToString();
            var       expectedEntries = Enumerable.Range(1, pages * pageSize).Select(x => LdapOps.AddEntry(cnPrefix)).ToList();

            var searchConstraints = new LdapSearchConstraints
            {
                BatchSize  = 0,
                MaxResults = 1000
            };

            var entries = new List <LdapEntry>();

            TestHelper.WithAuthenticatedLdapConnection(
                ldapConnection =>
            {
                var sortControl = new LdapSortControl(new LdapSortKey("cn"), true);
                var pageCount   = 1;
                while (true)
                {
                    searchConstraints.SetControls(new LdapControl[] { BuildLdapVirtualListControl(pageCount, pageSize), sortControl });
                    var searchResults = ldapConnection.Search(TestsConfig.LdapServer.BaseDn, LdapConnection.ScopeSub, "cn=" + cnPrefix + "*", null, false, searchConstraints).ToList();
                    entries.AddRange(searchResults);
                    if (searchResults.Count < pageSize)
                    {
                        break;
                    }

                    pageCount++;
                }
            });

            Assert.Equal(expectedEntries.Count, entries.Count);
            foreach (var pair in expectedEntries.OrderBy(x => x.Dn).Zip(entries.OrderBy(x => x.Dn)))
            {
                pair.First.AssertSameAs(pair.Second);
            }
        }