gpt4 book ai didi

ruby-on-rails - 如何在rspec rails请求测试中丢失authenticity_token进行POST?

转载 作者:行者123 更新时间:2023-12-04 00:03:57 27 4
gpt4 key购买 nike

我正在模拟来自外部服务的请求,该服务没有真实性 token 。如果 skip_before_action :verify_authenticity_token,我希望测试失败不见了。

如何从 Rspec 请求规范中执行此操作?

目前我正在使用 post如下,但它被愉快地接受了。

post endpoint, my_json_string, {'CONTENT_TYPE' => "application/json"}

最佳答案

CSRF 保护 disabled in test environment .尝试启用它使用:

before do
ActionController::Base.allow_forgery_protection = true
end

after do
ActionController::Base.allow_forgery_protection = false
end

关于ruby-on-rails - 如何在rspec rails请求测试中丢失authenticity_token进行POST?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28947241/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com