Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Directory Services Tests - 4 (#24590)
Browse files Browse the repository at this point in the history
The added test is mainly to test the interaction with the native COM interfaces.
  • Loading branch information
tarekgh authored Oct 12, 2017
1 parent 529a6ce commit c910a3d
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup Condition="'$(TargetsWindows)' == 'true'" >
<Compile Include="System\DirectoryServices\DirectoryServicesTests.Windows.cs" />
<Compile Include="System\DirectoryServices\ActiveDirectoryComInterop.cs" />
</ItemGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System;

namespace ActiveDirectoryComInterop
{
// , TypeLibType(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FDispatchable)
[Guid("9068270B-0939-11D1-8BE1-00C04FD8D503")]
[ComImport]
public interface IADsLargeInteger
{
[DispId(2)]
int HighPart
{
[DispId(2)]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[DispId(2)]
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}

[DispId(3)]
int LowPart
{
[DispId(3)]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[DispId(3)]
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
}

// , TypeLibType(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FDispatchable)
[Guid("FD8256D0-FD15-11CE-ABC4-02608C9E7553")]
[ComImport]
public interface IADs
{
[DispId(2)]
string Name
{
[DispId(2)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
}

[DispId(3)]
string Class
{
[DispId(3)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
}

[DispId(4)]
string GUID
{
[DispId(4)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
}

[DispId(5)]
string ADsPath
{
[DispId(5)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
}

[DispId(6)]
string Parent
{
[DispId(6)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
}

[DispId(7)]
string Schema
{
[DispId(7)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
}

[DispId(8)]
[MethodImpl(MethodImplOptions.InternalCall)]
void GetInfo();

[DispId(9)]
[MethodImpl(MethodImplOptions.InternalCall)]
void SetInfo();

[DispId(10)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.Struct)]
object Get([MarshalAs(UnmanagedType.BStr)] [In] string bstrName);

[DispId(11)]
[MethodImpl(MethodImplOptions.InternalCall)]
void Put([MarshalAs(UnmanagedType.BStr)] [In] string bstrName, [MarshalAs(UnmanagedType.Struct)] [In] object vProp);

[DispId(12)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.Struct)]
object GetEx([MarshalAs(UnmanagedType.BStr)] [In] string bstrName);

[DispId(13)]
[MethodImpl(MethodImplOptions.InternalCall)]
void PutEx([In] int lnControlCode, [MarshalAs(UnmanagedType.BStr)] [In] string bstrName, [MarshalAs(UnmanagedType.Struct)] [In] object vProp);

[DispId(14)]
[MethodImpl(MethodImplOptions.InternalCall)]
void GetInfoEx([MarshalAs(UnmanagedType.Struct)] [In] object vProperties, [In] int lnReserved);
}

// , TypeLibType(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FDispatchable)
[Guid("B8C787CA-9BDD-11D0-852C-00C04FD8D503")]
[ComImport]
public interface IADsSecurityDescriptor
{
[DispId(2)]
int Revision
{
[DispId(2)]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[DispId(2)]
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}

[DispId(3)]
int Control
{
[DispId(3)]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[DispId(3)]
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}

[DispId(4)]
string Owner
{
[DispId(4)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
[DispId(4)]
[MethodImpl(MethodImplOptions.InternalCall)]
[param: MarshalAs(UnmanagedType.BStr)]
set;
}

[DispId(5)]
bool OwnerDefaulted
{
[DispId(5)]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[DispId(5)]
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}

[DispId(6)]
string Group
{
[DispId(6)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
[DispId(6)]
[MethodImpl(MethodImplOptions.InternalCall)]
[param: MarshalAs(UnmanagedType.BStr)]
set;
}

[DispId(7)]
bool GroupDefaulted
{
[DispId(7)]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[DispId(7)]
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}

[DispId(8)]
object DiscretionaryAcl
{
[DispId(8)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.IDispatch)]
get;
[DispId(8)]
[MethodImpl(MethodImplOptions.InternalCall)]
[param: MarshalAs(UnmanagedType.IDispatch)]
set;
}

[DispId(9)]
bool DaclDefaulted
{
[DispId(9)]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[DispId(9)]
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}

[DispId(10)]
object SystemAcl
{
[DispId(10)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.IDispatch)]
get;
[DispId(10)]
[MethodImpl(MethodImplOptions.InternalCall)]
[param: MarshalAs(UnmanagedType.IDispatch)]
set;
}

[DispId(11)]
bool SaclDefaulted
{
[DispId(11)]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[DispId(11)]
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}

[DispId(12)]
[MethodImpl(MethodImplOptions.InternalCall)]
[return: MarshalAs(UnmanagedType.IDispatch)]
object CopySecurityDescriptor();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Collections;
using Xunit;
using ActiveDirectoryComInterop;

namespace System.DirectoryServices.Tests
{
public partial class DirectoryServicesTests
{
[ConditionalFact(nameof(IsActiveDirectoryServer))]
public void TestComInterfaces()
{
using (DirectoryEntry de = CreateRootEntry())
{
DeleteOU(de, "dateRoot");

try
{
using (DirectoryEntry rootOU = CreateOU(de, "dateRoot", "Date OU"))
{
long deTime = GetTimeValue((IADsLargeInteger) de.Properties["uSNCreated"].Value);
long rootOUTime = GetTimeValue((IADsLargeInteger) rootOU.Properties["uSNCreated"].Value);

// we are sure rootOU is created after de
Assert.True(rootOUTime > deTime);

IADs iads = (IADs) rootOU.NativeObject;
Assert.Equal("ou=dateRoot", iads.Name);
Assert.Equal("Class", iads.Class);
Assert.True(iads.ADsPath.IndexOf(LdapConfiguration.Configuration.ServerName, StringComparison.OrdinalIgnoreCase) >= 0);

IADsSecurityDescriptor iadsSD = (IADsSecurityDescriptor) de.Properties["ntSecurityDescriptor"].Value;
Assert.True(LdapConfiguration.Configuration.Domain.IndexOf(iadsSD.Owner.Split('\\')[0], StringComparison.OrdinalIgnoreCase) >= 0);
Assert.True(LdapConfiguration.Configuration.Domain.IndexOf(iadsSD.Group.Split('\\')[0], StringComparison.OrdinalIgnoreCase) >= 0);
}
}
finally
{
DeleteOU(de, "dateRoot");
}
}
}

private long GetTimeValue(IADsLargeInteger largeInteger)
{
return (long) largeInteger.LowPart | (long) (largeInteger.HighPart << 32);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace System.DirectoryServices.Tests
{
public class DirectoryServicesTests
public partial class DirectoryServicesTests
{
internal static bool IsLdapConfigurationExist => LdapConfiguration.Configuration != null;
internal static bool IsActiveDirectoryServer => IsLdapConfigurationExist && LdapConfiguration.Configuration.IsActiveDirectoryServer;
Expand Down

0 comments on commit c910a3d

Please sign in to comment.