【发布时间】:2025-11-26 22:30:02
【问题描述】:
我将如何编写一个用于 rspec 测试的方法来访问需要用户名和密码以进行 HTTP Digest 身份验证的页面。比如这个测试...
it "edit" do
http_login
post :edit, id: @post
assigns[:post].should eq(@post)
end
需要http_login 方法是这样的......
def http_login
user = {"username" =>
Digest::MD5.hexdigest(["username","Application","password"].join(":"))}
request.env['HTTP_AUTHORIZATION'] =
ActionController::HttpAuthentication::Digest.encode_credentials(?,?,?,?)
end
我的问题是我在四个参数中为编码凭据添加了什么。参数将是 http_method, credentials, password, password_is_ha1,但我不确定如何编写 http_method 和 credentials 以在测试中实现。
【问题讨论】:
-
(不,这是基本的)。看起来在这里得到回答*.com/questions/3768718/…
-
那是基本的http认证。我正在做摘要式 http 身份验证。
-
也许是这个? gist.github.com/1282275
-
嗯.. 今晚晚些时候我会测试一下。它看起来很容易使用。如果它有效,我会通知您,如果您将其作为答案发布,我会为您提供答案。
标签: ruby-on-rails ruby-on-rails-3 rspec digest-authentication