如何单元测试对Active Directory中的NextPasswordChangeDate功能 [英] How to unit-test a NextPasswordChangeDate function against the Active Directory

查看:459
本文介绍了如何单元测试对Active Directory中的NextPasswordChangeDate功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中工作使用Active Directory,深入。我设置了几个单元测试对AD几件事情,其中​​一些我实现用嘲笑的对象,其中一些我实现通过对AD真正的电话。

I am working on a project using the Active Directory, intensively. I set up a few unit tests for several things against the AD, some of which I achieve using mocked objects, some which I achieve through real calls against the AD.

由于我的项目的功能之一,我必须找回所谓的用户配置文件。该用户配置文件大多为简单的属性,比如CN,公司,雇员等。不过,我试图填补一个属性是不是一个简单的NextPasswordChangeDate。

As one of the functions of my project, I have to retrieve a so called "user profile". This user profile consists mostly of simple attributes, like "cn", "company", "employeeid", etc. However, one property that I am trying to fill is not a simple one "NextPasswordChangeDate".

要尽我所知,得到这个唯一的办法,就是用的pwdLastSet聚聚域策略的maxPwdAge并利用这些信息。

To the best of my knowledge, the only way to get this, is by getting the domain policy's maxPwdAge and use this information together with pwdLastSet.

现在我的问题:如何以智能的方式我的单元测试吗?我想出了三个选项,所有这一切都不是很大:

Now my question: How can I unit test this in an intelligent way? I came up with three options, all of which are not great:

  1. 使用我自己的帐户作为搜索的帐户,发现通过其他途径和c很难$ C $在单元测试的日期。通过这种方式,我可以单元测试我的code不错,但每个月,我必须要改变的单元测试,因为我改变了我的密码。
  2. 使用具有密码永不过期设置一些帐户。这是一种毫无意义的,因为我真的不能由测试我的code是正确的。
  3. 使用一个模拟对象,并确保正确的API调用发生。该选项允许测试函数的行为的正确性,但随后的测试逻辑其实是在单元测试,所以我不能肯定,这是做正确的事,即使测试通过。

你建议哪三个?或者,也许你有一个更好的选择?

Which of the three do you suggest? Or maybe you have a better option?

推荐答案

由于1和2的依靠现有的AD和具有已知值看起来更像集成测试我的。

Since 1 and 2 the rely on AD existing and having known values seem more like integration tests to me.

我一般采取任何不确定性的行为应当接口出来,如果​​可能的话嘲笑侧(#3)。正如你指出,这将永远离开的真正落实code,是不是单元测试的一个数额,但将被投保已知的广告系统运行集成测试。

I generally take the side that any non-deterministic behavior should be interfaced out and mocked if possible (#3). As you noted this will always leave an amount of real implementation code that is not unit-testable, but would then be covered by your integration tests running against a known AD system.

<一个href="http://stackoverflow.com/questions/876715/unit-tests-for-$c$c-accessing-activedirectory">Related提问/回答

这篇关于如何单元测试对Active Directory中的NextPasswordChangeDate功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆