Testing a `PrincipalContext` using `ValidateCredentials(null, null)` behaves unexpectedly

Wes Toleman

I need to validate the credentials that are used to connect to an AD server. If if pass invalid credentials to PrincipalContext(ContextType, String, String, String), PrincipalContext.ConnectedServer throws a System.DirectoryServices.DirectoryServicesCOMException which is discovered on the first use of the PrincipalContext.

I am trying to test the credentials with PrincipalContext.ValidateCredentials(null, null) but I am having issues. According to the .NET Core 2.0 docs

The ValidateCredentials method binds to the server specified in the constructor. If the username and password parameters are null, the credentials specified in the constructor are validated.

I create a connnection to the server.

string username = "username"
string password = "password"

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "my_domain.local", username, password);

And then to test the connection I try:

if (ctx.ValidateCredentials(null, null))
{
    // This block does not get hit!
    // This is surprising because the credentials are valid
}

Which has different behaviour to:

if (ctx.ValidateCredentials(username, password))
{
    // Credentials are valid, this block gets hit
}

The docs lead me to believe these calls should behave identically yet I am experiencing different results. Why is this and what is the proper way to test a connection?

Gabriel Luci

I was able to replicate this by running your code under a local account on my computer and passing valid domain credentials in the constructor. ValidateCredentials(null, null) does indeed fail.

This sounds like a bug, either in the code or in the documentation, so I've filed a bug on GitHub: https://github.com/dotnet/corefx/issues/29369

Edit: looks like they've decided to leave the implementation as-is and correct the documentation.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

jsonschema - oneOf keyword behaves unexpectedly

分類Dev

Fragment shader behaves unexpectedly (Test grid)

分類Dev

Go concurrency with for loop and anonymous function behaves unexpectedly

分類Dev

Child fragment from onListItemClick within viewPager behaves unexpectedly

分類Dev

Using Fused Location API and App Crashing Unexpectedly

分類Dev

SqlConnection closes unexpectedly inside using statement

分類Dev

In Antlr4 enter listener, accessor function unexpectedly returns null

分類Dev

Using setTimeout() in React and Testing it

分類Dev

「ValidateCredentials(null、null)」を使用して「PrincipalContext」をテストすると、予期しない動作が発生します

分類Dev

Unexpectedly found nil when using variable outside of declared function

分類Dev

Unexpected null reference when testing with NUnit and Moq

分類Dev

Angular testing: Cannot read property 'nativeElement' of null

分類Dev

Testing default IFS against null IFS

分類Dev

Testing `instanceof` is redundant and can be replaced with `!= null`?

分類Dev

Testing Subject using TestScheduler in RxJs

分類Dev

Testing argument using Python Click

分類Dev

PrincipalContextのしくみ

分類Dev

Testing a controller not using $scope using karma

分類Dev

Detox partially visible Button behaves differently using toBeVisible() expectation and tap() action

分類Dev

Why does one of my two Dell monitors unexpectedly enter power save mode when using DisplayPort daisychaining?

分類Dev

Parameterized testing with Mockito by using JUnit @Rule?

分類Dev

Testing concrete methods in abstract classes using subclasses

分類Dev

Testing MVC controller using reactor with WebClient

分類Dev

Using queries with ORDER BY when testing with the embedded runtime

分類Dev

Using react-testing-library with storyshots?

分類Dev

Testing with Jest in Typescript using a Bazel custom rule

分類Dev

Testing functions with properties using Jest and Sinon

分類Dev

Jmeter load testing using single machine

分類Dev

Automated Testing using MS Coded UI

Related 関連記事

  1. 1

    jsonschema - oneOf keyword behaves unexpectedly

  2. 2

    Fragment shader behaves unexpectedly (Test grid)

  3. 3

    Go concurrency with for loop and anonymous function behaves unexpectedly

  4. 4

    Child fragment from onListItemClick within viewPager behaves unexpectedly

  5. 5

    Using Fused Location API and App Crashing Unexpectedly

  6. 6

    SqlConnection closes unexpectedly inside using statement

  7. 7

    In Antlr4 enter listener, accessor function unexpectedly returns null

  8. 8

    Using setTimeout() in React and Testing it

  9. 9

    「ValidateCredentials(null、null)」を使用して「PrincipalContext」をテストすると、予期しない動作が発生します

  10. 10

    Unexpectedly found nil when using variable outside of declared function

  11. 11

    Unexpected null reference when testing with NUnit and Moq

  12. 12

    Angular testing: Cannot read property 'nativeElement' of null

  13. 13

    Testing default IFS against null IFS

  14. 14

    Testing `instanceof` is redundant and can be replaced with `!= null`?

  15. 15

    Testing Subject using TestScheduler in RxJs

  16. 16

    Testing argument using Python Click

  17. 17

    PrincipalContextのしくみ

  18. 18

    Testing a controller not using $scope using karma

  19. 19

    Detox partially visible Button behaves differently using toBeVisible() expectation and tap() action

  20. 20

    Why does one of my two Dell monitors unexpectedly enter power save mode when using DisplayPort daisychaining?

  21. 21

    Parameterized testing with Mockito by using JUnit @Rule?

  22. 22

    Testing concrete methods in abstract classes using subclasses

  23. 23

    Testing MVC controller using reactor with WebClient

  24. 24

    Using queries with ORDER BY when testing with the embedded runtime

  25. 25

    Using react-testing-library with storyshots?

  26. 26

    Testing with Jest in Typescript using a Bazel custom rule

  27. 27

    Testing functions with properties using Jest and Sinon

  28. 28

    Jmeter load testing using single machine

  29. 29

    Automated Testing using MS Coded UI

ホットタグ

アーカイブ