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

First DirectoryServcies tests which runs against real server #24316

Merged
merged 4 commits into from
Sep 29, 2017

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Sep 28, 2017

This is the first test collection which intended to run against real servers supports LDAP.

Read the comment in the file LDAP.Configuration.xml to know how can enable such tests. by default, these tests will be skipped till providing the real server info in the file LDAP.Configuration.xml.

These are just initial tests which we should add more as we go. It is recommended when adding any more tests to test it against AD servers (i.e. Windows Server) and against OpenDJ too to avoid the behavior differences.

One more note, I have written every test case as self-contained so every test case will exit in a clean state of the server.

@tarekgh
Copy link
Member Author

tarekgh commented Sep 28, 2017

CC @AlexGhiondea @karelz @danmosemsft

@tarekgh
Copy link
Member Author

tarekgh commented Sep 28, 2017

Looks msbuild complaining

error MSB4066: The attribute "CopyToOutputDirectory" in element <None> is unrecognized

I'll try to fix this one.

@karelz
Copy link
Member

karelz commented Sep 28, 2017

Very cool.
If we can create Docker image with the server, that would be awesome for even easier automation.

cc @hughbe

return ouCoreDevs;
}

private DirectoryEntry CreateCN(DirectoryEntry ouEntry, string cn, string description, string phone)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CN isn't really a "type" it stands for common name. I would change this name to match the object type that is actually getting created.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll fix that

}
}

private void SearchCNByName(DirectoryEntry de, string cnName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback on naming

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll fix that

DirectoryEntry rootOU = CreateOU(de, "CoreFxRootOU", "CoreFx Root OU");
try
{
DirectoryEntry child1OU = CreateOU(rootOU, "CoreFxChild1OU", "CoreFx Child OU 1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need using statements

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll fix that


CreateCN(child1OU, "user.ou1.1", "User 1 is in CoreFx ou 1", "1 111 111 11111");
CreateCN(child1OU, "user.ou1.2", "User 2 is in CoreFx ou 1", "1 222 222 22222");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we'll add some test logging in the future so it's clear which of these sub steps failed when the test fails?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XUnit will catch any thrown exception and have it in the logs.


private void SearchOUByName(DirectoryEntry de, string ouName)
{
using (DirectorySearcher ds = new DirectorySearcher(de))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set ds.ClientTimeout to some reasonable value. I think the default is infinite wait.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll fix that. I'll use 2 minutes timeout which I think can be reasonable.

LdapConfiguration.Configuration.AuthenticationTypes))
{
string ouName = "NetCoreDevs";
CreateOU(de, ouName, ".Net Core Developers Unit");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should try and remove any pre-exisiting OUs with the target name first to take care of tests which leave the environment dirty

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll fix that

DeleteDirectoryEntry(de, child);
}

parent.Children.Remove(de);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad formatting

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll fix that

}
}

private void SearchCNByName(DirectoryEntry de, string cnName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all of these test* methods, should we add a finally block and then assert if any exception is thrown? That way you know which action failed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. XUnit is catching the thrown exception and fail the test with the exception logs. we should be fine here.

internal string Port { get; set; }
internal string Domain { get; set; }
internal AuthenticationTypes AuthenticationTypes { get; set; }
internal string LdapPath => String.IsNullOrEmpty(Port) ? $"LDAP://{ServerName}/{Domain}" : $"LDAP://{ServerName}:{Port}/{Domain}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This format is very specific to the System.DirectoryServices* assembly but doesn't apply to System.DirectoryServices.Protocols We may want to reuse this config class for all the S.DS.* assemblies to maybe this assembly specific logic should be moved to the assembly specific tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding tests to System.DirectoryServices.Protocols, we can look at what configuration is used there and then can update the configuration class to support it. or to use another specific configuration class.

@tarekgh tarekgh merged commit f4c2ba6 into dotnet:master Sep 29, 2017
@tarekgh
Copy link
Member Author

tarekgh commented Sep 29, 2017

Thanks @tquerec for your review

@karelz karelz added this to the 2.1.0 milestone Oct 11, 2017
@tarekgh tarekgh deleted the InitalDirectoryServicesRealTests branch October 27, 2017 17:49
pjanotti pushed a commit to pjanotti/corefx that referenced this pull request Oct 31, 2017
…24316)

* First DirectoryServcies tests which runs against real server

* Fix msbuild failure with None element

* Address the feedback

* Fix some formatting
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…corefx#24316)

* First DirectoryServcies tests which runs against real server

* Fix msbuild failure with None element

* Address the feedback

* Fix some formatting


Commit migrated from dotnet/corefx@f4c2ba6
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants