使用 LDAP 服务器进行 Rails Cucumber 测试
我正在尝试为我的应用程序编写一些 Cucumber 测试,该应用程序使用 Authlogic 进行身份验证,但实际上将用户存储在 LDAP 服务器中。
该应用程序似乎工作正常,但我遇到麻烦的是为其编写测试(我知道,我知道,我应该先编写测试。)很容易有一个测试数据库,其中数据在之后被清除每次运行,但使用 LDAP 服务器就不那么容易了。
我的想法是编写一个 rake 任务(如 rake ldap:test:prepare)来在每次运行之前刷新 ldap 服务器(或使其成为依赖项),但这在我进行测试时似乎相当耗时(并使自动测试接近)不可能。)
有更好的方法吗?是否有一个基于 ruby 的假 LDAP 服务器,我可以使用预定义的装置绑定到该服务器?还有其他我没有想到的更优雅的解决方案吗? (不使用 LDAP 不是一个选项。)
I am trying to write some cucumber tests for my application that uses Authlogic for authentication, but actually stores users in a LDAP server.
The application seems to work fine, but where I am running into trouble is writing tests for it (I know, I know, I should've wrote the tests first.) It's easy to have a test database where the data is cleared out after each run, but not so easy with an LDAP server.
My idea was to write a rake task (like rake ldap:test:prepare) to refresh the ldap server before each run (or make it a dependency), but that seems pretty time consuming when I am working on tests (and makes autotest near impossible.)
Is there a better way to do this? Is there a ruby-based fake LDAP server I can bind to with pre-defined fixtures? Is there some other even more elegant solution that I am not thinking of? (not using LDAP isn't an option.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试使用 Ladle 作为测试 LDAP 服务器:“Ladle 提供轻量级目录访问 (LDAP) 的强大帮助,用于使用 rspec、cucumber 或任何其他 ruby 测试框架进行测试”。
https://github.com/NUBIC/ladle
Have a go using Ladle as a test LDAP server: "Ladle dishes out steaming helpings of lightweight directory access (LDAP) for use in testing with rspec, cucumber, or any other ruby test framework".
https://github.com/NUBIC/ladle
所以一般来说,Cucumber 测试用于集成和验收测试。既然如此,它应该对系统进行端到端测试,因此它也应该测试 LDAP 集成。如果您可以的话,我的建议是设置另一台 LDAP 服务器,并从您的实时服务器中定期转储,以便使用您需要的任何测试数据来设置它。
我想说的是,您的第一个想法是在每次运行之前刷新 LDAP 数据库的依赖项是“正确”的方法。集成/验收测试应该需要很长时间。它正在测试系统的整体功能,而不仅仅是小(单元)部分。
Cucumber 不是单元测试框架,不应该以这种方式使用。如果您的应用程序在迁移到 2.3.4 后因为没有测试而崩溃,我认为您应该进入那里并开始编写一些单元测试...
现在这是我个人的偏见,但如果您没有适当的单元测试,我会看一下 RSpec。如果你喜欢 Cucumber 类似英文的语法,RSpec 肯定会有类似的感觉。如果您已经在 Test::Unit 中进行了一些测试,我绝对建议将 Shoulda 带到聚会中,或者可能使用 Context/Matchy(所有这些都可以在 github 上找到),以在 Test::Unit 框架中获得 RSpec 感觉。
So in general Cucumber tests are for integration and acceptance testing. That being the case it is supposed to test the system end-to-end, so it should be testing the LDAP integration as well. My suggestion, if you can swing it, would be to set up another LDAP server and do a periodic dump from your live one to set it up with whatever test data you need.
I will say though that your first idea of having the dependency that refreshes the LDAP db before each run is the "right" way to do it. Integration/acceptance testing is supposed to take a long time. It is testing the entirety of the functionality of the system, not just small (unit) pieces.
Cucumber is not a unit testing framework, and shouldn't be used in that manner. If your application broke after migrating to 2.3.4 because you didn't have tests I think you should get in there and start writing some unit tests...
Now this is my personal bias, but if you have no unit tests in place I would take a look at RSpec. If you like the english-like syntax of Cucumber, RSpec will definitely feel similar. If you are already somewhat tested in Test::Unit, I would definitely suggest bringing Shoulda to the party or possibly Context/Matchy (all of which are available on github) to get the RSpec feel within the Test::Unit framework.
我终于能够在运行每个 Cucumber 场景之前对 LDAP 服务器进行基本清理。我通过在 cucumber 中添加一个钩子
然后添加我的 LdapConnect 类来完成此操作(因为多个模型可能需要接触 ldap 服务器,所以我可以传递这个对象)。我正在使用 ruby-net-ldap gem 进行 LDAP 交互
所以,我的黄瓜功能看起来像这样:
最后是步骤
I was finally able to get around to basically cleaning the ldap server before each cucumber scenario was run. I did this by adding a hook into cucumber
And then my LdapConnect class (since multiple models might need to touch the ldap server, I can just pass around this object). I am using the ruby-net-ldap gem for LDAP interaction
So, my cucumber feature looks something like:
And finally the steps
我自己刚刚对此进行了研究,并发现了相当不为人所知的 fakeldap 宝石。
http://github.com/aanand/fakeldap
http://rubygems.org/gems/fakeldap
在我使用过它之后,我可能会用一些经验来添加这个答案。
I've just been looking into this myself, and have come across the rather under-the-radar fakeldap gem.
http://github.com/aanand/fakeldap
http://rubygems.org/gems/fakeldap
I may add to this answer with some experience after i've used it.
并不是真正的答案,但是......我正在解决一个非常相似的问题,用 cucumber 测试 LDAP 身份验证和查找代码。您是否考虑过在测试中使用存根?我正在考虑存根我的 LDAP 响应...只是还没有弄清楚如何做到这一点。
马特
Not really an answer but...I'm working on a very similar problem, testing LDAP authentication and lookup code with cucumber. Have you looked into using a stub in your test? I was thinking of stubbing my LDAP responses...just haven't figured out how to do it yet.
Matt