}
// Throw if user wants to do anonymous bind but specifies credentials.
- if (AuthType == AuthType.Anonymous && (newCredential != null && (!string.IsNullOrEmpty(newCredential.Password) || string.IsNullOrEmpty(newCredential.UserName))))
+ if (AuthType == AuthType.Anonymous && (newCredential != null && (!string.IsNullOrEmpty(newCredential.Password) || !string.IsNullOrEmpty(newCredential.UserName))))
{
throw new InvalidOperationException(SR.InvalidAuthCredential);
}
Assert.Equal(AuthType.Basic, connection.AuthType);
}
- [Fact]
- public void AuthType_Anonymous_DoesNotThrowNull()
+ public static IEnumerable<object[]> AuthType_Anonymous_DoesNotThrowNull_TestData()
{
- var connection = new LdapConnection("server");
- connection.AuthType = AuthType.Anonymous;
+ yield return new object[] { new LdapDirectoryIdentifier("server"), null };
+ yield return new object[] { new LdapDirectoryIdentifier("server"), new NetworkCredential() };
+ }
+
+ [Theory]
+ [MemberData(nameof(AuthType_Anonymous_DoesNotThrowNull_TestData))]
+ public void AuthType_Anonymous_DoesNotThrowNull(LdapDirectoryIdentifier identifier, NetworkCredential credential)
+ {
+ var connection = new LdapConnection(identifier, credential, AuthType.Anonymous);
// When calling Bind we make sure that the exception thrown is not that there was a NullReferenceException
// trying to retrieve a null password's length, but instead an LdapException given the server cannot be reached.
Assert.Throws<LdapException>(() => connection.Bind());