我正在尝试使用基本身份验证进行测试签名。我尝试了一些方法。请参阅下面的代码以获取失败的尝试和代码列表。有什么明显的我做错了。谢谢集成测试具有基本身份验证的Rails API
class ClientApiTest < ActionController::IntegrationTest
fixtures :all
test "adding an entry" do
# No access to @request
#@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("[email protected]:qwerty123")
# Not sure why this didn't work
#session["warden.user.user.key"] = [User, 1]
# This didn't work either
# url = URI.parse("http://localhost.co.uk/diary/people/1/entries.xml")
# req = Net::HTTP::Post.new(url.path)
# req.basic_auth '[email protected]', 'qwerty123'
post "/diary/people/1/entries.xml", {:diary_entry => {
:drink_product_id => 4,
:drink_amount_id => 1,
:quantity => 3
},
}
puts response.body
assert_response 200
end
end
Je sse的回答是正确的。你应该标记答案是正确的。 – 2011-03-25 19:57:03