简体   繁体   English

如何使用文字给定的querystring测试请求?

[英]How can I test a request with a literal given querystring?

For testing a given API I have to test a request with an exact querystring, because the whole querystring is hashed together with a shared secret for security, like 为了测试给定的API,我必须使用精确的查询字符串来测试请求,因为整个查询字符串都与用于安全性的共享密钥一起进行了哈希处理,例如

inject?a=1&b[a]=2&b[b]=3&d=4&sign=76c8abec496a5e6c8a51c57e231e3a62612aeff0

I can only see a way to give parameters as a hash, which does not ensure the order (at least not if it's a nested hash): 我只能看到一种以散列方式提供参数的方法,这种方法不能确保顺序(至少如果是嵌套散列,则不能保证顺序):

test "right signature injects" do
  get :inject, a:1 , b: {a:2, b:3}, d: 4, sign: '76c8abec496a5e6c8a51c57e231e3a62612aeff0'
  assert_response :success
end

How can I test a get request with an exact query string? 如何测试具有确切查询字符串的get请求?

Why does the order make a difference? 为什么顺序会有所不同? If you are passing GET variables surely order doesn't matter? 如果您要传递GET变量,那么顺序肯定没关系吗? I can't see any reason why your test shouldn't do what you need unless there is something in the controller that responds to this request. 我看不出任何原因,除非您的控制器中有响应此请求的东西,否则您的测试不应满足您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何测试当前页面是否在给定的路径/控制器中? - How can I test if the current page is in a given path/controller? 如何在Ruby on Rails中的请求之间保留查询字符串值? - How can I preserve querystring values across requests in Ruby on Rails? 如何在Rails测试用例中发送不明确的请求? - How can I send an ambiguous request in Rails Test Case? 如何从 Rspec 中的 model 规范测试 HTTP 请求 - How can I test an HTTP request from a model spec in Rspec 如何直接使用rspec测试POST请求? - How can I test a POST request directly using rspec? 如何使用rspec测试Ajax请求? - how can I use rspec to test an Ajax request? 如何测试(使用RSpec)在Rails中发送HTTP请求(作为单元测试的一部分)? - How can I test (with RSpec) that an HTTP request is send in Rails (as part of an unit test)? 如何在create.js.erb文件中测试哪个页面发送了AJAX请求? - How can I test which page sent an AJAX request in my create.js.erb file? 如何使用xml作为输入来测试Rails RESTful API发布请求? - How can I test a Rails RESTful API post request with xml as input? 如何使用application_helper_spec.rb中的特定URL测试请求对象? - How can I test the request object using a specific URL in application_helper_spec.rb?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM