├── .gitignore ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── README.md ├── System.DirectoryServices.Protocols.sln ├── src ├── ConsoleTestApp │ ├── ConsoleTestApp.csproj │ ├── Program.cs │ └── appsettings.json └── System.DirectoryServices.Protocols │ ├── Program.cs │ ├── Resources │ ├── Strings.Designer.cs │ └── Strings.resx │ ├── System.DirectoryServices.Protocols.csproj │ └── System │ └── DirectoryServices │ └── Protocols │ ├── common │ ├── AuthTypes.cs │ ├── BerConverter.cs │ ├── DereferenceAlias.cs │ ├── DirectoryAttribute.cs │ ├── DirectoryAttributeOperation.cs │ ├── DirectoryConnection.cs │ ├── DirectoryControl.cs │ ├── DirectoryException.cs │ ├── DirectoryIdentifier.cs │ ├── DirectoryOperation.cs │ ├── DirectoryRequest.cs │ ├── DirectoryResponse.cs │ ├── PartialResultsCollection.cs │ ├── ReferralChasingOption.cs │ ├── ResultCode.cs │ ├── SearchResults.cs │ ├── SearchScope.cs │ ├── encoding.Unix.cs │ ├── encoding.Windows.cs │ └── utils.cs │ └── ldap │ ├── LdapAsyncResult.cs │ ├── LdapConnection.cs │ ├── LdapDirectoryIdentifier.cs │ ├── LdapException.cs │ ├── LdapPartialResultsProcessor.cs │ ├── LdapSessionOptions.Unix.cs │ ├── LdapSessionOptions.Windows.cs │ ├── LdapSessionOptions.cs │ ├── SafeHandles.cs │ └── Wldap32UnsafeMethods.cs └── tests ├── AddRequestTests.cs ├── AsqRequestControlTests.cs ├── BerConversionExceptionTests.cs ├── BerConverterTests.cs ├── CompareRequestTests.cs ├── Configurations.props ├── CoreFx.Private.TestUtilities └── AssertExtensions.cs ├── CrossDomainMoveControlTests.cs ├── DeleteRequestTests.cs ├── DirSyncRequestControlTests.cs ├── DirectoryAttributeCollectionTests.cs ├── DirectoryAttributeModificationCollectionTests.cs ├── DirectoryAttributeModificationTests.cs ├── DirectoryAttributeTests.cs ├── DirectoryConnectionTests.cs ├── DirectoryControlCollectionTests.cs ├── DirectoryControlTests.cs ├── DirectoryExceptionTests.cs ├── DirectoryNotificationControlTests.cs ├── DirectoryOperationExceptionTests.cs ├── DirectoryServices └── LdapConfiguration.cs ├── DirectoryServicesProtocolsTests.cs ├── DomainScopeControlTests.cs ├── DsmlAuthRequestTests.cs ├── ExtendedDNControlTests.cs ├── ExtendedRequestTests.cs ├── LDAP.Configuration.xml ├── LazyCommitControlTests.cs ├── LdapConnectionTests.cs ├── LdapDirectoryIdentifierTests.cs ├── LdapExceptionTests.cs ├── LdapSessionOptionsTests.cs ├── ModifyDNRequestTests.cs ├── ModifyRequestTests.cs ├── PageResultRequestControlTests.cs ├── PermissiveModifyControlTests.cs ├── QuotaControlTests.cs ├── ReferralCallbackTests.cs ├── SearchOptionsControlTests.cs ├── SearchRequestTests.cs ├── SecurityDescriptorFlagControlTests.cs ├── ShowDeletedControlTests.cs ├── SortKeyTests.cs ├── SortRequestControlTests.cs ├── System.DirectoryServices.Protocols.Tests.csproj ├── TlsOperationExceptionTests.cs ├── TreeDeleteControlTests.cs ├── VerifyNameControlTests.cs ├── VlvRequestControlTests.cs └── xunit.netcore.extensions ├── Attributes ├── ActiveIssueAttribute.cs ├── ConditionalFactAttribute.cs └── SkipOnTargetFrameworkAttribute.cs ├── Discoverers ├── ConditionalFactDiscoverer .cs └── ConditionalTestDiscoverer.cs ├── SkippedTestCase.cs ├── TargetFrameworkMonikers.cs └── TestPlatforms.cs /.gitignore: -------------------------------------------------------------------------------- 1 | # Build results 2 | [Dd]ebug/ 3 | [Dd]ebugPublic/ 4 | [Rr]elease/ 5 | [Rr]eleases/ 6 | x64/ 7 | x86/ 8 | build/ 9 | bld/ 10 | [Bb]in/ 11 | [Oo]bj/ 12 | [Oo]ut/ 13 | msbuild.log 14 | msbuild.err 15 | msbuild.wrn -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/src/ConsoleTestApp/bin/Debug/netcoreapp2.1/ConsoleTestApp.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/src/ConsoleTestApp", 16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window 17 | "console": "internalConsole", 18 | "stopAtEntry": false, 19 | "internalConsoleOptions": "openOnSessionStart" 20 | }, 21 | { 22 | "name": ".NET Core Attach", 23 | "type": "coreclr", 24 | "request": "attach", 25 | "processId": "${command:pickProcess}" 26 | } 27 | ,] 28 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "todo-tree.tags": [ 3 | "TODO", 4 | "FIXME", 5 | "NOTE" 6 | ] 7 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build", 8 | "command": "dotnet", 9 | "args": [ 10 | "build", 11 | "/p:GenerateFullPaths=true" 12 | ], 13 | "type": "shell", 14 | "group": "build", 15 | "presentation": { 16 | "reveal": "silent" 17 | }, 18 | "problemMatcher": "$msCompile" 19 | }, 20 | { 21 | "label": "test", 22 | "command": "dotnet", 23 | "type": "process", 24 | "args": [ 25 | "test", 26 | "/p:GenerateFullPaths=true", 27 | "${workspaceFolder}/tests/System.DirectoryServices.Protocols.Tests.csproj", 28 | ], 29 | "problemMatcher": "$msCompile", 30 | "group": { 31 | "kind": "test", 32 | "isDefault": true 33 | } 34 | }, 35 | 36 | 37 | ] 38 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Summary 2 | 3 | **Proof-Of-Concept** port of core-fx "System.DirectoryServices.Protocols" to Linux (using libldap) 4 | 5 | The ideal port would be fully managed of course, but unfortunately isn't here (yet?), so for the time being... 6 | 7 | 8 | ## Nuget 9 | 10 | [https://www.nuget.org/packages/S.DS.P.linux](https://www.nuget.org/packages/S.DS.P.linux/) 11 | 12 | 13 | ## Prerequisites 14 | 15 | * Linux (obviously) 16 | 17 | * .NET Core 2.1(+) 18 | 19 | * libldap 20 | 21 | ## What isn't working / known issues 22 | * Most of the SessionOptions aren't implemented 23 | * Referrals are not implemented 24 | * Only Anonymous and Basic authentication are work 25 | * No LDAPS, but StartTransportLayerSecurity works 26 | 27 | 28 | ## Tested 29 | 30 | * Debian 9-x64, .NET Core SDK 2.1.300, libldap-2.4-2 31 | * Directories: 32 | * 389 Directory Server (1.3.4.0) 33 | * Active Directory (2012 R2) 34 | 35 | 36 | ## Disclaimer 37 | 38 | Quick (and somewhat dirty) port that suits my personal needs and might serve yours. 39 | **Use at your onwn risk** 40 | 41 | 42 | 43 | 44 | 45 | ## Relevant github issue 46 | 47 | [Support System.DirectoryServices.Protocols on Linux/Mac #24843](https://github.com/dotnet/corefx/issues/24843) 48 | 49 | -------------------------------------------------------------------------------- /System.DirectoryServices.Protocols.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{64AF1C61-1379-4190-A890-254EC77AC449}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.DirectoryServices.Protocols", "src\System.DirectoryServices.Protocols\System.DirectoryServices.Protocols.csproj", "{6D36F705-495A-4956-9CEA-9AB09345E5B2}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.DirectoryServices.Protocols.Tests", "tests\System.DirectoryServices.Protocols.Tests.csproj", "{9F7796C5-2846-46E3-9245-5885D2526A07}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTestApp", "src\ConsoleTestApp\ConsoleTestApp.csproj", "{A8353C87-3788-41DB-AD7A-D657A2976D26}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Debug|x64 = Debug|x64 18 | Debug|x86 = Debug|x86 19 | Release|Any CPU = Release|Any CPU 20 | Release|x64 = Release|x64 21 | Release|x86 = Release|x86 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Debug|x64.ActiveCfg = Debug|Any CPU 30 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Debug|x64.Build.0 = Debug|Any CPU 31 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Debug|x86.ActiveCfg = Debug|Any CPU 32 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Debug|x86.Build.0 = Debug|Any CPU 33 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Release|x64.ActiveCfg = Release|Any CPU 36 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Release|x64.Build.0 = Release|Any CPU 37 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Release|x86.ActiveCfg = Release|Any CPU 38 | {6D36F705-495A-4956-9CEA-9AB09345E5B2}.Release|x86.Build.0 = Release|Any CPU 39 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Debug|x64.ActiveCfg = Debug|Any CPU 42 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Debug|x64.Build.0 = Debug|Any CPU 43 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Debug|x86.ActiveCfg = Debug|Any CPU 44 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Debug|x86.Build.0 = Debug|Any CPU 45 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Release|x64.ActiveCfg = Release|Any CPU 48 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Release|x64.Build.0 = Release|Any CPU 49 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Release|x86.ActiveCfg = Release|Any CPU 50 | {9F7796C5-2846-46E3-9245-5885D2526A07}.Release|x86.Build.0 = Release|Any CPU 51 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 52 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Debug|Any CPU.Build.0 = Debug|Any CPU 53 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Debug|x64.ActiveCfg = Debug|Any CPU 54 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Debug|x64.Build.0 = Debug|Any CPU 55 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Debug|x86.ActiveCfg = Debug|Any CPU 56 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Debug|x86.Build.0 = Debug|Any CPU 57 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Release|Any CPU.ActiveCfg = Release|Any CPU 58 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Release|Any CPU.Build.0 = Release|Any CPU 59 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Release|x64.ActiveCfg = Release|Any CPU 60 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Release|x64.Build.0 = Release|Any CPU 61 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Release|x86.ActiveCfg = Release|Any CPU 62 | {A8353C87-3788-41DB-AD7A-D657A2976D26}.Release|x86.Build.0 = Release|Any CPU 63 | EndGlobalSection 64 | GlobalSection(NestedProjects) = preSolution 65 | {6D36F705-495A-4956-9CEA-9AB09345E5B2} = {64AF1C61-1379-4190-A890-254EC77AC449} 66 | {A8353C87-3788-41DB-AD7A-D657A2976D26} = {64AF1C61-1379-4190-A890-254EC77AC449} 67 | EndGlobalSection 68 | EndGlobal 69 | -------------------------------------------------------------------------------- /src/ConsoleTestApp/ConsoleTestApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | consoletestapp-eb00853f-de89-4222-a3ec-7083267dd9d0 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/ConsoleTestApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Microsoft.Extensions.Configuration; 4 | using System.Collections.Generic; 5 | using System.DirectoryServices.Protocols; 6 | using System.Security.Cryptography.X509Certificates; 7 | 8 | 9 | namespace ConsoleTestApp 10 | { 11 | class Program 12 | { 13 | public static IConfiguration Configuration { get; private set; } 14 | 15 | public class LdapDirectoryConfiguration 16 | { 17 | public string[] Server { get; set; } 18 | public int PortNumber { get; set; } = 389; 19 | public AuthType AuthType { get; set; } 20 | public string BindDn { get; set; } 21 | public string BindPasswordUserSecret { get; set; } 22 | public System.Net.NetworkCredential NetworkCredential 23 | { 24 | get 25 | { 26 | if (!string.IsNullOrEmpty(BindDn)) 27 | { 28 | return new System.Net.NetworkCredential(BindDn, Configuration[BindPasswordUserSecret]); 29 | } 30 | else 31 | { 32 | return null; 33 | } 34 | } 35 | } 36 | public LdapDirectoryIdentifier LdapDirectoryIdentifier 37 | { 38 | get 39 | { 40 | return new LdapDirectoryIdentifier(Server, PortNumber, false, false); 41 | } 42 | } 43 | } 44 | 45 | public static bool VerifyServerCertificateCallback(LdapConnection connection, X509Certificate certificate) 46 | { 47 | Console.WriteLine(); 48 | return true; 49 | } 50 | 51 | static void Main(string[] args) 52 | { 53 | Configuration = new ConfigurationBuilder() 54 | .SetBasePath(Directory.GetCurrentDirectory()) 55 | .AddJsonFile("appsettings.json", true) 56 | .AddEnvironmentVariables() 57 | .AddUserSecrets("consoletestapp-eb00853f-de89-4222-a3ec-7083267dd9d0") 58 | .Build(); 59 | 60 | // var ldapident = new LdapDirectoryIdentifier("bl18-05.internal.uzgent.be", 389, false, false); 61 | 62 | //var ldapident = new LdapDirectoryIdentifier("ai.internal.uzgent.be", 389, false, false); 63 | 64 | var directoryConfigurations = Configuration.GetSection("DirectoryConfigurations").Get>(); 65 | var activeConfiguration = directoryConfigurations["AD"]; 66 | 67 | var ldapDirectoryIdentifier = activeConfiguration.LdapDirectoryIdentifier; 68 | var networkCredential = activeConfiguration.NetworkCredential; 69 | var authType = activeConfiguration.AuthType; 70 | 71 | 72 | LdapConnection ldapConnection = new LdapConnection(ldapDirectoryIdentifier, networkCredential, authType); 73 | 74 | ldapConnection.SessionOptions.ProtocolVersion = 3; 75 | 76 | ldapConnection.SessionOptions.StartTransportLayerSecurity(new DirectoryControlCollection()); 77 | ldapConnection.Bind(networkCredential); 78 | 79 | 80 | //var sRequest = new SearchRequest("ou=persoon,dc=internal,dc=uzgent,dc=be", "uzguid=bve", SearchScope.OneLevel, new String[] { "dn", "cn", "mobile", "jpegPhoto" }); 81 | var sRequest = new SearchRequest("OU=LDAP,OU=UZUsers,DC=ai,DC=internal,DC=uzgent,DC=be", "employeeNumber=32233", SearchScope.Subtree, new String[] { "dn", "cn", "mobile", "jpegPhoto" }); 82 | 83 | var sResponse = ldapConnection.SendRequest(sRequest) as SearchResponse; 84 | 85 | foreach (SearchResultEntry entry in sResponse.Entries) 86 | { 87 | 88 | string foundDN = entry.DistinguishedName; 89 | 90 | Console.WriteLine("Found: " + foundDN); 91 | 92 | Console.WriteLine(" |-> " + entry.Attributes["cn"][0].ToString()); 93 | 94 | Console.WriteLine(" |-> " + entry.Attributes["mobile"]?[0].ToString() ?? ""); 95 | 96 | var pic = entry.Attributes["jpegPhoto"]?.GetValues(typeof(byte[]))[0]; 97 | 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/ConsoleTestApp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "DirectoriesOld": [{ 3 | "Server": "uzgldap389", 4 | "PortNumber": 389 5 | }], 6 | 7 | "DirectoryConfigurations": { 8 | "AD": { 9 | "Server": ["vdc1p.ai.internal.uzgent.be"], 10 | "AuthType": "Basic", 11 | "BindDn": "bve@ai.internal.uzgent.be", 12 | "BindPasswordUserSecret": "employeeNumber=32233:userPassword" 13 | }, 14 | "389DS": { 15 | "Server": ["uzgldap389.internal.uzgent.be"], 16 | "AuthType": "Basic", 17 | "BindDn": "employeeNumber=32233,ou=persoon,dc=internal,dc=uzgent,dc=be", 18 | "BindPasswordUserSecret": "employeeNumber=32233:userPassword" 19 | } 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Diagnostics; 4 | using System.DirectoryServices.Protocols; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using Microsoft.Win32.SafeHandles; 8 | 9 | namespace System.DirectoryServices.ProtocolsX 10 | { 11 | 12 | class Program 13 | { 14 | 15 | static void Main(string[] args) 16 | { 17 | 18 | 19 | } 20 | }// 21 | } 22 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System.DirectoryServices.Protocols.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netstandard2.0 6 | true 7 | true 8 | false 9 | false 10 | true 11 | 12 | 13 | 14 | S.DS.P.linux 15 | 0.0.2-alpha.2 16 | dogguts 17 | Proof of concept port of dotnet/corefx System.DirectoryServices.Protocols against libldap/openldap for Linux 18 | false 19 | ldap linux directory services 20 | https://github.com/dogguts/System.DirectoryServices.Protocol_linux 21 | Not even pre-pre-alpha. Don't even dare using this on a production environment. 22 | True 23 | True 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/AuthTypes.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | 7 | namespace System.DirectoryServices.Protocols 8 | { 9 | public enum AuthType 10 | { 11 | Anonymous = 0, 12 | Basic = 1, 13 | Negotiate = 2, 14 | Ntlm = 3, 15 | Digest = 4, 16 | Sicily = 5, 17 | Dpa = 6, 18 | Msn = 7, 19 | External = 8, 20 | Kerberos = 9 21 | } 22 | 23 | public enum PartialResultProcessing 24 | { 25 | NoPartialResultSupport, 26 | ReturnPartialResults, 27 | ReturnPartialResultsAndNotifyCallback 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/DereferenceAlias.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | namespace System.DirectoryServices.Protocols 6 | { 7 | public enum DereferenceAlias 8 | { 9 | Never = 0, 10 | InSearching = 1, 11 | FindingBaseObject = 2, 12 | Always = 3 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/DirectoryAttributeOperation.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | namespace System.DirectoryServices.Protocols 6 | { 7 | public enum DirectoryAttributeOperation 8 | { 9 | Add = 0, 10 | Delete = 1, 11 | Replace = 2 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/DirectoryConnection.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Globalization; 6 | using System.Net; 7 | using System.Security.Cryptography.X509Certificates; 8 | 9 | namespace System.DirectoryServices.Protocols 10 | { 11 | public abstract class DirectoryConnection 12 | { 13 | internal NetworkCredential _directoryCredential; 14 | private X509CertificateCollection _certificatesCollection; 15 | internal TimeSpan _connectionTimeOut = new TimeSpan(0, 0, 30); 16 | internal DirectoryIdentifier _directoryIdentifier; 17 | 18 | protected DirectoryConnection() => _certificatesCollection = new X509CertificateCollection(); 19 | 20 | public virtual DirectoryIdentifier Directory => _directoryIdentifier; 21 | 22 | public X509CertificateCollection ClientCertificates => _certificatesCollection; 23 | 24 | public virtual TimeSpan Timeout 25 | { 26 | get => _connectionTimeOut; 27 | set 28 | { 29 | if (value < TimeSpan.Zero) 30 | { 31 | throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.NoNegativeTimeLimit), nameof(value)); 32 | } 33 | 34 | _connectionTimeOut = value; 35 | } 36 | } 37 | 38 | public virtual NetworkCredential Credential 39 | { 40 | set 41 | { 42 | _directoryCredential = (value != null) ? new NetworkCredential(value.UserName, value.Password, value.Domain) : null; 43 | } 44 | } 45 | 46 | public abstract DirectoryResponse SendRequest(DirectoryRequest request); 47 | 48 | internal NetworkCredential GetCredential() => _directoryCredential; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/DirectoryException.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Runtime.Serialization; 6 | 7 | namespace System.DirectoryServices.Protocols 8 | { 9 | [Serializable] 10 | [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] 11 | public class DirectoryException : Exception 12 | { 13 | protected DirectoryException(SerializationInfo info, StreamingContext context) : base(info, context) 14 | { 15 | } 16 | 17 | public DirectoryException(string message, Exception inner) : base(message, inner) 18 | { 19 | } 20 | 21 | public DirectoryException(string message) : base(message) 22 | { 23 | } 24 | 25 | public DirectoryException() : base() 26 | { 27 | } 28 | } 29 | 30 | [Serializable] 31 | [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] 32 | public class DirectoryOperationException : DirectoryException, ISerializable 33 | { 34 | protected DirectoryOperationException(SerializationInfo info, StreamingContext context) : base(info, context) { } 35 | 36 | public DirectoryOperationException() : base() { } 37 | 38 | public DirectoryOperationException(string message) : base(message) { } 39 | 40 | public DirectoryOperationException(string message, Exception inner) : base(message, inner) { } 41 | 42 | public DirectoryOperationException(DirectoryResponse response) : base(SR.DefaultOperationsError) 43 | { 44 | Response = response; 45 | } 46 | 47 | public DirectoryOperationException(DirectoryResponse response, string message) : base(message) 48 | { 49 | Response = response; 50 | } 51 | 52 | public DirectoryOperationException(DirectoryResponse response, string message, Exception inner) : base(message, inner) 53 | { 54 | Response = response; 55 | } 56 | 57 | public DirectoryResponse Response { get; internal set; } 58 | } 59 | 60 | [Serializable] 61 | [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] 62 | public class BerConversionException : DirectoryException 63 | { 64 | protected BerConversionException(SerializationInfo info, StreamingContext context) : base(info, context) { } 65 | 66 | public BerConversionException() : base(SR.BerConversionError) 67 | { 68 | } 69 | 70 | public BerConversionException(string message) : base(message) 71 | { 72 | } 73 | 74 | public BerConversionException(string message, Exception inner) : base(message, inner) 75 | { 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/DirectoryIdentifier.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | 7 | namespace System.DirectoryServices.Protocols 8 | { 9 | public abstract class DirectoryIdentifier 10 | { 11 | protected DirectoryIdentifier() 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/DirectoryOperation.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | namespace System.DirectoryServices.Protocols 6 | { 7 | public abstract class DirectoryOperation 8 | { 9 | internal string _directoryRequestID; 10 | 11 | protected DirectoryOperation() { } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/DirectoryResponse.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | namespace System.DirectoryServices.Protocols 6 | { 7 | public abstract class DirectoryResponse : DirectoryOperation 8 | { 9 | private DirectoryControl[] _directoryControls; 10 | internal Uri[] _directoryReferral; 11 | 12 | internal DirectoryResponse(string dn, DirectoryControl[] controls, ResultCode result, string message, Uri[] referral) 13 | { 14 | MatchedDN = dn; 15 | _directoryControls = controls; 16 | ResultCode = result; 17 | ErrorMessage = message; 18 | _directoryReferral = referral; 19 | } 20 | 21 | public string RequestId { get; } 22 | 23 | public virtual string MatchedDN { get; } 24 | 25 | public virtual DirectoryControl[] Controls 26 | { 27 | get 28 | { 29 | if (_directoryControls == null) 30 | { 31 | return Array.Empty(); 32 | } 33 | 34 | DirectoryControl[] tempControls = new DirectoryControl[_directoryControls.Length]; 35 | for (int i = 0; i < _directoryControls.Length; i++) 36 | { 37 | tempControls[i] = new DirectoryControl(_directoryControls[i].Type, _directoryControls[i].GetValue(), _directoryControls[i].IsCritical, _directoryControls[i].ServerSide); 38 | } 39 | DirectoryControl.TransformControls(tempControls); 40 | return tempControls; 41 | } 42 | } 43 | 44 | public virtual ResultCode ResultCode { get; } 45 | 46 | public virtual string ErrorMessage { get; } 47 | 48 | public virtual Uri[] Referral 49 | { 50 | get 51 | { 52 | if (_directoryReferral == null) 53 | { 54 | return Array.Empty(); 55 | } 56 | 57 | Uri[] tempReferral = new Uri[_directoryReferral.Length]; 58 | for (int i = 0; i < _directoryReferral.Length; i++) 59 | { 60 | tempReferral[i] = new Uri(_directoryReferral[i].AbsoluteUri); 61 | } 62 | return tempReferral; 63 | } 64 | } 65 | } 66 | 67 | public class DeleteResponse : DirectoryResponse 68 | { 69 | internal DeleteResponse(string dn, DirectoryControl[] controls, ResultCode result, string message, Uri[] referral) : base(dn, controls, result, message, referral) { } 70 | } 71 | 72 | public class AddResponse : DirectoryResponse 73 | { 74 | internal AddResponse(string dn, DirectoryControl[] controls, ResultCode result, string message, Uri[] referral) : base(dn, controls, result, message, referral) { } 75 | } 76 | 77 | public class ModifyResponse : DirectoryResponse 78 | { 79 | internal ModifyResponse(string dn, DirectoryControl[] controls, ResultCode result, string message, Uri[] referral) : base(dn, controls, result, message, referral) { } 80 | } 81 | 82 | public class ModifyDNResponse : DirectoryResponse 83 | { 84 | internal ModifyDNResponse(string dn, DirectoryControl[] controls, ResultCode result, string message, Uri[] referral) : base(dn, controls, result, message, referral) { } 85 | } 86 | 87 | public class CompareResponse : DirectoryResponse 88 | { 89 | internal CompareResponse(string dn, DirectoryControl[] controls, ResultCode result, string message, Uri[] referral) : base(dn, controls, result, message, referral) { } 90 | } 91 | 92 | public class ExtendedResponse : DirectoryResponse 93 | { 94 | private byte[] _value; 95 | 96 | internal ExtendedResponse(string dn, DirectoryControl[] controls, ResultCode result, string message, Uri[] referral) : base(dn, controls, result, message, referral) { } 97 | 98 | public string ResponseName { get; internal set; } 99 | 100 | public byte[] ResponseValue 101 | { 102 | get 103 | { 104 | if (_value == null) 105 | { 106 | return Array.Empty(); 107 | } 108 | 109 | byte[] tmpValue = new byte[_value.Length]; 110 | for (int i = 0; i < _value.Length; i++) 111 | { 112 | tmpValue[i] = _value[i]; 113 | } 114 | return tmpValue; 115 | } 116 | internal set => _value = value; 117 | } 118 | } 119 | 120 | public class SearchResponse : DirectoryResponse 121 | { 122 | private SearchResultReferenceCollection _referenceCollection = new SearchResultReferenceCollection(); 123 | private SearchResultEntryCollection _entryCollection = new SearchResultEntryCollection(); 124 | internal bool searchDone = false; 125 | internal SearchResponse(string dn, DirectoryControl[] controls, ResultCode result, string message, Uri[] referral) : base(dn, controls, result, message, referral) { } 126 | 127 | public SearchResultReferenceCollection References 128 | { 129 | get => _referenceCollection; 130 | internal set => _referenceCollection = value; 131 | } 132 | 133 | public SearchResultEntryCollection Entries 134 | { 135 | get => _entryCollection; 136 | internal set => _entryCollection = value; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/PartialResultsCollection.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections; 6 | 7 | namespace System.DirectoryServices.Protocols 8 | { 9 | public class PartialResultsCollection : ReadOnlyCollectionBase 10 | { 11 | internal PartialResultsCollection() { } 12 | 13 | public object this[int index] => InnerList[index]; 14 | 15 | internal int Add(object value) => InnerList.Add(value); 16 | 17 | public bool Contains(object value) => InnerList.Contains(value); 18 | 19 | public int IndexOf(object value) => InnerList.IndexOf(value); 20 | 21 | public void CopyTo(object[] values, int index) => InnerList.CopyTo(values, index); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/ReferralChasingOption.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | namespace System.DirectoryServices.Protocols 6 | { 7 | [Flags] 8 | public enum ReferralChasingOptions 9 | { 10 | None = 0, 11 | Subordinate = 0x20, 12 | External = 0x40, 13 | All = Subordinate | External 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/ResultCode.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | 7 | namespace System.DirectoryServices.Protocols 8 | { 9 | public enum ResultCode 10 | { 11 | Success = 0, 12 | OperationsError = 1, 13 | ProtocolError = 2, 14 | TimeLimitExceeded = 3, 15 | SizeLimitExceeded = 4, 16 | CompareFalse = 5, 17 | CompareTrue = 6, 18 | AuthMethodNotSupported = 7, 19 | StrongAuthRequired = 8, 20 | ReferralV2 = 9, 21 | Referral = 10, 22 | AdminLimitExceeded = 11, 23 | UnavailableCriticalExtension = 12, 24 | ConfidentialityRequired = 13, 25 | SaslBindInProgress = 14, 26 | NoSuchAttribute = 16, 27 | UndefinedAttributeType = 17, 28 | InappropriateMatching = 18, 29 | ConstraintViolation = 19, 30 | AttributeOrValueExists = 20, 31 | InvalidAttributeSyntax = 21, 32 | NoSuchObject = 32, 33 | AliasProblem = 33, 34 | InvalidDNSyntax = 34, 35 | AliasDereferencingProblem = 36, 36 | InappropriateAuthentication = 48, 37 | InsufficientAccessRights = 50, 38 | Busy = 51, 39 | Unavailable = 52, 40 | UnwillingToPerform = 53, 41 | LoopDetect = 54, 42 | SortControlMissing = 60, 43 | OffsetRangeError = 61, 44 | NamingViolation = 64, 45 | ObjectClassViolation = 65, 46 | NotAllowedOnNonLeaf = 66, 47 | NotAllowedOnRdn = 67, 48 | EntryAlreadyExists = 68, 49 | ObjectClassModificationsProhibited = 69, 50 | ResultsTooLarge = 70, 51 | AffectsMultipleDsas = 71, 52 | VirtualListViewError = 76, 53 | Other = 80 54 | } 55 | 56 | internal class OperationErrorMappings 57 | { 58 | private static readonly Dictionary s_resultCodeMapping = new Dictionary(capacity: 43) 59 | { 60 | { ResultCode.Success, SR.LDAP_SUCCESS }, 61 | { ResultCode.OperationsError, SR.LDAP_OPERATIONS_ERROR }, 62 | { ResultCode.ProtocolError, SR.LDAP_PROTOCOL_ERROR }, 63 | { ResultCode.TimeLimitExceeded, SR.LDAP_TIMELIMIT_EXCEEDED }, 64 | { ResultCode.SizeLimitExceeded, SR.LDAP_SIZELIMIT_EXCEEDED }, 65 | { ResultCode.CompareFalse, SR.LDAP_COMPARE_FALSE }, 66 | { ResultCode.CompareTrue, SR.LDAP_COMPARE_TRUE }, 67 | { ResultCode.AuthMethodNotSupported, SR.LDAP_AUTH_METHOD_NOT_SUPPORTED }, 68 | { ResultCode.StrongAuthRequired, SR.LDAP_STRONG_AUTH_REQUIRED }, 69 | { ResultCode.ReferralV2, SR.LDAP_PARTIAL_RESULTS }, 70 | { ResultCode.Referral, SR.LDAP_REFERRAL }, 71 | { ResultCode.AdminLimitExceeded, SR.LDAP_ADMIN_LIMIT_EXCEEDED }, 72 | { ResultCode.UnavailableCriticalExtension, SR.LDAP_UNAVAILABLE_CRIT_EXTENSION }, 73 | { ResultCode.ConfidentialityRequired, SR.LDAP_CONFIDENTIALITY_REQUIRED }, 74 | { ResultCode.SaslBindInProgress, SR.LDAP_SASL_BIND_IN_PROGRESS }, 75 | { ResultCode.NoSuchAttribute, SR.LDAP_NO_SUCH_ATTRIBUTE }, 76 | { ResultCode.UndefinedAttributeType, SR.LDAP_UNDEFINED_TYPE }, 77 | { ResultCode.InappropriateMatching, SR.LDAP_INAPPROPRIATE_MATCHING }, 78 | { ResultCode.ConstraintViolation, SR.LDAP_CONSTRAINT_VIOLATION }, 79 | { ResultCode.AttributeOrValueExists, SR.LDAP_ATTRIBUTE_OR_VALUE_EXISTS }, 80 | { ResultCode.InvalidAttributeSyntax, SR.LDAP_INVALID_SYNTAX }, 81 | { ResultCode.NoSuchObject, SR.LDAP_NO_SUCH_OBJECT }, 82 | { ResultCode.AliasProblem, SR.LDAP_ALIAS_PROBLEM }, 83 | { ResultCode.InvalidDNSyntax, SR.LDAP_INVALID_DN_SYNTAX }, 84 | { ResultCode.AliasDereferencingProblem, SR.LDAP_ALIAS_DEREF_PROBLEM }, 85 | { ResultCode.InappropriateAuthentication, SR.LDAP_INAPPROPRIATE_AUTH }, 86 | { ResultCode.InsufficientAccessRights, SR.LDAP_INSUFFICIENT_RIGHTS }, 87 | { ResultCode.Busy, SR.LDAP_BUSY }, 88 | { ResultCode.Unavailable, SR.LDAP_UNAVAILABLE }, 89 | { ResultCode.UnwillingToPerform, SR.LDAP_UNWILLING_TO_PERFORM }, 90 | { ResultCode.LoopDetect, SR.LDAP_LOOP_DETECT }, 91 | { ResultCode.SortControlMissing, SR.LDAP_SORT_CONTROL_MISSING }, 92 | { ResultCode.OffsetRangeError, SR.LDAP_OFFSET_RANGE_ERROR }, 93 | { ResultCode.NamingViolation, SR.LDAP_NAMING_VIOLATION }, 94 | { ResultCode.ObjectClassViolation, SR.LDAP_OBJECT_CLASS_VIOLATION }, 95 | { ResultCode.NotAllowedOnNonLeaf, SR.LDAP_NOT_ALLOWED_ON_NONLEAF }, 96 | { ResultCode.NotAllowedOnRdn, SR.LDAP_NOT_ALLOWED_ON_RDN }, 97 | { ResultCode.EntryAlreadyExists, SR.LDAP_ALREADY_EXISTS }, 98 | { ResultCode.ObjectClassModificationsProhibited, SR.LDAP_NO_OBJECT_CLASS_MODS }, 99 | { ResultCode.ResultsTooLarge, SR.LDAP_RESULTS_TOO_LARGE }, 100 | { ResultCode.AffectsMultipleDsas, SR.LDAP_AFFECTS_MULTIPLE_DSAS }, 101 | { ResultCode.VirtualListViewError, SR.LDAP_VIRTUAL_LIST_VIEW_ERROR }, 102 | { ResultCode.Other, SR.LDAP_OTHER } 103 | }; 104 | 105 | public static string MapResultCode(int errorCode) 106 | { 107 | s_resultCodeMapping.TryGetValue((ResultCode)errorCode, out string errorMessage); 108 | return errorMessage; 109 | } 110 | } 111 | 112 | internal enum LdapOperation 113 | { 114 | LdapAdd = 0, 115 | LdapModify = 1, 116 | LdapSearch = 2, 117 | LdapDelete = 3, 118 | LdapModifyDn = 4, 119 | LdapCompare = 5, 120 | LdapExtendedRequest = 6 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/SearchResults.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections; 6 | 7 | namespace System.DirectoryServices.Protocols 8 | { 9 | public class SearchResultReference 10 | { 11 | private Uri[] _resultReferences; 12 | private DirectoryControl[] _resultControls; 13 | 14 | internal SearchResultReference(Uri[] uris) => _resultReferences = uris; 15 | 16 | public Uri[] Reference 17 | { 18 | get 19 | { 20 | if (_resultReferences == null) 21 | { 22 | return Array.Empty(); 23 | } 24 | 25 | Uri[] tempUri = new Uri[_resultReferences.Length]; 26 | for (int i = 0; i < _resultReferences.Length; i++) 27 | { 28 | tempUri[i] = new Uri(_resultReferences[i].AbsoluteUri); 29 | } 30 | return tempUri; 31 | } 32 | } 33 | 34 | public DirectoryControl[] Controls 35 | { 36 | get 37 | { 38 | if (_resultControls == null) 39 | { 40 | return Array.Empty(); 41 | } 42 | 43 | DirectoryControl[] controls = new DirectoryControl[_resultControls.Length]; 44 | for (int i = 0; i < _resultControls.Length; i++) 45 | { 46 | controls[i] = new DirectoryControl(_resultControls[i].Type, _resultControls[i].GetValue(), _resultControls[i].IsCritical, _resultControls[i].ServerSide); 47 | } 48 | DirectoryControl.TransformControls(controls); 49 | return controls; 50 | } 51 | } 52 | } 53 | 54 | public class SearchResultReferenceCollection : ReadOnlyCollectionBase 55 | { 56 | internal SearchResultReferenceCollection() { } 57 | 58 | public SearchResultReference this[int index] => (SearchResultReference)InnerList[index]; 59 | 60 | internal int Add(SearchResultReference reference) => InnerList.Add(reference); 61 | 62 | public bool Contains(SearchResultReference value) => InnerList.Contains(value); 63 | 64 | public int IndexOf(SearchResultReference value) => InnerList.IndexOf(value); 65 | 66 | public void CopyTo(SearchResultReference[] values, int index) => InnerList.CopyTo(values, index); 67 | 68 | internal void Clear() => InnerList.Clear(); 69 | } 70 | 71 | public class SearchResultEntry 72 | { 73 | private DirectoryControl[] _resultControls = null; 74 | 75 | internal SearchResultEntry(string dn) : this(dn, new SearchResultAttributeCollection()) {} 76 | 77 | internal SearchResultEntry(string dn, SearchResultAttributeCollection attrs) 78 | { 79 | DistinguishedName = dn; 80 | Attributes = attrs; 81 | } 82 | 83 | public string DistinguishedName { get; internal set; } 84 | 85 | public SearchResultAttributeCollection Attributes { get; } 86 | 87 | public DirectoryControl[] Controls 88 | { 89 | get 90 | { 91 | if (_resultControls == null) 92 | { 93 | return Array.Empty(); 94 | } 95 | 96 | DirectoryControl[] controls = new DirectoryControl[_resultControls.Length]; 97 | for (int i = 0; i < _resultControls.Length; i++) 98 | { 99 | controls[i] = new DirectoryControl(_resultControls[i].Type, _resultControls[i].GetValue(), _resultControls[i].IsCritical, _resultControls[i].ServerSide); 100 | } 101 | DirectoryControl.TransformControls(controls); 102 | return controls; 103 | } 104 | } 105 | } 106 | 107 | public class SearchResultEntryCollection : ReadOnlyCollectionBase 108 | { 109 | internal SearchResultEntryCollection() { } 110 | 111 | public SearchResultEntry this[int index] => (SearchResultEntry)InnerList[index]; 112 | 113 | internal int Add(SearchResultEntry entry) => InnerList.Add(entry); 114 | 115 | public bool Contains(SearchResultEntry value) => InnerList.Contains(value); 116 | 117 | public int IndexOf(SearchResultEntry value) => InnerList.IndexOf(value); 118 | 119 | public void CopyTo(SearchResultEntry[] values, int index) => InnerList.CopyTo(values, index); 120 | 121 | internal void Clear() => InnerList.Clear(); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/SearchScope.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | namespace System.DirectoryServices.Protocols 6 | { 7 | public enum SearchScope 8 | { 9 | Base = 0, 10 | OneLevel = 1, 11 | Subtree = 2 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/encoding.Unix.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace System.DirectoryServices.Protocols 4 | { 5 | internal class Encoding 6 | { 7 | internal static Func PtrToString = PtrToStringUTF8; 8 | internal static Func StringToHGlobal = StringToHGlobalUTF8; 9 | 10 | private static IntPtr StringToHGlobalUTF8(string s, out int length) 11 | { 12 | if (s == null) 13 | { 14 | length = 0; 15 | return IntPtr.Zero; 16 | } 17 | 18 | var bytes = System.Text.Encoding.UTF8.GetBytes(s); 19 | var ptr = Marshal.AllocHGlobal(bytes.Length + 1); 20 | Marshal.Copy(bytes, 0, ptr, bytes.Length); 21 | Marshal.WriteByte(ptr, bytes.Length, 0); 22 | length = bytes.Length; 23 | 24 | return ptr; 25 | } 26 | 27 | private static IntPtr StringToHGlobalUTF8(string s) 28 | { 29 | int temp; 30 | return StringToHGlobalUTF8(s, out temp); 31 | } 32 | 33 | private static string PtrToStringUtf8(IntPtr ptr, int length) 34 | { 35 | if (ptr == IntPtr.Zero) 36 | return null; 37 | 38 | byte[] buff = new byte[length]; 39 | Marshal.Copy(ptr, buff, 0, length); 40 | return System.Text.UTF8Encoding.UTF8.GetString(buff); 41 | } 42 | 43 | public static string PtrToStringUTF8(IntPtr ptr) 44 | { 45 | if (ptr == IntPtr.Zero) 46 | { 47 | return null; 48 | } 49 | 50 | int len = 0; 51 | 52 | while (Marshal.ReadByte(ptr, len) != 0) 53 | { 54 | ++len; 55 | } 56 | 57 | if (len == 0) 58 | { 59 | return string.Empty; 60 | } 61 | 62 | byte[] buffer = new byte[len]; 63 | Marshal.Copy(ptr, buffer, 0, buffer.Length); 64 | return System.Text.Encoding.UTF8.GetString(buffer); 65 | } 66 | 67 | 68 | 69 | } 70 | } -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/encoding.Windows.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace System.DirectoryServices.Protocols 4 | { 5 | internal class Encoding 6 | { 7 | internal static Func PtrToString = Marshal.PtrToStringUni; 8 | internal static Func StringToHGlobal = Marshal.StringToHGlobalUni; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/common/utils.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Runtime.InteropServices; 6 | 7 | namespace System.DirectoryServices.Protocols 8 | { 9 | internal class Utility 10 | { 11 | internal static bool IsLdapError(LdapError error) 12 | { 13 | if (error == LdapError.IsLeaf || error == LdapError.InvalidCredentials || error == LdapError.SendTimeOut) 14 | { 15 | return true; 16 | } 17 | 18 | return (error >= LdapError.ServerDown && error <= LdapError.ReferralLimitExceeded); 19 | } 20 | 21 | internal static bool IsResultCode(ResultCode code) 22 | { 23 | if (code >= ResultCode.Success && code <= ResultCode.SaslBindInProgress) 24 | { 25 | return true; 26 | } 27 | 28 | if (code >= ResultCode.NoSuchAttribute && code <= ResultCode.InvalidAttributeSyntax) 29 | { 30 | return true; 31 | } 32 | 33 | if (code >= ResultCode.NoSuchObject && code <= ResultCode.InvalidDNSyntax) 34 | { 35 | return true; 36 | } 37 | 38 | if (code >= ResultCode.InsufficientAccessRights && code <= ResultCode.LoopDetect) 39 | { 40 | return true; 41 | } 42 | 43 | if (code >= ResultCode.NamingViolation && code <= ResultCode.AffectsMultipleDsas) 44 | { 45 | return true; 46 | } 47 | 48 | return (code == ResultCode.AliasDereferencingProblem || code == ResultCode.InappropriateAuthentication || code == ResultCode.SortControlMissing || code == ResultCode.OffsetRangeError || code == ResultCode.VirtualListViewError || code == ResultCode.Other); 49 | } 50 | 51 | internal static IntPtr AllocHGlobalIntPtrArray(int size) 52 | { 53 | checked 54 | { 55 | IntPtr intPtrArray = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * size); 56 | for (int i = 0; i < size; i++) 57 | { 58 | IntPtr tempPtr = (IntPtr)((long)intPtrArray + Marshal.SizeOf(typeof(IntPtr)) * i); 59 | Marshal.WriteIntPtr(tempPtr, IntPtr.Zero); 60 | } 61 | return intPtrArray; 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/ldap/LdapAsyncResult.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Threading; 6 | using Microsoft.Win32.SafeHandles; 7 | 8 | namespace System.DirectoryServices.Protocols 9 | { 10 | internal class LdapAsyncResult : IAsyncResult 11 | { 12 | private LdapAsyncWaitHandle _asyncWaitHandle = null; 13 | internal AsyncCallback _callback = null; 14 | internal bool _completed = false; 15 | private bool _completedSynchronously = false; 16 | internal ManualResetEvent _manualResetEvent = null; 17 | private object _stateObject = null; 18 | internal LdapRequestState _resultObject = null; 19 | internal bool _partialResults = false; 20 | 21 | public LdapAsyncResult(AsyncCallback callbackRoutine, object state, bool partialResults) 22 | { 23 | _stateObject = state; 24 | _callback = callbackRoutine; 25 | _manualResetEvent = new ManualResetEvent(false); 26 | _partialResults = partialResults; 27 | } 28 | 29 | object IAsyncResult.AsyncState => _stateObject; 30 | 31 | WaitHandle IAsyncResult.AsyncWaitHandle 32 | { 33 | get => _asyncWaitHandle ?? (_asyncWaitHandle = new LdapAsyncWaitHandle(_manualResetEvent.SafeWaitHandle)); 34 | } 35 | 36 | bool IAsyncResult.CompletedSynchronously => _completedSynchronously; 37 | 38 | bool IAsyncResult.IsCompleted => _completed; 39 | 40 | public override int GetHashCode() => _manualResetEvent.GetHashCode(); 41 | 42 | public override bool Equals(object obj) 43 | { 44 | if (!(obj is LdapAsyncResult otherAsyncResult)) 45 | { 46 | return false; 47 | } 48 | 49 | return this == otherAsyncResult; 50 | } 51 | 52 | private sealed class LdapAsyncWaitHandle : WaitHandle 53 | { 54 | public LdapAsyncWaitHandle(SafeWaitHandle handle) : base() 55 | { 56 | SafeWaitHandle = handle; 57 | } 58 | 59 | ~LdapAsyncWaitHandle() => SafeWaitHandle = null; 60 | } 61 | } 62 | 63 | internal class LdapRequestState 64 | { 65 | internal DirectoryResponse _response = null; 66 | internal LdapAsyncResult _ldapAsync = null; 67 | internal Exception _exception = null; 68 | internal bool _abortCalled = false; 69 | 70 | public LdapRequestState() { } 71 | } 72 | 73 | internal enum ResultsStatus 74 | { 75 | PartialResult = 0, 76 | CompleteResult = 1, 77 | Done = 2 78 | } 79 | 80 | internal class LdapPartialAsyncResult : LdapAsyncResult 81 | { 82 | internal LdapConnection _con; 83 | internal int _messageID = -1; 84 | internal bool _partialCallback; 85 | internal ResultsStatus _resultStatus = ResultsStatus.PartialResult; 86 | internal TimeSpan _requestTimeout; 87 | 88 | internal SearchResponse _response = null; 89 | internal Exception _exception = null; 90 | internal DateTime _startTime; 91 | 92 | public LdapPartialAsyncResult(int messageID, AsyncCallback callbackRoutine, object state, bool partialResults, LdapConnection con, bool partialCallback, TimeSpan requestTimeout) : base(callbackRoutine, state, partialResults) 93 | { 94 | _messageID = messageID; 95 | _con = con; 96 | _partialResults = true; 97 | _partialCallback = partialCallback; 98 | _requestTimeout = requestTimeout; 99 | _startTime = DateTime.Now; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/ldap/LdapDirectoryIdentifier.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | namespace System.DirectoryServices.Protocols 6 | { 7 | public class LdapDirectoryIdentifier : DirectoryIdentifier 8 | { 9 | private string[] _servers = null; 10 | 11 | public LdapDirectoryIdentifier(string server) : this(server != null ? new string[] { server } : null, false, false) 12 | { 13 | } 14 | 15 | public LdapDirectoryIdentifier(string server, int portNumber) : this(server != null ? new string[] { server } : null, portNumber, false, false) 16 | { 17 | } 18 | 19 | public LdapDirectoryIdentifier(string server, bool fullyQualifiedDnsHostName, bool connectionless) : this(server != null ? new string[] { server } : null, fullyQualifiedDnsHostName, connectionless) 20 | { 21 | } 22 | 23 | public LdapDirectoryIdentifier(string server, int portNumber, bool fullyQualifiedDnsHostName, bool connectionless) : this(server != null ? new string[] { server } : null, portNumber, fullyQualifiedDnsHostName, connectionless) 24 | { 25 | } 26 | 27 | public LdapDirectoryIdentifier(string[] servers, bool fullyQualifiedDnsHostName, bool connectionless) 28 | { 29 | // validate the servers, we don't allow space in the server name 30 | if (servers != null) 31 | { 32 | _servers = new string[servers.Length]; 33 | for (int i = 0; i < servers.Length; i++) 34 | { 35 | if (servers[i] != null) 36 | { 37 | string trimmedName = servers[i].Trim(); 38 | string[] result = trimmedName.Split(new char[] { ' ' }); 39 | if (result.Length > 1) 40 | { 41 | throw new ArgumentException(SR.WhiteSpaceServerName); 42 | } 43 | 44 | _servers[i] = trimmedName; 45 | } 46 | } 47 | } 48 | 49 | FullyQualifiedDnsHostName = fullyQualifiedDnsHostName; 50 | Connectionless = connectionless; 51 | } 52 | 53 | public LdapDirectoryIdentifier(string[] servers, int portNumber, bool fullyQualifiedDnsHostName, bool connectionless) : this(servers, fullyQualifiedDnsHostName, connectionless) 54 | { 55 | PortNumber = portNumber; 56 | } 57 | 58 | public string[] Servers 59 | { 60 | get 61 | { 62 | if (_servers == null) 63 | { 64 | return Array.Empty(); 65 | } 66 | 67 | var temporaryServers = new string[_servers.Length]; 68 | for (int i = 0; i < _servers.Length; i++) 69 | { 70 | if (_servers[i] != null) 71 | { 72 | temporaryServers[i] = string.Copy(_servers[i]); 73 | } 74 | else 75 | { 76 | temporaryServers[i] = null; 77 | } 78 | } 79 | 80 | return temporaryServers; 81 | } 82 | } 83 | 84 | public bool Connectionless { get; } 85 | 86 | public bool FullyQualifiedDnsHostName { get; } 87 | 88 | public int PortNumber { get; } = 389; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/ldap/LdapException.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using System.Runtime.Serialization; 7 | 8 | namespace System.DirectoryServices.Protocols 9 | { 10 | internal enum LdapError 11 | { 12 | IsLeaf = 0x23, 13 | InvalidCredentials = 49, 14 | ServerDown = 0x51, 15 | LocalError = 0x52, 16 | EncodingError = 0x53, 17 | DecodingError = 0x54, 18 | TimeOut = 0x55, 19 | AuthUnknown = 0x56, 20 | FilterError = 0x57, 21 | UserCancelled = 0x58, 22 | ParameterError = 0x59, 23 | NoMemory = 0x5a, 24 | ConnectError = 0x5b, 25 | NotSupported = 0x5c, 26 | NoResultsReturned = 0x5e, 27 | ControlNotFound = 0x5d, 28 | MoreResults = 0x5f, 29 | ClientLoop = 0x60, 30 | ReferralLimitExceeded = 0x61, 31 | SendTimeOut = 0x70 32 | } 33 | 34 | internal class LdapErrorMappings 35 | { 36 | private static readonly Dictionary s_resultCodeMapping = new Dictionary(capacity: 20) 37 | { 38 | { LdapError.IsLeaf, SR.LDAP_IS_LEAF }, 39 | { LdapError.InvalidCredentials, SR.LDAP_INVALID_CREDENTIALS }, 40 | { LdapError.ServerDown, SR.LDAP_SERVER_DOWN }, 41 | { LdapError.LocalError, SR.LDAP_LOCAL_ERROR }, 42 | { LdapError.EncodingError, SR.LDAP_ENCODING_ERROR }, 43 | { LdapError.DecodingError, SR.LDAP_DECODING_ERROR }, 44 | { LdapError.TimeOut, SR.LDAP_TIMEOUT }, 45 | { LdapError.AuthUnknown, SR.LDAP_AUTH_UNKNOWN }, 46 | { LdapError.FilterError, SR.LDAP_FILTER_ERROR }, 47 | { LdapError.UserCancelled, SR.LDAP_USER_CANCELLED }, 48 | { LdapError.ParameterError, SR.LDAP_PARAM_ERROR }, 49 | { LdapError.NoMemory, SR.LDAP_NO_MEMORY }, 50 | { LdapError.ConnectError, SR.LDAP_CONNECT_ERROR }, 51 | { LdapError.NotSupported, SR.LDAP_NOT_SUPPORTED }, 52 | { LdapError.NoResultsReturned, SR.LDAP_NO_RESULTS_RETURNED }, 53 | { LdapError.ControlNotFound, SR.LDAP_CONTROL_NOT_FOUND }, 54 | { LdapError.MoreResults, SR.LDAP_MORE_RESULTS_TO_RETURN }, 55 | { LdapError.ClientLoop, SR.LDAP_CLIENT_LOOP }, 56 | { LdapError.ReferralLimitExceeded, SR.LDAP_REFERRAL_LIMIT_EXCEEDED }, 57 | { LdapError.SendTimeOut, SR.LDAP_SEND_TIMEOUT } 58 | }; 59 | 60 | public static string MapResultCode(int errorCode) 61 | { 62 | s_resultCodeMapping.TryGetValue((LdapError)errorCode, out string errorMessage); 63 | return errorMessage; 64 | } 65 | } 66 | 67 | [Serializable] 68 | [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] 69 | public class LdapException : DirectoryException, ISerializable 70 | { 71 | protected LdapException(SerializationInfo info, StreamingContext context) : base(info, context) { } 72 | 73 | public LdapException() : base() { } 74 | 75 | public LdapException(string message) : base(message) { } 76 | 77 | public LdapException(string message, Exception inner) : base(message, inner) { } 78 | 79 | public LdapException(int errorCode) : base(SR.DefaultLdapError) 80 | { 81 | ErrorCode = errorCode; 82 | } 83 | 84 | public LdapException(int errorCode, string message) : base(message) 85 | { 86 | ErrorCode = errorCode; 87 | } 88 | 89 | public LdapException(int errorCode, string message, string serverErrorMessage) : base(message) 90 | { 91 | ErrorCode = errorCode; 92 | ServerErrorMessage = serverErrorMessage; 93 | } 94 | 95 | public LdapException(int errorCode, string message, Exception inner) : base(message, inner) 96 | { 97 | ErrorCode = errorCode; 98 | } 99 | 100 | public int ErrorCode { get; } 101 | 102 | public string ServerErrorMessage { get; } 103 | 104 | public PartialResultsCollection PartialResults { get; } = new PartialResultsCollection(); 105 | } 106 | 107 | [Serializable] 108 | [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] 109 | public class TlsOperationException : DirectoryOperationException 110 | { 111 | protected TlsOperationException(SerializationInfo info, StreamingContext context) : base(info, context) { } 112 | 113 | public TlsOperationException() : base() { } 114 | 115 | public TlsOperationException(string message) : base(message) { } 116 | 117 | public TlsOperationException(string message, Exception inner) : base(message, inner) { } 118 | 119 | public TlsOperationException(DirectoryResponse response) : base(response) 120 | { 121 | } 122 | 123 | public TlsOperationException(DirectoryResponse response, string message) : base(response, message) 124 | { 125 | } 126 | 127 | public TlsOperationException(DirectoryResponse response, string message, Exception inner) : base(response, message, inner) 128 | { 129 | } 130 | } 131 | 132 | internal class ErrorChecking 133 | { 134 | public static void CheckAndSetLdapError(int error) 135 | { 136 | if (error != (int)ResultCode.Success) 137 | { 138 | if (Utility.IsResultCode((ResultCode)error)) 139 | { 140 | string errorMessage = OperationErrorMappings.MapResultCode(error); 141 | throw new DirectoryOperationException(null, errorMessage); 142 | } 143 | else if (Utility.IsLdapError((LdapError)error)) 144 | { 145 | string errorMessage = LdapErrorMappings.MapResultCode(error); 146 | throw new LdapException(error, errorMessage); 147 | } 148 | else 149 | { 150 | throw new LdapException(error); 151 | } 152 | } 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/System.DirectoryServices.Protocols/System/DirectoryServices/Protocols/ldap/SafeHandles.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Microsoft.Win32.SafeHandles; 6 | using System.Runtime.InteropServices; 7 | using System.Security; 8 | 9 | namespace System.DirectoryServices.Protocols 10 | { 11 | internal sealed class BerSafeHandle : SafeHandleZeroOrMinusOneIsInvalid 12 | { 13 | internal BerSafeHandle() : base(true) 14 | { 15 | SetHandle(Wldap32.ber_alloc(1)); 16 | if (handle == IntPtr.Zero) 17 | { 18 | throw new OutOfMemoryException(); 19 | } 20 | } 21 | 22 | internal BerSafeHandle(berval value) : base(true) 23 | { 24 | SetHandle(Wldap32.ber_init(value)); 25 | if (handle == IntPtr.Zero) 26 | { 27 | throw new BerConversionException(); 28 | } 29 | } 30 | 31 | override protected bool ReleaseHandle() 32 | { 33 | Wldap32.ber_free(handle, 1); 34 | return true; 35 | } 36 | } 37 | 38 | internal sealed class HGlobalMemHandle : SafeHandleZeroOrMinusOneIsInvalid 39 | { 40 | internal HGlobalMemHandle(IntPtr value) : base(true) 41 | { 42 | SetHandle(value); 43 | } 44 | 45 | override protected bool ReleaseHandle() 46 | { 47 | Marshal.FreeHGlobal(handle); 48 | return true; 49 | } 50 | } 51 | 52 | internal sealed class ConnectionHandle : SafeHandleZeroOrMinusOneIsInvalid 53 | { 54 | internal bool _needDispose = false; 55 | 56 | internal ConnectionHandle() : base(true) 57 | { 58 | SetHandle(Wldap32.ldap_init(null, 389)); 59 | 60 | if (handle == IntPtr.Zero) 61 | { 62 | int error = Wldap32.LdapGetLastError(); 63 | if (Utility.IsLdapError((LdapError)error)) 64 | { 65 | string errorMessage = LdapErrorMappings.MapResultCode(error); 66 | throw new LdapException(error, errorMessage); 67 | } 68 | else 69 | { 70 | throw new LdapException(error); 71 | } 72 | } 73 | } 74 | 75 | internal ConnectionHandle(IntPtr value, bool disposeHandle) : base(true) 76 | { 77 | _needDispose = disposeHandle; 78 | if (value == IntPtr.Zero) 79 | { 80 | int error = Wldap32.LdapGetLastError(); 81 | if (Utility.IsLdapError((LdapError)error)) 82 | { 83 | string errorMessage = LdapErrorMappings.MapResultCode(error); 84 | throw new LdapException(error, errorMessage); 85 | } 86 | else 87 | { 88 | throw new LdapException(error); 89 | } 90 | } 91 | else 92 | { 93 | SetHandle(value); 94 | } 95 | } 96 | override protected bool ReleaseHandle() 97 | { 98 | if (handle != IntPtr.Zero) 99 | { 100 | if (_needDispose) 101 | { 102 | Wldap32.ldap_unbind(handle); 103 | } 104 | 105 | handle = IntPtr.Zero; 106 | } 107 | return true; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /tests/AddRequestTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Xunit; 8 | 9 | namespace System.DirectoryServices.Protocols.Tests 10 | { 11 | public class AddRequestTests 12 | { 13 | [Fact] 14 | public void Ctor_Default() 15 | { 16 | var request = new AddRequest(); 17 | Assert.Empty(request.Attributes); 18 | Assert.Empty(request.Controls); 19 | Assert.Null(request.DistinguishedName); 20 | Assert.Null(request.RequestId); 21 | } 22 | 23 | public static IEnumerable Ctor_DistinguishedName_Attributes_TestData() 24 | { 25 | yield return new object[] { null, null }; 26 | yield return new object[] { string.Empty, new DirectoryAttribute[0] }; 27 | yield return new object[] { "DistinguishedName", new DirectoryAttribute[] { new DirectoryAttribute("name", "value") } }; 28 | } 29 | 30 | [Theory] 31 | [MemberData(nameof(Ctor_DistinguishedName_Attributes_TestData))] 32 | public void Ctor_DistinguishedString_Attributes(string distinguishedName, DirectoryAttribute[] attributes) 33 | { 34 | var request = new AddRequest(distinguishedName, attributes); 35 | Assert.Equal(attributes ?? Enumerable.Empty(), request.Attributes.Cast()); 36 | Assert.Empty(request.Controls); 37 | Assert.Equal(distinguishedName, request.DistinguishedName); 38 | Assert.Null(request.RequestId); 39 | } 40 | 41 | [Fact] 42 | public void Ctor_NullObjectInAttributes_ThrowsArgumentException() 43 | { 44 | AssertExtensions.Throws(null, () => new AddRequest("DistinguishedName", new DirectoryAttribute[] { null })); 45 | } 46 | 47 | [Theory] 48 | [InlineData(null, "")] 49 | [InlineData("DistinguishedName", "ObjectClass")] 50 | public void Ctor_DistinguishedName_ObjectClass(string distinguishedName, string objectClass) 51 | { 52 | var request = new AddRequest(distinguishedName, objectClass); 53 | DirectoryAttribute attribute = (DirectoryAttribute)Assert.Single(request.Attributes); 54 | Assert.Equal("objectClass", attribute.Name); 55 | Assert.Equal(new string[] { objectClass }, attribute.GetValues(typeof(string))); 56 | 57 | Assert.Empty(request.Controls); 58 | Assert.Equal(distinguishedName, request.DistinguishedName); 59 | Assert.Null(request.RequestId); 60 | } 61 | 62 | [Fact] 63 | public void Ctor_NullObjectClass_ThrowsArgumentNullException() 64 | { 65 | AssertExtensions.Throws("objectClass", () => new AddRequest("DistinguishedName", (string)null)); 66 | } 67 | 68 | [Fact] 69 | public void DistinguishedName_Set_GetReturnsExpected() 70 | { 71 | var request = new AddRequest { DistinguishedName = "Name" }; 72 | Assert.Equal("Name", request.DistinguishedName); 73 | } 74 | 75 | [Fact] 76 | public void RequestId_Set_GetReturnsExpected() 77 | { 78 | var request = new AddRequest { RequestId = "Id" }; 79 | Assert.Equal("Id", request.RequestId); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/AsqRequestControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class AsqRequestControlTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var control = new AsqRequestControl(); 15 | Assert.Null(control.AttributeName); 16 | Assert.True(control.IsCritical); 17 | Assert.True(control.ServerSide); 18 | Assert.Equal("1.2.840.113556.1.4.1504", control.Type); 19 | 20 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 2, 4, 0 }, control.GetValue()); 21 | } 22 | 23 | [Theory] 24 | [InlineData(null, new byte[] { 48, 132, 0, 0, 0, 2, 4, 0 })] 25 | [InlineData("", new byte[] { 48, 132, 0, 0, 0, 2, 4, 0 })] 26 | [InlineData("A", new byte[] { 48, 132, 0, 0, 0, 3, 4, 1, 65 })] 27 | public void Ctor_String(string attributeName, byte[] expectedValue) 28 | { 29 | var control = new AsqRequestControl(attributeName); 30 | Assert.Equal(attributeName, control.AttributeName); 31 | Assert.True(control.IsCritical); 32 | Assert.True(control.ServerSide); 33 | Assert.Equal("1.2.840.113556.1.4.1504", control.Type); 34 | 35 | Assert.Equal(expectedValue, control.GetValue()); 36 | } 37 | 38 | [Fact] 39 | public void AttributeName_Set_GetReturnsExpected() 40 | { 41 | var control = new AsqRequestControl { AttributeName = "Name" }; 42 | Assert.Equal("Name", control.AttributeName); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/BerConversionExceptionTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.IO; 6 | using System.Reflection; 7 | using System.Runtime.Serialization; 8 | using System.Runtime.Serialization.Formatters.Binary; 9 | using Xunit; 10 | 11 | namespace System.DirectoryServices.Protocols.Tests 12 | { 13 | public class BerConversionExceptionTests 14 | { 15 | [Fact] 16 | public void Ctor_Default() 17 | { 18 | var exception = new BerConversionException(); 19 | Assert.NotEmpty(exception.Message); 20 | Assert.Null(exception.InnerException); 21 | } 22 | 23 | [Fact] 24 | public void Ctor_Message() 25 | { 26 | var exception = new BerConversionException("message"); 27 | Assert.Equal("message", exception.Message); 28 | Assert.Null(exception.InnerException); 29 | } 30 | 31 | [Fact] 32 | public void Ctor_Message_InnerException() 33 | { 34 | var innerException = new Exception(); 35 | var exception = new BerConversionException("message", innerException); 36 | Assert.Equal("message", exception.Message); 37 | Assert.Same(innerException, exception.InnerException); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/BerConverterTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.Linq; 8 | using Xunit; 9 | 10 | //NOTE: Not all test will run successfully thanks to this; 11 | // https://github.com/dotnet/coreclr/issues/2502 12 | 13 | namespace System.DirectoryServices.Protocols.Tests 14 | { 15 | public class BerConverterTests 16 | { 17 | public static IEnumerable Encode_TestData() 18 | { 19 | yield return new object[] { "", null, new byte[0] }; 20 | yield return new object[] { "", new object[10], new byte[0] }; 21 | yield return new object[] { "b", new object[] { true, false, true, false }, new byte[] { 1, 1, 255 } }; 22 | yield return new object[] { "{", new object[] { "a" }, new byte[] { 48, 0, 0, 0, 0, 0 } }; 23 | yield return new object[] { "{}", new object[] { "a" }, new byte[] { 48, 132, 0, 0, 0, 0 } }; 24 | yield return new object[] { "[", new object[] { "a" }, new byte[] { 49, 0, 0, 0, 0, 0 } }; 25 | yield return new object[] { "[]", new object[] { "a" }, new byte[] { 49, 132, 0, 0, 0, 0 } }; 26 | yield return new object[] { "n", new object[] { "a" }, new byte[] { 5, 0 } }; 27 | yield return new object[] { "tetie", new object[] { -1, 0, 1, 2, 3 }, new byte[] { 255, 1, 0, 1, 1, 2, 10, 1, 3 } }; 28 | yield return new object[] { "{tetie}", new object[] { -1, 0, 1, 2, 3 }, new byte[] { 48, 132, 0, 0, 0, 9, 255, 1, 0, 1, 1, 2, 10, 1, 3 } }; 29 | yield return new object[] { "bb", new object[] { true, false }, new byte[] { 1, 1, 255, 1, 1, 0 } }; 30 | yield return new object[] { "{bb}", new object[] { true, false }, new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 } }; 31 | yield return new object[] { "ssss", new object[] { null, "", "abc", "\0" }, new byte[] { 4, 0, 4, 0, 4, 3, 97, 98, 99, 4, 1, 0 } }; 32 | yield return new object[] { "oXo", new object[] { null, new byte[] { 0, 1, 2, 255 }, new byte[0] }, new byte[] { 4, 0, 3, 4, 0, 1, 2, 255, 4, 0 } }; 33 | yield return new object[] { "vv", new object[] { null, new string[] { "abc", "", null } }, new byte[] { 4, 3, 97, 98, 99, 4, 0, 4, 0 } }; 34 | yield return new object[] { "{vv}", new object[] { null, new string[] { "abc", "", null } }, new byte[] { 48, 132, 0, 0, 0, 9, 4, 3, 97, 98, 99, 4, 0, 4, 0 } }; 35 | yield return new object[] { "VVVV", new object[] { null, new byte[][] { new byte[] { 0, 1, 2, 3 }, null }, new byte[][] { new byte[0] }, new byte[0][] }, new byte[] { 4, 4, 0, 1, 2, 3, 4, 0, 4, 0 } }; 36 | } 37 | 38 | [Theory] 39 | [MemberData(nameof(Encode_TestData))] 40 | public void Encode_Objects_ReturnsExpected(string format, object[] values, byte[] expected) 41 | { 42 | Console.WriteLine("format:" + format); 43 | AssertExtensions.Equal(expected, BerConverter.Encode(format, values)); 44 | } 45 | 46 | [Fact] 47 | public void Encode_NullFormat_ThrowsArgumentNullException() 48 | { 49 | AssertExtensions.Throws("format", () => BerConverter.Encode(null, new object[0])); 50 | } 51 | 52 | public static IEnumerable Encode_Invalid_TestData() 53 | { 54 | yield return new object[] { "t", new object[0] }; 55 | yield return new object[] { "t", new object[] { "string" } }; 56 | yield return new object[] { "t", new object[] { null } }; 57 | 58 | yield return new object[] { "i", new object[0] }; 59 | yield return new object[] { "i", new object[] { "string" } }; 60 | yield return new object[] { "i", new object[] { null } }; 61 | 62 | yield return new object[] { "e", new object[0] }; 63 | yield return new object[] { "e", new object[] { "string" } }; 64 | yield return new object[] { "e", new object[] { null } }; 65 | 66 | yield return new object[] { "b", new object[0] }; 67 | yield return new object[] { "b", new object[] { "string" } }; 68 | yield return new object[] { "b", new object[] { null } }; 69 | 70 | yield return new object[] { "s", new object[0] }; 71 | yield return new object[] { "s", new object[] { 123 } }; 72 | 73 | yield return new object[] { "o", new object[0] }; 74 | yield return new object[] { "o", new object[] { "string" } }; 75 | yield return new object[] { "o", new object[] { 123 } }; 76 | 77 | yield return new object[] { "X", new object[0] }; 78 | yield return new object[] { "X", new object[] { "string" } }; 79 | yield return new object[] { "X", new object[] { 123 } }; 80 | 81 | yield return new object[] { "v", new object[0] }; 82 | yield return new object[] { "v", new object[] { "string" } }; 83 | yield return new object[] { "v", new object[] { 123 } }; 84 | 85 | yield return new object[] { "V", new object[0] }; 86 | yield return new object[] { "V", new object[] { "string" } }; 87 | yield return new object[] { "V", new object[] { new byte[0] } }; 88 | 89 | yield return new object[] { "a", new object[0] }; 90 | } 91 | 92 | [Theory] 93 | [MemberData(nameof(Encode_Invalid_TestData))] 94 | public void Encode_Invalid_ThrowsArgumentException(string format, object[] values) 95 | { 96 | try 97 | { 98 | AssertExtensions.Throws(null, () => BerConverter.Encode(format, values)); 99 | } 100 | catch (System.Exception ex) 101 | { 102 | Console.WriteLine(ex.GetType().Name + ":" + ex.Message); 103 | } 104 | } 105 | 106 | [Theory] 107 | [InlineData("]")] 108 | [InlineData("}")] 109 | [InlineData("{{}}}")] 110 | public void Encode_InvalidFormat_ThrowsBerConversionException(string format) 111 | { 112 | Assert.Throws(() => BerConverter.Encode(format, new object[0])); 113 | } 114 | 115 | public static IEnumerable Decode_TestData() 116 | { 117 | yield return new object[] { "{}", new byte[] { 48, 0, 0, 0, 0, 0 }, new object[0] }; 118 | yield return new object[] { "{a}", new byte[] { 48, 132, 0, 0, 0, 5, 4, 3, 97, 98, 99 }, new object[] { "abc" } }; 119 | yield return new object[] { "{ie}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 }, new object[] { -1, 0 } }; 120 | yield return new object[] { "{bb}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 }, new object[] { true, false } }; 121 | yield return new object[] { "{OO}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 }, new object[] { new byte[] { 255 }, new byte[] { 0 } } }; 122 | yield return new object[] { "{BB}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 }, new object[] { new byte[] { 255 }, new byte[] { 0 } } }; 123 | yield return new object[] { "{vv}", new byte[] { 48, 132, 0, 0, 0, 9, 4, 3, 97, 98, 99, 4, 0, 4, 0 }, new object[] { null, null } }; 124 | yield return new object[] { "{vv}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 }, new object[] { new string[] { "\x01" }, null } }; 125 | yield return new object[] { "{VV}", new byte[] { 48, 132, 0, 0, 0, 9, 4, 3, 97, 98, 99, 4, 0, 4, 0 }, new object[] { null, null } }; 126 | yield return new object[] { "{VV}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 }, new object[] { new byte[][] { new byte[] { 1 } }, null } }; 127 | } 128 | 129 | [Theory] 130 | [MemberData(nameof(Decode_TestData))] 131 | public void Decode_Bytes_ReturnsExpected(string format, byte[] values, object[] expected) 132 | { 133 | object value = BerConverter.Decode(format, values); 134 | Assert.Equal(expected, value); 135 | } 136 | 137 | [Fact] 138 | public void Decode_NullFormat_ThrowsArgumentNullException() 139 | { 140 | AssertExtensions.Throws("format", () => BerConverter.Decode(null, new byte[0])); 141 | } 142 | 143 | [Theory] 144 | [InlineData("p", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 })] 145 | public void UnknownFormat_ThrowsArgumentException(string format, byte[] values) 146 | { 147 | AssertExtensions.Throws(null, () => BerConverter.Decode(format, values)); 148 | } 149 | /* 150 | [Theory] 151 | [InlineData("n", null)] 152 | [InlineData("n", new byte[0])] 153 | [InlineData("{", new byte[] { 1 })] 154 | [InlineData("}", new byte[] { 1 })] 155 | [InlineData("{}{}{}{}{}{}{}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 })] 156 | [InlineData("aaa", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 })] 157 | [InlineData("iii", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 })] 158 | [InlineData("eee", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 })] 159 | [InlineData("bbb", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 })] 160 | [InlineData("OOO", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 })] 161 | [InlineData("BBB", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 })] 162 | public void Decode_Invalid_ThrowsBerConversionException(string format, byte[] values) 163 | { 164 | var hexValues = string.Join(",", values?.Select(v => v.ToString("X2")) ?? new string[] { "null" }); 165 | Console.WriteLine("Decode_Invalid_ThrowsBerConversionException format:" + format + " values:" + hexValues); 166 | 167 | Assert.Throws(() => BerConverter.Decode(format, values)); 168 | } */ 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /tests/CompareRequestTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using Xunit; 7 | 8 | namespace System.DirectoryServices.Protocols.Tests 9 | { 10 | public class CompareRequestTests 11 | { 12 | [Fact] 13 | public void Ctor_Default() 14 | { 15 | var request = new CompareRequest(); 16 | Assert.Empty(request.Assertion); 17 | Assert.Empty(request.Controls); 18 | Assert.Null(request.DistinguishedName); 19 | Assert.Null(request.RequestId); 20 | } 21 | 22 | [Theory] 23 | [InlineData(null, "", "")] 24 | [InlineData("DistinguishedName", "AttributeName", "value")] 25 | public void Ctor_DistinguishedName_AttributeName_StringValue(string distinguishedName, string attributeName, string value) 26 | { 27 | var request = new CompareRequest(distinguishedName, attributeName, value); 28 | Assert.Equal(attributeName, request.Assertion.Name); 29 | Assert.Equal(new string[] { value }, request.Assertion.GetValues(typeof(string))); 30 | 31 | Assert.Empty(request.Controls); 32 | Assert.Equal(distinguishedName, request.DistinguishedName); 33 | Assert.Null(request.RequestId); 34 | } 35 | 36 | [Theory] 37 | [InlineData(null, "", new byte[0])] 38 | [InlineData("DistinguishedName", "AttributeName", new byte[] { 1, 2, 3 })] 39 | public void Ctor_DistinguishedName_AttributeName_ByteArrayValue(string distinguishedName, string attributeName, byte[] value) 40 | { 41 | var request = new CompareRequest(distinguishedName, attributeName, value); 42 | Assert.Equal(attributeName, request.Assertion.Name); 43 | Assert.Equal(new byte[][] { value }, request.Assertion.GetValues(typeof(byte[]))); 44 | 45 | Assert.Empty(request.Controls); 46 | Assert.Equal(distinguishedName, request.DistinguishedName); 47 | Assert.Null(request.RequestId); 48 | } 49 | 50 | [Fact] 51 | public void Ctor_DistinguishedName_AttributeName_Uri() 52 | { 53 | var uri = new Uri("http://microsoft.com"); 54 | var request = new CompareRequest("DistinguishedName", "AttributeName", uri); 55 | 56 | Assert.Equal("AttributeName", request.Assertion.Name); 57 | Assert.Equal(uri, Assert.Single(request.Assertion)); 58 | 59 | Assert.Empty(request.Controls); 60 | Assert.Equal("DistinguishedName", request.DistinguishedName); 61 | Assert.Null(request.RequestId); 62 | } 63 | 64 | [Fact] 65 | public void Ctor_NullAttributeName_ThrowsArgumentNullException() 66 | { 67 | AssertExtensions.Throws("attributeName", () => new CompareRequest("DistinguishedName", null, "Value")); 68 | AssertExtensions.Throws("attributeName", () => new CompareRequest("DistinguishedName", null, new byte[0])); 69 | AssertExtensions.Throws("attributeName", () => new CompareRequest("DistinguishedName", null, new Uri("http://microsoft.com"))); 70 | } 71 | 72 | [Fact] 73 | public void Ctor_NullValue_ThrowsArgumentNullException() 74 | { 75 | AssertExtensions.Throws("value", () => new CompareRequest("DistinguishedName", "AttributeName", (string)null)); 76 | AssertExtensions.Throws("value", () => new CompareRequest("DistinguishedName", "AttributeName", (byte[])null)); 77 | AssertExtensions.Throws("value", () => new CompareRequest("DistinguishedName", "AttributeName", (Uri)null)); 78 | } 79 | 80 | [Fact] 81 | public void Ctor_DistinguishedName_Assertion() 82 | { 83 | var assertion = new DirectoryAttribute { "value" }; 84 | var request = new CompareRequest("DistinguishedName", assertion); 85 | 86 | Assert.NotSame(assertion, request.Assertion); 87 | Assert.Equal(assertion, request.Assertion); 88 | Assert.Empty(request.Controls); 89 | Assert.Equal("DistinguishedName", request.DistinguishedName); 90 | Assert.Null(request.RequestId); 91 | } 92 | 93 | [Fact] 94 | public void Ctor_NullAssertion_ThrowsArgumentNullException() 95 | { 96 | AssertExtensions.Throws("assertion", () => new CompareRequest("DistinguishedName", null)); 97 | } 98 | 99 | public static IEnumerable InvalidAssertion_TestData() 100 | { 101 | yield return new object[] { new DirectoryAttribute { "value1", "value2" } }; 102 | yield return new object[] { new DirectoryAttribute() }; 103 | } 104 | 105 | [Theory] 106 | [MemberData(nameof(InvalidAssertion_TestData))] 107 | public void Ctor_InvalidAssertion_ThrowsArgumentException(DirectoryAttribute assertion) 108 | { 109 | AssertExtensions.Throws(null, () => new CompareRequest("DistinguishedName", assertion)); 110 | } 111 | 112 | [Fact] 113 | public void DistinguishedName_Set_GetReturnsExpected() 114 | { 115 | var request = new CompareRequest { DistinguishedName = "Name" }; 116 | Assert.Equal("Name", request.DistinguishedName); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /tests/Configurations.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | netcoreapp-Windows_NT; 6 | netfx; 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/CrossDomainMoveControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class CrossDomainMoveControlTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var control = new CrossDomainMoveControl(); 15 | Assert.True(control.IsCritical); 16 | Assert.True(control.ServerSide); 17 | Assert.Null(control.TargetDomainController); 18 | Assert.Equal("1.2.840.113556.1.4.521", control.Type); 19 | 20 | Assert.Empty(control.GetValue()); 21 | } 22 | 23 | [Theory] 24 | [InlineData(null, new byte[0])] 25 | [InlineData("", new byte[] { 0, 0 })] 26 | [InlineData("A", new byte[] { 65, 0, 0 })] 27 | public void Ctor_String(string targetDomainController, byte[] expectedValue) 28 | { 29 | var control = new CrossDomainMoveControl(targetDomainController); 30 | Assert.True(control.IsCritical); 31 | Assert.True(control.ServerSide); 32 | Assert.Equal(targetDomainController, control.TargetDomainController); 33 | Assert.Equal("1.2.840.113556.1.4.521", control.Type); 34 | 35 | Assert.Equal(expectedValue, control.GetValue()); 36 | } 37 | 38 | [Fact] 39 | public void TargetDomainController_Set_GetReturnsExpected() 40 | { 41 | var control = new CrossDomainMoveControl { TargetDomainController = "Name" }; 42 | Assert.Equal("Name", control.TargetDomainController); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/DeleteRequestTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class DeleteRequestTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var request = new DeleteRequest(); 15 | Assert.Empty(request.Controls); 16 | Assert.Null(request.DistinguishedName); 17 | Assert.Null(request.RequestId); 18 | } 19 | 20 | [Theory] 21 | [InlineData(null)] 22 | [InlineData("DistinguishedName")] 23 | public void Ctor_DistinguishedName(string distinguishedName) 24 | { 25 | var request = new DeleteRequest(distinguishedName); 26 | Assert.Empty(request.Controls); 27 | Assert.Equal(distinguishedName, request.DistinguishedName); 28 | Assert.Null(request.RequestId); 29 | } 30 | 31 | [Fact] 32 | public void DistinguishedName_Set_GetReturnsExpected() 33 | { 34 | var request = new DeleteRequest { DistinguishedName = "Name" }; 35 | Assert.Equal("Name", request.DistinguishedName); 36 | } 37 | 38 | [Fact] 39 | public void RequestId_Set_GetReturnsExpected() 40 | { 41 | var request = new DeleteRequest { RequestId = "Id" }; 42 | Assert.Equal("Id", request.RequestId); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/DirSyncRequestControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Linq; 6 | using Xunit; 7 | 8 | namespace System.DirectoryServices.Protocols.Tests 9 | { 10 | public class DirSyncRequestControlTests 11 | { 12 | [Fact] 13 | public void Ctor_Default() 14 | { 15 | var control = new DirSyncRequestControl(); 16 | Assert.Equal(1048576, control.AttributeCount); 17 | Assert.Empty(control.Cookie); 18 | Assert.Equal(DirectorySynchronizationOptions.None, control.Option); 19 | 20 | Assert.True(control.IsCritical); 21 | Assert.True(control.ServerSide); 22 | Assert.Equal("1.2.840.113556.1.4.841", control.Type); 23 | 24 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 10, 2, 1, 0, 2, 3, 16, 0, 0, 4, 0 }, control.GetValue()); 25 | } 26 | 27 | [Theory] 28 | [InlineData(null, new byte[] { 48, 132, 0, 0, 0, 10, 2, 1, 0, 2, 3, 16, 0, 0, 4, 0 })] 29 | [InlineData(new byte[0], new byte[] { 48, 132, 0, 0, 0, 10, 2, 1, 0, 2, 3, 16, 0, 0, 4, 0 })] 30 | [InlineData(new byte[] { 97, 98, 99 }, new byte[] { 48, 132, 0, 0, 0, 13, 2, 1, 0, 2, 3, 16, 0, 0, 4, 3, 97, 98, 99 })] 31 | public void Ctor_Cookie(byte[] cookie, byte[] expectedValue) 32 | { 33 | var control = new DirSyncRequestControl(cookie); 34 | Assert.Equal(1048576, control.AttributeCount); 35 | Assert.Equal(cookie ?? Array.Empty(), control.Cookie); 36 | Assert.Equal(DirectorySynchronizationOptions.None, control.Option); 37 | 38 | Assert.True(control.IsCritical); 39 | Assert.True(control.ServerSide); 40 | Assert.Equal("1.2.840.113556.1.4.841", control.Type); 41 | 42 | Assert.Equal(expectedValue, control.GetValue()); 43 | } 44 | 45 | [Theory] 46 | [InlineData(null, DirectorySynchronizationOptions.None, new byte[] { 48, 132, 0, 0, 0, 10, 2, 1, 0, 2, 3, 16, 0, 0, 4, 0 })] 47 | [InlineData(new byte[0], DirectorySynchronizationOptions.None - 1, new byte[] { 0x30, 0x84, 0x00, 0x00, 0x00, 0x0A, 0x02, 0x01, 0xFF, 0x02, 0x03, 0x10, 0x00, 0x00, 0x04, 0x00 })]//NOTE: updated openldap 48 | [InlineData(new byte[] { 97, 98, 99 }, DirectorySynchronizationOptions.ObjectSecurity, new byte[] { 48, 132, 0, 0, 0, 13, 2, 1, 1, 2, 3, 16, 0, 0, 4, 3, 97, 98, 99 })] 49 | public void Ctor_Cookie_Options(byte[] cookie, DirectorySynchronizationOptions option, byte[] expectedValue) 50 | { 51 | var control = new DirSyncRequestControl(cookie, option); 52 | Assert.Equal(1048576, control.AttributeCount); 53 | Assert.Equal(cookie ?? Array.Empty(), control.Cookie); 54 | Assert.Equal(option, control.Option); 55 | 56 | Assert.True(control.IsCritical); 57 | Assert.True(control.ServerSide); 58 | Assert.Equal("1.2.840.113556.1.4.841", control.Type); 59 | 60 | Assert.Equal(expectedValue, control.GetValue()); 61 | } 62 | 63 | [Theory] 64 | [InlineData(null, DirectorySynchronizationOptions.None, 1048576, new byte[] { 48, 132, 0, 0, 0, 10, 2, 1, 0, 2, 3, 16, 0, 0, 4, 0 })] 65 | [InlineData(new byte[0], DirectorySynchronizationOptions.None - 1, 0, new byte[] { 48,132,0,0,0,8,2,1,255,2,1,0,4,0 })]//NOTE: updated openldap 66 | [InlineData(new byte[] { 97, 98, 99 }, DirectorySynchronizationOptions.ObjectSecurity, 10, new byte[] { 48, 132, 0, 0, 0, 11, 2, 1, 1, 2, 1, 10, 4, 3, 97, 98, 99 })] 67 | public void Ctor_Cookie_Options_AttributeCount(byte[] cookie, DirectorySynchronizationOptions option, int attributeCount, byte[] expectedValue) 68 | { 69 | var control = new DirSyncRequestControl(cookie, option, attributeCount); 70 | Assert.Equal(attributeCount, control.AttributeCount); 71 | Assert.Equal(cookie ?? Array.Empty(), control.Cookie); 72 | Assert.Equal(option, control.Option); 73 | 74 | Assert.True(control.IsCritical); 75 | Assert.True(control.ServerSide); 76 | Assert.Equal("1.2.840.113556.1.4.841", control.Type); 77 | 78 | Assert.Equal(expectedValue, control.GetValue()); 79 | } 80 | 81 | [Fact] 82 | public void Ctor_NegativeAttributeCount_ThrowsArgumentException() 83 | { 84 | AssertExtensions.Throws("value", () => new DirSyncRequestControl(new byte[0], DirectorySynchronizationOptions.None, -1)); 85 | } 86 | 87 | [Fact] 88 | public void AttributeCount_SetValid_GetReturnsExpected() 89 | { 90 | var control = new DirSyncRequestControl { AttributeCount = 0 }; 91 | Assert.Equal(0, control.AttributeCount); 92 | } 93 | 94 | [Fact] 95 | public void AttributeCount_SetNegative_ThrowsArgumentException() 96 | { 97 | var control = new DirSyncRequestControl(); 98 | AssertExtensions.Throws("value", () => control.AttributeCount = -1); 99 | } 100 | 101 | [Fact] 102 | public void Cookie_Set_GetReturnsExpected() 103 | { 104 | byte[] cookie = new byte[] { 1, 2, 3 }; 105 | var control = new DirSyncRequestControl { Cookie = cookie }; 106 | Assert.NotSame(cookie, control.Cookie); 107 | Assert.Equal(cookie, control.Cookie); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /tests/DirectoryAttributeCollectionTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using Xunit; 9 | 10 | namespace System.DirectoryServices.Protocols.Tests 11 | { 12 | public class DirectoryAttributeCollectionTests 13 | { 14 | [Fact] 15 | public void Ctor_Default() 16 | { 17 | var collection = new DirectoryAttributeCollection(); 18 | Assert.Equal(0, collection.Count); 19 | Assert.Equal(0, collection.Capacity); 20 | } 21 | 22 | [Fact] 23 | public void Indexer_Set_GetReturnsExpected() 24 | { 25 | var attribute = new DirectoryAttribute { "value" }; 26 | var collection = new DirectoryAttributeCollection { new DirectoryAttribute() }; 27 | collection[0] = attribute; 28 | Assert.Equal(attribute, collection[0]); 29 | } 30 | 31 | [Fact] 32 | public void Indexer_SetNull_ThrowsArgumentException() 33 | { 34 | var collection = new DirectoryAttributeCollection(); 35 | AssertExtensions.Throws(null, () => collection[0] = null); 36 | } 37 | 38 | [Fact] 39 | public void Add_ValidAttribute_AppendsToList() 40 | { 41 | var attribute1 = new DirectoryAttribute("name1", "value"); 42 | var attribute2 = new DirectoryAttribute("name2", "value"); 43 | var collection = new DirectoryAttributeCollection { attribute1, attribute2 }; 44 | Assert.Equal(2, collection.Count); 45 | Assert.Equal(new DirectoryAttribute[] { attribute1, attribute2 }, collection.Cast()); 46 | } 47 | 48 | [Fact] 49 | public void Add_NullAttribute_ThrowsArgumentException() 50 | { 51 | var collection = new DirectoryAttributeCollection(); 52 | AssertExtensions.Throws(null, () => collection.Add(null)); 53 | } 54 | 55 | [Fact] 56 | public void AddRange_ValidAttributes_AddsToCollection() 57 | { 58 | DirectoryAttribute[] attributes = new DirectoryAttribute[] { new DirectoryAttribute(), new DirectoryAttribute() }; 59 | 60 | var collection = new DirectoryAttributeCollection(); 61 | collection.AddRange(attributes); 62 | 63 | Assert.Equal(attributes, collection.Cast()); 64 | } 65 | 66 | [Fact] 67 | public void AddRange_NullAttributes_ThrowsArgumentNullException() 68 | { 69 | var collection = new DirectoryAttributeCollection(); 70 | AssertExtensions.Throws("attributes", () => collection.AddRange((DirectoryAttribute[])null)); 71 | } 72 | 73 | [Fact] 74 | public void AddRange_NullObjectInValues_ThrowsArgumentException() 75 | { 76 | DirectoryAttribute[] attributes = new DirectoryAttribute[] { new DirectoryAttribute(), null, new DirectoryAttribute() }; 77 | var collection = new DirectoryAttributeCollection(); 78 | 79 | AssertExtensions.Throws(null, () => collection.AddRange(attributes)); 80 | Assert.Equal(0, collection.Count); 81 | } 82 | 83 | [Fact] 84 | public void AddRange_ValidAttributeCollection_AddsToCollection() 85 | { 86 | DirectoryAttribute[] attributes = new DirectoryAttribute[] { new DirectoryAttribute(), new DirectoryAttribute() }; 87 | var attributeCollection = new DirectoryAttributeCollection(); 88 | attributeCollection.AddRange(attributes); 89 | 90 | var collection = new DirectoryAttributeCollection(); 91 | collection.AddRange(attributeCollection); 92 | 93 | Assert.Equal(attributes, collection.Cast()); 94 | } 95 | 96 | [Fact] 97 | public void AddRange_NullAttributeCollection_ThrowsArgumentNullException() 98 | { 99 | var collection = new DirectoryAttributeCollection(); 100 | AssertExtensions.Throws("attributeCollection", () => collection.AddRange((DirectoryAttributeCollection)null)); 101 | } 102 | 103 | [Fact] 104 | public void Contains_Valid_ReturnsExpected() 105 | { 106 | var attribute = new DirectoryAttribute { "value" }; 107 | var collection = new DirectoryAttributeCollection { attribute }; 108 | Assert.True(collection.Contains(attribute)); 109 | Assert.False(collection.Contains(new DirectoryAttribute())); 110 | Assert.False(collection.Contains(null)); 111 | } 112 | 113 | [Fact] 114 | public void CopyTo_MultipleTypes_Success() 115 | { 116 | DirectoryAttribute[] array = new DirectoryAttribute[3]; 117 | var attribute = new DirectoryAttribute { "value" }; 118 | 119 | var collection = new DirectoryAttributeCollection { attribute }; 120 | collection.CopyTo(array, 1); 121 | Assert.Equal(new DirectoryAttribute[] { null, attribute, null }, array); 122 | } 123 | 124 | [Fact] 125 | public void Insert_ValidDirectoryAttribute_Success() 126 | { 127 | var attribute1 = new DirectoryAttribute { "value1" }; 128 | var attribute2 = new DirectoryAttribute { "value2" }; 129 | var collection = new DirectoryAttributeCollection(); 130 | collection.Insert(0, attribute1); 131 | collection.Insert(1, attribute2); 132 | 133 | Assert.Equal(new DirectoryAttribute[] { attribute1, attribute2 }, collection.Cast()); 134 | } 135 | 136 | [Fact] 137 | public void Insert_NullValue_ThrowsArgumentException() 138 | { 139 | var collection = new DirectoryAttributeCollection(); 140 | AssertExtensions.Throws(null, () => collection.Insert(0, null)); 141 | } 142 | 143 | [Fact] 144 | public void IndexOf_Valid_ReturnsExpected() 145 | { 146 | var attribute = new DirectoryAttribute { "value" }; 147 | var collection = new DirectoryAttributeCollection { attribute }; 148 | Assert.Equal(0, collection.IndexOf(attribute)); 149 | Assert.Equal(-1, collection.IndexOf(new DirectoryAttribute())); 150 | Assert.Equal(-1, collection.IndexOf(null)); 151 | } 152 | 153 | [Fact] 154 | public void Remove_Valid_Success() 155 | { 156 | var attribute = new DirectoryAttribute { "value" }; 157 | var collection = new DirectoryAttributeCollection { attribute }; 158 | collection.Remove(attribute); 159 | Assert.Empty(collection); 160 | } 161 | 162 | public static IEnumerable Remove_InvalidValue_TestData() 163 | { 164 | yield return new object[] { null, null }; 165 | yield return new object[] { new DirectoryAttribute(), null }; 166 | yield return new object[] { 1, "value" }; 167 | } 168 | 169 | [Theory] 170 | [MemberData(nameof(Remove_InvalidValue_TestData))] 171 | public void Remove_InvalidValue_ThrowsArgumentException(object value, string paramName) 172 | { 173 | IList collection = new DirectoryAttributeCollection { new DirectoryAttribute() }; 174 | AssertExtensions.Throws(paramName, () => collection.Remove(value)); 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /tests/DirectoryAttributeModificationCollectionTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using Xunit; 9 | 10 | namespace System.DirectoryServices.Protocols.Tests 11 | { 12 | public class DirectoryAttributeModificationCollectionTests 13 | { 14 | [Fact] 15 | public void Ctor_Default() 16 | { 17 | var collection = new DirectoryAttributeModificationCollection(); 18 | Assert.Equal(0, collection.Count); 19 | Assert.Equal(0, collection.Capacity); 20 | } 21 | 22 | [Fact] 23 | public void Indexer_Set_GetReturnsExpected() 24 | { 25 | var attribute = new DirectoryAttributeModification { "value" }; 26 | var collection = new DirectoryAttributeModificationCollection { new DirectoryAttributeModification() }; 27 | collection[0] = attribute; 28 | Assert.Equal(attribute, collection[0]); 29 | } 30 | 31 | [Fact] 32 | public void Indexer_SetNull_ThrowsArgumentException() 33 | { 34 | var collection = new DirectoryAttributeModificationCollection(); 35 | AssertExtensions.Throws(null, () => collection[0] = null); 36 | } 37 | 38 | [Fact] 39 | public void Add_ValidAttribute_AppendsToList() 40 | { 41 | var attribute1 = new DirectoryAttributeModification { "value1" }; 42 | var attribute2 = new DirectoryAttributeModification { "value2" }; 43 | var collection = new DirectoryAttributeModificationCollection { attribute1, attribute2 }; 44 | Assert.Equal(2, collection.Count); 45 | Assert.Equal(new DirectoryAttributeModification[] { attribute1, attribute2 }, collection.Cast()); 46 | } 47 | 48 | [Fact] 49 | public void Add_NullAttribute_ThrowsArgumentException() 50 | { 51 | var collection = new DirectoryAttributeModificationCollection(); 52 | AssertExtensions.Throws(null, () => collection.Add(null)); 53 | } 54 | 55 | [Fact] 56 | public void AddRange_ValidAttributes_AddsToCollection() 57 | { 58 | DirectoryAttributeModification[] attributes = new DirectoryAttributeModification[] { new DirectoryAttributeModification(), new DirectoryAttributeModification() }; 59 | 60 | var collection = new DirectoryAttributeModificationCollection(); 61 | collection.AddRange(attributes); 62 | 63 | Assert.Equal(attributes, collection.Cast()); 64 | } 65 | 66 | [Fact] 67 | public void AddRange_NullAttributes_ThrowsArgumentNullException() 68 | { 69 | var collection = new DirectoryAttributeModificationCollection(); 70 | AssertExtensions.Throws("attributes", () => collection.AddRange((DirectoryAttributeModification[])null)); 71 | } 72 | 73 | [Fact] 74 | public void AddRange_NullObjectInValues_ThrowsArgumentException() 75 | { 76 | DirectoryAttributeModification[] attributes = new DirectoryAttributeModification[] { new DirectoryAttributeModification(), null, new DirectoryAttributeModification() }; 77 | var collection = new DirectoryAttributeModificationCollection(); 78 | 79 | AssertExtensions.Throws(null, () => collection.AddRange(attributes)); 80 | Assert.Equal(0, collection.Count); 81 | } 82 | 83 | [Fact] 84 | public void AddRange_ValidAttributeCollection_AddsToCollection() 85 | { 86 | DirectoryAttributeModification[] attributes = new DirectoryAttributeModification[] { new DirectoryAttributeModification(), new DirectoryAttributeModification() }; 87 | var attributeCollection = new DirectoryAttributeModificationCollection(); 88 | attributeCollection.AddRange(attributes); 89 | 90 | var collection = new DirectoryAttributeModificationCollection(); 91 | collection.AddRange(attributeCollection); 92 | 93 | Assert.Equal(attributes, collection.Cast()); 94 | } 95 | 96 | [Fact] 97 | public void AddRange_NullAttributeCollection_ThrowsArgumentNullException() 98 | { 99 | var collection = new DirectoryAttributeModificationCollection(); 100 | AssertExtensions.Throws("attributeCollection", () => collection.AddRange((DirectoryAttributeModificationCollection)null)); 101 | } 102 | 103 | [Fact] 104 | public void Contains_Valid_ReturnsExpected() 105 | { 106 | var attribute = new DirectoryAttributeModification { "value" }; 107 | var collection = new DirectoryAttributeModificationCollection { attribute }; 108 | Assert.True(collection.Contains(attribute)); 109 | Assert.False(collection.Contains(new DirectoryAttributeModification())); 110 | Assert.False(collection.Contains(null)); 111 | } 112 | 113 | [Fact] 114 | public void CopyTo_MultipleTypes_Success() 115 | { 116 | DirectoryAttributeModification[] array = new DirectoryAttributeModification[3]; 117 | var attribute = new DirectoryAttributeModification { "value" }; 118 | 119 | var collection = new DirectoryAttributeModificationCollection { attribute }; 120 | collection.CopyTo(array, 1); 121 | Assert.Equal(new DirectoryAttributeModification[] { null, attribute, null }, array); 122 | } 123 | 124 | [Fact] 125 | public void Insert_ValidDirectoryAttribute_Success() 126 | { 127 | var attribute1 = new DirectoryAttributeModification { "value1" }; 128 | var attribute2 = new DirectoryAttributeModification { "value2" }; 129 | var collection = new DirectoryAttributeModificationCollection(); 130 | collection.Insert(0, attribute1); 131 | collection.Insert(1, attribute2); 132 | 133 | Assert.Equal(new DirectoryAttributeModification[] { attribute1, attribute2 }, collection.Cast()); 134 | } 135 | 136 | [Fact] 137 | public void Insert_NullValue_ThrowsArgumentException() 138 | { 139 | var collection = new DirectoryAttributeModificationCollection(); 140 | AssertExtensions.Throws(null, () => collection.Insert(0, null)); 141 | } 142 | 143 | [Fact] 144 | public void IndexOf_Valid_ReturnsExpected() 145 | { 146 | var attribute = new DirectoryAttributeModification { "value" }; 147 | var collection = new DirectoryAttributeModificationCollection { attribute }; 148 | Assert.Equal(0, collection.IndexOf(attribute)); 149 | Assert.Equal(-1, collection.IndexOf(new DirectoryAttributeModification())); 150 | Assert.Equal(-1, collection.IndexOf(null)); 151 | } 152 | 153 | [Fact] 154 | public void Remove_Valid_Success() 155 | { 156 | var attribute = new DirectoryAttributeModification { "value" }; 157 | var collection = new DirectoryAttributeModificationCollection { attribute }; 158 | collection.Remove(attribute); 159 | Assert.Empty(collection); 160 | } 161 | 162 | public static IEnumerable Remove_InvalidValue_TestData() 163 | { 164 | yield return new object[] { null, null }; 165 | yield return new object[] { new DirectoryAttributeModification(), null }; 166 | yield return new object[] { 1, "value" }; 167 | } 168 | 169 | [Theory] 170 | [MemberData(nameof(Remove_InvalidValue_TestData))] 171 | public void Remove_InvalidValue_ThrowsArgumentException(object value, string paramName) 172 | { 173 | IList collection = new DirectoryAttributeModificationCollection { new DirectoryAttributeModification() }; 174 | AssertExtensions.Throws(paramName, () => collection.Remove(value)); 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /tests/DirectoryAttributeModificationTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.ComponentModel; 6 | using Xunit; 7 | 8 | namespace System.DirectoryServices.Protocols.Tests 9 | { 10 | public class DirectoryAttributeModificationTests 11 | { 12 | [Fact] 13 | public void Ctor_Default() 14 | { 15 | var modification = new DirectoryAttributeModification(); 16 | Assert.Empty(modification.Name); 17 | Assert.Empty(modification); 18 | Assert.Equal(DirectoryAttributeOperation.Replace, modification.Operation); 19 | } 20 | 21 | [Fact] 22 | public void Operation_SetValid_GetReturnsExpected() 23 | { 24 | var modification = new DirectoryAttributeModification { Operation = DirectoryAttributeOperation.Delete }; 25 | Assert.Equal(DirectoryAttributeOperation.Delete, modification.Operation); 26 | } 27 | 28 | [Theory] 29 | [InlineData(DirectoryAttributeOperation.Add - 1)] 30 | [InlineData(DirectoryAttributeOperation.Replace + 1)] 31 | public void Operation_SetInvalid_InvalidEnumArgumentException(DirectoryAttributeOperation operation) 32 | { 33 | var modification = new DirectoryAttributeModification(); 34 | AssertExtensions.Throws("value", () => modification.Operation = operation); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/DirectoryConnectionTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Net; 6 | using Xunit; 7 | 8 | namespace System.DirectoryServices.Protocols.Tests 9 | { 10 | public class DirectoryConnectionTests 11 | { 12 | [Fact] 13 | public void Ctor_Default() 14 | { 15 | var connection = new SubDirectoryConnection(); 16 | Assert.Empty(connection.ClientCertificates); 17 | Assert.Null(connection.Directory); 18 | Assert.Equal(new TimeSpan(0, 0, 30), connection.Timeout); 19 | } 20 | 21 | [Fact] 22 | public void Timeout_SetValid_GetReturnsExpected() 23 | { 24 | var connection = new SubDirectoryConnection { Timeout = TimeSpan.Zero }; 25 | Assert.Equal(TimeSpan.Zero, connection.Timeout); 26 | } 27 | 28 | [Fact] 29 | public void Timeout_SetNegative_ThrowsArgumentException() 30 | { 31 | var connection = new SubDirectoryConnection(); 32 | AssertExtensions.Throws("value", () => connection.Timeout = TimeSpan.FromTicks(-1)); 33 | } 34 | 35 | [Fact] 36 | public void Credential_Set_Success() 37 | { 38 | var connection = new SubDirectoryConnection { Credential = new NetworkCredential("username", "password") }; 39 | connection.Credential = null; 40 | } 41 | 42 | public class SubDirectoryConnection : DirectoryConnection 43 | { 44 | public override DirectoryResponse SendRequest(DirectoryRequest request) => throw new NotImplementedException(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/DirectoryControlCollectionTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using Xunit; 9 | 10 | namespace System.DirectoryServices.Protocols.Tests 11 | { 12 | public class DirectoryControlCollectionTests 13 | { 14 | [Fact] 15 | public void Ctor_Default() 16 | { 17 | var collection = new DirectoryControlCollection(); 18 | Assert.Equal(0, collection.Count); 19 | Assert.Equal(0, collection.Capacity); 20 | } 21 | 22 | [Fact] 23 | public void Indexer_Set_GetReturnsExpected() 24 | { 25 | var control = new AsqRequestControl("name"); 26 | var collection = new DirectoryControlCollection { new AsqRequestControl() }; 27 | collection[0] = control; 28 | Assert.Equal(control, collection[0]); 29 | } 30 | 31 | [Fact] 32 | public void Indexer_SetNull_ThrowsArgumentException() 33 | { 34 | var collection = new DirectoryControlCollection(); 35 | AssertExtensions.Throws("value", () => collection[0] = null); 36 | } 37 | 38 | [Fact] 39 | public void Add_ValidControl_AppendsToList() 40 | { 41 | var control1 = new AsqRequestControl("name1"); 42 | var control2 = new AsqRequestControl("name2"); 43 | var collection = new DirectoryControlCollection { control1, control2 }; 44 | Assert.Equal(2, collection.Count); 45 | Assert.Equal(new DirectoryControl[] { control1, control2 }, collection.Cast()); 46 | } 47 | 48 | [Fact] 49 | public void Add_NullControl_ThrowsArgumentNullException() 50 | { 51 | var collection = new DirectoryControlCollection(); 52 | AssertExtensions.Throws("control", () => collection.Add(null)); 53 | } 54 | 55 | [Fact] 56 | public void AddRange_ValidControls_AddsToCollection() 57 | { 58 | DirectoryControl[] controls = new DirectoryControl[] { new AsqRequestControl(), new AsqRequestControl() }; 59 | 60 | var collection = new DirectoryControlCollection(); 61 | collection.AddRange(controls); 62 | 63 | Assert.Equal(controls, collection.Cast()); 64 | } 65 | 66 | [Fact] 67 | public void AddRange_NullControls_ThrowsArgumentNullException() 68 | { 69 | var collection = new DirectoryControlCollection(); 70 | AssertExtensions.Throws("controls", () => collection.AddRange((DirectoryControl[])null)); 71 | } 72 | 73 | [Fact] 74 | public void AddRange_NullObjectInValues_ThrowsArgumentException() 75 | { 76 | DirectoryControl[] controls = new DirectoryControl[] { new AsqRequestControl(), null, new AsqRequestControl() }; 77 | var collection = new DirectoryControlCollection(); 78 | 79 | AssertExtensions.Throws("controls", () => collection.AddRange(controls)); 80 | Assert.Equal(0, collection.Count); 81 | } 82 | 83 | [Fact] 84 | public void AddRange_ValidControlCollection_AddsToCollection() 85 | { 86 | DirectoryControl[] controls = new DirectoryControl[] { new AsqRequestControl(), new AsqRequestControl() }; 87 | var attributeCollection = new DirectoryControlCollection(); 88 | attributeCollection.AddRange(controls); 89 | 90 | var collection = new DirectoryControlCollection(); 91 | collection.AddRange(attributeCollection); 92 | 93 | Assert.Equal(controls, collection.Cast()); 94 | } 95 | 96 | [Fact] 97 | public void AddRange_NullControlCollection_ThrowsArgumentNullException() 98 | { 99 | var collection = new DirectoryControlCollection(); 100 | AssertExtensions.Throws("controlCollection", () => collection.AddRange((DirectoryControlCollection)null)); 101 | } 102 | 103 | [Fact] 104 | public void Contains_Valid_ReturnsExpected() 105 | { 106 | var control = new AsqRequestControl("name"); 107 | var collection = new DirectoryControlCollection { control }; 108 | Assert.True(collection.Contains(control)); 109 | Assert.False(collection.Contains(new AsqRequestControl())); 110 | Assert.False(collection.Contains(null)); 111 | } 112 | 113 | [Fact] 114 | public void CopyTo_MultipleTypes_Success() 115 | { 116 | DirectoryControl[] array = new DirectoryControl[3]; 117 | var control = new AsqRequestControl("name"); 118 | 119 | var collection = new DirectoryControlCollection { control }; 120 | collection.CopyTo(array, 1); 121 | Assert.Equal(new DirectoryControl[] { null, control, null }, array); 122 | } 123 | 124 | [Fact] 125 | public void Insert_ValidDirectoryAttribute_Success() 126 | { 127 | var control1 = new AsqRequestControl("name1"); 128 | var control2 = new AsqRequestControl("name1"); 129 | var collection = new DirectoryControlCollection(); 130 | collection.Insert(0, control1); 131 | collection.Insert(1, control2); 132 | 133 | Assert.Equal(new DirectoryControl[] { control1, control2 }, collection.Cast()); 134 | } 135 | 136 | [Fact] 137 | public void Insert_NullValue_ThrowsArgumentNullException() 138 | { 139 | var collection = new DirectoryControlCollection(); 140 | AssertExtensions.Throws("value", () => collection.Insert(0, null)); 141 | } 142 | 143 | [Fact] 144 | public void IndexOf_Valid_ReturnsExpected() 145 | { 146 | var control = new AsqRequestControl("name"); 147 | var collection = new DirectoryControlCollection { control }; 148 | Assert.Equal(0, collection.IndexOf(control)); 149 | Assert.Equal(-1, collection.IndexOf(new AsqRequestControl())); 150 | Assert.Equal(-1, collection.IndexOf(null)); 151 | } 152 | 153 | [Fact] 154 | public void Remove_Valid_Success() 155 | { 156 | var control = new AsqRequestControl("name"); 157 | var collection = new DirectoryControlCollection { control }; 158 | collection.Remove(control); 159 | Assert.Empty(collection); 160 | } 161 | 162 | [Fact] 163 | public void Remove_NullValue_ThrowsArgumentNullException() 164 | { 165 | var collection = new DirectoryControlCollection { new AsqRequestControl() }; 166 | AssertExtensions.Throws("value", () => collection.Remove(null)); 167 | } 168 | 169 | public static IEnumerable Remove_InvalidValue_TestData() 170 | { 171 | yield return new object[] { new AsqRequestControl(), null }; 172 | yield return new object[] { 1, "value" }; 173 | } 174 | 175 | [Theory] 176 | [MemberData(nameof(Remove_InvalidValue_TestData))] 177 | public void Remove_InvalidValue_ThrowsArgumentException(object value, string paramName) 178 | { 179 | IList collection = new DirectoryControlCollection { new AsqRequestControl() }; 180 | AssertExtensions.Throws(paramName, () => collection.Remove(value)); 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /tests/DirectoryControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class DirectoryControlTests 10 | { 11 | [Theory] 12 | [InlineData("", null, false, false)] 13 | [InlineData("Type", new byte[] { 1, 2, 3 }, true, true)] 14 | public void Ctor_Type_Value_IsCritical_ServerSide(string type, byte[] value, bool isCritical, bool serverSide) 15 | { 16 | var control = new DirectoryControl(type, value, isCritical, serverSide); 17 | Assert.Equal(type, control.Type); 18 | Assert.Equal(isCritical, control.IsCritical); 19 | Assert.Equal(serverSide, control.ServerSide); 20 | 21 | byte[] controlValue = control.GetValue(); 22 | Assert.NotSame(controlValue, value); 23 | Assert.Equal(value ?? Array.Empty(), controlValue); 24 | } 25 | 26 | [Fact] 27 | public void Ctor_NullType_ThrowsArgumentNullException() 28 | { 29 | AssertExtensions.Throws("type", () => new DirectoryControl(null, new byte[0], false, false)); 30 | } 31 | 32 | [Fact] 33 | public void IsCritical_Set_GetReturnsExpected() 34 | { 35 | var control = new DirectoryControl("Type", null, false, true); 36 | Assert.False(control.IsCritical); 37 | 38 | control.IsCritical = true; 39 | Assert.True(control.IsCritical); 40 | } 41 | 42 | [Fact] 43 | public void ServerSide_Set_GetReturnsExpected() 44 | { 45 | var control = new DirectoryControl("Type", null, true, false); 46 | Assert.False(control.ServerSide); 47 | 48 | control.ServerSide = true; 49 | Assert.True(control.ServerSide); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/DirectoryExceptionTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.IO; 6 | using System.Reflection; 7 | using System.Runtime.Serialization; 8 | using System.Runtime.Serialization.Formatters.Binary; 9 | using Xunit; 10 | 11 | namespace System.DirectoryServices.Protocols.Tests 12 | { 13 | public class DirectoryExceptionTests 14 | { 15 | [Fact] 16 | public void Ctor_Default() 17 | { 18 | var exception = new DirectoryException(); 19 | Assert.NotEmpty(exception.Message); 20 | Assert.Null(exception.InnerException); 21 | } 22 | 23 | [Fact] 24 | public void Ctor_Message() 25 | { 26 | var exception = new DirectoryException("message"); 27 | Assert.Equal("message", exception.Message); 28 | Assert.Null(exception.InnerException); 29 | } 30 | 31 | [Fact] 32 | public void Ctor_Message_InnerException() 33 | { 34 | var innerException = new Exception(); 35 | var exception = new DirectoryException("message", innerException); 36 | Assert.Equal("message", exception.Message); 37 | Assert.Same(innerException, exception.InnerException); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/DirectoryNotificationControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class DirectoryNotificationRequestControlTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var control = new DirectoryNotificationControl(); 15 | Assert.True(control.IsCritical); 16 | Assert.True(control.ServerSide); 17 | Assert.Equal("1.2.840.113556.1.4.528", control.Type); 18 | 19 | Assert.Empty(control.GetValue()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/DirectoryOperationExceptionTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.IO; 6 | using System.Reflection; 7 | using System.Runtime.Serialization; 8 | using System.Runtime.Serialization.Formatters.Binary; 9 | using Xunit; 10 | 11 | namespace System.DirectoryServices.Protocols.Tests 12 | { 13 | public class DirectoryOperationExceptionTests 14 | { 15 | [Fact] 16 | public void Ctor_Default() 17 | { 18 | var exception = new DirectoryOperationException(); 19 | Assert.NotEmpty(exception.Message); 20 | Assert.Null(exception.InnerException); 21 | } 22 | 23 | [Fact] 24 | public void Ctor_Message() 25 | { 26 | var exception = new DirectoryOperationException("message"); 27 | Assert.Equal("message", exception.Message); 28 | Assert.Null(exception.Response); 29 | Assert.Null(exception.InnerException); 30 | } 31 | 32 | [Fact] 33 | public void Ctor_Message_InnerException() 34 | { 35 | var innerException = new Exception(); 36 | var exception = new DirectoryOperationException("message", innerException); 37 | Assert.Equal("message", exception.Message); 38 | Assert.Null(exception.Response); 39 | Assert.Same(innerException, exception.InnerException); 40 | } 41 | 42 | [Fact] 43 | public void Ctor_Response() 44 | { 45 | var exception = new DirectoryOperationException((DirectoryResponse)null); 46 | Assert.NotEmpty(exception.Message); 47 | Assert.Null(exception.Response); 48 | Assert.Null(exception.InnerException); 49 | } 50 | 51 | [Fact] 52 | public void Ctor_Response_Message() 53 | { 54 | var exception = new DirectoryOperationException(null, "message"); 55 | Assert.Equal("message", exception.Message); 56 | Assert.Null(exception.Response); 57 | Assert.Null(exception.InnerException); 58 | } 59 | 60 | [Fact] 61 | public void Ctor_Response_Message_InnerException() 62 | { 63 | var innerException = new Exception(); 64 | var exception = new DirectoryOperationException(null, "message", innerException); 65 | Assert.Equal("message", exception.Message); 66 | Assert.Null(exception.Response); 67 | Assert.Same(innerException, exception.InnerException); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/DomainScopeControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class DomainScopeControlTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var control = new DomainScopeControl(); 15 | Assert.True(control.IsCritical); 16 | Assert.True(control.ServerSide); 17 | Assert.Equal("1.2.840.113556.1.4.1339", control.Type); 18 | 19 | Assert.Empty(control.GetValue()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/DsmlAuthRequestTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class DsmlAuthRequestTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var request = new DsmlAuthRequest(); 15 | Assert.Empty(request.Controls); 16 | Assert.Empty(request.Principal); 17 | Assert.Null(request.RequestId); 18 | } 19 | 20 | [Theory] 21 | [InlineData(null)] 22 | [InlineData("Principal")] 23 | public void Ctor_Principal(string principal) 24 | { 25 | var request = new DsmlAuthRequest(principal); 26 | Assert.Empty(request.Controls); 27 | Assert.Equal(principal, request.Principal); 28 | Assert.Null(request.RequestId); 29 | } 30 | 31 | [Fact] 32 | public void Principal_Set_GetReturnsExpected() 33 | { 34 | var request = new DsmlAuthRequest { Principal = "Principal" }; 35 | Assert.Equal("Principal", request.Principal); 36 | } 37 | 38 | [Fact] 39 | public void RequestId_Set_GetReturnsExpected() 40 | { 41 | var request = new DsmlAuthRequest { RequestId = "Id" }; 42 | Assert.Equal("Id", request.RequestId); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/ExtendedDNControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.ComponentModel; 6 | using Xunit; 7 | 8 | namespace System.DirectoryServices.Protocols.Tests 9 | { 10 | public class ExtendedDNControlTests 11 | { 12 | [Fact] 13 | public void Ctor_Default() 14 | { 15 | var control = new ExtendedDNControl(); 16 | Assert.True(control.IsCritical); 17 | Assert.Equal(ExtendedDNFlag.HexString, control.Flag); 18 | Assert.True(control.ServerSide); 19 | Assert.Equal("1.2.840.113556.1.4.529", control.Type); 20 | 21 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 3, 2, 1, 0 }, control.GetValue()); 22 | } 23 | 24 | [Fact] 25 | public void Ctor_Flag() 26 | { 27 | var control = new ExtendedDNControl(ExtendedDNFlag.StandardString); 28 | Assert.True(control.IsCritical); 29 | Assert.Equal(ExtendedDNFlag.StandardString, control.Flag); 30 | Assert.True(control.ServerSide); 31 | Assert.Equal("1.2.840.113556.1.4.529", control.Type); 32 | 33 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 3, 2, 1, 1 }, control.GetValue()); 34 | } 35 | 36 | [Theory] 37 | [InlineData(ExtendedDNFlag.HexString - 1)] 38 | [InlineData(ExtendedDNFlag.StandardString + 1)] 39 | public void Ctor_InvalidFlag_ThrowsInvalidEnumArgumentException(ExtendedDNFlag flag) 40 | { 41 | AssertExtensions.Throws("value", () => new ExtendedDNControl(flag)); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/ExtendedRequestTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class ExtendedRequestTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var request = new ExtendedRequest(); 15 | Assert.Empty(request.Controls); 16 | Assert.Null(request.RequestId); 17 | Assert.Null(request.RequestName); 18 | Assert.Empty(request.RequestValue); 19 | } 20 | 21 | [Theory] 22 | [InlineData(null)] 23 | [InlineData("RequestName")] 24 | public void Ctor_RequestName(string requestName) 25 | { 26 | var request = new ExtendedRequest(requestName); 27 | Assert.Empty(request.Controls); 28 | Assert.Null(request.RequestId); 29 | Assert.Equal(requestName, request.RequestName); 30 | Assert.Empty(request.RequestValue); 31 | } 32 | 33 | [Theory] 34 | [InlineData(null, null)] 35 | [InlineData("RequestName", new byte[] { 1, 2, 3 })] 36 | public void Ctor_RequestName_RequestValue(string requestName, byte[] requestValue) 37 | { 38 | var request = new ExtendedRequest(requestName, requestValue); 39 | Assert.Empty(request.Controls); 40 | Assert.Null(request.RequestId); 41 | Assert.Equal(requestName, request.RequestName); 42 | Assert.NotSame(requestValue, request.RequestValue); 43 | Assert.Equal(requestValue ?? Array.Empty(), request.RequestValue); 44 | } 45 | 46 | [Fact] 47 | public void RequestName_Set_GetReturnsExpected() 48 | { 49 | var request = new ExtendedRequest { RequestName = "RequestName" }; 50 | Assert.Equal("RequestName", request.RequestName); 51 | } 52 | 53 | [Fact] 54 | public void RequestValue_Set_GetReturnsExpected() 55 | { 56 | var request = new ExtendedRequest { RequestValue = new byte[] { 1, 2, 3 } }; 57 | Assert.Equal(new byte[] { 1, 2, 3 }, request.RequestValue); 58 | } 59 | 60 | [Fact] 61 | public void RequestId_Set_GetReturnsExpected() 62 | { 63 | var request = new ExtendedRequest { RequestId = "Id" }; 64 | Assert.Equal("Id", request.RequestId); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/LDAP.Configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | vldaplbt 5 | ou=UZ Gent,dc=internal,dc=uzgent,dc=be 6 | 389 7 | cn=administrator,ou=applicatie,dc=internal,dc=uzgent,dc=be 8 | xxx 9 | ServerBind,None 10 | 11 | -------------------------------------------------------------------------------- /tests/LazyCommitControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class LazyCommitControlTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var control = new LazyCommitControl(); 15 | Assert.True(control.IsCritical); 16 | Assert.True(control.ServerSide); 17 | Assert.Equal("1.2.840.113556.1.4.619", control.Type); 18 | 19 | Assert.Empty(control.GetValue()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/LdapDirectoryIdentifierTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class LdapDirectoryIdentifierTests 10 | { 11 | [Theory] 12 | [InlineData(null, new string[0])] 13 | [InlineData("", new string[] { "" })] 14 | [InlineData("server", new string[] { "server" })] 15 | public void Ctor_Server(string server, string[] expectedServers) 16 | { 17 | var identifier = new LdapDirectoryIdentifier(server); 18 | Assert.False(identifier.Connectionless); 19 | Assert.False(identifier.FullyQualifiedDnsHostName); 20 | Assert.Equal(389, identifier.PortNumber); 21 | Assert.Equal(expectedServers, identifier.Servers); 22 | } 23 | 24 | [Theory] 25 | [InlineData(null, 389, new string[0])] 26 | [InlineData("", -1, new string[] { "" })] 27 | [InlineData("server", int.MaxValue, new string[] { "server" })] 28 | public void Ctor_Server_PortNumber(string server, int portNumber, string[] expectedServers) 29 | { 30 | var identifier = new LdapDirectoryIdentifier(server, portNumber); 31 | Assert.False(identifier.Connectionless); 32 | Assert.False(identifier.FullyQualifiedDnsHostName); 33 | Assert.Equal(portNumber, identifier.PortNumber); 34 | Assert.Equal(expectedServers, identifier.Servers); 35 | } 36 | 37 | [Theory] 38 | [InlineData(null, true, false, new string[0])] 39 | [InlineData("", false, true, new string[] { "" })] 40 | [InlineData("server", true, true, new string[] { "server" })] 41 | public void Ctor_Server_FullQualifiedDnsHostName_Conectionless(string server, bool fullyQualifiedDnsHostName, bool connectionless, string[] expectedServers) 42 | { 43 | var identifier = new LdapDirectoryIdentifier(server, fullyQualifiedDnsHostName, connectionless); 44 | Assert.Equal(connectionless, identifier.Connectionless); 45 | Assert.Equal(fullyQualifiedDnsHostName, identifier.FullyQualifiedDnsHostName); 46 | Assert.Equal(389, identifier.PortNumber); 47 | Assert.Equal(expectedServers, identifier.Servers); 48 | } 49 | 50 | [Theory] 51 | [InlineData(null, -1, true, false, new string[0])] 52 | [InlineData("", 389, false, true, new string[] { "" })] 53 | [InlineData("server", int.MaxValue, true, true, new string[] { "server" })] 54 | public void Ctor_PortNumber_Server_FullQualifiedDnsHostName_Conectionless(string server, int portNumber, bool fullyQualifiedDnsHostName, bool connectionless, string[] expectedServers) 55 | { 56 | var identifier = new LdapDirectoryIdentifier(server, portNumber, fullyQualifiedDnsHostName, connectionless); 57 | Assert.Equal(connectionless, identifier.Connectionless); 58 | Assert.Equal(fullyQualifiedDnsHostName, identifier.FullyQualifiedDnsHostName); 59 | Assert.Equal(portNumber, identifier.PortNumber); 60 | Assert.Equal(expectedServers, identifier.Servers); 61 | } 62 | 63 | [Theory] 64 | [InlineData(null, false, true)] 65 | [InlineData(new string[0], true, false)] 66 | [InlineData(new string[] { "server" }, true, true)] 67 | [InlineData(new string[] { "server", null }, false, false)] 68 | public void Ctor_Servers_FullQualifiedDnsHostName_Conectionless(string[] servers, bool fullyQualifiedDnsHostName, bool connectionless) 69 | { 70 | var identifier = new LdapDirectoryIdentifier(servers, fullyQualifiedDnsHostName, connectionless); 71 | Assert.Equal(connectionless, identifier.Connectionless); 72 | Assert.Equal(fullyQualifiedDnsHostName, identifier.FullyQualifiedDnsHostName); 73 | Assert.Equal(389, identifier.PortNumber); 74 | Assert.NotSame(servers, identifier.Servers); 75 | Assert.Equal(servers ?? Array.Empty(), identifier.Servers); 76 | } 77 | 78 | [Fact] 79 | public void Ctor_ServerHasSpaceInName_ThrowsArgumentException() 80 | { 81 | AssertExtensions.Throws(null, () => new LdapDirectoryIdentifier("se rver")); 82 | AssertExtensions.Throws(null, () => new LdapDirectoryIdentifier("se rver", 0)); 83 | AssertExtensions.Throws(null, () => new LdapDirectoryIdentifier("se rver", false, false)); 84 | AssertExtensions.Throws(null, () => new LdapDirectoryIdentifier("se rver", 0, false, false)); 85 | AssertExtensions.Throws(null, () => new LdapDirectoryIdentifier(new string[] { "se rver" }, false, false)); 86 | AssertExtensions.Throws(null, () => new LdapDirectoryIdentifier(new string[] { "se rver" }, 0, false, false)); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/LdapExceptionTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.IO; 6 | using System.Reflection; 7 | using System.Runtime.Serialization; 8 | using System.Runtime.Serialization.Formatters.Binary; 9 | using Xunit; 10 | 11 | namespace System.DirectoryServices.Protocols.Tests 12 | { 13 | public class LdapExceptionTests 14 | { 15 | [Fact] 16 | public void Ctor_Default() 17 | { 18 | var exception = new LdapException(); 19 | Assert.NotEmpty(exception.Message); 20 | Assert.Null(exception.InnerException); 21 | 22 | Assert.Equal(0, exception.ErrorCode); 23 | Assert.Null(exception.ServerErrorMessage); 24 | Assert.Empty(exception.PartialResults); 25 | } 26 | 27 | [Fact] 28 | public void Ctor_Message() 29 | { 30 | var exception = new LdapException("message"); 31 | Assert.Equal("message", exception.Message); 32 | Assert.Null(exception.InnerException); 33 | 34 | Assert.Equal(0, exception.ErrorCode); 35 | Assert.Null(exception.ServerErrorMessage); 36 | Assert.Empty(exception.PartialResults); 37 | } 38 | 39 | [Fact] 40 | public void Ctor_Message_InnerException() 41 | { 42 | var innerException = new Exception(); 43 | var exception = new LdapException("message", innerException); 44 | Assert.Equal("message", exception.Message); 45 | Assert.Same(innerException, exception.InnerException); 46 | 47 | Assert.Equal(0, exception.ErrorCode); 48 | Assert.Null(exception.ServerErrorMessage); 49 | Assert.Empty(exception.PartialResults); 50 | } 51 | 52 | [Fact] 53 | public void Ctor_ErrorCode() 54 | { 55 | var exception = new LdapException(10); 56 | Assert.NotEmpty(exception.Message); 57 | Assert.Null(exception.InnerException); 58 | 59 | Assert.Equal(10, exception.ErrorCode); 60 | Assert.Null(exception.ServerErrorMessage); 61 | Assert.Empty(exception.PartialResults); 62 | } 63 | 64 | [Fact] 65 | public void Ctor_ErrorCode_Message() 66 | { 67 | var exception = new LdapException(10, "message"); 68 | Assert.Equal("message", exception.Message); 69 | Assert.Null(exception.InnerException); 70 | 71 | Assert.Equal(10, exception.ErrorCode); 72 | Assert.Null(exception.ServerErrorMessage); 73 | Assert.Empty(exception.PartialResults); 74 | } 75 | 76 | [Fact] 77 | public void Ctor_ErrorCode_Message_ServerErrorMessage() 78 | { 79 | var exception = new LdapException(10, "message", "serverErrorMessage"); 80 | Assert.Equal("message", exception.Message); 81 | Assert.Null(exception.InnerException); 82 | 83 | Assert.Equal(10, exception.ErrorCode); 84 | Assert.Equal("serverErrorMessage", exception.ServerErrorMessage); 85 | Assert.Empty(exception.PartialResults); 86 | } 87 | 88 | [Fact] 89 | public void Ctor_ErrorCode_Message_InnerException() 90 | { 91 | var innerException = new Exception(); 92 | var exception = new LdapException(10, "message", innerException); 93 | Assert.Equal("message", exception.Message); 94 | Assert.Same(innerException, exception.InnerException); 95 | 96 | Assert.Equal(10, exception.ErrorCode); 97 | Assert.Null(exception.ServerErrorMessage); 98 | Assert.Empty(exception.PartialResults); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /tests/ModifyDNRequestTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Xunit; 8 | 9 | namespace System.DirectoryServices.Protocols.Tests 10 | { 11 | public class ModifyDNRequestTests 12 | { 13 | [Fact] 14 | public void Ctor_Default() 15 | { 16 | var request = new ModifyDNRequest(); 17 | Assert.Empty(request.Controls); 18 | Assert.Null(request.DistinguishedName); 19 | Assert.Null(request.NewName); 20 | Assert.Null(request.NewParentDistinguishedName); 21 | Assert.True(request.DeleteOldRdn); 22 | Assert.Null(request.RequestId); 23 | } 24 | 25 | [Theory] 26 | [InlineData(null, null, null)] 27 | [InlineData("DistinguishedName", "NewParentDistinguishedName", "NewName")] 28 | public void Ctor_DistinguishedName_NewParentDistinguishedName_NewName(string distinguishedName, string newParentDistinguishedName, string newName) 29 | { 30 | var request = new ModifyDNRequest(distinguishedName, newParentDistinguishedName, newName); 31 | Assert.Empty(request.Controls); 32 | Assert.Equal(distinguishedName, request.DistinguishedName); 33 | Assert.Equal(newName, request.NewName); 34 | Assert.Equal(newParentDistinguishedName, request.NewParentDistinguishedName); 35 | Assert.True(request.DeleteOldRdn); 36 | Assert.Null(request.RequestId); 37 | } 38 | 39 | [Fact] 40 | public void DistinguishedName_Set_GetReturnsExpected() 41 | { 42 | var request = new ModifyDNRequest { DistinguishedName = "Name" }; 43 | Assert.Equal("Name", request.DistinguishedName); 44 | } 45 | 46 | [Fact] 47 | public void NewParentDistinguishedName_Set_GetReturnsExpected() 48 | { 49 | var request = new ModifyDNRequest { NewParentDistinguishedName = "NewParentDistinguishedName" }; 50 | Assert.Equal("NewParentDistinguishedName", request.NewParentDistinguishedName); 51 | } 52 | 53 | [Fact] 54 | public void NewName_Set_GetReturnsExpected() 55 | { 56 | var request = new ModifyDNRequest { NewName = "NewName" }; 57 | Assert.Equal("NewName", request.NewName); 58 | } 59 | 60 | [Fact] 61 | public void DeleteOldRdn_Set_GetReturnsExpected() 62 | { 63 | var request = new ModifyDNRequest { DeleteOldRdn = false }; 64 | Assert.False(request.DeleteOldRdn); 65 | } 66 | 67 | [Fact] 68 | public void RequestId_Set_GetReturnsExpected() 69 | { 70 | var request = new ModifyDNRequest { RequestId = "Id" }; 71 | Assert.Equal("Id", request.RequestId); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/ModifyRequestTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Xunit; 8 | 9 | namespace System.DirectoryServices.Protocols.Tests 10 | { 11 | public class ModifyRequestTests 12 | { 13 | [Fact] 14 | public void Ctor_Default() 15 | { 16 | var request = new ModifyRequest(); 17 | Assert.Empty(request.Controls); 18 | Assert.Null(request.DistinguishedName); 19 | Assert.Empty(request.Modifications); 20 | Assert.Null(request.RequestId); 21 | } 22 | 23 | public static IEnumerable Ctor_DistinguishedName_Modifications_TestData() 24 | { 25 | yield return new object[] { string.Empty, new DirectoryAttributeModification[0] }; 26 | yield return new object[] { "DistinguishedName", new DirectoryAttributeModification[] { new DirectoryAttributeModification() } }; 27 | } 28 | 29 | [Theory] 30 | [MemberData(nameof(Ctor_DistinguishedName_Modifications_TestData))] 31 | public void Ctor_DistinguishedString_Modifications(string distinguishedName, DirectoryAttributeModification[] modifications) 32 | { 33 | var request = new ModifyRequest(distinguishedName, modifications); 34 | Assert.Empty(request.Controls); 35 | Assert.Equal(distinguishedName, request.DistinguishedName); 36 | Assert.Equal(modifications ?? Enumerable.Empty(), request.Modifications.Cast()); 37 | Assert.Null(request.RequestId); 38 | } 39 | 40 | [Fact] 41 | public void Ctor_NullModifications_ThrowsArgumentNullException() 42 | { 43 | AssertExtensions.Throws("attributes", () => new ModifyRequest("DistinguishedName", null)); 44 | } 45 | 46 | [Fact] 47 | public void Ctor_NullObjectInAttributes_ThrowsArgumentException() 48 | { 49 | AssertExtensions.Throws(null, () => new ModifyRequest("DistinguishedName", new DirectoryAttributeModification[] { null })); 50 | } 51 | 52 | public static IEnumerable Ctor_DistinguishedName_Operation_AttributeName_Values_TestData() 53 | { 54 | yield return new object[] { null, null, "AttributeName", null }; 55 | yield return new object[] { string.Empty, null, "AttributeName", new object[0] }; 56 | yield return new object[] { "DistinguishedName", new DirectoryAttributeOperation(), "AttributeName", new object[] { "1", "2" } }; 57 | } 58 | 59 | [Theory] 60 | [MemberData(nameof(Ctor_DistinguishedName_Operation_AttributeName_Values_TestData))] 61 | public void Ctor_DistinguishedName_Operation_AttributeName_Values(string distinguishedName, DirectoryAttributeOperation operation, string attributeName, object[] values) 62 | { 63 | var request = new ModifyRequest(distinguishedName, operation, attributeName, values); 64 | Assert.Empty(request.Controls); 65 | DirectoryAttributeModification modification = (DirectoryAttributeModification)Assert.Single(request.Modifications); 66 | Assert.Equal(attributeName, modification.Name); 67 | Assert.Equal(operation, modification.Operation); 68 | Assert.Equal(values ?? Enumerable.Empty(), modification.Cast()); 69 | 70 | Assert.Equal(distinguishedName, request.DistinguishedName); 71 | Assert.Null(request.RequestId); 72 | } 73 | 74 | [Fact] 75 | public void Ctor_NullAttributeName_ThrowsArgumentNullException() 76 | { 77 | AssertExtensions.Throws("attributeName", () => new ModifyRequest("DistinguishedName", new DirectoryAttributeOperation(), null, new object[0])); 78 | } 79 | 80 | [Fact] 81 | public void Ctor_NullObjectInValues_ThrowsArgumentNullException() 82 | { 83 | AssertExtensions.Throws("value", () => new ModifyRequest("DistinguishedName", new DirectoryAttributeOperation(), "AttributeName", new object[] { null })); 84 | } 85 | 86 | [Fact] 87 | public void Ctor_InvalidObjectInValues_ThrowsArgumentException() 88 | { 89 | AssertExtensions.Throws("value", () => new ModifyRequest("DistinguishedName", new DirectoryAttributeOperation(), "AttributeName", new object[] { 1 })); 90 | } 91 | 92 | [Fact] 93 | public void DistinguishedName_Set_GetReturnsExpected() 94 | { 95 | var request = new ModifyRequest { DistinguishedName = "Name" }; 96 | Assert.Equal("Name", request.DistinguishedName); 97 | } 98 | 99 | [Fact] 100 | public void RequestId_Set_GetReturnsExpected() 101 | { 102 | var request = new ModifyRequest { RequestId = "Id" }; 103 | Assert.Equal("Id", request.RequestId); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /tests/PageResultRequestControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using System.ComponentModel; 7 | using System.Security.Principal; 8 | using Xunit; 9 | 10 | namespace System.DirectoryServices.Protocols.Tests 11 | { 12 | public class PageResultRequestControlTests 13 | { 14 | [Fact] 15 | public void Ctor_Default() 16 | { 17 | var control = new PageResultRequestControl(); 18 | Assert.True(control.IsCritical); 19 | Assert.Empty(control.Cookie); 20 | Assert.True(control.ServerSide); 21 | Assert.Equal(512, control.PageSize); 22 | Assert.Equal("1.2.840.113556.1.4.319", control.Type); 23 | 24 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 6, 2, 2, 2, 0, 4, 0 }, control.GetValue()); 25 | } 26 | 27 | [Theory] 28 | [InlineData(0, new byte[] { 48, 132, 0, 0, 0, 5, 2, 1, 0, 4, 0 })] 29 | [InlineData(10, new byte[] { 48, 132, 0, 0, 0, 5, 2, 1, 10, 4, 0 })] 30 | public void Ctor_PageSize(int pageSize, byte[] expectedValue) 31 | { 32 | var control = new PageResultRequestControl(pageSize); 33 | Assert.True(control.IsCritical); 34 | Assert.Empty(control.Cookie); 35 | Assert.True(control.ServerSide); 36 | Assert.Equal(pageSize, control.PageSize); 37 | Assert.Equal("1.2.840.113556.1.4.319", control.Type); 38 | 39 | Assert.Equal(expectedValue, control.GetValue()); 40 | } 41 | 42 | [Fact] 43 | public void Ctor_NegativePageSize_ThrowsArgumentException() 44 | { 45 | AssertExtensions.Throws("value", () => new PageResultRequestControl(-1)); 46 | } 47 | 48 | [Theory] 49 | [InlineData(null, new byte[] { 48, 132, 0, 0, 0, 6, 2, 2, 2, 0, 4, 0 })] 50 | [InlineData(new byte[0], new byte[] { 48, 132, 0, 0, 0, 6, 2, 2, 2, 0, 4, 0 })] 51 | [InlineData(new byte[] { 1, 2, 3, }, new byte[] { 48, 132, 0, 0, 0, 9, 2, 2, 2, 0, 4, 3, 1, 2, 3 })] 52 | public void Ctor_Cookie(byte[] cookie, byte[] expectedValue) 53 | { 54 | var control = new PageResultRequestControl(cookie); 55 | Assert.True(control.IsCritical); 56 | Assert.NotSame(cookie, control.Cookie); 57 | Assert.Equal(cookie ?? Array.Empty(), control.Cookie); 58 | Assert.True(control.ServerSide); 59 | Assert.Equal(512, control.PageSize); 60 | Assert.Equal("1.2.840.113556.1.4.319", control.Type); 61 | 62 | Assert.Equal(expectedValue, control.GetValue()); 63 | } 64 | 65 | [Fact] 66 | public void Cookie_Set_GetReturnsExpected() 67 | { 68 | var control = new PageResultRequestControl { Cookie = new byte[] { 1, 2, 3 } }; 69 | Assert.Equal(new byte[] { 1, 2, 3 }, control.Cookie); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /tests/PermissiveModifyControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class PermissiveModifyControlTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var control = new PermissiveModifyControl(); 15 | Assert.True(control.IsCritical); 16 | Assert.True(control.ServerSide); 17 | Assert.Equal("1.2.840.113556.1.4.1413", control.Type); 18 | 19 | Assert.Empty(control.GetValue()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/QuotaControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using System.ComponentModel; 7 | using System.Security.Principal; 8 | using Xunit; 9 | 10 | namespace System.DirectoryServices.Protocols.Tests 11 | { 12 | public class QuotaControlTests 13 | { 14 | /* [Fact] 15 | public void Ctor_Default() 16 | { 17 | var control = new QuotaControl(); 18 | Assert.True(control.IsCritical); 19 | Assert.Null(control.QuerySid); 20 | Assert.True(control.ServerSide); 21 | Assert.Equal("1.2.840.113556.1.4.1852", control.Type); 22 | 23 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 2, 4, 0 }, control.GetValue()); 24 | } 25 | public static IEnumerable Ctor_QuerySid_TestData() 26 | { 27 | yield return new object[] { new SecurityIdentifier("S-1-5-32-544"), new byte[] { 48, 132, 0, 0, 0, 18, 4, 16, 1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 32, 2, 0, 0 } }; 28 | yield return new object[] { null, new byte[] { 48, 132, 0, 0, 0, 2, 4, 0 } }; 29 | } 30 | 31 | [Theory] 32 | [MemberData(nameof(Ctor_QuerySid_TestData))] 33 | public void Ctor_QuerySid_TestData(SecurityIdentifier querySid, byte[] expectedValue) 34 | { 35 | var control = new QuotaControl(querySid); 36 | Assert.True(control.IsCritical); 37 | if (querySid != null) 38 | { 39 | Assert.NotSame(querySid, control.QuerySid); 40 | } 41 | Assert.Equal(querySid, control.QuerySid); 42 | Assert.True(control.ServerSide); 43 | Assert.Equal("1.2.840.113556.1.4.1852", control.Type); 44 | 45 | Assert.Equal(expectedValue, control.GetValue()); 46 | }*/ 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /tests/ReferralCallbackTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Net; 6 | using Xunit; 7 | 8 | namespace System.DirectoryServices.Protocols.Tests 9 | { 10 | public class ReferralCallbackTests 11 | { 12 | [Fact] 13 | public void Ctor_Default() 14 | { 15 | var callback = new ReferralCallback(); 16 | Assert.Null(callback.DereferenceConnection); 17 | Assert.Null(callback.NotifyNewConnection); 18 | Assert.Null(callback.QueryForConnection); 19 | } 20 | 21 | [Fact] 22 | public void DereferenceConnection_Set_GetReturnsExpected() 23 | { 24 | var callback = new ReferralCallback { DereferenceConnection = DereferenceConnection }; 25 | Assert.Equal(DereferenceConnection, callback.DereferenceConnection); 26 | } 27 | 28 | [Fact] 29 | public void NotifyNewConnection_Set_GetReturnsExpected() 30 | { 31 | var callback = new ReferralCallback { NotifyNewConnection = NotifyNewConnection }; 32 | Assert.Equal(NotifyNewConnection, callback.NotifyNewConnection); 33 | } 34 | 35 | [Fact] 36 | public void QueryForConnection_Set_GetReturnsExpected() 37 | { 38 | var callback = new ReferralCallback { QueryForConnection = QueryForConnection }; 39 | Assert.Equal(QueryForConnection, callback.QueryForConnection); 40 | } 41 | 42 | public static void DereferenceConnection(LdapConnection primaryConnection, LdapConnection connectionToDereference) { } 43 | public static bool NotifyNewConnection(LdapConnection primaryConnection, LdapConnection referralFromConnection, string newDistinguishedName, LdapDirectoryIdentifier identifier, LdapConnection newConnection, NetworkCredential credential, long currentUserToken, int errorCodeFromBind) => true; 44 | public static LdapConnection QueryForConnection(LdapConnection primaryConnection, LdapConnection referralFromConnection, string newDistinguishedName, LdapDirectoryIdentifier identifier, NetworkCredential credential, long currentUserToken) => null; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/SearchOptionsControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.ComponentModel; 6 | using Xunit; 7 | 8 | namespace System.DirectoryServices.Protocols.Tests 9 | { 10 | public class SearchOptionsControlTests 11 | { 12 | [Fact] 13 | public void Ctor_Default() 14 | { 15 | var control = new SearchOptionsControl(); 16 | Assert.True(control.IsCritical); 17 | Assert.Equal(SearchOption.DomainScope, control.SearchOption); 18 | Assert.True(control.ServerSide); 19 | Assert.Equal("1.2.840.113556.1.4.1340", control.Type); 20 | 21 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 3, 2, 1, 1 }, control.GetValue()); 22 | } 23 | 24 | [Fact] 25 | public void Ctor_Flags() 26 | { 27 | var control = new SearchOptionsControl(SearchOption.PhantomRoot); 28 | Assert.True(control.IsCritical); 29 | Assert.Equal(SearchOption.PhantomRoot, control.SearchOption); 30 | Assert.True(control.ServerSide); 31 | Assert.Equal("1.2.840.113556.1.4.1340", control.Type); 32 | 33 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 3, 2, 1, 2 }, control.GetValue()); 34 | } 35 | 36 | [Theory] 37 | [InlineData(SearchOption.DomainScope - 1)] 38 | [InlineData(SearchOption.PhantomRoot + 1)] 39 | public void Ctor_InvalidFlags_ThrowsInvalidEnumArgumentException(SearchOption flag) 40 | { 41 | AssertExtensions.Throws("value", () => new SearchOptionsControl(flag)); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/SearchRequestTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using System.Collections.Specialized; 7 | using System.ComponentModel; 8 | using System.Linq; 9 | using Xunit; 10 | 11 | namespace System.DirectoryServices.Protocols.Tests 12 | { 13 | public class SearchRequestTests 14 | { 15 | [Fact] 16 | public void Ctor_Default() 17 | { 18 | var request = new SearchRequest(); 19 | Assert.Equal(DereferenceAlias.Never, request.Aliases); 20 | Assert.Empty(request.Attributes); 21 | Assert.Empty(request.Controls); 22 | Assert.Null(request.DistinguishedName); 23 | Assert.Null(request.Filter); 24 | Assert.Equal(SearchScope.Subtree, request.Scope); 25 | Assert.Null(request.RequestId); 26 | Assert.Equal(TimeSpan.Zero, request.TimeLimit); 27 | Assert.False(request.TypesOnly); 28 | } 29 | 30 | [Theory] 31 | [InlineData(null, null, SearchScope.Subtree, null)] 32 | [InlineData("", "", SearchScope.OneLevel, new string[0])] 33 | [InlineData("DistinguishedName", "LdapFilter", SearchScope.Base, new string[] { "attribute" })] 34 | [InlineData("DistinguishedName", "LdapFilter", SearchScope.OneLevel, new string[] { null })] 35 | public void Ctor_DistinguishedName_LdapFilter_SearchScope_AttributeList(string distinguishedName, string ldapFilter, SearchScope searchScope, string[] attributeList) 36 | { 37 | var request = new SearchRequest(distinguishedName, ldapFilter, searchScope, attributeList); 38 | Assert.Equal(DereferenceAlias.Never, request.Aliases); 39 | Assert.Equal(attributeList ?? Enumerable.Empty(), request.Attributes.Cast()); 40 | Assert.Empty(request.Controls); 41 | Assert.Equal(distinguishedName, request.DistinguishedName); 42 | Assert.Equal(ldapFilter, request.Filter); 43 | Assert.Equal(searchScope, request.Scope); 44 | Assert.Null(request.RequestId); 45 | Assert.Equal(TimeSpan.Zero, request.TimeLimit); 46 | Assert.False(request.TypesOnly); 47 | } 48 | 49 | [Theory] 50 | [InlineData(SearchScope.Base - 1)] 51 | [InlineData(SearchScope.Subtree + 1)] 52 | public void Ctor_InvalidScope_ThrowsInvalidEnumArgumentException(SearchScope searchScope) 53 | { 54 | AssertExtensions.Throws("value", () => new SearchRequest("DistinguishedName", "LdapFilter", searchScope)); 55 | } 56 | 57 | [Fact] 58 | public void DistinguishedName_Set_GetReturnsExpected() 59 | { 60 | var request = new SearchRequest { DistinguishedName = "Name" }; 61 | Assert.Equal("Name", request.DistinguishedName); 62 | } 63 | 64 | [Fact] 65 | public void Filter_Set_GetReturnsExpected() 66 | { 67 | var request = new SearchRequest { Filter = "filter" }; 68 | Assert.Equal("filter", request.Filter); 69 | 70 | request.Filter = null; 71 | Assert.Null(request.Filter); 72 | } 73 | 74 | [Fact] 75 | public void Filter_SetInvalid_ThrowsArgumentException() 76 | { 77 | var request = new SearchRequest(); 78 | AssertExtensions.Throws("value", () => request.Filter = 1); 79 | } 80 | 81 | [Fact] 82 | public void Aliases_SetValid_GetReturnsExpected() 83 | { 84 | var request = new SearchRequest { Aliases = DereferenceAlias.Always }; 85 | Assert.Equal(DereferenceAlias.Always, request.Aliases); 86 | } 87 | 88 | [Theory] 89 | [InlineData(DereferenceAlias.Never - 1)] 90 | [InlineData(DereferenceAlias.Always + 1)] 91 | public void Aliases_SetInvalid_ThrowsInvalidEnumArgumentException(DereferenceAlias aliases) 92 | { 93 | var request = new SearchRequest(); 94 | AssertExtensions.Throws("value", () => request.Aliases = aliases); 95 | } 96 | 97 | 98 | [Fact] 99 | public void SizeLimit_SetValid_GetReturnsExpected() 100 | { 101 | var request = new SearchRequest { SizeLimit = 0 }; 102 | Assert.Equal(0, request.SizeLimit); 103 | } 104 | 105 | [Fact] 106 | public void SizeLimit_SetNegative_ThrowsArgumentException() 107 | { 108 | var request = new SearchRequest(); 109 | AssertExtensions.Throws("value", () => request.SizeLimit = -1); 110 | } 111 | 112 | [Fact] 113 | public void TimeLimit_SetValid_GetReturnsExpected() 114 | { 115 | var request = new SearchRequest { TimeLimit = TimeSpan.FromSeconds(1) }; 116 | Assert.Equal(TimeSpan.FromSeconds(1), request.TimeLimit); 117 | } 118 | 119 | [Theory] 120 | [InlineData(-1)] 121 | [InlineData((long)int.MaxValue + 1)] 122 | public void TimeLimit_SetInvalid_ThrowsArgumentException(long totalSeconds) 123 | { 124 | var request = new SearchRequest(); 125 | AssertExtensions.Throws("value", () => request.TimeLimit = TimeSpan.FromSeconds(totalSeconds)); 126 | } 127 | 128 | [Fact] 129 | public void TypesOnly_Set_GetReturnsExpected() 130 | { 131 | var request = new SearchRequest { TypesOnly = true }; 132 | Assert.True(request.TypesOnly); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /tests/SecurityDescriptorFlagControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.ComponentModel; 6 | using Xunit; 7 | 8 | namespace System.DirectoryServices.Protocols.Tests 9 | { 10 | public class SecurityDescriptorFlagControlTests 11 | { 12 | [Fact] 13 | public void Ctor_Default() 14 | { 15 | var control = new SecurityDescriptorFlagControl(); 16 | Assert.True(control.IsCritical); 17 | Assert.Equal(SecurityMasks.None, control.SecurityMasks); 18 | Assert.True(control.ServerSide); 19 | Assert.Equal("1.2.840.113556.1.4.801", control.Type); 20 | 21 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 3, 2, 1, 0 }, control.GetValue()); 22 | } 23 | 24 | [Theory] 25 | [InlineData(SecurityMasks.Group, new byte[] { 48, 132, 0, 0, 0, 3, 2, 1, 2 })] 26 | [InlineData(SecurityMasks.None - 1, new byte[] { 48, 132, 0, 0, 0, 6, 2, 4, 255, 255, 255, 255 })] 27 | public void Ctor_Flags(SecurityMasks masks, byte[] expectedValue) 28 | { 29 | var control = new SecurityDescriptorFlagControl(masks); 30 | Assert.True(control.IsCritical); 31 | Assert.Equal(masks, control.SecurityMasks); 32 | Assert.True(control.ServerSide); 33 | Assert.Equal("1.2.840.113556.1.4.801", control.Type); 34 | 35 | Assert.Equal(expectedValue, control.GetValue()); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/ShowDeletedControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections.Generic; 6 | using System.ComponentModel; 7 | using System.Security.Principal; 8 | using Xunit; 9 | 10 | namespace System.DirectoryServices.Protocols.Tests 11 | { 12 | public class ShowDeletedControlTests 13 | { 14 | [Fact] 15 | public void Ctor_Default() 16 | { 17 | var control = new ShowDeletedControl(); 18 | Assert.True(control.IsCritical); 19 | Assert.True(control.ServerSide); 20 | Assert.Equal("1.2.840.113556.1.4.417", control.Type); 21 | 22 | Assert.Empty(control.GetValue()); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/SortKeyTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class SortKeyTests 10 | { 11 | /* [Fact] 12 | public void Ctor_Default() 13 | { 14 | var sortKey = new SortKey(); 15 | Assert.Null(sortKey.AttributeName); 16 | Assert.Null(sortKey.MatchingRule); 17 | Assert.False(sortKey.ReverseOrder); 18 | }*/ 19 | 20 | [Theory] 21 | [InlineData("", null, false)] 22 | [InlineData("AttributeName", null, false)] 23 | public void Ctor_Default(string attributeName, string matchingRule, bool reverseOrder) 24 | { 25 | var sortKey = new SortKey(attributeName, matchingRule, reverseOrder); 26 | Assert.Equal(attributeName, sortKey.AttributeName); 27 | Assert.Equal(matchingRule, sortKey.MatchingRule); 28 | Assert.Equal(reverseOrder, sortKey.ReverseOrder); 29 | } 30 | 31 | [Fact] 32 | public void Ctor_NullAttributeName_ThrowsArgumentNullException() 33 | { 34 | AssertExtensions.Throws("value", () => new SortKey(null, "MatchingRule", false)); 35 | } 36 | 37 | [Fact] 38 | public void MatchingRule_Set_GetReturnsExpected() 39 | { 40 | var sortKey = new SortKey { MatchingRule = "MatchingRule" }; 41 | Assert.Equal("MatchingRule", sortKey.MatchingRule); 42 | } 43 | 44 | [Fact] 45 | public void ReverseOrder_Set_GetReturnsExpected() 46 | { 47 | var sortKey = new SortKey { ReverseOrder = true }; 48 | Assert.True(sortKey.ReverseOrder); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/SortRequestControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Reflection; 6 | using Xunit; 7 | 8 | namespace System.DirectoryServices.Protocols.Tests 9 | { 10 | public class SortRequestControlTests 11 | { 12 | [Theory] 13 | [InlineData(true)] 14 | [InlineData(false)] 15 | [ActiveIssue("https://github.com/dotnet/corefx/issues/21217", TargetFrameworkMonikers.UapAot)] 16 | public void Ctor_SortKeys(bool critical) 17 | { 18 | SortKey[] sortKeys = new SortKey[] { new SortKey("name1", "rule1", true), new SortKey("name2", "rule2", false) }; 19 | var control = new SortRequestControl(sortKeys); 20 | Assert.True(control.IsCritical); 21 | Assert.True(control.ServerSide); 22 | Assert.Equal("1.2.840.113556.1.4.473", control.Type); 23 | 24 | Assert.NotSame(sortKeys, control.SortKeys); 25 | for (int i = 0; i < sortKeys.Length; i++) 26 | { 27 | Assert.Equal(sortKeys[i].AttributeName, control.SortKeys[i].AttributeName); 28 | Assert.Equal(sortKeys[i].MatchingRule, control.SortKeys[i].MatchingRule); 29 | Assert.Equal(sortKeys[i].ReverseOrder, control.SortKeys[i].ReverseOrder); 30 | } 31 | 32 | control.IsCritical = critical; 33 | Assert.Equal(new byte[] 34 | { 35 | 0x30,0x23,0x30,0x11,0x04,0x05,0x6E,0x61,0x6D,0x65,0x31,0x80,0x05,0x72,0x75, 36 | 0x6C,0x65,0x31,0x81,0x01,0xFF,0x30,0x0E,0x04,0x05,0x6E,0x61,0x6D,0x65,0x32, 37 | 0x80,0x05,0x72,0x75,0x6C,0x65,0x32 38 | }, control.GetValue()); 39 | } 40 | 41 | [Fact] 42 | public void Ctor_NullSortKeys_ThrowsArgumentNullException() 43 | { 44 | AssertExtensions.Throws("sortKeys", () => new SortRequestControl(null)); 45 | } 46 | 47 | [Fact] 48 | public void CtorNullValueInSortKeys_ThrowsArgumentException() 49 | { 50 | AssertExtensions.Throws("sortKeys", () => new SortRequestControl(new SortKey[] { null })); 51 | } 52 | 53 | [Fact] 54 | public void Ctor_AttributeName_ReverseOrder() 55 | { 56 | var control = new SortRequestControl("AttributeName", true); 57 | SortKey sortKey = Assert.Single(control.SortKeys); 58 | Assert.Equal("AttributeName", sortKey.AttributeName); 59 | Assert.True(control.IsCritical); 60 | Assert.Null(sortKey.MatchingRule); 61 | Assert.True(sortKey.ReverseOrder); 62 | Assert.True(control.ServerSide); 63 | Assert.Equal("1.2.840.113556.1.4.473", control.Type); 64 | } 65 | 66 | [Fact] 67 | public void Ctor_AttributeName_MatchingRule_ReverseOrder() 68 | { 69 | var control = new SortRequestControl("AttributeName", "MatchingRule", true); 70 | SortKey sortKey = Assert.Single(control.SortKeys); 71 | Assert.Equal("AttributeName", sortKey.AttributeName); 72 | Assert.True(control.IsCritical); 73 | Assert.Equal("MatchingRule", sortKey.MatchingRule); 74 | Assert.True(sortKey.ReverseOrder); 75 | Assert.True(control.ServerSide); 76 | Assert.Equal("1.2.840.113556.1.4.473", control.Type); 77 | } 78 | 79 | [Fact] 80 | public void SortKeys_SetValid_GetReturnsExpected() 81 | { 82 | SortKey[] sortKeys = new SortKey[] { new SortKey("name1", "rule1", true), new SortKey("name2", "rule2", false) }; 83 | var control = new SortRequestControl { SortKeys = sortKeys }; 84 | Assert.NotSame(sortKeys, control.SortKeys); 85 | for (int i = 0; i < sortKeys.Length; i++) 86 | { 87 | Assert.Equal(sortKeys[i].AttributeName, control.SortKeys[i].AttributeName); 88 | Assert.Equal(sortKeys[i].MatchingRule, control.SortKeys[i].MatchingRule); 89 | Assert.Equal(sortKeys[i].ReverseOrder, control.SortKeys[i].ReverseOrder); 90 | } 91 | } 92 | 93 | [Fact] 94 | [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "The field _keys in full framework is called keys, so GetField returns null and ends up in a NRE")] 95 | public void SortKeys_GetNull_ReturnsEmptyArray() 96 | { 97 | var control = new SortRequestControl(); 98 | FieldInfo field = control.GetType().GetField("_keys", BindingFlags.NonPublic | BindingFlags.Instance); 99 | field.SetValue(control, null); 100 | Assert.Empty(control.SortKeys); 101 | } 102 | 103 | [Fact] 104 | public void SortKeys_SetNull_ThrowsArgumentNullException() 105 | { 106 | var control = new SortRequestControl(new SortKey[0]); 107 | AssertExtensions.Throws("value", () => control.SortKeys = null); 108 | } 109 | 110 | [Fact] 111 | public void SortKeys_SetNullInValue_ThrowsArgumentException() 112 | { 113 | var control = new SortRequestControl(new SortKey[0]); 114 | AssertExtensions.Throws("value", () => control.SortKeys = new SortKey[] { null }); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /tests/System.DirectoryServices.Protocols.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/TlsOperationExceptionTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.IO; 6 | using System.Reflection; 7 | using System.Runtime.Serialization; 8 | using System.Runtime.Serialization.Formatters.Binary; 9 | using Xunit; 10 | 11 | namespace System.DirectoryServices.Protocols.Tests 12 | { 13 | public class TlsOperationExceptionTests 14 | { 15 | [Fact] 16 | public void Ctor_Default() 17 | { 18 | var exception = new TlsOperationException(); 19 | Assert.NotEmpty(exception.Message); 20 | Assert.Null(exception.InnerException); 21 | } 22 | 23 | [Fact] 24 | public void Ctor_Message() 25 | { 26 | var exception = new TlsOperationException("message"); 27 | Assert.Equal("message", exception.Message); 28 | Assert.Null(exception.Response); 29 | Assert.Null(exception.InnerException); 30 | } 31 | 32 | [Fact] 33 | public void Ctor_Message_InnerException() 34 | { 35 | var innerException = new Exception(); 36 | var exception = new TlsOperationException("message", innerException); 37 | Assert.Equal("message", exception.Message); 38 | Assert.Null(exception.Response); 39 | Assert.Same(innerException, exception.InnerException); 40 | } 41 | 42 | [Fact] 43 | public void Ctor_Response() 44 | { 45 | var exception = new TlsOperationException((DirectoryResponse)null); 46 | Assert.NotEmpty(exception.Message); 47 | Assert.Null(exception.Response); 48 | Assert.Null(exception.InnerException); 49 | } 50 | 51 | [Fact] 52 | public void Ctor_Response_Message() 53 | { 54 | var exception = new TlsOperationException(null, "message"); 55 | Assert.Equal("message", exception.Message); 56 | Assert.Null(exception.Response); 57 | Assert.Null(exception.InnerException); 58 | } 59 | 60 | [Fact] 61 | public void Ctor_Response_Message_InnerException() 62 | { 63 | var innerException = new Exception(); 64 | var exception = new TlsOperationException(null, "message", innerException); 65 | Assert.Equal("message", exception.Message); 66 | Assert.Null(exception.Response); 67 | Assert.Same(innerException, exception.InnerException); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/TreeDeleteControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class TreeDeleteControlTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var control = new TreeDeleteControl(); 15 | Assert.True(control.IsCritical); 16 | Assert.True(control.ServerSide); 17 | Assert.Equal("1.2.840.113556.1.4.805", control.Type); 18 | 19 | Assert.Empty(control.GetValue()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/VerifyNameControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class VerifyNameControlTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var control = new VerifyNameControl(); 15 | Assert.True(control.IsCritical); 16 | Assert.Equal(0, control.Flag); 17 | Assert.Null(control.ServerName); 18 | Assert.True(control.ServerSide); 19 | Assert.Equal("1.2.840.113556.1.4.1338", control.Type); 20 | 21 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 5, 2, 1, 0, 4, 0 }, control.GetValue()); 22 | } 23 | 24 | [Theory] 25 | [InlineData("", new byte[] { 48, 132, 0, 0, 0, 5, 2, 1, 0, 4, 0 })] 26 | [InlineData("S", new byte[] { 48, 132, 0, 0, 0, 7, 2, 1, 0, 4, 2, 83, 0 })] 27 | public void Ctor_ServerName(string serverName, byte[] expectedValue) 28 | { 29 | var control = new VerifyNameControl(serverName); 30 | Assert.True(control.IsCritical); 31 | Assert.Equal(0, control.Flag); 32 | Assert.Equal(serverName, control.ServerName); 33 | Assert.True(control.ServerSide); 34 | Assert.Equal("1.2.840.113556.1.4.1338", control.Type); 35 | 36 | Assert.Equal(expectedValue, control.GetValue()); 37 | } 38 | 39 | [Theory] 40 | [InlineData("", -1, new byte[] { 48, 132, 0, 0, 0, 8, 2, 4, 255, 255, 255, 255, 4, 0 })] 41 | [InlineData("S", 10, new byte[] { 48, 132, 0, 0, 0, 7, 2, 1, 10, 4, 2, 83, 0 })] 42 | public void Ctor_ServerName_Flag(string serverName, int flag, byte[] expectedValue) 43 | { 44 | var control = new VerifyNameControl(serverName, flag); 45 | Assert.True(control.IsCritical); 46 | Assert.Equal(flag, control.Flag); 47 | Assert.Equal(serverName, control.ServerName); 48 | Assert.True(control.ServerSide); 49 | Assert.Equal("1.2.840.113556.1.4.1338", control.Type); 50 | 51 | Assert.Equal(expectedValue, control.GetValue()); 52 | } 53 | 54 | [Fact] 55 | public void Ctor_NullServerName_ThrowsArgumentNullException() 56 | { 57 | AssertExtensions.Throws("serverName", () => new VerifyNameControl(null)); 58 | AssertExtensions.Throws("serverName", () => new VerifyNameControl(null, 0)); 59 | } 60 | 61 | [Fact] 62 | public void ServerName_SetValid_GetReturnsExpected() 63 | { 64 | var control = new VerifyNameControl { ServerName = "ServerName" }; 65 | Assert.Equal("ServerName", control.ServerName); 66 | } 67 | 68 | [Fact] 69 | public void ServerName_SetNull_ThrowsArgumentNullException() 70 | { 71 | var control = new VerifyNameControl(); 72 | AssertExtensions.Throws("value", () => control.ServerName = null); 73 | } 74 | 75 | [Fact] 76 | public void Flag_Set_GetReturnsExpected() 77 | { 78 | var control = new VerifyNameControl { Flag = 10 }; 79 | Assert.Equal(10, control.Flag); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/VlvRequestControlTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using Xunit; 6 | 7 | namespace System.DirectoryServices.Protocols.Tests 8 | { 9 | public class VlvRequestControlTests 10 | { 11 | [Fact] 12 | public void Ctor_Default() 13 | { 14 | var control = new VlvRequestControl(); 15 | Assert.Equal(0, control.AfterCount); 16 | Assert.Equal(0, control.BeforeCount); 17 | Assert.True(control.IsCritical); 18 | Assert.Equal(0, control.Offset); 19 | Assert.Equal(0, control.EstimateCount); 20 | Assert.Empty(control.Target); 21 | Assert.Empty(control.ContextId); 22 | Assert.True(control.ServerSide); 23 | Assert.Equal("2.16.840.1.113730.3.4.9", control.Type); 24 | 25 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 18, 2, 1, 0, 2, 1, 0, 160, 132, 0, 0, 0, 6, 2, 1, 0, 2, 1, 0 }, control.GetValue()); 26 | } 27 | 28 | [Theory] 29 | [InlineData(0, 0, 0, new byte[] { 48, 132, 0, 0, 0, 18, 2, 1, 0, 2, 1, 0, 160, 132, 0, 0, 0, 6, 2, 1, 0, 2, 1, 0 })] 30 | [InlineData(10, 10, 10, new byte[] { 48, 132, 0, 0, 0, 18, 2, 1, 10, 2, 1, 10, 160, 132, 0, 0, 0, 6, 2, 1, 10, 2, 1, 0 })] 31 | public void Ctor_BeforeCount_AfterCount_Offset(int beforeCount, int afterCount, int offset, byte[] expectedValue) 32 | { 33 | var control = new VlvRequestControl(beforeCount, afterCount, offset); 34 | Assert.Equal(afterCount, control.AfterCount); 35 | Assert.Equal(beforeCount, control.BeforeCount); 36 | Assert.True(control.IsCritical); 37 | Assert.Equal(offset, control.Offset); 38 | Assert.Equal(0, control.EstimateCount); 39 | Assert.Empty(control.Target); 40 | Assert.Empty(control.ContextId); 41 | Assert.True(control.ServerSide); 42 | Assert.Equal("2.16.840.1.113730.3.4.9", control.Type); 43 | 44 | Assert.Equal(expectedValue, control.GetValue()); 45 | } 46 | 47 | [Theory] 48 | [InlineData(0, 0, null, new byte[0], new byte[] { 48, 132, 0, 0, 0, 18, 2, 1, 0, 2, 1, 0, 160, 132, 0, 0, 0, 6, 2, 1, 0, 2, 1, 0 })] 49 | [InlineData(10, 10, "abc", new byte[] { 97, 98, 99 }, new byte[] { 48, 132, 0, 0, 0, 11, 2, 1, 10, 2, 1, 10, 129, 3, 97, 98, 99 })] 50 | public void Ctor_BeforeCount_AfterCount_StringTarget(int beforeCount, int afterCount, string target, byte[] expectedTarget, byte[] expectedValue) 51 | { 52 | var control = new VlvRequestControl(beforeCount, afterCount, target); 53 | Assert.Equal(afterCount, control.AfterCount); 54 | Assert.Equal(beforeCount, control.BeforeCount); 55 | Assert.True(control.IsCritical); 56 | Assert.Equal(0, control.Offset); 57 | Assert.Equal(0, control.EstimateCount); 58 | Assert.NotSame(target, control.Target); 59 | Assert.Equal(expectedTarget ?? Array.Empty(), control.Target); 60 | Assert.Empty(control.ContextId); 61 | Assert.True(control.ServerSide); 62 | Assert.Equal("2.16.840.1.113730.3.4.9", control.Type); 63 | 64 | Assert.Equal(expectedValue, control.GetValue()); 65 | } 66 | 67 | [Theory] 68 | [InlineData(0, 0, null, new byte[] { 48, 132, 0, 0, 0, 18, 2, 1, 0, 2, 1, 0, 160, 132, 0, 0, 0, 6, 2, 1, 0, 2, 1, 0 })] 69 | [InlineData(10, 10, new byte[] { 1, 2, 3 }, new byte[] { 48, 132, 0, 0, 0, 11, 2, 1, 10, 2, 1, 10, 129, 3, 1, 2, 3 })] 70 | public void Ctor_BeforeCount_AfterCount_ByteArrayTarget(int beforeCount, int afterCount, byte[] target, byte[] expectedValue) 71 | { 72 | var control = new VlvRequestControl(beforeCount, afterCount, target); 73 | Assert.Equal(afterCount, control.AfterCount); 74 | Assert.Equal(beforeCount, control.BeforeCount); 75 | Assert.True(control.IsCritical); 76 | Assert.Equal(0, control.Offset); 77 | Assert.Equal(0, control.EstimateCount); 78 | Assert.NotSame(target, control.Target); 79 | Assert.Equal(target ?? Array.Empty(), control.Target); 80 | Assert.Empty(control.ContextId); 81 | Assert.True(control.ServerSide); 82 | Assert.Equal("2.16.840.1.113730.3.4.9", control.Type); 83 | 84 | Assert.Equal(expectedValue, control.GetValue()); 85 | } 86 | 87 | [Fact] 88 | public void Ctor_NegativeBeforeCount_ThrowsArgumentException() 89 | { 90 | AssertExtensions.Throws("value", () => new VlvRequestControl(-1, 0, "target")); 91 | AssertExtensions.Throws("value", () => new VlvRequestControl(-1, 0, 0)); 92 | AssertExtensions.Throws("value", () => new VlvRequestControl(-1, 0, new byte[0])); 93 | } 94 | 95 | [Fact] 96 | public void Ctor_NegativeAfterCount_ThrowsArgumentException() 97 | { 98 | AssertExtensions.Throws("value", () => new VlvRequestControl(0, -1, "target")); 99 | AssertExtensions.Throws("value", () => new VlvRequestControl(0, -1, 0)); 100 | AssertExtensions.Throws("value", () => new VlvRequestControl(0, -1, new byte[0])); 101 | } 102 | 103 | [Fact] 104 | public void Ctor_NegativeOffset_ThrowsArgumentException() 105 | { 106 | AssertExtensions.Throws("value", () => new VlvRequestControl(0, 0, -1)); 107 | } 108 | 109 | [Fact] 110 | public void EstimateCount_SetValid_GetReturnsExpected() 111 | { 112 | var control = new VlvRequestControl { EstimateCount = 10 }; 113 | Assert.Equal(10, control.EstimateCount); 114 | } 115 | 116 | [Fact] 117 | public void EstimateCount_SetNegative_ThrowsArgumentException() 118 | { 119 | var control = new VlvRequestControl(); 120 | AssertExtensions.Throws("value", () => control.EstimateCount = -1); 121 | } 122 | 123 | [Fact] 124 | public void ContextId_Set_GetReturnsExpected() 125 | { 126 | byte[] contextId = new byte[] { 1, 2, 3 }; 127 | var control = new VlvRequestControl { ContextId = contextId }; 128 | Assert.NotSame(contextId, control.ContextId); 129 | Assert.Equal(contextId, control.ContextId); 130 | 131 | Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 23, 2, 1, 0, 2, 1, 0, 160, 132, 0, 0, 0, 6, 2, 1, 0, 2, 1, 0, 4, 3, 1, 2, 3 }, control.GetValue()); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /tests/xunit.netcore.extensions/Attributes/ActiveIssueAttribute.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using Xunit.Sdk; 7 | 8 | namespace Xunit 9 | { 10 | /// 11 | /// Apply this attribute to your test method to specify an active issue. 12 | /// 13 | [TraitDiscoverer("Xunit.NetCore.Extensions.ActiveIssueDiscoverer", "Xunit.NetCore.Extensions")] 14 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)] 15 | public class ActiveIssueAttribute : Attribute, ITraitAttribute 16 | { 17 | public ActiveIssueAttribute(int issueNumber, TestPlatforms platforms) { } 18 | public ActiveIssueAttribute(string issue, TestPlatforms platforms) { } 19 | public ActiveIssueAttribute(int issueNumber, TargetFrameworkMonikers framework) { } 20 | public ActiveIssueAttribute(string issue, TargetFrameworkMonikers framework) { } 21 | public ActiveIssueAttribute(int issueNumber, TestPlatforms platforms = TestPlatforms.Any, TargetFrameworkMonikers framework = (TargetFrameworkMonikers)0) { } 22 | public ActiveIssueAttribute(string issue, TestPlatforms platforms = TestPlatforms.Any, TargetFrameworkMonikers framework = (TargetFrameworkMonikers)0) { } 23 | } 24 | } -------------------------------------------------------------------------------- /tests/xunit.netcore.extensions/Attributes/ConditionalFactAttribute.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using Xunit.Sdk; 7 | 8 | namespace Xunit 9 | { 10 | [XunitTestCaseDiscoverer("Xunit.NetCore.Extensions.ConditionalFactDiscoverer", "Xunit.NetCore.Extensions")] 11 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 12 | public sealed class ConditionalFactAttribute : FactAttribute 13 | { 14 | public Type CalleeType { get; private set; } 15 | public string[] ConditionMemberNames { get; private set; } 16 | 17 | public ConditionalFactAttribute(Type calleeType, params string[] conditionMemberNames) 18 | { 19 | CalleeType = calleeType; 20 | ConditionMemberNames = conditionMemberNames; 21 | } 22 | 23 | public ConditionalFactAttribute(params string[] conditionMemberNames) 24 | { 25 | ConditionMemberNames = conditionMemberNames; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /tests/xunit.netcore.extensions/Attributes/SkipOnTargetFrameworkAttribute.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using Xunit.Sdk; 7 | 8 | namespace Xunit 9 | { 10 | /// 11 | /// Apply this attribute to your test method to specify this is a platform specific test. 12 | /// 13 | [TraitDiscoverer("Xunit.NetCore.Extensions.SkipOnTargetFrameworkDiscoverer", "Xunit.NetCore.Extensions")] 14 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)] 15 | public class SkipOnTargetFrameworkAttribute : Attribute, ITraitAttribute 16 | { 17 | public SkipOnTargetFrameworkAttribute(TargetFrameworkMonikers platform, string reason = null) { } 18 | } 19 | } -------------------------------------------------------------------------------- /tests/xunit.netcore.extensions/Discoverers/ConditionalFactDiscoverer .cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using Xunit.Abstractions; 9 | using Xunit.Sdk; 10 | 11 | namespace Xunit.NetCore.Extensions 12 | { 13 | public class ConditionalFactDiscoverer : FactDiscoverer 14 | { 15 | private readonly IMessageSink _diagnosticMessageSink; 16 | 17 | public ConditionalFactDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnosticMessageSink) 18 | { 19 | _diagnosticMessageSink = diagnosticMessageSink; 20 | } 21 | 22 | public override IEnumerable Discover( 23 | ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) 24 | { 25 | IEnumerable testCases = base.Discover(discoveryOptions, testMethod, factAttribute); 26 | return ConditionalTestDiscoverer.Discover(discoveryOptions, _diagnosticMessageSink, testMethod, testCases, factAttribute.GetConstructorArguments().ToArray()); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /tests/xunit.netcore.extensions/Discoverers/ConditionalTestDiscoverer.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Reflection; 9 | using Xunit.Abstractions; 10 | using Xunit.Sdk; 11 | 12 | namespace Xunit.NetCore.Extensions 13 | { 14 | // Internal helper class for code common to conditional test discovery through 15 | // [ConditionalFact] and [ConditionalTheory] 16 | internal class ConditionalTestDiscoverer 17 | { 18 | // This helper method evaluates the given condition member names for a given set of test cases. 19 | // If any condition member evaluates to 'false', the test cases are marked to be skipped. 20 | // The skip reason is the collection of all the condition members that evalated to 'false'. 21 | internal static IEnumerable Discover( 22 | ITestFrameworkDiscoveryOptions discoveryOptions, 23 | IMessageSink diagnosticMessageSink, 24 | ITestMethod testMethod, 25 | IEnumerable testCases, 26 | object[] conditionArguments) 27 | { 28 | Type calleeType = null; 29 | string[] conditionMemberNames = null; 30 | 31 | if (CheckInputToSkipExecution(conditionArguments, ref calleeType, ref conditionMemberNames, testMethod)) return testCases; 32 | 33 | MethodInfo testMethodInfo = testMethod.Method.ToRuntimeMethod(); 34 | Type testMethodDeclaringType = testMethodInfo.DeclaringType; 35 | List falseConditions = new List(conditionMemberNames.Count()); 36 | 37 | foreach (string entry in conditionMemberNames) 38 | { 39 | string conditionMemberName = entry; 40 | 41 | // Null condition member names are silently tolerated 42 | if (string.IsNullOrWhiteSpace(conditionMemberName)) 43 | { 44 | continue; 45 | } 46 | 47 | Type declaringType; 48 | 49 | if (calleeType != null) 50 | { 51 | declaringType = calleeType; 52 | } 53 | else 54 | { 55 | declaringType = testMethodDeclaringType; 56 | 57 | string[] symbols = conditionMemberName.Split('.'); 58 | if (symbols.Length == 2) 59 | { 60 | conditionMemberName = symbols[1]; 61 | ITypeInfo type = testMethod.TestClass.Class.Assembly.GetTypes(false).Where(t => t.Name.Contains(symbols[0])).FirstOrDefault(); 62 | if (type != null) 63 | { 64 | declaringType = type.ToRuntimeType(); 65 | } 66 | } 67 | } 68 | 69 | MethodInfo conditionMethodInfo; 70 | if ((conditionMethodInfo = LookupConditionalMethod(declaringType, conditionMemberName)) == null) 71 | { 72 | return new[] 73 | { 74 | new ExecutionErrorTestCase( 75 | diagnosticMessageSink, 76 | discoveryOptions.MethodDisplayOrDefault(), 77 | testMethod, 78 | GetFailedLookupString(conditionMemberName, declaringType)) 79 | }; 80 | } 81 | 82 | // In the case of multiple conditions, collect the results of all 83 | // of them to produce a summary skip reason. 84 | try 85 | { 86 | if (!(bool)conditionMethodInfo.Invoke(null, null)) 87 | { 88 | falseConditions.Add(conditionMemberName); 89 | } 90 | } 91 | catch (Exception exc) 92 | { 93 | falseConditions.Add($"{conditionMemberName} ({exc.GetType().Name})"); 94 | } 95 | } 96 | 97 | // Compose a summary of all conditions that returned false. 98 | if (falseConditions.Count > 0) 99 | { 100 | string skippedReason = string.Format("Condition(s) not met: \"{0}\"", string.Join("\", \"", falseConditions)); 101 | return testCases.Select(tc => new SkippedTestCase(tc, skippedReason)); 102 | } 103 | 104 | // No conditions returned false (including the absence of any conditions). 105 | return testCases; 106 | } 107 | 108 | internal static string GetFailedLookupString(string name, Type type) 109 | { 110 | return 111 | $"An appropriate member '{name}' could not be found. " + 112 | $"The conditional method needs to be a static method or property on the type {type} or any ancestor, " + 113 | "of any visibility, accepting zero arguments, and having a return type of Boolean."; 114 | } 115 | 116 | internal static MethodInfo LookupConditionalMethod(Type t, string name) 117 | { 118 | if (t == null || name == null) 119 | return null; 120 | 121 | TypeInfo ti = t.GetTypeInfo(); 122 | 123 | MethodInfo mi = ti.GetDeclaredMethod(name); 124 | if (mi != null && mi.IsStatic && mi.GetParameters().Length == 0 && mi.ReturnType == typeof(bool)) 125 | return mi; 126 | 127 | PropertyInfo pi = ti.GetDeclaredProperty(name); 128 | if (pi != null && pi.PropertyType == typeof(bool) && pi.GetMethod != null && pi.GetMethod.IsStatic && pi.GetMethod.GetParameters().Length == 0) 129 | return pi.GetMethod; 130 | 131 | return LookupConditionalMethod(ti.BaseType, name); 132 | } 133 | 134 | internal static bool CheckInputToSkipExecution(object[] conditionArguments, ref Type calleeType, ref string[] conditionMemberNames, ITestMethod testMethod = null) 135 | { 136 | // A null or empty list of conditionArguments is treated as "no conditions". 137 | // and the test cases will be executed. 138 | // Example: [ConditionalClass()] 139 | if (conditionArguments == null || conditionArguments.Length == 0) return true; 140 | 141 | calleeType = conditionArguments[0] as Type; 142 | if (calleeType != null) 143 | { 144 | if (conditionArguments.Length < 2) 145 | { 146 | // [ConditionalFact(typeof(x))] no provided methods. 147 | return true; 148 | } 149 | 150 | // [ConditionalFact(typeof(x), "MethodName")] 151 | conditionMemberNames = conditionArguments[1] as string[]; 152 | } 153 | else 154 | { 155 | // For [ConditionalClass], unable to get the Type info. All test cases will be executed. 156 | if (testMethod == null) return true; 157 | 158 | // [ConditionalFact("MethodName")] 159 | conditionMemberNames = conditionArguments[0] as string[]; 160 | } 161 | 162 | // [ConditionalFact((string[]) null)] 163 | if (conditionMemberNames == null || conditionMemberNames.Count() == 0) return true; 164 | 165 | return false; 166 | } 167 | } 168 | } -------------------------------------------------------------------------------- /tests/xunit.netcore.extensions/SkippedTestCase.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using Xunit; 10 | using Xunit.Abstractions; 11 | using Xunit.Sdk; 12 | 13 | namespace Xunit.NetCore.Extensions 14 | { 15 | /// Wraps another test case that should be skipped. 16 | internal sealed class SkippedTestCase : LongLivedMarshalByRefObject, IXunitTestCase 17 | { 18 | private readonly IXunitTestCase _testCase; 19 | private readonly string _skippedReason; 20 | 21 | internal SkippedTestCase(IXunitTestCase testCase, string skippedReason) 22 | { 23 | _testCase = testCase; 24 | _skippedReason = skippedReason; 25 | } 26 | 27 | public string DisplayName { get { return _testCase.DisplayName; } } 28 | 29 | public IMethodInfo Method { get { return _testCase.Method; } } 30 | 31 | public string SkipReason { get { return _skippedReason; } } 32 | 33 | public ISourceInformation SourceInformation { get { return _testCase.SourceInformation; } set { _testCase.SourceInformation = value; } } 34 | 35 | public ITestMethod TestMethod { get { return _testCase.TestMethod; } } 36 | 37 | public object[] TestMethodArguments { get { return _testCase.TestMethodArguments; } } 38 | 39 | public Dictionary> Traits { get { return _testCase.Traits; } } 40 | 41 | public string UniqueID { get { return _testCase.UniqueID; } } 42 | 43 | public void Deserialize(IXunitSerializationInfo info) { _testCase.Deserialize(info); } 44 | 45 | public Task RunAsync( 46 | IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, 47 | ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) 48 | { 49 | return new XunitTestCaseRunner(this, DisplayName, _skippedReason, constructorArguments, TestMethodArguments, messageBus, aggregator, cancellationTokenSource).RunAsync(); 50 | } 51 | 52 | public void Serialize(IXunitSerializationInfo info) { _testCase.Serialize(info); } 53 | } 54 | } -------------------------------------------------------------------------------- /tests/xunit.netcore.extensions/TargetFrameworkMonikers.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | 7 | namespace Xunit 8 | { 9 | [Flags] 10 | public enum TargetFrameworkMonikers 11 | { 12 | Net45 = 0x1, 13 | Net451 = 0x2, 14 | Net452 = 0x4, 15 | Net46 = 0x8, 16 | Net461 = 0x10, 17 | Net462 = 0x20, 18 | Net463 = 0x40, 19 | Netcore50 = 0x80, 20 | Netcore50aot = 0x100, 21 | Netcoreapp1_0 = 0x200, 22 | Netcoreapp1_1 = 0x400, 23 | NetFramework = 0x800, 24 | Netcoreapp = 0x1000, 25 | UapNotUapAot = 0x2000, 26 | UapAot = 0x4000, 27 | Uap = UapAot | UapNotUapAot, 28 | NetcoreCoreRT = 0x8000, 29 | Mono = 0x10000 30 | } 31 | } -------------------------------------------------------------------------------- /tests/xunit.netcore.extensions/TestPlatforms.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | 7 | namespace Xunit 8 | { 9 | [Flags] 10 | public enum TestPlatforms 11 | { 12 | Windows = 1, 13 | Linux = 2, 14 | OSX = 4, 15 | FreeBSD = 8, 16 | NetBSD = 16, 17 | AnyUnix = FreeBSD | Linux | NetBSD | OSX, 18 | Any = ~0 19 | } 20 | } --------------------------------------------------------------------------------