我在測試錯誤密碼提供足夠多的時間來觸發鎖定時測試.net LDAP客戶端的行爲。在某些情況下,當用戶被鎖定時LDAP綁定到ActiveDirectory會成功
我看到這種奇怪的行爲:看起來,如果進程成功連接在任何時間,然後它能夠重新連接,即使有意識地觸發鎖定後。
這裏是我的綁定方法的簡寫:
private DirectoryEntry Bind(string userId, string password)
{
var entry = new DirectoryEntry(BasePath, userId, password);
// If the password is bad, the attempt to access entry.NativeObject throws an exception.
var obj = entry.NativeObject; // causes the bind to occur
return entry;
}
我的測試過程如下:
private void TestLockout()
{
// attempt with bad pw enough times to trigger a lockout.
for (int i=0; i < 5; i++)
{
try
{
// i.ToString() is a purposefully bad pw
Bind("testuser", i.ToString());
}
catch
{
}
}
// Now make sure that an attempt with a good pw fails due to lockout
var bindSuccess = true;
try
{
Bind("testuser", "correctpassword");
}
catch
{
bindSuccess = false;
}
// the output should be "false"
Console.WriteLine("Bind result is " + bindSuccess.ToString();
}
這工作正常原樣。但是,如果在測試之前使用密碼良好的方式調用Bind(),則會得到不同的結果。
督察,這樣的:
Bind("testuser", "correctpassword"); // succeeds
TestLockout(); // does not give the correct result
會出現以下情況。
a)TestLockout產生不正確的輸出,因爲最終的綁定成功,它不應該。
b)然而,由於後續的檢查,我知道用戶被鎖定。
因此,看起來某些組件正在跟蹤當前進程是否成功連接。我需要有一種方法來清除這種情況。此驗證代碼將在長時間運行的服務進程中執行,並且在用戶被鎖定時驗證用戶身份是不可接受的。
太棒了!就是這樣。 – 2012-07-17 23:46:37