Skip to content

Instantly share code, notes, and snippets.

@axelgenus
Created August 31, 2020 13:56
Show Gist options
  • Select an option

  • Save axelgenus/622eca57b4e6218f0789136671a5cf72 to your computer and use it in GitHub Desktop.

Select an option

Save axelgenus/622eca57b4e6218f0789136671a5cf72 to your computer and use it in GitHub Desktop.
Demonstration of binary attribute values conversion issue with LdapForNet.
using NUnit.Framework;
namespace LdapForNet.Tests
{
public class Tests
{
[TestCase("objectSid", 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})]
public void BinaryAttributeTest(string attributeName, byte[] attributeValue)
{
// Prepare directory attribute.
var attribute = new DirectoryAttribute();
attribute.Name = attributeName;
attribute.Add(attributeValue);
// Prepare directory entry.
var entry = new DirectoryEntry();
entry.Attributes = new SearchResultAttributeCollection();
entry.Attributes.Add(attribute);
// Convert DirectoryEntry to LdapEntry and then back to DirectoryEntry.
entry = entry.ToLdapEntry().ToDirectoryEntry();
attribute = entry.GetAttribute(attributeName);
// Assert.
Assert.IsNotNull(entry);
Assert.IsNotNull(attribute);
CollectionAssert.AreEqual(attributeName, attribute.Name);
CollectionAssert.AreEqual(attributeValue, attribute.GetValue<byte[]>());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment