Пример #1
0
        public void Add_NullValue_ThrowsArgumentNullException()
        {
            var attribute = new DirectoryAttribute();

            AssertExtensions.Throws <ArgumentNullException>("value", () => attribute.Add((string)null));
            AssertExtensions.Throws <ArgumentNullException>("value", () => attribute.Add((byte[])null));
            AssertExtensions.Throws <ArgumentNullException>("value", () => attribute.Add((Uri)null));
        }
Пример #2
0
        protected DirectoryAttribute CreateAttribute(string name, string value)
        {
            DirectoryAttribute result = new DirectoryAttribute();

            result.Name = name;
            result.Add(value);

            return(result);
        }
Пример #3
0
        public ExSearchResultEntry Clone(string distinguishedName)
        {
            DirectoryAttributeCollection directoryAttributeCollection = new DirectoryAttributeCollection();

            foreach (KeyValuePair <string, DirectoryAttribute> keyValuePair in this.attributes)
            {
                DirectoryAttribute value = keyValuePair.Value;
                DirectoryAttribute directoryAttribute = new DirectoryAttribute();
                directoryAttribute.Name = value.Name;
                foreach (object obj in value)
                {
                    if (obj is byte[])
                    {
                        byte[] array = new byte[((byte[])obj).Length];
                        Buffer.BlockCopy((byte[])obj, 0, array, 0, array.Length);
                        directoryAttribute.Add(array);
                    }
                    else if (obj is string)
                    {
                        string value2 = string.Copy((string)obj);
                        directoryAttribute.Add(value2);
                    }
                    else
                    {
                        if (!(obj is Uri))
                        {
                            throw new NotSupportedException("Type " + obj.GetType() + " is not supported");
                        }
                        Uri value3 = new Uri(((Uri)obj).OriginalString);
                        directoryAttribute.Add(value3);
                    }
                }
                directoryAttributeCollection.Add(directoryAttribute);
            }
            return(new ExSearchResultEntry(distinguishedName, directoryAttributeCollection));
        }
Пример #4
0
        private void AddLdapEntry()
        {
            using (var connection = new LdapConnection())
            {
                connection.Connect(Config.LdapHost, Config.LdapPort);
                connection.Bind(LdapAuthMechanism.SIMPLE, Config.LdapUserDn, Config.LdapPassword);
                var ldapEntry = new LdapEntry
                {
                    Dn         = $"cn=test,{Config.RootDn}",
                    Attributes = new Dictionary <string, List <string> >
                    {
                        { "cn", new List <string> {
                              "test"
                          } },
                        { "sn", new List <string> {
                              "Winston"
                          } },
                        { "objectclass", new List <string> {
                              "inetOrgPerson", "top"
                          } },
                        { "givenname", new List <string> {
                              "винстон"
                          } },
                        { "description", new List <string> {
                              "test_value"
                          } }
                    }
                };
                var directoryEntry = ldapEntry.ToDirectoryEntry();
                var image          = new DirectoryAttribute
                {
                    Name = "jpegPhoto"
                };
                image.Add(new byte[] { 1, 2, 3, 4 });
                directoryEntry.Attributes.Add(image);
                var response = (AddResponse)connection.SendRequest(new AddRequest(directoryEntry.Dn, directoryEntry.Attributes.ToArray()));
                Assert.True(response.ResultCode == 0);

                var entries = connection.Search(Config.RootDn, "(&(objectclass=top)(cn=test))");
                Assert.True(entries.Count == 1);
                _testOutputHelper.WriteLine(entries[0].Dn);

                Assert.Equal($"cn=test,{Config.RootDn}", entries[0].Dn);
                Assert.Equal("винстон", GetAttributeValue(entries[0].Attributes, "givenName")[0]);
                Assert.True(GetAttributeValue(entries[0].Attributes, "objectClass").Any());
            }
        }
Пример #5
0
        public void DirectoryEntry_GetObjectSid_Return_Sid_In_String_Format()
        {
            // Arrange
            var attribute = new DirectoryAttribute {
                Name = "objectSid"
            };

            attribute.Add(new byte[] { 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0xB0, 0x68, 0x77, 0x23, 0x28, 0xE5, 0x17, 0xDF, 0xDE, 0x78, 0x25, 0x94, 0x86, 0x13, 0x00, 0x00 });
            var entry = new DirectoryEntry {
                Attributes = new SearchResultAttributeCollection {
                    attribute
                }
            };

            //Act
            var objectSid = entry.GetObjectSid();

            //Assert
            Assert.Equal("S-1-5-21-595028144-3742885160-2485483742-4998", objectSid);
        }
Пример #6
0
        public void DirectoryEntry_Convert_Binary_Attributes_From_LdapEntry(string attributeName, byte[] attributeValue)
        {
            // Prepare directory attribute.
            var attribute = new DirectoryAttribute {
                Name = attributeName
            };

            attribute.Add(attributeValue);

            // Prepare directory entry.
            var entry = new DirectoryEntry {
                Attributes = new SearchResultAttributeCollection {
                    attribute
                }
            };

            // Convert DirectoryEntry to LdapEntry and then back to DirectoryEntry.
            entry     = entry.ToLdapEntry().ToDirectoryEntry();
            attribute = entry.GetAttribute(attributeName);

            // Assert.
            Assert.Equal(attributeName, attribute.Name);
            Assert.Equal(attributeValue, attribute.GetValue <byte[]>());
        }