This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Directory Services Tests - 4 (#24590)
The added test is mainly to test the interaction with the native COM interfaces.
- Loading branch information
Showing
4 changed files
with
318 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
257 changes: 257 additions & 0 deletions
257
src/System.DirectoryServices/tests/System/DirectoryServices/ActiveDirectoryComInterop.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...System.DirectoryServices/tests/System/DirectoryServices/DirectoryServicesTests.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters