public void AttributeCollection_CaseInsensitivity() { var searchCollection = new SearchResultAttributeCollection(); var modifyCollection = new ModifyAttributeCollection(); var gnAttr = new DirectoryAttribute { Name = LdapAttributes.GivenName.ToLowerInvariant() }; var modifAttr = new DirectoryModificationAttribute { Name = LdapAttributes.GivenName.ToLowerInvariant() }; searchCollection.Add(gnAttr); modifyCollection.Add(modifAttr); Assert.True(searchCollection.Contains(LdapAttributes.GivenName.ToUpperInvariant())); Assert.True(modifyCollection.Contains(LdapAttributes.GivenName.ToUpperInvariant())); }
private static Native.Native.LDAPMod ToLdapMod(DirectoryModificationAttribute attribute) { var modValue = attribute.GetValues <byte[]>().ToList() ?? new List <byte[]>(); var modValuePtr = Marshal.AllocHGlobal(IntPtr.Size * (modValue.Count + 1)); MarshalUtils.ByteArraysToBerValueArray(modValue.Select(_ => _ ?? new byte[0]).ToArray(), modValuePtr); return(new Native.Native.LDAPMod { mod_op = (int)attribute.LdapModOperation | (int)LdapForNet.Native.Native.LdapModOperation.LDAP_MOD_BVALUES, mod_type = Encoder.Instance.StringToPtr(attribute.Name), mod_vals_u = new Native.Native.LDAPMod.mod_vals { modv_bvals = modValuePtr }, mod_next = IntPtr.Zero }); }
private static void ModifyBinaryValues() { using (var connection = new LdapConnection()) { connection.Connect(Config.LdapHost, Config.LdapPort); connection.Bind(LdapAuthMechanism.SIMPLE, Config.LdapUserDn, Config.LdapPassword); var image = new DirectoryModificationAttribute { LdapModOperation = LdapModOperation.LDAP_MOD_REPLACE, Name = "jpegPhoto" }; image.Add(new byte[] { 5, 6, 7, 8 }); var response = (ModifyResponse)connection.SendRequest(new ModifyRequest($"cn=test,{Config.RootDn}", image)); Assert.True(response.ResultCode == 0); var actual = (SearchResponse)connection.SendRequest(new SearchRequest(Config.RootDn, "(&(objectclass=top)(cn=test))", LdapSearchScope.LDAP_SCOPE_SUBTREE)); var entries = actual.Entries; Assert.True(entries.Count == 1); Assert.Equal($"cn=test,{Config.RootDn}", entries[0].Dn); Assert.Equal(new byte[] { 5, 6, 7, 8 }, entries[0].Attributes["jpegPhoto"].GetValues <byte[]>().First()); } }